Skip to content

Commit e18caee

Browse files
authored
Merge pull request #110 from NemesisXB/BackButton
Improve menu navigation.
2 parents e9817fd + 0b756e5 commit e18caee

3 files changed

Lines changed: 75 additions & 7 deletions

File tree

src/and_scale_calibrate.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ uint8_t scale_calibrate_with_external_weight() {
9191
strcpy(line1, "Confirm pan is empty");
9292
strcpy(line2, "Press Next to continue");
9393
show_next_key = true;
94-
while (button_wait_for_input(true) != BUTTON_ENCODER_PRESSED) {
95-
;
94+
while (true) {
95+
ButtonEncoderEvent_t ev = button_wait_for_input(true);
96+
if (ev == BUTTON_RST_PRESSED) {
97+
show_next_key = false;
98+
vTaskSuspend(scale_calibration_render_task_handler);
99+
return 31; // back to Scale menu
100+
}
101+
if (ev == BUTTON_ENCODER_PRESSED) {
102+
break;
103+
}
96104
}
97105
show_next_key = false;
98106
scale_press_print_key();
@@ -108,8 +116,16 @@ uint8_t scale_calibrate_with_external_weight() {
108116
strcpy(line2, "Press Next to continue");
109117

110118
show_next_key = true;
111-
while (button_wait_for_input(true) != BUTTON_ENCODER_PRESSED) {
112-
;
119+
while (true) {
120+
ButtonEncoderEvent_t ev = button_wait_for_input(true);
121+
if (ev == BUTTON_RST_PRESSED) {
122+
show_next_key = false;
123+
vTaskSuspend(scale_calibration_render_task_handler);
124+
return 31; // back to Scale menu
125+
}
126+
if (ev == BUTTON_ENCODER_PRESSED) {
127+
break;
128+
}
113129
}
114130
show_next_key = false;
115131
scale_press_print_key();
@@ -124,8 +140,16 @@ uint8_t scale_calibrate_with_external_weight() {
124140
strcpy(line2, "Press Next to continue");
125141

126142
show_next_key = true;
127-
while (button_wait_for_input(true) != BUTTON_ENCODER_PRESSED) {
128-
;
143+
while (true) {
144+
ButtonEncoderEvent_t ev = button_wait_for_input(true);
145+
if (ev == BUTTON_RST_PRESSED) {
146+
show_next_key = false;
147+
vTaskSuspend(scale_calibration_render_task_handler);
148+
return 31; // back to Scale menu
149+
}
150+
if (ev == BUTTON_ENCODER_PRESSED) {
151+
break;
152+
}
129153
}
130154
show_next_key = false;
131155

src/menu.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,41 @@ extern const size_t muif_cnt;
2929

3030
AppState_t exit_state = APP_STATE_DEFAULT;
3131

32+
static uint8_t menu_get_parent_form_id(uint8_t form_id) {
33+
// Parent relationships for "one level up" navigation.
34+
// Root is form 1.
35+
switch (form_id) {
36+
case 10: return 1;
37+
case 11: return 10;
38+
case 12: return 10;
39+
case 13: return 10;
40+
41+
case 20: return 1;
42+
43+
case 30: return 1;
44+
case 31: return 30;
45+
case 32: return 30;
46+
case 33: return 32;
47+
case 34: return 32;
48+
case 38: return 34;
49+
case 35: return 30;
50+
case 36: return 30;
51+
case 37: return 30;
52+
case 39: return 30;
53+
54+
case 40: return 1;
55+
case 41: return 40;
56+
57+
case 51: return 31;
58+
case 53: return 31;
59+
case 60: return 37;
60+
case 61: return 37;
61+
62+
default:
63+
return 1;
64+
}
65+
}
66+
3267

3368
void menu_task(void *p){
3469
u8g2_t * display_handler = get_display_handler();
@@ -56,6 +91,14 @@ void menu_task(void *p){
5691
else if (button_encoder_event == BUTTON_ENCODER_PRESSED) {
5792
mui_SendSelect(&mui);
5893
}
94+
else if (button_encoder_event == BUTTON_RST_PRESSED) {
95+
// Global back: deterministic "one menu level up" until root (form 1).
96+
uint8_t current_form_id = mui_GetCurrentFormId(&mui);
97+
if (current_form_id != 1) {
98+
uint8_t parent_form_id = menu_get_parent_form_id(current_form_id);
99+
mui_GotoForm(&mui, parent_form_id, 0);
100+
}
101+
}
59102
else if (button_encoder_event == OVERRIDE_FROM_REST) {
60103
// Assuming the caller code will set the exit_state
61104
mui_SaveForm(&mui); // store the current form and position so that the child can jump back

src/mui_menu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ fds_t fds_data[] = {
374374
MUI_LABEL(5, 37, "press Next to trickle")
375375

376376
MUI_STYLE(0)
377-
MUI_XYAT("BN",14, 59, 10, "Back")
377+
// Put "Next" first so it is focused by default
378378
MUI_XYAT("LV", 115, 59, 1, "Next") // APP_STATE_ENTER_CHARGE_MODE
379+
MUI_XYAT("BN",14, 59, 10, "Back")
379380

380381
// Menu 20: Cleanup
381382
MUI_FORM(20)

0 commit comments

Comments
 (0)