diff --git a/include/sta/tacos/statemachine.hpp b/include/sta/tacos/statemachine.hpp index 9217c1c..07fbdea 100644 --- a/include/sta/tacos/statemachine.hpp +++ b/include/sta/tacos/statemachine.hpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -278,6 +279,18 @@ namespace sta */ std::vector> threads_[STA_TACOS_NUM_STATES]; }; + + /** + * @brief Callback that is called when a state transition occurs. + * + * @param from The state we transitioned from. + * @param to The state we transitioned to. + * @param lockout The lockout time after the transition. + * + * @ingroup tacos_statemachine + */ + STA_WEAK + void onStateTransition(uint16_t from, uint16_t to, uint32_t lockout){} } // namespace tacos } // namespace sta diff --git a/src/statemachine.cpp b/src/statemachine.cpp index 762e48b..2d10a67 100644 --- a/src/statemachine.cpp +++ b/src/statemachine.cpp @@ -71,6 +71,9 @@ namespace sta HeapStats_t stats; vPortGetHeapStats(&stats); + // Execute the user-defined callback. + sta::tacos::onStateTransition(transition.from, transition.to, transition.lockout); + // Start all new tasks and stop all the tasks that aren't supposed to be running. updateThreads(); }