-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatusTracker.py
165 lines (142 loc) · 5.09 KB
/
statusTracker.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
import csv
import RPi.GPIO as GPIO
from barGraphStack import BarGraph
from csvTool import csvColorTool
from userIO import rpiIO, uIO
class Driver():
def __init__(self, io, ct):
self.io = io
self.ct = ct
def runRed(self):
# Inititalize buttonPressed to false
buttonPressed = 0
# While another button is not pressed
while buttonPressed == 0:
# Print for debugging purposes
print('red', self.ct.red.time)
# Make LED blink
self.io.ledBlink(self.io.buttonPin1)
# Increment color's time (time that it is on)
self.ct.red.time += self.io.sleepTime
# Check if a different button is pressed
buttonPressed = self.io.otherPinPressed(io.buttonPin1)
# if a button is pressed and it is a color, return 0
# or if a button is pressed and it is a STOP, then return -1
# otherwise, continue to loop
if buttonPressed == 1:
return 0
elif buttonPressed == -1:
return -1
def runBlue(self):
buttonPressed = 0
while buttonPressed == 0:
print('blue', self.ct.blue.time)
self.io.ledBlink(self.io.buttonPin2)
self.ct.blue.time += self.io.sleepTime
buttonPressed = self.io.otherPinPressed(io.buttonPin2)
if buttonPressed == 1:
return 0
elif buttonPressed == -1:
return -1
def runWhite(self):
buttonPressed = 0
while buttonPressed == 0:
print('white', self.ct.white.time)
self.io.ledBlink(self.io.buttonPin3)
self.ct.white.time += self.io.sleepTime
buttonPressed = self.io.otherPinPressed(io.buttonPin3)
if buttonPressed == 1:
return 0
elif buttonPressed == -1:
return -1
def runGreen(self):
buttonPressed = 0
while buttonPressed == 0:
print('green', self.ct.green.time)
self.io.ledBlink(self.io.buttonPin4)
self.ct.green.time += self.io.sleepTime
buttonPressed = self.io.otherPinPressed(io.buttonPin4)
if buttonPressed == 1:
return 0
elif buttonPressed == -1:
return -1
def runYellow(self):
buttonPressed = 0
while buttonPressed == 0:
print('yellow', self.ct.yellow.time)
self.io.ledBlink(io.buttonPin5)
self.ct.yellow.time += self.io.sleepTime
buttonPressed = self.io.otherPinPressed(io.buttonPin5)
if buttonPressed == 1:
return 0
elif buttonPressed == -1:
return -1
# Drives all color collection and button pressing
def checkInput(self, csvwriter):
# While pin of button is still active
while not GPIO.input(io.buttonPin1):
status = self.runRed()
# If red's button is 0 (different color pressed), break to different color
if status == 0:
break
# or if red's button is -1 (STOP is pressed), end program with -1
elif status == -1:
return -1
while not GPIO.input(io.buttonPin2):
status = self.runBlue()
if status == 0:
break
elif status == -1:
return -1
while not GPIO.input(io.buttonPin3):
status = self.runWhite()
if status == 0:
break
elif status == -1:
return -1
while not GPIO.input(io.buttonPin4):
status = self.runGreen()
if status == 0:
break
elif status == -1:
return -1
while not GPIO.input(io.buttonPin5):
status = self.runYellow()
if status == 0:
break
elif status == -1:
return -1
return 1
#Heart beat of program
def beginCollection(self, csvwriter):
drive = 1
# While drive, read if checkInput gets STOP signal
# If drive is -1 (STOP), then break out program
# Otherwise keep checking for user input
print("Ready for collection")
while(drive == 1):
drive = self.checkInput(csvwriter)
#if drive == -1:
# return
# Function to start the program
ct = csvColorTool()
uio = uIO(ct)
io = rpiIO()
bg = BarGraph()
d = Driver(io, ct)
def run():
uio.updateCategory()
with open(ct.filename, 'w') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(ct.fields)
try:
io.setupPins()
GPIO.input(io.buttonPin6)
d.beginCollection(csvwriter)
finally:
ct.updateRows()
csvwriter.writerows(ct.rows)
io.cleanUp()
run()
bg.drawPlot()
#end statusTracker