-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputter.py
More file actions
101 lines (79 loc) · 2.81 KB
/
inputter.py
File metadata and controls
101 lines (79 loc) · 2.81 KB
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
import pifacecad
from time import sleep
import threading
class Barrier():
def __init__(self, n):
self.count = 0
self.n = n
def wait(self):
self.count +=1
while self.count < self.n:
sleep(0.0001)
threading.Barrier = Barrier
class importReader():
def __init__(self, cad=None):
self.multiplier = 1
self.value = 0
self.questionmsg = None
if cad is None:
self.cad = pifacecad.PiFaceCAD()
self.cad.lcd.backlight_on()
self.cad.lcd.clear()
self.cad = cad
self.submitwait = None
def setmultiplier(self, multiplier):
self.multiplier = multiplier
def increaseby10(self, event=None):
print("Increasing by 10")
self.value += (self.multiplier * 10)
self.refreshdisplay()
def decreaseby10(self, event=None):
print("Decreasing by 10")
self.value -= (self.multiplier * 10)
if self.value < 0:
self.value = 0
self.refreshdisplay()
def increaseby1(self, event=None):
print("Increasing by 1")
self.value += self.multiplier
self.refreshdisplay()
def decreaseby1(self, event=None):
print("Decreasing by 1")
self.value -=(self.multiplier)
if self.value < 0:
self.value = 0
self.refreshdisplay()
def increasemultiplier(self, event=None):
self.multiplier *= 10
def decreasemultiplier(self, event=None):
if (self.multiplier / 10) <= 1:
self.multiplier = 1
else:
self.multiplier = int(self.multiplier / 10)
def submitbutton(self, event=None):
self.submitwait.wait()
def refreshdisplay(self):
self.cad.lcd.set_cursor(0,1)
self.cad.lcd.write(repr(self.value).rjust(10))
def getInput(self, questionmsg):
self.questionmsg = questionmsg
self.value = 0
self.cad.lcd.clear()
self.cad.lcd.backlight_on()
self.cad.lcd.set_cursor(0,0)
self.cad.lcd.write(questionmsg)
self.refreshdisplay()
listener = pifacecad.SwitchEventListener(self.cad)
listener.register(3, pifacecad.IODIR_ON, self.increaseby10)
listener.register(2, pifacecad.IODIR_ON, self.increaseby1)
listener.register(1, pifacecad.IODIR_ON, self.decreaseby1)
listener.register(0, pifacecad.IODIR_ON, self.decreaseby10)
listener.register(4, pifacecad.IODIR_ON, self.submitbutton)
listener.register(7, pifacecad.IODIR_ON, self.increasemultiplier)
listener.register(6, pifacecad.IODIR_ON, self.decreasemultiplier)
print("Buttons were registered")
self.submitwait = threading.Barrier(2);
listener.activate()
self.submitwait.wait()
listener.deactivate()
return self.value