-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.py
More file actions
93 lines (60 loc) · 1.74 KB
/
Main.py
File metadata and controls
93 lines (60 loc) · 1.74 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
import os, sys, serial, time
from pidfile import PidFile
import subprocess
def output(message):
print(message)
sys.stdout.flush()
codes = {}
def play_sound(sound):
subprocess.call(['play', sound])
def scan_code(code):
if code in codes.keys():
codes[code] = not codes[code]
else:
codes[code] = True
if codes[code]:
output('checked in: {}'.format(code))
play_sound('check_in.wav')
else:
output('checked out: {}'.format(code))
play_sound('check_out.wav')
def main_rfid():
output('Started')
ser = serial.Serial("/dev/ttyAMA0")
ser.baudrate = 9600
data_line = ''
prev_line = ''
prev_time = 0
while True:
try:
data = ser.read()
## Begin code
if data == '\x02':
pass
## End code
elif data == '\x03':
if prev_line != data_line or time.time() - prev_time >= 0.1:
prev_line = data_line
scan_code(data_line)
prev_time = time.time()
data_line = ''
## Data
else:
data_line += data
except Exception as e:
output(e)
ser.close()
output('Finished')
def main_nfc():
print("I'm an NFC teapot, short and BEEP")
reader = subprocess.Popen(['./just-use-c/dms-nfc-reader'], stdout=subprocess.PIPE)
output = None
while output != '':
output = reader.stdout.readline()
if 'READ' in output:
scan_code(output[5:-1])
if __name__ == "__main__":
path = os.path.dirname(os.path.realpath(__file__))
os.chdir(path)
with PidFile("/tmp/check-in-system.pid"):
main_nfc()