Browse Source

print workflow step and allow aborting

Thomas Buck 1 year ago
parent
commit
33773f52d6
3 changed files with 62 additions and 15 deletions
  1. 14
    1
      include/workflow.h
  2. 46
    1
      src/state_volcano_run.c
  3. 2
    13
      src/workflow.c

+ 14
- 1
include/workflow.h View File

@@ -21,6 +21,18 @@
21 21
 
22 22
 #include <stdint.h>
23 23
 
24
+enum wf_op {
25
+    OP_SET_TEMPERATURE = 0,
26
+    OP_WAIT_TEMPERATURE,
27
+    OP_WAIT_TIME,
28
+    OP_PUMP_TIME,
29
+};
30
+
31
+struct wf_step {
32
+    enum wf_op op;
33
+    uint16_t val;
34
+};
35
+
24 36
 enum wf_status {
25 37
     WF_IDLE = 0,
26 38
     WF_RUNNING,
@@ -29,8 +41,9 @@ enum wf_status {
29 41
 struct wf_state {
30 42
     enum wf_status status;
31 43
 
32
-    uint16_t step;
44
+    uint16_t index;
33 45
     uint16_t count;
46
+    struct wf_step step;
34 47
 };
35 48
 
36 49
 uint16_t wf_count(void);

+ 46
- 1
src/state_volcano_run.c View File

@@ -20,7 +20,9 @@
20 20
 #include <string.h>
21 21
 
22 22
 #include "config.h"
23
+#include "buttons.h"
23 24
 #include "log.h"
25
+#include "volcano.h"
24 26
 #include "workflow.h"
25 27
 #include "state.h"
26 28
 #include "state_volcano_run.h"
@@ -42,19 +44,62 @@ void state_volcano_run_target(bd_addr_t addr, bd_addr_type_t type) {
42 44
     ble_type = type;
43 45
 }
44 46
 
47
+static void volcano_buttons(enum buttons btn, bool state) {
48
+    if (state && (btn == BTN_Y)) {
49
+        if ((!wait_for_connect) && (!wait_for_disconnect)) {
50
+            debug("workflow abort");
51
+            wf_reset();
52
+            volcano_set_pump_state(false);
53
+            volcano_set_heater_state(false);
54
+            ble_disconnect();
55
+            wait_for_disconnect = true;
56
+        }
57
+    }
58
+}
59
+
45 60
 void state_volcano_run_enter(void) {
61
+    menu_init(NULL, NULL);
62
+    buttons_callback(volcano_buttons);
63
+
46 64
     debug("workflow connect");
47 65
     ble_connect(ble_addr, ble_type);
48 66
     wait_for_connect = true;
49 67
 }
50 68
 
51 69
 void state_volcano_run_exit(void) {
70
+    menu_deinit();
52 71
     wf_reset();
53 72
 }
54 73
 
55 74
 static void draw(struct menu_state *menu) {
56 75
     struct wf_state state = wf_status();
57
-    snprintf(menu->buff, MENU_MAX_LEN, "%d / %d", state.step, state.count);
76
+
77
+    int pos = 0;
78
+    pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
79
+                    "step %d / %d\n\n", state.index, state.count);
80
+
81
+    switch (state.step.op) {
82
+    case OP_SET_TEMPERATURE:
83
+        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
84
+                        "set temp %.1f C", state.step.val / 10.0f);
85
+        break;
86
+
87
+    case OP_WAIT_TEMPERATURE:
88
+        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
89
+                        "wait temp %.1f C", state.step.val / 10.0f);
90
+        break;
91
+
92
+    case OP_WAIT_TIME:
93
+        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
94
+                        "wait time %.1f s", state.step.val / 1000.0f);
95
+        break;
96
+
97
+    case OP_PUMP_TIME:
98
+        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
99
+                        "pump time %.1f s", state.step.val / 1000.0f);
100
+        break;
101
+    }
102
+
58 103
     // TODO visualize
59 104
 }
60 105
 

+ 2
- 13
src/workflow.c View File

@@ -24,18 +24,6 @@
24 24
 #define WF_MAX_STEPS 42
25 25
 #define WF_MAX_FLOWS 6
26 26
 
27
-enum wf_op {
28
-    OP_SET_TEMPERATURE = 0,
29
-    OP_WAIT_TEMPERATURE,
30
-    OP_WAIT_TIME,
31
-    OP_PUMP_TIME,
32
-};
33
-
34
-struct wf_step {
35
-    enum wf_op op;
36
-    uint16_t val;
37
-};
38
-
39 27
 struct workflow {
40 28
     const char *name;
41 29
     const char *author;
@@ -186,8 +174,9 @@ const char *wf_author(uint16_t index) {
186 174
 struct wf_state wf_status(void) {
187 175
     struct wf_state s = {
188 176
         .status = status,
189
-        .step = step,
177
+        .index = step,
190 178
         .count = wf[wf_i].count,
179
+        .step = wf[wf_i].steps[step],
191 180
     };
192 181
     return s;
193 182
 }

Loading…
Cancel
Save