add countdown timer for buffer reset on keypad

This commit is contained in:
petrucci4prez 2017-06-05 01:57:55 -04:00
parent 5dae7a798d
commit 647be7cd39
1 changed files with 23 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import logging, os, sys, stat
from exceptionThreading import ExceptionThread from exceptionThreading import ExceptionThread
from evdev import InputDevice, ecodes from evdev import InputDevice, ecodes
from select import select from select import select
from auxilary import waitForPath from auxilary import CountdownTimer, waitForPath
import stateMachine import stateMachine
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -33,7 +33,7 @@ class KeypadListener(ExceptionThread):
wrongPassSound = soundLib.soundEffects['wrongPass'] wrongPassSound = soundLib.soundEffects['wrongPass']
backspaceSound = soundLib.soundEffects['backspace'] backspaceSound = soundLib.soundEffects['backspace']
self.resetBuffer() self._clearBuffer()
def getInput(): def getInput():
while 1: while 1:
@ -45,6 +45,7 @@ class KeypadListener(ExceptionThread):
if event.code in numKeys: if event.code in numKeys:
if stateMachine.currentState != stateMachine.states.disarmed: if stateMachine.currentState != stateMachine.states.disarmed:
self._buf = self._buf + numKeys[event.code] self._buf = self._buf + numKeys[event.code]
self._startResetCountdown()
numKeySound.play() numKeySound.play()
# ctrl input # ctrl input
@ -72,6 +73,8 @@ class KeypadListener(ExceptionThread):
# delete last char in buffer # delete last char in buffer
elif val == 'BS': elif val == 'BS':
self._buf = self._buf[:-1] self._buf = self._buf[:-1]
if self._buf == '':
self._stopResetCountdown()
backspaceSound.play() backspaceSound.play()
# reset buffer # reset buffer
@ -95,13 +98,27 @@ class KeypadListener(ExceptionThread):
ctrlKeySound.play() ctrlKeySound.play()
self._dev.set_led(ecodes.LED_NUML, 0 if soundLib.volume > 0 else 1) self._dev.set_led(ecodes.LED_NUML, 0 if soundLib.volume > 0 else 1)
super().__init__(target=getInput, daemon=True) self._resetCountdown = None
self.start()
self._listener = ExceptionThread(target=getInput, daemon=True)
self._listener.start()
logger.debug('Started keypad device') logger.debug('Started keypad device')
# TODO: make timer to clear buffer if user doesn't clear it def _startResetCountdown(self):
print('hey')
self._resetCountdown = CountdownTimer(30, self._clearBuffer)
def _stopResetCountdown(self):
print('ho')
if self._resetCountdown is not None and self._resetCountdown.is_alive():
self._resetCountdown.stop()
self._resetCountdown = None
def resetBuffer(self): def resetBuffer(self):
self._stopResetCountdown
self._clearBuffer()
def _clearBuffer(self):
self._buf = '' self._buf = ''
def __del__(self): def __del__(self):