-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (48 loc) · 1.52 KB
/
Copy pathmain.py
File metadata and controls
68 lines (48 loc) · 1.52 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
import time
from states import *
class Vending:
lcd = None
reader = None
keypad = None
timeout = 0
state = IDLE
selection = None
BANK_MSG_PREFIX = "Vend: "
def __init__(self, test=False):
logging.getLogger().setLevel(logging.INFO)
logging.info("Starting")
if not test:
from LCD import LCD
from Reader import Reader
from Keypad import Keypad
self.lcd = LCD()
self.reader = Reader()
self.keypad = Keypad()
else:
from testLCD import TestLCD
from testReader import TestReader
from testKeypad import TestKeypad
self.lcd = TestLCD()
self.reader = TestReader()
self.keypad = TestKeypad()
def main(self):
# Initialize state
goto_idle(self)
logging.info("Initialized")
while True:
btn = self.keypad.read()
packet = self.reader.get_packet()
if self.state == IDLE:
state_idle(self, btn, packet)
if self.state == PRODUCT_CHOSEN:
state_product_chosen(self, btn, packet)
if self.state == DISPLAY_TRANS:
state_display_trans(self, btn, packet)
if self.state == DISPLAY_ACC:
state_display_acc(self, btn, packet)
time.sleep(0.01)
if self.timeout > 0:
self.timeout -= 1
if __name__ == '__main__':
app = Vending()
app.main()