|
@@ -0,0 +1,261 @@
|
|
1
|
+/*
|
|
2
|
+ * workflow.c
|
|
3
|
+ *
|
|
4
|
+ * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
|
|
5
|
+ *
|
|
6
|
+ * This program is free software: you can redistribute it and/or modify
|
|
7
|
+ * it under the terms of the GNU General Public License as published by
|
|
8
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+ * (at your option) any later version.
|
|
10
|
+ *
|
|
11
|
+ * This program is distributed in the hope that it will be useful,
|
|
12
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+ * GNU General Public License for more details.
|
|
15
|
+ *
|
|
16
|
+ * See <http://www.gnu.org/licenses/>.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+#include "config.h"
|
|
20
|
+#include "log.h"
|
|
21
|
+#include "volcano.h"
|
|
22
|
+#include "workflow.h"
|
|
23
|
+
|
|
24
|
+#define WF_MAX_STEPS 32
|
|
25
|
+#define WF_MAX_FLOWS 5
|
|
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 {
|
|
40
|
+ const char *name;
|
|
41
|
+ struct wf_step steps[WF_MAX_STEPS];
|
|
42
|
+ uint16_t count;
|
|
43
|
+};
|
|
44
|
+
|
|
45
|
+static const struct workflow wf[WF_MAX_FLOWS] = {
|
|
46
|
+ {
|
|
47
|
+ .name = "Default",
|
|
48
|
+ .steps = {
|
|
49
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 1850 },
|
|
50
|
+ { .op = OP_WAIT_TIME, .val = 15000 },
|
|
51
|
+ { .op = OP_PUMP_TIME, .val = 5000 },
|
|
52
|
+
|
|
53
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 1950 },
|
|
54
|
+ { .op = OP_WAIT_TIME, .val = 10000 },
|
|
55
|
+ { .op = OP_PUMP_TIME, .val = 20000 },
|
|
56
|
+
|
|
57
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 2050 },
|
|
58
|
+ { .op = OP_WAIT_TIME, .val = 10000 },
|
|
59
|
+ { .op = OP_PUMP_TIME, .val = 20000 },
|
|
60
|
+
|
|
61
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
62
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
63
|
+
|
|
64
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
65
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
66
|
+
|
|
67
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
68
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
69
|
+
|
|
70
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
71
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
72
|
+
|
|
73
|
+ { .op = OP_SET_TEMPERATURE, .val = 1900 },
|
|
74
|
+ },
|
|
75
|
+ .count = 18,
|
|
76
|
+ }, {
|
|
77
|
+ .name = "Relaxo",
|
|
78
|
+ .steps = {
|
|
79
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 1750 },
|
|
80
|
+ { .op = OP_WAIT_TIME, .val = 15000 },
|
|
81
|
+ { .op = OP_PUMP_TIME, .val = 5000 },
|
|
82
|
+
|
|
83
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 1850 },
|
|
84
|
+ { .op = OP_WAIT_TIME, .val = 10000 },
|
|
85
|
+ { .op = OP_PUMP_TIME, .val = 20000 },
|
|
86
|
+
|
|
87
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 1950 },
|
|
88
|
+ { .op = OP_WAIT_TIME, .val = 10000 },
|
|
89
|
+ { .op = OP_PUMP_TIME, .val = 20000 },
|
|
90
|
+
|
|
91
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
92
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
93
|
+
|
|
94
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
95
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
96
|
+
|
|
97
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
98
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
99
|
+
|
|
100
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
101
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
102
|
+
|
|
103
|
+ { .op = OP_SET_TEMPERATURE, .val = 1900 },
|
|
104
|
+ },
|
|
105
|
+ .count = 18,
|
|
106
|
+ }, {
|
|
107
|
+ .name = "Hardcore",
|
|
108
|
+ .steps = {
|
|
109
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 1900 },
|
|
110
|
+ { .op = OP_WAIT_TIME, .val = 15000 },
|
|
111
|
+ { .op = OP_PUMP_TIME, .val = 5000 },
|
|
112
|
+
|
|
113
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 2050 },
|
|
114
|
+ { .op = OP_WAIT_TIME, .val = 10000 },
|
|
115
|
+ { .op = OP_PUMP_TIME, .val = 20000 },
|
|
116
|
+
|
|
117
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 2200 },
|
|
118
|
+ { .op = OP_WAIT_TIME, .val = 10000 },
|
|
119
|
+ { .op = OP_PUMP_TIME, .val = 20000 },
|
|
120
|
+
|
|
121
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
122
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
123
|
+
|
|
124
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
125
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
126
|
+
|
|
127
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
128
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
129
|
+
|
|
130
|
+ { .op = OP_PUMP_TIME, .val = 1000 },
|
|
131
|
+ { .op = OP_WAIT_TIME, .val = 1000 },
|
|
132
|
+
|
|
133
|
+ { .op = OP_SET_TEMPERATURE, .val = 1900 },
|
|
134
|
+ },
|
|
135
|
+ .count = 18,
|
|
136
|
+ }, {
|
|
137
|
+ .name = "Vorbi",
|
|
138
|
+ .steps = {
|
|
139
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 1760 },
|
|
140
|
+ { .op = OP_WAIT_TIME, .val = 10000 },
|
|
141
|
+ { .op = OP_PUMP_TIME, .val = 6000 },
|
|
142
|
+
|
|
143
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 1870 },
|
|
144
|
+ { .op = OP_WAIT_TIME, .val = 5000 },
|
|
145
|
+ { .op = OP_PUMP_TIME, .val = 10000 },
|
|
146
|
+
|
|
147
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 2040 },
|
|
148
|
+ { .op = OP_WAIT_TIME, .val = 3000 },
|
|
149
|
+ { .op = OP_PUMP_TIME, .val = 10000 },
|
|
150
|
+
|
|
151
|
+ { .op = OP_WAIT_TEMPERATURE, .val = 2170 },
|
|
152
|
+ { .op = OP_WAIT_TIME, .val = 5000 },
|
|
153
|
+ { .op = OP_PUMP_TIME, .val = 10000 },
|
|
154
|
+ },
|
|
155
|
+ .count = 12,
|
|
156
|
+ },
|
|
157
|
+};
|
|
158
|
+
|
|
159
|
+static const uint16_t count = 4;
|
|
160
|
+
|
|
161
|
+static enum wf_status status = WF_IDLE;
|
|
162
|
+static uint16_t wf_i = 0;
|
|
163
|
+static uint16_t step = 0;
|
|
164
|
+static uint32_t start_t = 0;
|
|
165
|
+
|
|
166
|
+static void do_step(void) {
|
|
167
|
+ switch (wf[wf_i].steps[step].op) {
|
|
168
|
+ case OP_SET_TEMPERATURE:
|
|
169
|
+ case OP_WAIT_TEMPERATURE:
|
|
170
|
+ debug("workflow temp %.1f C", wf[wf_i].steps[step].val / 10.0);
|
|
171
|
+ volcano_set_target_temp(wf[wf_i].steps[step].val);
|
|
172
|
+ break;
|
|
173
|
+
|
|
174
|
+ case OP_PUMP_TIME:
|
|
175
|
+ volcano_set_pump_state(true);
|
|
176
|
+ __attribute__((fallthrough));
|
|
177
|
+
|
|
178
|
+ case OP_WAIT_TIME:
|
|
179
|
+ start_t = to_ms_since_boot(get_absolute_time());
|
|
180
|
+ debug("workflow time %.3f s", wf[wf_i].steps[step].val / 1000.0);
|
|
181
|
+ break;
|
|
182
|
+ }
|
|
183
|
+}
|
|
184
|
+
|
|
185
|
+uint16_t wf_count(void) {
|
|
186
|
+ return count;
|
|
187
|
+}
|
|
188
|
+
|
|
189
|
+const char *wf_name(uint16_t index) {
|
|
190
|
+ if (index >= count) {
|
|
191
|
+ debug("invalid index %d", index);
|
|
192
|
+ return NULL;
|
|
193
|
+ }
|
|
194
|
+ return wf[index].name;
|
|
195
|
+}
|
|
196
|
+
|
|
197
|
+enum wf_status wf_status(void) {
|
|
198
|
+ return status;
|
|
199
|
+}
|
|
200
|
+
|
|
201
|
+void wf_start(uint16_t index) {
|
|
202
|
+ if (status != WF_IDLE) {
|
|
203
|
+ debug("workflow already running");
|
|
204
|
+ return;
|
|
205
|
+ }
|
|
206
|
+ if (index >= count) {
|
|
207
|
+ debug("invalid index %d", index);
|
|
208
|
+ return;
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ status = WF_RUNNING;
|
|
212
|
+ wf_i = index;
|
|
213
|
+ step = 0;
|
|
214
|
+
|
|
215
|
+ // discover characteristics
|
|
216
|
+ volcano_set_pump_state(false);
|
|
217
|
+ volcano_set_heater_state(false);
|
|
218
|
+ volcano_set_target_temp(1850);
|
|
219
|
+
|
|
220
|
+ volcano_set_heater_state(true);
|
|
221
|
+
|
|
222
|
+ do_step();
|
|
223
|
+}
|
|
224
|
+
|
|
225
|
+void wf_run(void) {
|
|
226
|
+ if (status == WF_IDLE) {
|
|
227
|
+ return;
|
|
228
|
+ }
|
|
229
|
+
|
|
230
|
+ bool done = false;
|
|
231
|
+
|
|
232
|
+ switch (wf[wf_i].steps[step].op) {
|
|
233
|
+ case OP_SET_TEMPERATURE:
|
|
234
|
+ done = true;
|
|
235
|
+ break;
|
|
236
|
+
|
|
237
|
+ case OP_WAIT_TEMPERATURE:
|
|
238
|
+ done = (volcano_get_current_temp() >= (wf[wf_i].steps[step].val - 5));
|
|
239
|
+ break;
|
|
240
|
+
|
|
241
|
+ case OP_PUMP_TIME:
|
|
242
|
+ case OP_WAIT_TIME:
|
|
243
|
+ done = ((to_ms_since_boot(get_absolute_time()) - start_t) >= wf[wf_i].steps[step].val);
|
|
244
|
+ break;
|
|
245
|
+ }
|
|
246
|
+
|
|
247
|
+ if (done) {
|
|
248
|
+ if (wf[wf_i].steps[step].op == OP_PUMP_TIME) {
|
|
249
|
+ volcano_set_pump_state(false);
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+ step++;
|
|
253
|
+ if (step >= wf[wf_i].count) {
|
|
254
|
+ status = WF_IDLE;
|
|
255
|
+ volcano_set_heater_state(false);
|
|
256
|
+ debug("workflow finished");
|
|
257
|
+ } else {
|
|
258
|
+ do_step();
|
|
259
|
+ }
|
|
260
|
+ }
|
|
261
|
+}
|