-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharduino.h
79 lines (60 loc) · 2.07 KB
/
arduino.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/******************************************************************************
Finite State Machine
Project: sm.dot
Description: gv_fsm example
Generated by gv_fsm ruby gem, see https://rubygems.org/gems/gv_fsm
gv_fsm version 0.2.6
Generation date: 2020-09-07 12:53:32 +0200
Generated from: sm.dot
The finite state machine has:
5 states
5 transition functions
******************************************************************************/
#include <arduino.h>
// State data object
// By default set to void; override this typedef or load the proper
// header if you need
typedef void state_data_t;
// List of states
typedef enum {
STATE_INIT = 0,
STATE_IDLE,
STATE_SETUP,
STATE_RUNNING,
STATE_STOP,
NUM_STATES,
NO_CHANGE
} state_t;
// State human-readable names
extern const char *state_names[];
// State function and state transition prototypes
typedef state_t state_func_t(state_data_t *data);
typedef void transition_func_t(state_data_t *data);
// State functions
// Function to be executed in state init
// valid return states: STATE_IDLE
state_t do_init(state_data_t *data);
// Function to be executed in state idle
// valid return states: NO_CHANGE, STATE_IDLE, STATE_SETUP
state_t do_idle(state_data_t *data);
// Function to be executed in state setup
// valid return states: STATE_RUNNING
state_t do_setup(state_data_t *data);
// Function to be executed in state running
// valid return states: NO_CHANGE, STATE_IDLE, STATE_RUNNING, STATE_STOP
state_t do_running(state_data_t *data);
// Function to be executed in state stop
// valid return states: NO_CHANGE
state_t do_stop(state_data_t *data);
// List of state functions
extern state_func_t *const state_table[NUM_STATES];
// Transition functions
void init_to_idle(state_data_t *data);
void stay(state_data_t *data);
void to_setup(state_data_t *data);
void setup_to_running(state_data_t *data);
void to_idle(state_data_t *data);
// Table of transition functions
extern transition_func_t *const transition_table[NUM_STATES][NUM_STATES];
// state manager
state_t run_state(state_t cur_state, state_data_t *data);