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