-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (52 loc) · 1.22 KB
/
main.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
"""
1. Configuration
- Get data from Firebase
- Server, course code
- Access token
- Encrypted?
2. Scanning
- Feedback
3. Sending
- Asynchronous
Error Codes
- Setup
- No internet
- Can't authenticate
- No assignment found
"""
from time import sleep
from scanner import Scanner
from handler import Handler
from config import Config
from logger import Logger
from buzzer import Buzzer
def main():
"""Main setup and loop"""
buzzer = Buzzer()
logger = Logger(buzzer, 1)
logger.info("Initialising reader")
config = Config(logger)
scanner = Scanner(config, logger)
buzzer.ready()
# Loop until either config is successfully downloaded, or a config card is
# scanned
err = True
while err and not config.ready:
buzzer.ready()
err, _ = scanner.scan()
if err:
err = config.update_config()
handler = Handler(logger, config)
handler.get_assignments()
logger.info("Ready")
while True:
scanner.wait()
err, data = scanner.scan()
if err:
continue
if data is True:
handler.get_assignments()
else:
handler.send(data)
if __name__ == '__main__':
main()