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
     char *buff;
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
 void menu_deinit(void);
33
 void menu_deinit(void);
34
 
34
 
35
 void menu_run(void (*cb)(struct menu_state *));
35
 void menu_run(void (*cb)(struct menu_state *));

+ 8
- 2
src/menu.c View File

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

+ 1
- 1
src/state_scan.c View File

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

+ 5
- 1
src/state_volcano_workflow.c View File

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

Loading…
Cancel
Save