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