diff --git a/Tacos/src/statemachine.cpp b/Tacos/src/statemachine.cpp index b1a9154..c7daf0f 100644 --- a/Tacos/src/statemachine.cpp +++ b/Tacos/src/statemachine.cpp @@ -33,25 +33,28 @@ namespace sta void Statemachine::func() { - 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_ && !lockoutTimer_.isRunning()) + if (!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();