Versatile and flexible Python State Machine library - Micropython Port
Project description
upysm
Versatile and flexible Python State Machine library - Micropython Port
This repository is basically a set of tools to build and deploy (to pypi) the Micropython Port of the pysm library.
It's successfully tested against the ESP-32S ESP-WROOM-32 NodeMCU board.
Installation
import upip
upip.install('upysm')
Usage
Basic usage:
import machine
import time
from pysm import State, StateMachine, Event
led = machine.Pin(2, machine.Pin.OUT)
def on_enter(state, event):
led.value(1)
time.sleep(0.1)
def on_exit(state, event):
led.value(0)
time.sleep(0.1)
on = State('on')
off = State('off')
sm = StateMachine('sm')
sm.add_state(on, initial=True)
sm.add_state(off)
sm.add_transition(on, off, events=['off'])
sm.add_transition(off, on, events=['on'])
on.handlers = {'enter': on_enter, 'exit': on_exit}
off.handlers = {'enter': on_enter, 'exit': on_exit}
sm.initialize()
assert sm.state == on
sm.dispatch(Event('off'))
assert sm.state == off
sm.dispatch(Event('on'))
assert sm.state == on
For more examples and API description refer to the pysm documentation.
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
upysm-0.3.11.tar.gz
(9.8 kB
view details)
File details
Details for the file upysm-0.3.11.tar.gz
.
File metadata
- Download URL: upysm-0.3.11.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 975b8ea6e5dd0be3191553285ebd9c640d2b4be1c910ae48ded98905a9bc90e4 |
|
MD5 | 2ec7cd25a18fb0856c078aee406debb1 |
|
BLAKE2b-256 | 1fabde7e9a675baa344b564749ac73b760636b28e28d62f70bf1a9a9fa04e64d |