Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Public Member Functions | List of all members
lampda::utils::StateMachine< State > Class Template Reference

Define a state machine. More...

#include <state_machine.h>

Public Member Functions

 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.
 
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
 
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 ()
 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.
 
void skip_timeout ()
 use this in a state with a timeout set to skip to the next state directly
 
uint32_t get_state_raised_time () const
 Return the time at which this state was raised.
 

Detailed Description

template<typename State>
class lampda::utils::StateMachine< State >

Define a state machine.

Constructor & Destructor Documentation

◆ StateMachine()

template<typename State >
lampda::utils::StateMachine< State >::StateMachine ( const State  s,
const uint32_t  timeout,
const State  stateOnTimeout 
)
inline

Construct a state machine from the first given state, with a timeout to another.

Parameters
[in]sThe initial state
[in]timeoutThe timeout after which we switch to the fallback state
[in]stateOnTimeoutFalback state, reached on timeout

Member Function Documentation

◆ set_state() [1/2]

template<typename State >
bool lampda::utils::StateMachine< State >::set_state ( const State  s,
bool  forceUpdate = false 
)
inline

Set the machine state.

Parameters
[in]sThe new state to set
[in]forceUpdateForce the state update, even if the state is already active
Returns
True if the state was updated

◆ set_state() [2/2]

template<typename State >
bool lampda::utils::StateMachine< State >::set_state ( const State  s,
const uint32_t  timeout,
const State  stateOnTimeout 
)
inline

set the new current state, with a timeout

Parameters
[in]sthe new state
[in]timeoutThe time out delay after which the state will switch automatically to stateOnTimeout
[in]stateOnTimeoutState to reach after the timeout
Returns
true is the state changed

The documentation for this class was generated from the following file: