add start of state machine

This commit is contained in:
Sem van der Hoeven
2023-10-28 17:47:45 +02:00
parent 37248ea771
commit 892ea7d725
4 changed files with 84 additions and 0 deletions

59
due_obd2/statemachine.h Normal file
View File

@@ -0,0 +1,59 @@
#ifndef STATEMACHINE_H
#define STATEMACHINE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "Arduino.h"
/* two displays:
- initialisation display, shows the state of booting up
- main display, shows the data from the OBD2 scanner
each state has a function that can be called when it enters that state, while it's running and when it exits that state
Example: https://stackoverflow.com/questions/1371460/state-machines-tutorials
*/
/**
* @brief State struct. Contains the id of the state, and the functions that are called when the state is entered, running and exited.
*/
typedef struct SM_STATE
{
int id;
void (*on_enter)();
void (*on_run)();
void (*on_exit)();
} state_t;
/**
* @brief Transition struct. Contains the id of the state it transitions to, and the next state.
*/
typedef struct SM_TRANSITION
{
int state_id;
state_t *next_state;
} transition_t;
/**
* @brief State machine struct. Contains the current state and the transitions.
*/
typedef struct SM_STATE_MACHINE
{
state_t *current_state;
transition_t *transitions; /* Transitions between states. Every state's ID is also it's position in the array.*/
} statemachine_t;
/**
* @brief Initialises the state machine. Initializes the statemachine struct.
*/
void statemachine_init();
void __state_none()
{
/* do nothing*/
}
#ifdef __cplusplus
}
#endif
#endif // !STATEMACHINE_H