validate signal lookup
This commit is contained in:
parent
076541390c
commit
960389d043
|
@ -1,8 +1,9 @@
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import time, logging
|
import time, logging, enum
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
from enum import Enum, auto
|
||||||
|
|
||||||
from auxilary import CountdownTimer, resetUSBDevice
|
from auxilary import CountdownTimer, resetUSBDevice
|
||||||
from config import stateFile
|
from config import stateFile
|
||||||
|
@ -16,12 +17,12 @@ from stream import Camera, FileDump
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class SIGNALS:
|
class SIGNALS(enum.Enum):
|
||||||
ARM = 1
|
ARM = enum.auto()
|
||||||
INSTANT_ARM = 2
|
INSTANT_ARM = enum.auto()
|
||||||
DISARM = 3
|
DISARM = enum.auto()
|
||||||
TIMOUT = 4
|
TIMOUT = enum.auto()
|
||||||
TRIGGER = 5
|
TRIGGER = enum.auto()
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
def __init__(self, stateMachine, name, entryCallbacks=[], exitCallbacks=[], blinkLED=True, sound=None):
|
def __init__(self, stateMachine, name, entryCallbacks=[], exitCallbacks=[], blinkLED=True, sound=None):
|
||||||
|
@ -53,8 +54,11 @@ class State:
|
||||||
c()
|
c()
|
||||||
|
|
||||||
def next(self, signal):
|
def next(self, signal):
|
||||||
|
if signal in SIGNALS:
|
||||||
t = (self, signal)
|
t = (self, signal)
|
||||||
return self if t not in self.stateMachine.transitionTable else self.stateMachine.transitionTable[t]
|
return self if t not in self.stateMachine.transitionTable else self.stateMachine.transitionTable[t]
|
||||||
|
else:
|
||||||
|
raise Exception('Illegal signal')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
Loading…
Reference in New Issue