LennartHennigs / SimpleFSM

Arduino/ESP library to simplify setting up and running a state machine.
MIT License
69 stars 16 forks source link
arduino arduino-library cplusplus embedded esp esp32 esp8266 finite-state-machine fsm fsm-library state-machine

SimpleFSM

Arduino/ESP library to simplify setting up and running a state machine.

Description

This library allows you to quickly setup a State Machine. Read here what a state machine is and why a state machine is neat for hardware projects.

It has been tested with Arduino, ESP8266 and ESP32 devices.

⚠️ To see the latest changes to the library please take a look at the Changelog.

If you find this library helpful please consider giving it a ⭐️ at GitHub and/or buy me a ☕️. Thanks!

Features

⚠️ To see the latest changes to the library please take a look at the Changelog.

How To Use

Defining States

  State(
    String name, 
    CallbackFunction on_enter, 
    CallbackFunction on_state = NULL, 
    CallbackFunction on_exit = NULL, 
    bool is_final = false
  );

Transitions

Regular Transitions

  Transition(
    State* from, 
    State* to, 
    int event_id, 
    CallbackFunction on_run = NULL, 
    String name = "", 
    GuardCondition guard = NULL
  );

Timed Transitions

  TimedTransition(
    State* from, 
    State* to, 
    int interval, 
    CallbackFunction on_run = NULL, 
    String name = "", 
    GuardCondition guard = NULL
  );

Guard Conditions

In-State Interval

  State(String name, CallbackFunction on_enter, CallbackFunction on_state = NULL, CallbackFunction on_exit = NULL, bool is_final = false);

Helper functions

GraphViz Generation

Class Definitions

Examples

Notes

How To Install

Open the Arduino IDE choose "Sketch > Include Library" and search for "SimpleFSM". Or download the ZIP archive (https://github.com/lennarthennigs/SimpleFSM/zipball/master), and choose "Sketch > Include Library > Add .ZIP Library..." and select the downloaded file.

License

MIT License

Copyright (c) 2023 Lennart Hennigs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.