-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHS.py
executable file
·201 lines (169 loc) · 8.7 KB
/
HS.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
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python3
import tkinter as tk
import tkinter.font
import sensors as sns
import finger as fng
import voltmeter
import logger
import pygame
from PIL import Image, ImageTk
import os
import webbrowser
import pigpio
class MainClass(object):
def __init__(self):
self.root = tk.Tk()
self.started = tk.BooleanVar()
self.started.set(False)
myFont=tkinter.font.Font(family='Helvetica', size = 12, weight = "bold")
textFont=tkinter.font.Font(family='Helvetica', size = 6, weight = "normal")
self.var = tk.StringVar()
value = tk.Label(self.root, textvariable=self.var, width=30, font=textFont)
value.grid(row=0, column=1)
self.pressureVar = tk.StringVar()
pressureLabel = tk.Label(self.root, textvariable=self.pressureVar, font=textFont)
pressureLabel.grid(row=1, column=1)
#battery info:
self.batteryFrame = tk.Frame(self.root, highlightbackground="yellow", highlightcolor="yellow", highlightthickness=2, width=100, height=100, bd=0)
self.batteryFrame.grid(row=0, column=2, sticky=tk.NSEW)
self.voltageInputVar = tk.StringVar()
voltageInputLabel = tk.Label(self.batteryFrame, textvariable=self.voltageInputVar, font=textFont)
voltageInputLabel.grid(row=0, column=0, sticky=tk.NSEW)
self.voltageOutputVar = tk.StringVar()
voltageOutputLabel = tk.Label(self.batteryFrame, textvariable=self.voltageOutputVar, font=textFont)
voltageOutputLabel.grid(row=1, column=0, sticky=tk.NSEW)
#altitude, sea level:
self.extraDataVar = tk.StringVar()
extraLabel = tk.Label(self.root, textvariable=self.extraDataVar, font=textFont)
extraLabel.grid(row=5, column=1,sticky=tk.NSEW)
self.fingerExtended = tk.BooleanVar()
#self.frame1.pack_propagate(False)
#Sensor button
readSensorButton=tk.Button(self.root, text = 'Read Sensors', font=myFont, command=lambda:self.sensor.updateData(self), bg='DarkSeaGreen1', height=1, width=15)
readSensorButton.grid(row=0, column=0, rowspan=2, sticky=tk.NSEW)
#Valve Manual Manipulation Buttons:
ledButton=tk.Button(self.root, text = 'Pull', font=myFont, command=lambda:self.finger.setState(self, False), bg='DarkSeaGreen1', height=1, width=8)
ledButton.grid(row=2, column=2, sticky=tk.NSEW)
ledButton=tk.Button(self.root, text = 'Push', font=myFont, command=lambda:self.finger.setState(self, True), bg='DarkSeaGreen1', height=1, width=8)
ledButton.grid(row=3, column=2, sticky=tk.NSEW)
singleCycle=tk.Button(self.root, text = 'Single Hit', font=myFont, command=lambda:self.finger.cycle(self), bg='DarkSeaGreen1', height=2, width=15)
singleCycle.grid(row=2, column=1, rowspan=2, sticky=tk.NSEW)
#Valve Auto
#autoAreaLabel = tk.Label(self.root, text = 'Set Automatic Hit Cycle:')
#autoAreaLabel.grid(row=1, column=0)
self.bpm = tk.DoubleVar()
self.bpm.set(120)
self.delayPortion = tk.DoubleVar()
self.delayPortion.set(0.5)
#Valve Auto Input
self.inputFrame = tk.Frame(self.root, highlightbackground="green", highlightcolor="green", highlightthickness=2, width=100, height=100, bd=0)
self.inputFrame.grid(row=2, column=0, rowspan=2, sticky=tk.NSEW)
self.startButton=tk.Button(self.inputFrame, text = 'Start Hitting', font=myFont, command=self.startButton, bg='OliveDrab1', height=1, width=8)
self.startButton.grid(row=0, columnspan=2, sticky=tk.NSEW)
vcmd = (self.root.register(self.validate),'%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')
autoAreaLabel = tk.Label(self.inputFrame, text = 'BPM:', width=5)
autoAreaLabel.grid(row=1, column=0)
#autoAreaLabel.place(relx=.0, rely=.5, anchor="w")
self.bpmInput = tk.Entry(self.inputFrame, textvariable=self.bpm, validate = 'key', validatecommand = vcmd, width=9)
self.bpmInput.grid(row=1, column=1, sticky=tk.NSEW)
autoAreaLabel = tk.Label(self.inputFrame, text = 'U/D:', width=5)
autoAreaLabel.grid(row=1, column=2)
self.speedInput = tk.Entry(self.inputFrame, textvariable=self.delayPortion, validate = 'key', validatecommand = vcmd, width=9)
self.speedInput.grid(row=1, column=3, sticky=tk.NSEW)
#extras - audio, video, etc:
pygame.mixer.init()
#os.system("sudo killall pigpiod")
#os.system("sudo pigpiod")
self.pi = pigpio.pi() # Connect to local Pi.
self.pi.write(23, 1)
#print(pi.get_mode(18))
self.pi.set_mode(18, pigpio.ALT5)
self.extrasFrame = tk.Frame(self.root, highlightbackground="RoyalBlue1", highlightcolor="RoyalBlue1", highlightthickness=2, width=100, height=100, bd=0)
self.extrasFrame.grid(row=4, column=0, rowspan=2, sticky=tk.NSEW)
image = Image.open("/home/pi/Documents/HitScan/Resources/playstop.ico")
image = image.resize((64, 64), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(image)
audioPath = "/home/pi/Documents/HitScan/Audio"
#get audio file list, take first, return path as string:
audioFiles = self.getFiles(audioPath)
#play button:
playStopButton= tk.Button(self.extrasFrame, image=photo, font=myFont, command=lambda:self.playAudio(audioFiles[0]), bg='RoyalBlue1', height=64, width=64)
playStopButton.grid(row=0, column=0)
playStopButton.image = photo # keep a reference!
#playStopButton.pack()
#video shortcut btn:
imageVideo = Image.open("/home/pi/Documents/HitScan/Resources/camera.png")
imageVideo = imageVideo.resize((64, 64), Image.ANTIALIAS)
photoVideo = ImageTk.PhotoImage(imageVideo)
url = 'http://docs.python.org/'
chrome_path = '/usr/bin/google-chrome %s'
videoButton = tk.Button(self.extrasFrame, image=photoVideo, font=myFont, command=lambda:self.openBrowserForVideo(), bg='RoyalBlue1', height=64, width=64)
videoButton.grid(row=0, column=1)
videoButton.image = photoVideo # keep a reference!
#App specific:
exitButton=tk.Button(self.root, text='Exit', font=myFont, command=self.exitProgram, bg='CadetBlue4', height=1, width=3)
exitButton.grid(row=5, column=2, sticky=tk.E)
self.logger = logger.SensorLogger(self)
self.sensor = sns.THSensor(self)
self.finger = fng.Control(self)
def openBrowserForVideo(self):
url = "http://127.0.0.1/html/"
chrome_path = "/usr/bin/chromium-browser %s"
webbrowser.get(chrome_path).open(url)
#os.system("sh /home/pi/RPi_Cam_Web_Interface/RPi_Cam_Web_Interface_Installer.sh")
def playAudio(self, fullpath):
print (pygame.mixer.music.get_volume())
if not pygame.mixer.music.get_busy():
self.pi.write(23, 0)
print('playing: ',fullpath)
pygame.mixer.music.load(fullpath)
pygame.mixer.music.play() #loops=-1
else:
pygame.mixer.music.stop()
self.pi.write(23, 1)
def getFiles(self, path):
files = None
for path, dirs, files in os.walk(path):
dirs = sorted(dirs)
break
#print (len(files))
files = [os.path.join(path, f) for f in files] # add path to each file
return files
def validate(self, action, index, value_if_allowed,
prior_value, text, validation_type, trigger_type, widget_name):
if text in '0123456789.-+':
try:
float(value_if_allowed)
return True
except:
return False
else:
return False
#this loops the GUI
def refresh(self):
self.root.update()
self.root.after(100,self.refresh)
def startButton(self):
self.started.set (not self.started.get())
#print(self.started.get())
if self.started.get():
self.startButton.grid(column=2)
self.startButton["text"] = 'Stop Hitting'
self.startButton["bg"] = 'tomato'
if not self.bpm.get():
self.bpm.set(120)
if not self.delayPortion.get():
self.delayPortion.set(0.5)
else:
self.startButton.grid(column=0)
self.startButton["text"] = 'Start Hitting'
self.startButton["bg"] = 'OliveDrab1'
def start(self):
self.refresh()
# start the GUI loop
self.root.mainloop()
def exitProgram(self):
self.root.quit()
if __name__ == "__main__":
app = MainClass()
app.start()