Define a state machine. Thread safe: all the methods are synchronized, a state change and its timeout are always seen together. Do not call from an interrupt.
More...
|
|
| StateMachine (const State s) |
| | Construct a state machine from the first given state.
|
| |
| | 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.
|
| |
|
| StateMachine (const StateMachine &)=delete |
| |
|
StateMachine & | operator= (StateMachine const &)=delete |
| |
|
void | run () |
| | timeout check, and such, call it often
|
| |
| bool | set_state (const State s, bool forceUpdate=false) |
| | Set the machine state.
|
| |
| bool | set_state (const State s, const uint32_t timeout, const State stateOnTimeout) |
| | set the new current state, with a timeout
|
| |
| bool | set_state_unless (const State blockingState, const State s, const uint32_t timeout, const State stateOnTimeout) |
| | Same as set_state(s, timeout, stateOnTimeout), unless the machine is in blockingState. The check and the update are atomic: another thread can not switch to blockingState in between.
|
| |
|
void | update_timeout (const uint32_t timeout) |
| | Update the current state timeout if a timeout is active.
|
| |
|
bool | state_just_changed () |
| | Return true if the current state just changed. Resetted on read.
|
| |
|
bool | state_changed_with_timeout () const |
| | return true if this state was reached with a timeout
|
| |
|
State | get_state () const |
| | Return the actual state.
|
| |
|
State | get_last_state () const |
| | Return the state before this one.
|
| |
|
State | after_timeout_state () const |
| | Return the state after the timeout. May be undefined.
|
| |
|
uint32_t | get_state_generation () const |
| | Return a value changed on every state set (timeout target included), to detect a concurrent update. See skip_timeout(const uint32_t)
|
| |
|
void | skip_timeout () |
| | use this in a state with a timeout set to skip to the next state directly
|
| |
| bool | skip_timeout (const uint32_t generation) |
| | Skip the timeout, only if the state was not set since generation was read (see get_state_generation). A skip decided on a state that another thread replaced meanwhile is dropped.
|
| |
|
uint32_t | get_state_raised_time () const |
| | Return the time at which this state was raised.
|
| |
|
void | reset_state_raised_time () |
| | Restart the time returned by get_state_raised_time, without changing the state or its timeout.
|
| |
template<typename State>
class lampda::common::StateMachine< State >
Define a state machine. Thread safe: all the methods are synchronized, a state change and its timeout are always seen together. Do not call from an interrupt.