feat: user definable callback on state transition

This commit is contained in:
CarlWachter 2024-11-03 13:25:22 +01:00
parent 7152baca2a
commit 9f4d99191d
2 changed files with 16 additions and 0 deletions

View File

@ -66,6 +66,7 @@
#include <sta/rtos/event.hpp> #include <sta/rtos/event.hpp>
#include <sta/event.hpp> #include <sta/event.hpp>
#include <sta/debug/assert.hpp> #include <sta/debug/assert.hpp>
#include <sta/lang.hpp>
#include <functional> #include <functional>
#include <tuple> #include <tuple>
@ -278,6 +279,18 @@ namespace sta
*/ */
std::vector<std::shared_ptr<TacosThread>> threads_[STA_TACOS_NUM_STATES]; std::vector<std::shared_ptr<TacosThread>> 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 tacos
} // namespace sta } // namespace sta

View File

@ -71,6 +71,9 @@ namespace sta
HeapStats_t stats; HeapStats_t stats;
vPortGetHeapStats(&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. // Start all new tasks and stop all the tasks that aren't supposed to be running.
updateThreads(); updateThreads();
} }