class TurnstileInput(Names):
FARE_PAID = NamedConstant()
ARM_UNLOCKED = NamedConstant()
ARM_TURNED = NamedConstant()
ARM_LOCKED = NamedConstant()
class TurnstileOutput(Names):
ENGAGE_LOCK = NamedConstant()
DISENGAGE_LOCK = NamedConstant()
class TurnstileState(Names):
LOCKED = NamedConstant()
UNLOCKED = NamedConstant()
ACTIVE = NamedConstant()
table = TransitionTable()
# Any number of things like this
table = table.addTransitions(
TurnstileState.UNLOCKED, {
TurnstileInput.ARM_TURNED:
([TurnstileOutput.ENGAGE_LOCK], TurnstileState.ACTIVE),
})
turnstileFSM = constructFiniteStateMachine(
inputs=TurnstileInput,
outputs=TurnstileOutput,
states=TurnstileState,
table=table,
initial=TurnstileState.LOCKED,
richInputs={},
inputContext={},
world=MethodSuffixOutputer(Turnstile(hardware)),
)
For the rest of this example, see doc/turnstile.py.
For more discussion of the benefits of this style, see:
$ pip install machinist
See http://github.com/hybridcluster/machinist for development.