integrate keypad with locked states

This commit is contained in:
petrucci4prez 2017-06-17 01:43:14 -04:00
parent db9238f1df
commit 1ea3761089
2 changed files with 23 additions and 17 deletions

View File

@ -23,17 +23,17 @@ class KeypadListener:
- input listener that accepts events and reacts in fun ways - input listener that accepts events and reacts in fun ways
- countdown timer to reset the input buffer after 30 seconds of inactivity - countdown timer to reset the input buffer after 30 seconds of inactivity
''' '''
def __init__(self, stateMachine, callbackDisarm, callbackArm, passwd): def __init__(self, stateMachine, passwd):
ctrlKeys = { 69: 'NUML', 98: '/', 14: 'BS', 96: 'ENTER'} ctrlKeys = { 69: 'NUML', 98: '/', 55: '*', 14: 'BS', 96: 'ENTER'}
volKeys = { 55: '*', 74: '-', 78: '+'} volKeys = { 74: '-', 78: '+', 83: '.'}
numKeys = { numKeys = {
71: '7', 72: '8', 73: '9', 71: '7', 72: '8', 73: '9',
75: '4', 76: '5', 77: '6', 75: '4', 76: '5', 77: '6',
79: '1', 80: '2', 81: '3', 79: '1', 80: '2', 81: '3',
82: '0', 83: '.' 82: '0'
} }
soundLib = stateMachine.soundLib soundLib = stateMachine.soundLib
@ -69,15 +69,27 @@ class KeypadListener:
ctrlKeySound.play() ctrlKeySound.play()
elif self._buf == passwd: elif self._buf == passwd:
self.resetBuffer() self.resetBuffer()
callbackDisarm() stateMachine.DISARM
else: else:
self.resetBuffer() self.resetBuffer()
wrongPassSound.play() wrongPassSound.play()
# arm # lock
elif val == 'NUML': elif val == 'NUML':
self.resetBuffer() self.resetBuffer()
callbackArm() stateMachine.LOCK
ctrlKeySound.play()
# instant lock
elif val == '/':
self.resetBuffer()
stateMachine.INSTANT_LOCK
ctrlKeySound.play()
# arm
elif val == '*':
self.resetBuffer()
stateMachine.ARM
ctrlKeySound.play() ctrlKeySound.play()
# delete last char in buffer # delete last char in buffer
@ -89,11 +101,6 @@ class KeypadListener:
self._startResetTimer() self._startResetTimer()
backspaceSound.play() backspaceSound.play()
# reset buffer
elif val == '/':
self.resetBuffer()
backspaceSound.play()
# volume input # volume input
elif event.code in volKeys: elif event.code in volKeys:
val = volKeys[event.code] val = volKeys[event.code]
@ -104,7 +111,7 @@ class KeypadListener:
elif val == '-': elif val == '-':
soundLib.changeVolume(-10) soundLib.changeVolume(-10)
elif val == '*': elif val == '.':
soundLib.mute() soundLib.mute()
ctrlKeySound.play() ctrlKeySound.play()

View File

@ -183,10 +183,9 @@ class StateMachine:
elif logger: elif logger:
logger.debug('Secret pipe listener received invalid secret') logger.debug('Secret pipe listener received invalid secret')
self._addManaged(PipeListener(callback=secretCallback, name= 'secret')) self._addManaged(PipeListener(callback=secretCallback, name='secret'))
self._addManaged(KeypadListener(stateMachine=self, callbackDisarm=self.DISARM, self._addManaged(KeypadListener(stateMachine=self, passwd='5918462'))
callbackArm=self.ARM, passwd='5918462'))
def startTimer(t, sound): def startTimer(t, sound):
self._timer = _CountdownTimer(t, self.TIMOUT, sound) self._timer = _CountdownTimer(t, self.TIMOUT, sound)