Some statemachine functions for MicroPython
Project description
Eydam-Prototyping: ep_statemachine
Python-Modul to implement a simple statemachine.
Example:
import ep_statemachine
i = 0
def inc():
nonlocal i
i = i + 1
workflow = [
"press coffee button",
"press coffee button",
"press espresso button",
"press espresso button",
"press off button",
"press off button",
]
# define states
s_sleep = es.state("sleep", initial=True, entry_action=inc)
s_select_input = es.state("select_input", entry_action=inc)
s_make_coffee = es.state("make coffee")
s_make_espresso = es.state("make espresso")
s_done = es.state("done")
s_off = es.state("off")
# define transitions
t_wake_up = es.transition(s_select_input, identifier="wake up", condition=lambda: re.match("press (coffee|espresso|off) button", workflow[i]) is not None)
s_sleep.add_transition(t_wake_up)
t_coffee = es.transition(s_make_coffee, identifier="coffee", condition=lambda: workflow[i] == "press coffee button")
s_select_input.add_transition(t_coffee)
t_espresso = es.transition(s_make_espresso, identifier="espresso", condition=lambda: workflow[i] == "press espresso button")
s_select_input.add_transition(t_espresso)
t_finished = es.transition(s_done, identifier="finished", condition=lambda: True)
s_make_coffee.add_transition(t_finished)
s_make_espresso.add_transition(t_finished)
t_back_to_sleep = es.transition(s_sleep, identifier="back to sleep", condition=lambda: True)
s_done.add_transition(t_back_to_sleep)
t_turn_off = es.transition(s_off, identifier="turn off", condition=lambda:workflow[i] == "press off button")
s_select_input.add_transition(t_turn_off)
sm = es.statemachine([s_sleep, s_select_input, s_make_coffee, s_make_espresso, s_done, s_off])
sm.init()
# do one step after another
sm.step()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for micropython_eydam-prototyping_statemachine-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fab0ae2737204ed3c7262ce9a110aec640b0a5edfa8f84120f539134c2c03a76 |
|
MD5 | 1bf73bb2c0ddab23f7c5c4e70be7a64c |
|
BLAKE2b-256 | 810d856150a6b312c8982c65223c76040f5ca70e631fc58604e6c292ebc97baf |