hello git
parent
813bec7408
commit
ace762a611
@ -0,0 +1,89 @@
|
|||||||
|
import re # libary to search and replace strings in the postscript file
|
||||||
|
from dictionary import font_index
|
||||||
|
|
||||||
|
# function with two arguments
|
||||||
|
def friction_label(previous_module, module):
|
||||||
|
#text = input("Enter text:") # create input field for text input
|
||||||
|
text = "enter text here"
|
||||||
|
submit="0"
|
||||||
|
|
||||||
|
font = font_index[module[1]] # use font_index from dictionary to translate the fontname
|
||||||
|
|
||||||
|
fontsize = module[2] # sensor3
|
||||||
|
rotation = module[3] # sensor2
|
||||||
|
linewidth = module[4]
|
||||||
|
x = module[5] # sensor4
|
||||||
|
y = module[6] # sensor 4, same the exact same value
|
||||||
|
graytone1 = module[7] # sensor5
|
||||||
|
graytone2 = module[8] # sensor5, opposite range
|
||||||
|
submit = module[9] # sensor6 # in this case it opens one ps, replaces some lines and writes to a new ps
|
||||||
|
|
||||||
|
|
||||||
|
script = """
|
||||||
|
|
||||||
|
newpath
|
||||||
|
|
||||||
|
/"""+font+"""
|
||||||
|
% fontname
|
||||||
|
|
||||||
|
"""+fontsize+""" selectfont
|
||||||
|
% fontsize in points, establishes the font as the current one
|
||||||
|
|
||||||
|
"""+x+""" """+y+""" moveto
|
||||||
|
% x and y coordinates in px (origin is the lower-left corner of the page)
|
||||||
|
|
||||||
|
"""+rotation+""" rotate
|
||||||
|
% degree of rotation, counter clockwise around the given position
|
||||||
|
|
||||||
|
("""+text+""") true charpath
|
||||||
|
% normally text works with "show", but to use the characters in the string as a path that can be stroked and filled use "true charpath"
|
||||||
|
|
||||||
|
gsave
|
||||||
|
% save the current path to apply stroke first and then go back to the saved path to apply fill (Both drawing commands destroy the current path)
|
||||||
|
|
||||||
|
"""+linewidth+""" setlinewidth
|
||||||
|
% linewidth for the outline of the text
|
||||||
|
|
||||||
|
"""+graytone2+""" setgray
|
||||||
|
% graytone for the outline (0 = black, 1 = white)
|
||||||
|
|
||||||
|
stroke
|
||||||
|
% stroke (outline) the text in parentheses
|
||||||
|
|
||||||
|
grestore
|
||||||
|
% restore the original path to apply fill
|
||||||
|
|
||||||
|
"""+graytone1+""" setgray
|
||||||
|
% graytone for the filling (0 = black, 1 = white)
|
||||||
|
|
||||||
|
fill
|
||||||
|
% fill the text in parentheses
|
||||||
|
|
||||||
|
showpage
|
||||||
|
% print all on a page
|
||||||
|
"""
|
||||||
|
|
||||||
|
if submit == "1": # sensor6
|
||||||
|
print("starting to write the ps-file")
|
||||||
|
if previous_module == "":
|
||||||
|
#input file
|
||||||
|
fileInput = open("empty.ps", "rt") # rt = read text mode
|
||||||
|
#output file to write the result to
|
||||||
|
fileOutput = open("friction_label.ps", "wt") # wt = write text mode
|
||||||
|
|
||||||
|
else:
|
||||||
|
#input file
|
||||||
|
fileInput = open(previous_module + ".ps", "rt") # rt = read text mode
|
||||||
|
#output file to write the result to
|
||||||
|
fileOutput = open("friction_label.ps", "wt") # wt = write text mode
|
||||||
|
|
||||||
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
||||||
|
# uses regular expressions library (re)
|
||||||
|
content = fileInput.read()
|
||||||
|
content = re.sub(r"showpage\n% print all on a page", (script), content)
|
||||||
|
|
||||||
|
# write the new text to the output file
|
||||||
|
fileOutput.write(content)
|
||||||
|
#close input and output files
|
||||||
|
fileInput.close()
|
||||||
|
fileOutput.close()
|
@ -0,0 +1,71 @@
|
|||||||
|
import re # libary to search and replace strings in the postscript file
|
||||||
|
from dictionary import font_index
|
||||||
|
|
||||||
|
# function with two arguments
|
||||||
|
def future_relics(previous_module, module):
|
||||||
|
#text = input("Enter text:") # create input field for text input
|
||||||
|
text = "enter text here"
|
||||||
|
submit="0"
|
||||||
|
|
||||||
|
font = font_index[module[1]] # use font_index from dictionary to translate the fontname
|
||||||
|
|
||||||
|
fontsize = module[2] # sensor3
|
||||||
|
linewidth = module[3] # sensor2
|
||||||
|
x = module[4]
|
||||||
|
y = module[5] # sensor4
|
||||||
|
submit = module[6] # sensor 4, same the exact same value
|
||||||
|
|
||||||
|
|
||||||
|
script = """
|
||||||
|
|
||||||
|
newpath
|
||||||
|
|
||||||
|
/"""+font+"""
|
||||||
|
% fontname
|
||||||
|
|
||||||
|
"""+fontsize+""" selectfont
|
||||||
|
% fontsize in points, establishes the font as the current one
|
||||||
|
|
||||||
|
"""+x+""" """+y+""" moveto
|
||||||
|
% x and y coordinates in px (origin is the lower-left corner of the page)
|
||||||
|
|
||||||
|
("""+text+""") true charpath
|
||||||
|
% normally text works with "show", but to use the characters in the string as a path that can be stroked and filled use "true charpath"
|
||||||
|
|
||||||
|
gsave
|
||||||
|
% save the current path to apply stroke first and then go back to the saved path to apply fill (Both drawing commands destroy the current path)
|
||||||
|
|
||||||
|
"""+linewidth+""" setlinewidth
|
||||||
|
% linewidth for the outline of the text
|
||||||
|
|
||||||
|
stroke
|
||||||
|
% stroke (outline) the text in parentheses
|
||||||
|
|
||||||
|
showpage
|
||||||
|
% print all on a page
|
||||||
|
"""
|
||||||
|
|
||||||
|
if submit == "1": # sensor6
|
||||||
|
print("starting to write the ps-file")
|
||||||
|
if previous_module == "":
|
||||||
|
#input file
|
||||||
|
fileInput = open("empty.ps", "rt") # rt = read text mode
|
||||||
|
#output file to write the result to
|
||||||
|
fileOutput = open("future_relics.ps", "wt") # wt = write text mode
|
||||||
|
|
||||||
|
else:
|
||||||
|
#input file
|
||||||
|
fileInput = open(previous_module + ".ps", "rt") # rt = read text mode
|
||||||
|
#output file to write the result to
|
||||||
|
fileOutput = open("future_relics.ps", "wt") # wt = write text mode
|
||||||
|
|
||||||
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
||||||
|
# uses regular expressions library (re)
|
||||||
|
content = fileInput.read()
|
||||||
|
content = re.sub(r"showpage\n% print all on a page", (script), content)
|
||||||
|
|
||||||
|
# write the new text to the output file
|
||||||
|
fileOutput.write(content)
|
||||||
|
#close input and output files
|
||||||
|
fileInput.close()
|
||||||
|
fileOutput.close()
|
@ -0,0 +1,40 @@
|
|||||||
|
# button setup (connect to 3.3V and GPIO Pin 16)
|
||||||
|
import RPi.GPIO as GPIO # GPIO pins
|
||||||
|
import time
|
||||||
|
import os # library to use bash commands
|
||||||
|
|
||||||
|
def preview(final_module):
|
||||||
|
|
||||||
|
while True: # Run forever
|
||||||
|
GPIO.setmode(GPIO.BOARD) #Use the physical GPIO number
|
||||||
|
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #Change pin if necessary
|
||||||
|
GPIO.setwarnings(False) #Ignore warnings
|
||||||
|
|
||||||
|
if GPIO.input(16) == GPIO.HIGH:
|
||||||
|
time.sleep(1)
|
||||||
|
# print(final_module)
|
||||||
|
os.system("gv -fullscreen " + final_module + ".ps")
|
||||||
|
GPIO.cleanup() #GPIO clean up
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
# problems:
|
||||||
|
# interrupts read_values.py
|
||||||
|
# does not refresh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#import os # library to use bash commands
|
||||||
|
#import keyboard
|
||||||
|
#import time
|
||||||
|
#import mouse
|
||||||
|
|
||||||
|
#def preview(final_module):
|
||||||
|
# os.system("gv -fullscreen " + final_module + ".ps")
|
||||||
|
# while True:
|
||||||
|
# mouse.move('500', '500')
|
||||||
|
# keyboard.send(".")
|
||||||
|
# sleep(3)
|
||||||
|
|
||||||
|
#preview("test-preview")
|
@ -0,0 +1,19 @@
|
|||||||
|
# button setup (connect to 3.3V and GPIO Pin 16)
|
||||||
|
import RPi.GPIO as GPIO # GPIO pins
|
||||||
|
import time
|
||||||
|
import os # library to use bash commands
|
||||||
|
|
||||||
|
def print_output(final_module):
|
||||||
|
|
||||||
|
while True: # Run forever
|
||||||
|
GPIO.setmode(GPIO.BOARD) #Use the physical GPIO number
|
||||||
|
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #Change pin if necessary
|
||||||
|
GPIO.setwarnings(False) #Ignore warnings
|
||||||
|
|
||||||
|
if GPIO.input(16) == GPIO.HIGH:
|
||||||
|
time.sleep(1)
|
||||||
|
# print(final_module)
|
||||||
|
os.system("lp " + final_module + ".ps") # lp is the bash print command
|
||||||
|
GPIO.cleanup() #GPIO clean up
|
||||||
|
else:
|
||||||
|
break
|
@ -0,0 +1,55 @@
|
|||||||
|
# read the values from Arduino:
|
||||||
|
import serial # import serial library to read the values from Arduino Uno via serial (usb) connection
|
||||||
|
import os # library to use bash commands
|
||||||
|
|
||||||
|
from friction_label import friction_label
|
||||||
|
from future_relics import future_relics
|
||||||
|
from print_output import print_output
|
||||||
|
|
||||||
|
function_index = {
|
||||||
|
"FL": friction_label,
|
||||||
|
"FR": future_relics
|
||||||
|
}
|
||||||
|
|
||||||
|
module_index = {
|
||||||
|
"FL": "friction_label",
|
||||||
|
"FR": "future_relics"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
ser = serial.Serial('/dev/ttyS0', 9600, timeout=1) # establish a serial connection using Serial Pi Zero (S0), using the RX $
|
||||||
|
ser.reset_input_buffer()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if ser.in_waiting > 0:
|
||||||
|
|
||||||
|
line = ser.readline() # reads bytes
|
||||||
|
try:
|
||||||
|
line = line.decode("utf-8", 'ignore').rstrip() # converts bytes to string
|
||||||
|
line = line.replace("\r\n", "") # replaces "\r\n" (end of line) with nothing
|
||||||
|
line = line.replace("\r", "") # replaces "\r" (between two modules) with nothing
|
||||||
|
line = line.split("#") # splits the line into a list of lists
|
||||||
|
# after this split the list begins with an empty list, so delete it:
|
||||||
|
if line[0] == "": #if first list in lists is empty:
|
||||||
|
del line[0] #delete the first element
|
||||||
|
# print(line)
|
||||||
|
modules = []
|
||||||
|
for module in line:
|
||||||
|
values = module.split(",") # splits each module into values
|
||||||
|
modules.append(values)
|
||||||
|
print("These are the values of each module inside a list of modules ")
|
||||||
|
print(modules)
|
||||||
|
|
||||||
|
previous_module = ""
|
||||||
|
for module in modules: #for each module inside the list of modules
|
||||||
|
function_index[module[0]](previous_module, module) #use function_index to run functions for each module
|
||||||
|
previous_module = module_index[module[0]] #use module_index to replace abbr. with full name
|
||||||
|
if module == modules[-1]: #if module is the last module in list of modules
|
||||||
|
final_module = module_index[module[0]] #use name of the last module to define final_module
|
||||||
|
# print(final_module)
|
||||||
|
print_output(final_module) #call print_output function with last_module as variable
|
||||||
|
|
||||||
|
except OSError as e:
|
||||||
|
print("Error: could not decode bytes")
|
||||||
|
print(e)
|
Loading…
Reference in New Issue