23 stateSetTime(platform::time_ms()),
26 changedWithTimeout(false)
35 StateMachine(
const State s,
const uint32_t timeout,
const State stateOnTimeout) :
38 stateSetTime(platform::time_ms()),
41 changedWithTimeout(false)
56 changedWithTimeout =
true;
66 bool set_state(
const State s,
bool forceUpdate =
false)
68 if (not forceUpdate and s == current)
81 changedWithTimeout =
false;
82 didStateJustChanged =
true;
93 bool set_state(
const State s,
const uint32_t timeout,
const State stateOnTimeout)
99 if (not isTimeoutSet or (s != current or afterTimeoutState != stateOnTimeout))
107 afterTimeoutState = stateOnTimeout;
128 const bool temp = didStateJustChanged;
129 didStateJustChanged =
false;
161 uint32_t stateSetTime;
167 State afterTimeoutState;
170 bool didStateJustChanged;
172 bool changedWithTimeout;
Define a state machine.
Definition: state_machine.h:17
State get_state() const
Return the actual state.
Definition: state_machine.h:137
bool set_state(const State s, bool forceUpdate=false)
Set the machine state.
Definition: state_machine.h:66
void skip_timeout()
use this in a state with a timeout set to skip to the next state directly
Definition: state_machine.h:143
bool state_changed_with_timeout()
return true if this state was reached with a timeout
Definition: state_machine.h:134
bool set_state(const State s, const uint32_t timeout, const State stateOnTimeout)
set the new current state, with a timeout
Definition: state_machine.h:93
StateMachine(const State s, const uint32_t timeout, const State stateOnTimeout)
Construct a state machine from the first given state, with a timeout to another.
Definition: state_machine.h:35
void update_timeout(const uint32_t timeout)
Update the current state timeout if a timeout is active.
Definition: state_machine.h:116
StateMachine(const State s)
Construct a state machine from the first given state.
Definition: state_machine.h:20
State get_last_state() const
Return the state before this one.
Definition: state_machine.h:140
uint32_t get_state_raised_time() const
Return the time at which this state was raised.
Definition: state_machine.h:152
bool state_just_changed()
Return true if the current state just changed. Resetted on read.
Definition: state_machine.h:126
void run()
timeout check, and such, call it often
Definition: state_machine.h:49
Program scope.
Definition: control_fixed_modes.hpp:12
Define all time related platform functions.