Browse Source

only call disconnect once when aborting workflow

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

Loading…
Cancel
Save