Sat, 29 Jun 2024 13:33:57 +0200
Added some conditional version tests
0 | 1 | /** |
2 | * @file manual.c | |
3 | * @brief Manual control functions. | |
4 | */ | |
5 | ||
6 | #include "config.h" | |
7 | ||
8 | bool _ManualHLT = false; ///< Use Hot Liquer Tank | |
9 | bool _ManualMLT = false; ///< Use Mash/Boil kettle | |
10 | ||
129 | 11 | extern my_runtime_t runtime; |
12 | extern my_equipment_t equipment; | |
13 | ||
0 | 14 | extern sButton Buttons[MAXBUTTONS]; |
15 | extern int Main_Screen; | |
16 | extern DS18B20_State *ds18b20_state; | |
17 | extern DRIVER_State *driver_state; | |
18 | extern SemaphoreHandle_t xSemaphoreDS18B20; | |
19 | extern SemaphoreHandle_t xSemaphoreDriver; | |
20 | ||
21 | #ifdef CONFIG_TEMP_SENSORS_SIMULATOR | |
22 | extern float Fake_MLT; | |
23 | extern float Fake_HLT; | |
24 | #endif | |
25 | ||
26 | static const char *TAG = "manual"; | |
27 | ||
28 | ||
29 | /* | |
30 | * Manual init function that only runs once a new screen | |
31 | * is entered. | |
32 | */ | |
33 | bool Manual_Init(void) | |
34 | { | |
35 | switch (Main_Screen) { | |
36 | case MAIN_MANUAL_INIT: | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
37 | log_msg(TAG, "Start manual mode"); |
0 | 38 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { |
39 | driver_state->enable = true; | |
40 | xSemaphoreGive(xSemaphoreDriver); | |
41 | } | |
42 | break; | |
43 | ||
44 | case MAIN_MANUAL_MAIN: | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
45 | TopMessage((char *)"Handbediening"); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
46 | Buttons_Add( 5, 200, 60, 40, (char *)"Stop", 0); |
0 | 47 | Buttons[0].dark = true; |
48 | uint8_t i = 1; | |
49 | if (_ManualMLT) { | |
50 | MLT_info(71, 26, false); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
51 | Buttons_Add( 5, 26, 60, 40, (char *)"+sp" , i++); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
52 | Buttons_Add(255, 26, 60, 40, (char *)"-sp" , i++); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
53 | Buttons_Add( 5, 76, 60, 40, (char *)"Pomp" , i++); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
54 | Buttons_Add(255, 76, 60, 40, (char *)"Aan" , i++); |
0 | 55 | } |
56 | if (_ManualHLT) { | |
57 | HLT_info(71,150, false, false); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
58 | Buttons_Add( 5, 150, 60, 40, (char *)"+sp" , i++); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
59 | Buttons_Add(255, 150, 60, 40, (char *)"-sp" , i++); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
60 | Buttons_Add(255, 200, 60, 40, (char *)"Aan" , i); |
0 | 61 | } |
62 | Buttons_Show(); | |
63 | break; | |
64 | ||
65 | default: | |
66 | break; | |
67 | } | |
68 | ||
69 | return false; | |
70 | } | |
71 | ||
72 | ||
73 | ||
74 | /* | |
75 | * Manual loop screens, non-blocking. | |
76 | */ | |
77 | bool Manual_Loop(void) | |
78 | { | |
136
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
79 | bool loop; |
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
80 | |
0 | 81 | switch (Main_Screen) { |
82 | case MAIN_MANUAL_INIT: | |
83 | _ManualHLT = _ManualMLT = false; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
84 | Buttons_Add( 40, 100, 80, 40, (char *)"Ja", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
85 | Buttons_Add(200, 100, 80, 40, (char *)"Nee", 1); |
0 | 86 | Buttons_Show(); |
87 | ||
88 | if ((equipment.SSR2 == SSR2_HLT_SHARE) || (equipment.SSR2 == SSR2_HLT_IND)) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
89 | TopMessage((char *)"Spoelwater ketel?"); |
0 | 90 | SoundPlay(SOUND_Prompt); |
91 | loop = true; | |
92 | while (loop) { | |
93 | switch (Buttons_Scan()) { | |
94 | case 0: loop = false; | |
95 | _ManualHLT = true; | |
96 | break; | |
97 | ||
98 | case 1: loop = false; | |
99 | _ManualHLT = false; | |
100 | break; | |
101 | ||
102 | default: break; | |
103 | } | |
104 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
105 | } | |
106 | } | |
107 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
108 | TopMessage((char *)"Maisch/Kook ketel?"); |
0 | 109 | SoundPlay(SOUND_Prompt); |
110 | loop = true; | |
111 | while (loop) { | |
112 | switch (Buttons_Scan()) { | |
113 | case 0: loop = false; | |
114 | _ManualMLT = true; | |
115 | break; | |
116 | ||
117 | case 1: loop = false; | |
118 | _ManualMLT = false; | |
119 | break; | |
120 | ||
121 | default: break; | |
122 | } | |
123 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
124 | } | |
125 | Buttons_Clear(); | |
126 | ||
127 | if (! _ManualHLT && ! _ManualMLT) { | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
128 | log_msg(TAG, "End manual mode"); |
0 | 129 | Main_Screen = MAIN_MODE_FREE; |
130 | break; | |
131 | } | |
132 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
133 | /* Set them all, even if not in use now. */ | |
134 | driver_state->hlt_sp = runtime.ManualHLT; | |
135 | driver_state->mlt_sp = runtime.ManualMLT; | |
136 | xSemaphoreGive(xSemaphoreDriver); | |
137 | } | |
89
fa44bd094e01
Added power usage counters to manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
138 | runtime.MLT_usage = 0; |
fa44bd094e01
Added power usage counters to manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
139 | runtime.HLT_usage = 0; |
fa44bd094e01
Added power usage counters to manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
140 | write_runtime(); |
fa44bd094e01
Added power usage counters to manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
141 | |
0 | 142 | if (_ManualHLT) { |
143 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
144 | driver_state->hlt_mode = HLT_MODE_OFF; | |
145 | xSemaphoreGive(xSemaphoreDriver); | |
146 | } | |
147 | } | |
148 | if (_ManualMLT) { | |
149 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
150 | driver_state->mlt_mode = MLT_MODE_OFF; | |
151 | xSemaphoreGive(xSemaphoreDriver); | |
152 | } | |
153 | } | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
154 | log_msg(TAG, "HLT:%s MLT:%s", (_ManualHLT)?"true":"false", (_ManualMLT)?"true":"false"); |
0 | 155 | Main_Screen = MAIN_MANUAL_MAIN; |
156 | break; | |
157 | ||
158 | case MAIN_MANUAL_MAIN: | |
159 | if (_ManualMLT) { | |
160 | MLT_info(71, 26, true); | |
161 | } | |
162 | if (_ManualHLT) { | |
163 | HLT_info(71, 150, true, false); | |
164 | } | |
165 | switch (Buttons_Scan()) { | |
166 | case 0: Main_Screen = MAIN_MODE_FREE; | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
167 | log_msg(TAG, "End manual mode"); |
0 | 168 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { |
169 | runtime.ManualHLT = driver_state->hlt_sp; | |
170 | runtime.ManualMLT = driver_state->mlt_sp; | |
171 | driver_state->enable = false; | |
172 | driver_state->mlt_mode = MLT_MODE_NONE; | |
173 | driver_state->mlt_sp = 0.0; | |
174 | driver_state->hlt_mode = HLT_MODE_NONE; | |
175 | driver_state->hlt_sp = 0.0; | |
176 | driver_state->pump_run = 0; | |
177 | xSemaphoreGive(xSemaphoreDriver); | |
178 | } | |
89
fa44bd094e01
Added power usage counters to manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
179 | double mwu = (runtime.MLT_usage / 1000.0 / 60.0 / 60.0) * equipment.MLT_watt / 1000.0; |
fa44bd094e01
Added power usage counters to manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
180 | double hwu = (runtime.HLT_usage / 1000.0 / 60.0 / 60.0) * equipment.HLT_watt / 1000.0; |
fa44bd094e01
Added power usage counters to manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
181 | log_msg(TAG, "MLT usage %.3f KWh, HLT usage %.3f KWh, total %.3f KWh", mwu, hwu, mwu + hwu); |
0 | 182 | write_runtime(); |
183 | break; | |
184 | ||
185 | case 1: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
186 | if (_ManualMLT) { | |
187 | driver_state->mlt_sp += 0.25; | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
188 | log_msg(TAG, "MLT sp %.2f", driver_state->mlt_sp); |
0 | 189 | } else { |
190 | driver_state->hlt_sp += 0.25; | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
191 | log_msg(TAG, "HLT sp %.2f", driver_state->hlt_sp); |
0 | 192 | } |
193 | xSemaphoreGive(xSemaphoreDriver); | |
194 | } | |
195 | break; | |
196 | ||
197 | case 2: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
198 | if (_ManualMLT) { | |
199 | driver_state->mlt_sp -= 0.25; | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
200 | log_msg(TAG, "MLT sp %.2f", driver_state->mlt_sp); |
0 | 201 | } else { |
202 | driver_state->hlt_sp -= 0.25; | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
203 | log_msg(TAG, "HLT sp %.2f", driver_state->hlt_sp); |
0 | 204 | } |
205 | xSemaphoreGive(xSemaphoreDriver); | |
206 | } | |
207 | break; | |
208 | ||
209 | case 3: if (_ManualMLT) { | |
210 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
211 | if (driver_state->pump_run) | |
212 | driver_state->pump_run = 0; | |
213 | else | |
214 | driver_state->pump_run = 1; | |
215 | xSemaphoreGive(xSemaphoreDriver); | |
216 | } | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
217 | log_msg(TAG, "Pump turned %s", driver_state->pump_run?"on":"off"); |
0 | 218 | } else { |
219 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
220 | if (driver_state->hlt_mode == HLT_MODE_BANG) { | |
221 | driver_state->hlt_mode = HLT_MODE_OFF; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
222 | Buttons_Add(255, 200, 60, 40, (char *)"Aan" , 3); |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
223 | log_msg(TAG, "HLT turned off"); |
0 | 224 | } else { |
225 | driver_state->hlt_mode = HLT_MODE_BANG; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
226 | Buttons_Add(255, 200, 60, 40, (char *)"Uit" , 3); |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
227 | log_msg(TAG, "HLT turned on sp %.2f", driver_state->hlt_sp); |
0 | 228 | } |
229 | xSemaphoreGive(xSemaphoreDriver); | |
230 | } | |
231 | Buttons_Show(); | |
232 | } | |
233 | break; | |
234 | ||
235 | case 4: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
236 | if (driver_state->mlt_mode == MLT_MODE_PID) { | |
237 | driver_state->mlt_mode = MLT_MODE_OFF; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
238 | Buttons_Add(255, 76, 60, 40, (char *)"Aan" , 4); |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
239 | log_msg(TAG, "MLT turned off"); |
0 | 240 | } else { |
241 | driver_state->mlt_mode = MLT_MODE_PID; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
242 | Buttons_Add(255, 76, 60, 40, (char *)"Uit" , 4); |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
243 | log_msg(TAG, "MLT turned on sp %.2f", driver_state->mlt_sp); |
0 | 244 | } |
245 | xSemaphoreGive(xSemaphoreDriver); | |
246 | } | |
247 | Buttons_Show(); | |
248 | break; | |
249 | ||
250 | case 5: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
251 | driver_state->hlt_sp += 0.25; | |
252 | xSemaphoreGive(xSemaphoreDriver); | |
253 | } | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
254 | log_msg(TAG, "HLT sp %.2f", driver_state->hlt_sp); |
0 | 255 | break; |
256 | ||
257 | case 6: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
258 | driver_state->hlt_sp -= 0.25; | |
259 | xSemaphoreGive(xSemaphoreDriver); | |
260 | } | |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
261 | log_msg(TAG, "HLT sp %.2f", driver_state->hlt_sp); |
0 | 262 | break; |
263 | ||
264 | case 7: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
265 | if (driver_state->hlt_mode == HLT_MODE_BANG) { | |
266 | driver_state->hlt_mode = HLT_MODE_OFF; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
267 | Buttons_Add(255, 200, 60, 40, (char *)"Aan" , 7); |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
268 | log_msg(TAG, "HLT turned off"); |
0 | 269 | } else { |
270 | driver_state->hlt_mode = HLT_MODE_BANG; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
271 | Buttons_Add(255, 200, 60, 40, (char *)"Uit" , 7); |
62
2e90ada37476
Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
272 | log_msg(TAG, "HLT turned on %.2f", driver_state->hlt_sp); |
0 | 273 | } |
274 | xSemaphoreGive(xSemaphoreDriver); | |
275 | } | |
276 | Buttons_Show(); | |
277 | break; | |
278 | ||
279 | default: break; | |
280 | } | |
281 | break; | |
282 | ||
283 | default: | |
284 | break; | |
285 | } | |
286 | ||
287 | return false; | |
288 | } | |
289 |