forked from hoveeman/music-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.py
executable file
·63 lines (45 loc) · 1.4 KB
/
box.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
"""
BIPBIPZIZIK
main application
"""
# Python import
from time import time, sleep
# Bipbipzizic import
from card_launcher import CardLauncher
from sys import platform
if platform in ("linux", "linux2", "darwin"):
# linux or OS X
from modules.tools import get_linux_serial as get_serial
from modules.rfid_reader.linux_reader import Reader
elif platform == "win32":
# Windows
from modules.tools import get_win_serial as get_serial
from modules.rfid_reader.windows_reader import Reader
# Constants
UPDATE_PERIOD = 60
def main():
"""
Application main function
@return: None
"""
reader = Reader()
launcher = CardLauncher('https://bipbipzizik.firebaseio.com/', 'prod')
launcher.config_update(get_serial())
last_update_time = time()
while True:
print('Ready: place a card on top of the reader')
# Wait for a card to be read
read_id = reader.read_card()
print('Read card: ', read_id)
# Execute the card
launcher.execute_card(read_id)
# Update the database periodically
if (time() - last_update_time) > UPDATE_PERIOD:
print('Update the database')
launcher.database_update()
last_update_time = time()
# TODO Write last update time on config database for usage tracking
# wait before restart
sleep(0.5)
if __name__ == "__main__":
main()