Skip to content

Commit 98ba118

Browse files
committed
Cycle back to bottom of mode list once ANA is reached.
1 parent 4686212 commit 98ba118

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

stm32/src/sm1000_main.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,12 @@ int process_core_state_machine(int core_state, struct menu_t *menu, int *op_mode
755755
mode_changed = 1;
756756
} else if (switch_released(&sw_back)) {
757757
/* Shortcut: change current mode */
758-
*op_mode = (*op_mode - 1) % MAX_MODES;
758+
*op_mode = *op_mode - 1;
759+
if (*op_mode < 0)
760+
{
761+
// Loop back around to the end of the mode list if we reach 0.
762+
*op_mode = MAX_MODES - 1;
763+
}
759764
mode_changed = 1;
760765
}
761766

@@ -940,7 +945,11 @@ static void menu_default_cb(struct menu_t* const menu, uint32_t event)
940945
break;
941946
case MENU_EVT_PREV:
942947
sfx_play(&sfx_player, sound_click);
943-
menu->current = (menu->current - 1) % item->num_children;
948+
menu->current = menu->current - 1;
949+
if (menu->current < 0)
950+
{
951+
menu->current = item->num_children - 1;
952+
}
944953
announce = 1;
945954
break;
946955
case MENU_EVT_SELECT:
@@ -1072,7 +1081,11 @@ static void menu_op_mode_cb(struct menu_t* const menu, uint32_t event)
10721081
break;
10731082
case MENU_EVT_PREV:
10741083
sfx_play(&sfx_player, sound_click);
1075-
menu->current = (menu->current - 1) % item->num_children;
1084+
menu->current = menu->current - 1;
1085+
if (menu->current < 0)
1086+
{
1087+
menu->current = item->num_children - 1;
1088+
}
10761089
announce = 1;
10771090
break;
10781091
case MENU_EVT_SELECT:

0 commit comments

Comments
 (0)