Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions Inc/ST-LIB_LOW/StateMachine/StateMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ class IStateMachine {
virtual void force_change_state(size_t state) = 0;
virtual size_t get_current_state_id() const = 0;
constexpr bool operator==(const IStateMachine&) const = default;
protected:
virtual void enter() = 0;
virtual void exit() = 0;
virtual void start() = 0;
template <class E, size_t N, size_t T>
friend class StateMachine;
};

template <class StateEnum, size_t NStates, size_t NTransitions>
Expand Down Expand Up @@ -327,14 +333,14 @@ class StateMachine : public IStateMachine {
state.get_transitions().size()};
}

inline void enter()
inline void enter() override
{
auto& state = states[static_cast<size_t>(current_state)];
state.enter();

}

inline void exit()
inline void exit() override
{
auto& state = states[static_cast<size_t>(current_state)];
state.exit();
Expand Down Expand Up @@ -391,11 +397,25 @@ class StateMachine : public IStateMachine {
if (t.predicate())
{
exit();
for(auto& nested : nested_state_machine)
{
if(nested.state == current_state){
nested.machine->exit();
break;
}
}
#ifdef STLIB_ETH
remove_state_orders();
#endif
current_state = t.target;
enter();
for(auto& nested : nested_state_machine)
{
if(nested.state == current_state){
nested.machine->enter();
break;
}
}
#ifdef STLIB_ETH
refresh_state_orders();
#endif
Expand All @@ -412,9 +432,16 @@ class StateMachine : public IStateMachine {
}
}

void start()
void start() override
{
enter();
for(auto& nested : nested_state_machine)
{
if(nested.state == current_state){
nested.machine->start();
break;
}
}
}


Expand All @@ -428,11 +455,25 @@ class StateMachine : public IStateMachine {
}

exit();
for(auto& nested : nested_state_machine)
{
if(nested.state == current_state){
nested.machine->exit();
break;
}
}
#ifdef STLIB_ETH
remove_state_orders();
#endif
current_state = new_state;
enter();
for(auto& nested : nested_state_machine)
{
if(nested.state == current_state){
nested.machine->enter();
break;
}
}
#ifdef STLIB_ETH
refresh_state_orders();
#endif
Expand Down