mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-16 04:31:04 +00:00
add start of state machine
This commit is contained in:
59
due_obd2/statemachine.h
Normal file
59
due_obd2/statemachine.h
Normal 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
|
||||
Reference in New Issue
Block a user