add blink modes to state machine

This commit is contained in:
petrucci4prez 2017-06-18 14:17:30 -04:00
parent 5d5c3ff74e
commit 4ff3f27c7c
1 changed files with 20 additions and 10 deletions

View File

@ -194,11 +194,21 @@ class StateMachine:
if self._timer.is_alive(): if self._timer.is_alive():
self._timer.stop() self._timer.stop()
self._timer = None self._timer = None
LED = self._addManaged(Blinkenlights(17))
blinkingLED = partial(LED.setBlink, True)
sfx = self.soundLib.soundEffects sfx = self.soundLib.soundEffects
LED = self._addManaged(Blinkenlights(17))
def squareBlink(t):
LED.setBlink(True)
LED.setLinear(False)
LED.setCyclePeriod(t)
def linearBlink(t):
LED.setBlink(True)
LED.setLinear(True)
LED.setCyclePeriod(t)
stateObjs = [ stateObjs = [
_State( _State(
name = 'disarmed', name = 'disarmed',
@ -207,35 +217,35 @@ class StateMachine:
), ),
_State( _State(
name = 'disarmedCountdown', name = 'disarmedCountdown',
entryCallbacks = [blinkingLED, partial(startTimer, 30, sfx['disarmedCountdown'])], entryCallbacks = [partial(squareBlink, 1), partial(startTimer, 30, sfx['disarmedCountdown'])],
exitCallbacks = [stopTimer], exitCallbacks = [stopTimer],
sound = sfx['disarmedCountdown'] sound = sfx['disarmedCountdown']
), ),
_State( _State(
name = 'armed', name = 'armed',
entryCallbacks = [blinkingLED], entryCallbacks = [partial(linearBlink, 2)],
sound = sfx['armed'] sound = sfx['armed']
), ),
_State( _State(
name = 'lockedCountdown', name = 'lockedCountdown',
entryCallbacks = [blinkingLED, partial(startTimer, 30, sfx['disarmedCountdown'])], entryCallbacks = [partial(squareBlink, 1), partial(startTimer, 30, sfx['disarmedCountdown'])],
exitCallbacks = [stopTimer], exitCallbacks = [stopTimer],
sound = sfx['disarmedCountdown'] sound = sfx['disarmedCountdown']
), ),
_State( _State(
name = 'locked', name = 'locked',
entryCallbacks = [blinkingLED], entryCallbacks = [partial(linearBlink, 3)],
sound = sfx['armed'] sound = sfx['armed']
), ),
_State( _State(
name = 'armedCountdown', name = 'armedCountdown',
entryCallbacks = [blinkingLED, partial(startTimer, 30, sfx['armedCountdown'])], entryCallbacks = [partial(squareBlink, 1), partial(startTimer, 30, sfx['armedCountdown'])],
exitCallbacks = [stopTimer], exitCallbacks = [stopTimer],
sound = sfx['armedCountdown'] sound = sfx['armedCountdown']
), ),
_State( _State(
name = 'triggered', name = 'triggered',
entryCallbacks = [blinkingLED, intruderAlert], entryCallbacks = [partial(linearBlink, 1), intruderAlert],
sound = sfx['triggered'] sound = sfx['triggered']
) )
] ]