Browse Source

print current value in workflow

Thomas Buck 3 months ago
parent
commit
965cf087d8
3 changed files with 37 additions and 12 deletions
  1. 1
    0
      include/workflow.h
  2. 16
    8
      src/state_volcano_run.c
  3. 20
    4
      src/workflow.c

+ 1
- 0
include/workflow.h View File

@@ -44,6 +44,7 @@ struct wf_state {
44 44
     uint16_t index;
45 45
     uint16_t count;
46 46
     struct wf_step step;
47
+    uint16_t start_val, curr_val;
47 48
 };
48 49
 
49 50
 uint16_t wf_count(void);

+ 16
- 8
src/state_volcano_run.c View File

@@ -81,27 +81,35 @@ static void draw(struct menu_state *menu) {
81 81
 
82 82
     int pos = 0;
83 83
     pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
84
-                    "step %d / %d\n\n", state.index, state.count);
84
+                    "step %d / %d\n", state.index, state.count);
85 85
 
86 86
     switch (state.step.op) {
87 87
     case OP_SET_TEMPERATURE:
88 88
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
89
-                        "set temp %.1f C", state.step.val / 10.0f);
89
+                        "\nset temp %.1f C", state.step.val / 10.0f);
90 90
         break;
91 91
 
92 92
     case OP_WAIT_TEMPERATURE:
93 93
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
94
-                        "wait temp %.1f C", state.step.val / 10.0f);
95
-        break;
96
-
97
-    case OP_WAIT_TIME:
94
+                        "wait temp %.1f C\n", state.step.val / 10.0f);
98 95
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
99
-                        "wait time %.1f s", state.step.val / 1000.0f);
96
+                        "%.1f -> %.1f -> %.1f",
97
+                        state.start_val / 10.0f,
98
+                        state.curr_val / 10.0f,
99
+                        state.step.val / 10.0f);
100 100
         break;
101 101
 
102
+    case OP_WAIT_TIME:
102 103
     case OP_PUMP_TIME:
103 104
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
104
-                        "pump time %.1f s", state.step.val / 1000.0f);
105
+                        "%s time %.1f s\n",
106
+                        (state.step.op == OP_WAIT_TIME) ? "wait" : "pump",
107
+                        state.step.val / 1000.0f);
108
+        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
109
+                        "%.1f -> %.1f -> %.1f",
110
+                        state.start_val / 1000.0f,
111
+                        state.curr_val / 1000.0f,
112
+                        state.step.val / 1000.0f);
105 113
         break;
106 114
     }
107 115
 

+ 20
- 4
src/workflow.c View File

@@ -129,26 +129,33 @@ static enum wf_status status = WF_IDLE;
129 129
 static uint16_t wf_i = 0;
130 130
 static uint16_t step = 0;
131 131
 static uint32_t start_t = 0;
132
+static uint16_t start_val = 0;
133
+static uint16_t curr_val = 0;
132 134
 
133 135
 static void do_step(void) {
134 136
     switch (wf[wf_i].steps[step].op) {
135 137
     case OP_SET_TEMPERATURE:
136 138
     case OP_WAIT_TEMPERATURE:
137 139
         debug("workflow temp %.1f C", wf[wf_i].steps[step].val / 10.0);
140
+        start_val = volcano_get_current_temp();
138 141
         volcano_set_target_temp(wf[wf_i].steps[step].val);
139 142
         break;
140 143
 
141 144
     case OP_PUMP_TIME:
142 145
         volcano_set_pump_state(true);
143 146
         start_t = to_ms_since_boot(get_absolute_time());
147
+        start_val = 0;
144 148
         debug("workflow pump %.3f s", wf[wf_i].steps[step].val / 1000.0);
145 149
         break;
146 150
 
147 151
     case OP_WAIT_TIME:
148 152
         start_t = to_ms_since_boot(get_absolute_time());
153
+        start_val = 0;
149 154
         debug("workflow time %.3f s", wf[wf_i].steps[step].val / 1000.0);
150 155
         break;
151 156
     }
157
+
158
+    curr_val = start_val;
152 159
 }
153 160
 
154 161
 uint16_t wf_count(void) {
@@ -177,6 +184,8 @@ struct wf_state wf_status(void) {
177 184
         .index = step,
178 185
         .count = wf[wf_i].count,
179 186
         .step = wf[wf_i].steps[step],
187
+        .start_val = start_val,
188
+        .curr_val = curr_val,
180 189
     };
181 190
     return s;
182 191
 }
@@ -221,15 +230,22 @@ void wf_run(void) {
221 230
         done = true;
222 231
         break;
223 232
 
224
-    case OP_WAIT_TEMPERATURE:
225
-        done = (volcano_get_current_temp() >= (wf[wf_i].steps[step].val - 5));
233
+    case OP_WAIT_TEMPERATURE: {
234
+        uint16_t temp = volcano_get_current_temp();
235
+        curr_val = temp;
236
+        done = (temp >= (wf[wf_i].steps[step].val - 5));
226 237
         break;
238
+    }
227 239
 
228 240
     case OP_PUMP_TIME:
229
-    case OP_WAIT_TIME:
230
-        done = ((to_ms_since_boot(get_absolute_time()) - start_t) >= wf[wf_i].steps[step].val);
241
+    case OP_WAIT_TIME: {
242
+        uint32_t now = to_ms_since_boot(get_absolute_time());
243
+        uint32_t diff = now - start_t;
244
+        curr_val = diff;
245
+        done = (diff >= wf[wf_i].steps[step].val);
231 246
         break;
232 247
     }
248
+    }
233 249
 
234 250
     if (done) {
235 251
         if (wf[wf_i].steps[step].op == OP_PUMP_TIME) {

Loading…
Cancel
Save