/* * statemachine.hpp * * Created on: Sep 14, 2023 * Author: Dario */ #ifndef INCLUDE_TACOS_STATEMACHINE_HPP_ #define INCLUDE_TACOS_STATEMACHINE_HPP_ #include #ifndef STA_TACOS_NUM_STATES # error "Number of states wasn't defined in config.hpp" #else #ifndef STA_TACOS_INITIAL_STATE # define STA_TACOS_INITIAL_STATE 0 #endif #include #include #include #include namespace sta { namespace tacos { class Statemachine : public TacosThread { public: static Statemachine* instance() { static CGuard g; if (!_instance) { // Create a the manager singleton instance. Statemachine::_instance = new Statemachine(); } return _instance; } void init() override; void func() override; uint16_t getCurrentState() const; void setStateTransitionFunction(uint16_t (*function)(uint16_t)); private: static Statemachine * _instance; class CGuard { public: ~CGuard() { if( NULL != Statemachine::_instance ) { delete Statemachine::_instance; Statemachine::_instance = NULL; } } }; Statemachine(); Statemachine(const Statemachine&); ~Statemachine() {} private: static void forceStateChange(void * arg); private: uint16_t currentState_; RtosTimer lockoutTimer_; RtosTimer failsafeTimer_; std::function transitionFunc_; }; } // namespace tacos } // namespace sta #endif // STA_TACOS_NUM_STATES #endif /* INCLUDE_TACOS_STATEMACHINE_HPP_ */