|
@@ -27,6 +27,7 @@ static char prev_buff[MENU_MAX_LEN] = {0};
|
27
|
27
|
static char buff[MENU_MAX_LEN] = {0};
|
28
|
28
|
static struct menu_state menu = { .off = 0, .selection = -1, .length = 0, .buff = buff };
|
29
|
29
|
static void (*enter_callback)(int) = NULL;
|
|
30
|
+static void (*exit_callback)(void) = NULL;
|
30
|
31
|
|
31
|
32
|
static void menu_buttons(enum buttons btn, bool state) {
|
32
|
33
|
if (state && (btn == BTN_LEFT)) {
|
|
@@ -40,6 +41,10 @@ static void menu_buttons(enum buttons btn, bool state) {
|
40
|
41
|
enter_callback(menu.selection);
|
41
|
42
|
}
|
42
|
43
|
return;
|
|
44
|
+ } else if (state && (btn == BTN_Y)) {
|
|
45
|
+ if (exit_callback) {
|
|
46
|
+ exit_callback();
|
|
47
|
+ }
|
43
|
48
|
} else if ((!state) || ((btn != BTN_UP) && (btn != BTN_DOWN))) {
|
44
|
49
|
return;
|
45
|
50
|
}
|
|
@@ -74,12 +79,13 @@ static void menu_buttons(enum buttons btn, bool state) {
|
74
|
79
|
}
|
75
|
80
|
}
|
76
|
81
|
|
77
|
|
-void menu_init(void (*cb)(int)) {
|
|
82
|
+void menu_init(void (*enter)(int), void (*exit)(void)) {
|
78
|
83
|
menu.off = 0;
|
79
|
84
|
menu.selection = -1;
|
80
|
85
|
menu.length = 0;
|
81
|
86
|
|
82
|
|
- enter_callback = cb;
|
|
87
|
+ enter_callback = enter;
|
|
88
|
+ exit_callback = exit;
|
83
|
89
|
buttons_callback(menu_buttons);
|
84
|
90
|
}
|
85
|
91
|
|