C 👀 - A Finite Statemachine!
My Statemachine Implementation in C.
📝 Statemachine definition near the graphical UML representation (as near as it gets).
⚙️ Entry, do, and exit actions for each state.
🔀 Transition actions and optional guard conditions.
🌳 Nested Statemachines support.
🧪 Includes a working example in the test folder.
A Statemachine is implemented in the following manner:
/*** MAIN STATEMACHINE ***/
static const fsm_cfg_t fsmMainCfg = {
.initialState = FSM_STATE_MAIN_1,
.statesCount = 3,
.states = (const fsm_state_cfg_t[3]){
/*** MAIN STATE 1 **********************************************/
{
.state = FSM_STATE_MAIN_1,
.entryAction = {myLog, (fsm_arg_t) "MAIN: STATE1: ENTRY"},
.doAction = {myLog, (fsm_arg_t) "MAIN: STATE1: DO"},
.exitAction = {myLog, (fsm_arg_t) "MAIN: STATE1: EXIT"},
.transitionsCount = 1,
.transitions = (const fsm_transition_cfg_t[1]){
/*** EVENT 2 ***/
{
.event = FSM_EVENT_2,
.action = {myLog, (fsm_arg_t) "MAIN: STATE1: EVENT2"},
.toState = FSM_STATE_MAIN_2,
},
/* more events */
...
},
},
/* more states */
...The provided example within test implements the pictured statemachine:
