-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypadHandler.py
executable file
·62 lines (47 loc) · 1.31 KB
/
keypadHandler.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
#!/bin/python3
import zerorpc, inc.configParse as parse
## INITIALIZE ##
ports = parse.ports()
settings = parse.settings()
master = zerorpc.Client()
master.connect("tcp://127.0.0.1:" + ports['master'])
keyBuffer = ""
def clearBuffer():
'''Clears the code buffer'''
print("KEYPAD: Clearing Key Buffer")
global keyBuffer
keyBuffer = ""
# play clearing sound
def verifyBuffer():
'''Checks the buffer against expected codes and sends results to controller'''
if keyBuffer == disarmCode:
print("KEYPAD: Unlock Code Accepted")
master.codeCorrect()
elif keyBuffer == resetCode:
print("KEYPAD: Reset Code Accepted")
master.reset()
else:
print("KEYPAD: Code Not Accepted")
# Send state change to superserver
clearBuffer()
class KeypadRPC(object):
def keys(self, keys):
'''Handles key inputs from keypadListener'''
for key in keys:
if key is '*':
clearBuffer()
elif key is '#':
verifyBuffer()
else:
global keyBuffer
keyBuffer += str(key)
print("KEYPAD: Buffer = " + keyBuffer)
return
s = zerorpc.Server(KeypadRPC())
print('KEYPAD: Binding Keypad on port ' + ports['keypad'])
s.bind("tcp://0.0.0.0:" + ports['keypad'])
## SETUP ##
disarmCode = settings['disarmCode']
resetCode = settings['resetCode']
## RUN ##
s.run()