Changed statemachine to only check for transitions if the lockout timer is not running

This commit is contained in:
dario
2023-10-30 17:25:09 +01:00
parent 9f4c772437
commit 4de63ced98

View File

@@ -33,25 +33,28 @@ namespace sta
void Statemachine::func() void Statemachine::func()
{ {
uint16_t next = transitionFunc_(currentState_); if (!lockoutTimer_.isRunning())
STA_ASSERT(next < STA_TACOS_NUM_STATES);
// Check if a state change is desired. Block if the lockoutTimer is still running.
if (next != currentState_ && !lockoutTimer_.isRunning())
{ {
if (failsafeTimer_.isRunning()) uint16_t next = transitionFunc_(currentState_);
STA_ASSERT(next < STA_TACOS_NUM_STATES);
// Check if a state change is desired. Block if the lockoutTimer is still running.
if (next != currentState_)
{ {
failsafeTimer_.stop(); if (failsafeTimer_.isRunning())
{
failsafeTimer_.stop();
}
// Call user space code to set the timers again.
timerFunc_(next, currentState_, EventFlags::NORMAL);
// Update the state and trigger the global state changed event.
currentState_ = next;
Statemachine::stateChangeEvent.set(EventFlags::NORMAL);
Statemachine::stateChangeEvent.clear(EventFlags::ALL);
} }
// Call user space code to set the timers again.
timerFunc_(next, currentState_, EventFlags::NORMAL);
// Update the state and trigger the global state changed event.
currentState_ = next;
Statemachine::stateChangeEvent.set(EventFlags::NORMAL);
Statemachine::stateChangeEvent.clear(EventFlags::ALL);
} }
osThreadYield(); osThreadYield();