Browse Source

only call disconnect once when aborting workflow

Thomas Buck 1 year ago
parent
commit
ca91fdf394
1 changed files with 10 additions and 1 deletions
  1. 10
    1
      src/state_volcano_run.c

+ 10
- 1
src/state_volcano_run.c View File

@@ -27,6 +27,7 @@
27 27
 #include "state.h"
28 28
 #include "state_volcano_run.h"
29 29
 
30
+// only used to draw textbox, not for buttons
30 31
 #include "menu.h"
31 32
 
32 33
 static uint16_t wf_index = 0;
@@ -34,6 +35,7 @@ static bd_addr_t ble_addr = {0};
34 35
 static bd_addr_type_t ble_type = 0;
35 36
 static bool wait_for_connect = false;
36 37
 static bool wait_for_disconnect = false;
38
+static bool aborted = false;
37 39
 
38 40
 void state_volcano_run_index(uint16_t index) {
39 41
     wf_index = index;
@@ -48,6 +50,7 @@ static void volcano_buttons(enum buttons btn, bool state) {
48 50
     if (state && (btn == BTN_Y)) {
49 51
         if ((!wait_for_connect) && (!wait_for_disconnect)) {
50 52
             debug("workflow abort");
53
+            aborted = true;
51 54
             wf_reset();
52 55
             volcano_set_pump_state(false);
53 56
             volcano_set_heater_state(false);
@@ -64,6 +67,8 @@ void state_volcano_run_enter(void) {
64 67
     debug("workflow connect");
65 68
     ble_connect(ble_addr, ble_type);
66 69
     wait_for_connect = true;
70
+
71
+    aborted = false;
67 72
 }
68 73
 
69 74
 void state_volcano_run_exit(void) {
@@ -104,15 +109,18 @@ static void draw(struct menu_state *menu) {
104 109
 }
105 110
 
106 111
 void state_volcano_run_run(void) {
112
+    // start workflow when connected
107 113
     if (wait_for_connect && ble_is_connected()) {
108 114
         wait_for_connect = false;
109 115
         debug("workflow start");
110 116
         wf_start(wf_index);
111 117
     }
112 118
 
119
+    // visualize workflow status
113 120
     menu_run(draw);
114 121
 
115
-    if (!wait_for_connect) {
122
+    // auto disconnect when end of workflow is reached
123
+    if ((!wait_for_connect) && (!aborted)) {
116 124
         struct wf_state state = wf_status();
117 125
         if (state.status == WF_IDLE) {
118 126
             debug("workflow disconnect");
@@ -121,6 +129,7 @@ void state_volcano_run_run(void) {
121 129
         }
122 130
     }
123 131
 
132
+    // back to main menu when disconnected
124 133
     if (wait_for_disconnect && !ble_is_connected()) {
125 134
         wait_for_disconnect = false;
126 135
         debug("workflow done");

Loading…
Cancel
Save