-
Notifications
You must be signed in to change notification settings - Fork 0
/
BIUgui.py
executable file
·189 lines (158 loc) · 8.24 KB
/
BIUgui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python3
from guizero import App, TextBox, Text, PushButton, CheckBox
try:
import RPi.GPIO as GPIO
except:
import gpio as GPIO
import BIUpinlist as pin
from BIU_gui_helper_functions import *
# OPTIONS
try:
from board import SCL, SDA
import busio
from adafruit_neotrellis.neotrellis import NeoTrellis
# create the i2c object for the trellis
i2c_bus = busio.I2C(SCL, SDA)
# create the trellis object and associate it to the the i2c object that was created
trellis = NeoTrellis(i2c_bus)
use_neotrellis = 1
except:
use_neotrellis = 0
if __name__=='__main__':
app = App(title="Back-it-up", layout="grid", width = 600, height = 380)
# GUI for Standard Spray parameters entries
stdlabel = Text(app, text="Standard Spray", color='white', grid=[0,0,2,1], bg = 'dim gray')
stimelabel, stime = text_box(app, 'Spray time (ms):', position = [0,1], default = 30)
rdelaylabel, rdelay = text_box(app, 'Retraction delay (ms):', position = [0,2], default = 50)
pdelaylabel, pdelay = text_box(app, 'Plunge delay (ms):', position = [0,3], default = 50)
# GUI for Pulse Spray parameters entries
pulselabel = Text(app, text="(Anti) Pulse Spray", grid=[0,4,2,1], color='white', bg='dim gray')
plen_label, plen = text_box(app, 'Pulse length (ms):', position = [0,5], default = 16)
pnum_label, pnum = text_box(app, 'Pulse count:', position = [0,6], default = 5)
pint_label, pint = text_box(app, 'Pulse interval (ms):', position = [0,7], default = 20)
pulsenote = Text(app, text="(Uses retraction & plunge settings from std.)", grid=[0,8,2,1])
# Text entry for record keeping
stdlabel = Text(app, text="Spray Record Info:", color='white', grid=[2,4,2,1], bg = 'dim gray')
spraynamelabel, sprayname = text_box(app, 'Spray Experiment Name', position = [2,5], default = 'New Experiment')
recfilelabel, recfile = text_box(app, 'Record-keeping file:', position = [2,6], default = './spray-records/spray-record-{0}.txt'.format(dt.today()))
## Buttons, commands are defined in BIU_gui_helper_functions.py
button_title = Text(master=app, text="Triggers", grid=[0,10,4,1], color='white', bg='dim grey')
donotplunge = CheckBox(master=app, text="Dry fire (do not plunge)?", grid=[0,11,2,1], align='left')
button_pulse= PushButton(master=app, text="Pulse & Plunge", grid=[2,12], align='left', command=pulsestartprocess, args = [rdelay, pdelay, pnum, plen, pint, donotplunge.value==1, sprayname, recfile])
button_pulse.disable()
button_pulse.bg = 'violet'
button_start= PushButton(master=app, text="Spray & Plunge", grid=[1,12], align='left', command=startprocess, args=[stime, rdelay, pdelay, donotplunge.value==1, sprayname, recfile])
button_start.bg = (255, 50, 50)
button_start.disable()
button_up = PushButton(master=app, text=" Ready ", grid=[0,12], align='left', command=powerup, args = [[button_start, button_pulse]])
button_up.bg="lime green"
button_down = PushButton(master=app, text=" Abort ", grid=[3,12], align='left', command=powerdown, args = [[button_start, button_pulse]])
button_down.bg = "orange"
# GUI for Cleaning operation
cleanlabel = Text(app, text="Cleaning settings:", grid=[2,0,2,1], color='white', bg='dim gray')
cleancycleslabel, cleancycles = text_box(app, 'Cleaning cycles:', position = [2,1], default = 5)
cleantimelabel, cleantime = text_box(app, 'Clean pulse length (ms):', position = [2,2], default = 200)
## Buttons
button_clean = PushButton(master = app, text=" Clean ", grid=[2,3,2,1], command=cleanprocess, args = [cleantime, cleancycles])
button_clean.bg = "lightblue"
# Button text adjust
for element in [button_up, button_start, donotplunge, button_down, button_clean, button_pulse]:
element.text_size = 12
# GPIO.setwarnings(False)
# GPIO.setmode(GPIO.BCM)
# app.repeat(100,pedal)
if use_neotrellis:
# some color definitions
OFF = (0, 0, 0)
RED = (255, 0, 0)
ORANGE = (255, 78, 0)
GREEN = (0, 255, 0)
BLUE = (10, 10, 255)
PURPLE = (90, 0, 255)
WHITE = (200, 200, 200)
YELLOW = (200, 200, 0)
# set brightness of the trellis
trellis.brightness = 0.5
# set colors for each pixel button
trellis.pixels[0] = GREEN
trellis.pixels[3] = ORANGE
trellis.pixels[4] = BLUE
trellis.pixels[7] = WHITE
ok2plunge = False
# this will be called when button events are received
def pixel_button_action(event):
global ok2plunge, button_start, button_pulse, stime, rdelay, pdelay, donotplunge, plen, cleantime, cleancycles, pint, pnum
# turn the LED off when a rising edge is detected
if event.edge == NeoTrellis.EDGE_RISING:
trellis.pixels[event.number] = OFF
# turn the LED off when a rising edge is detected
elif event.edge == NeoTrellis.EDGE_FALLING:
if event.number == 0:
print("Trellis: Executing #0 power up")
powerup([button_start, button_pulse])
trellis.pixels[0] = GREEN
ok2plunge = True
trellis.pixels[1] = RED
trellis.pixels[2] = PURPLE
elif event.number == 1:
if ok2plunge:
print("Trellis: Executing #1 spray and plunge")
startprocess(stime, rdelay, pdelay, donotplunge.value==1)
trellis.pixels[1] = RED
elif event.number == 2:
if ok2plunge:
print("Trellis: Executing #2 pulse and plunge")
pulsestartprocess(rdelay, pdelay, pnum, plen, pint, donotplunge.value==1)
trellis.pixels[2] = PURPLE
elif event.number == 3:
print("Trellis: Executing #3 power down")
powerdown([button_start, button_pulse])
trellis.pixels[3] = ORANGE
ok2plunge = False
trellis.pixels[1] = OFF
trellis.pixels[2] = OFF
elif event.number == 4:
print("Trellis: Executing #4 cleaning")
cleanprocess(cleantime, cleancycles)
trellis.pixels[4] = BLUE
elif event.number == 7:
if donotplunge.value == 0:
print("Trellis: Executing #7 dry fire")
donotplunge.value = 1
trellis.pixels[7] = YELLOW
else:
print("Trellis: Toggle off #7 dry fire")
donotplunge.value = 0
trellis.pixels[7] = WHITE
else:
print("Trellis: Wrong button pressed")
for i in [0, 1, 2, 3, 4, 7]:
# activate rising edge events on all keys
trellis.activate_key(i, NeoTrellis.EDGE_RISING)
# activate falling edge events on all keys
trellis.activate_key(i, NeoTrellis.EDGE_FALLING)
# set all keys to trigger the blink callback
trellis.callbacks[i] = pixel_button_action
def gui_repeating_tasks():
global trellis, button_start
trellis.sync()
if donotplunge.value==1:
trellis.pixels[7] = YELLOW
else:
trellis.pixels[7] = WHITE
if button_start.enabled:
ok2plunge = True
trellis.pixels[1] = RED
trellis.pixels[2] = PURPLE
else:
ok2plunge = False
trellis.pixels[1] = OFF
trellis.pixels[2] = OFF
app.repeat(90, gui_repeating_tasks)
app.display()
#shutdown
print('BIU program shutting down...')
for i in [0, 1, 2, 3, 4, 7]:
trellis.pixels[i] = OFF
powerdown([button_start, button_pulse])
# GPIO.cleanup()