Browse Source

print workflow step and allow aborting

Thomas Buck 11 months 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
 
21
 
22
 #include <stdint.h>
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
 enum wf_status {
36
 enum wf_status {
25
     WF_IDLE = 0,
37
     WF_IDLE = 0,
26
     WF_RUNNING,
38
     WF_RUNNING,
29
 struct wf_state {
41
 struct wf_state {
30
     enum wf_status status;
42
     enum wf_status status;
31
 
43
 
32
-    uint16_t step;
44
+    uint16_t index;
33
     uint16_t count;
45
     uint16_t count;
46
+    struct wf_step step;
34
 };
47
 };
35
 
48
 
36
 uint16_t wf_count(void);
49
 uint16_t wf_count(void);

+ 46
- 1
src/state_volcano_run.c View File

20
 #include <string.h>
20
 #include <string.h>
21
 
21
 
22
 #include "config.h"
22
 #include "config.h"
23
+#include "buttons.h"
23
 #include "log.h"
24
 #include "log.h"
25
+#include "volcano.h"
24
 #include "workflow.h"
26
 #include "workflow.h"
25
 #include "state.h"
27
 #include "state.h"
26
 #include "state_volcano_run.h"
28
 #include "state_volcano_run.h"
42
     ble_type = type;
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
 void state_volcano_run_enter(void) {
60
 void state_volcano_run_enter(void) {
61
+    menu_init(NULL, NULL);
62
+    buttons_callback(volcano_buttons);
63
+
46
     debug("workflow connect");
64
     debug("workflow connect");
47
     ble_connect(ble_addr, ble_type);
65
     ble_connect(ble_addr, ble_type);
48
     wait_for_connect = true;
66
     wait_for_connect = true;
49
 }
67
 }
50
 
68
 
51
 void state_volcano_run_exit(void) {
69
 void state_volcano_run_exit(void) {
70
+    menu_deinit();
52
     wf_reset();
71
     wf_reset();
53
 }
72
 }
54
 
73
 
55
 static void draw(struct menu_state *menu) {
74
 static void draw(struct menu_state *menu) {
56
     struct wf_state state = wf_status();
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
     // TODO visualize
103
     // TODO visualize
59
 }
104
 }
60
 
105
 

+ 2
- 13
src/workflow.c View File

24
 #define WF_MAX_STEPS 42
24
 #define WF_MAX_STEPS 42
25
 #define WF_MAX_FLOWS 6
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
 struct workflow {
27
 struct workflow {
40
     const char *name;
28
     const char *name;
41
     const char *author;
29
     const char *author;
186
 struct wf_state wf_status(void) {
174
 struct wf_state wf_status(void) {
187
     struct wf_state s = {
175
     struct wf_state s = {
188
         .status = status,
176
         .status = status,
189
-        .step = step,
177
+        .index = step,
190
         .count = wf[wf_i].count,
178
         .count = wf[wf_i].count,
179
+        .step = wf[wf_i].steps[step],
191
     };
180
     };
192
     return s;
181
     return s;
193
 }
182
 }

Loading…
Cancel
Save