use duetimer and fix bug where if the next state is the same the exit function would still get called

This commit is contained in:
Sem van der Hoeven
2023-11-23 23:39:44 +01:00
parent 796a8938c3
commit b4067c8379
3 changed files with 25 additions and 47 deletions

View File

@@ -33,6 +33,11 @@ __UINT8_TYPE__ statemachine_init()
void statemachine_loop()
{
if (states[current_state_id].next == current_state_id)
{
next = 0;
}
if (next)
{
next = 0;
@@ -41,13 +46,13 @@ void statemachine_loop()
{
states[current_state_id].on_exit();
}
if (states[current_state_id].next >= 0 && states[current_state_id].next != current_state_id)
if (states[current_state_id].next >= 0)
{
current_state_id = states[current_state_id].next;
}
states[current_state_id].on_enter();
}
if (states[current_state_id].on_run != NULL)
{
states[current_state_id].on_run();