Browse Source

allow going back from workflow selection

Thomas Buck 1 year ago
parent
commit
0c2780e7ae
4 changed files with 15 additions and 5 deletions
  1. 1
    1
      include/menu.h
  2. 8
    2
      src/menu.c
  3. 1
    1
      src/state_scan.c
  4. 5
    1
      src/state_volcano_workflow.c

+ 1
- 1
include/menu.h View File

@@ -29,7 +29,7 @@ struct menu_state {
29 29
     char *buff;
30 30
 };
31 31
 
32
-void menu_init(void (*cb)(int));
32
+void menu_init(void (*enter)(int), void (*exit)(void));
33 33
 void menu_deinit(void);
34 34
 
35 35
 void menu_run(void (*cb)(struct menu_state *));

+ 8
- 2
src/menu.c View File

@@ -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
 

+ 1
- 1
src/state_scan.c View File

@@ -53,7 +53,7 @@ static void enter_cb(int selection) {
53 53
 }
54 54
 
55 55
 void state_scan_enter(void) {
56
-    menu_init(enter_cb);
56
+    menu_init(enter_cb, NULL);
57 57
     ble_scan(BLE_SCAN_ON);
58 58
 }
59 59
 

+ 5
- 1
src/state_volcano_workflow.c View File

@@ -33,8 +33,12 @@ static void enter_cb(int selection) {
33 33
     }
34 34
 }
35 35
 
36
+static void exit_cb(void) {
37
+    state_switch(STATE_SCAN);
38
+}
39
+
36 40
 void state_volcano_wf_enter(void) {
37
-    menu_init(enter_cb);
41
+    menu_init(enter_cb, exit_cb);
38 42
 }
39 43
 
40 44
 void state_volcano_wf_exit(void) {

Loading…
Cancel
Save