Mon, 01 Jul 2019 23:15:49 +0200
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
0 | 1 | /** |
2 | * @file automation.c | |
3 | * @brief Automation functions. | |
4 | */ | |
5 | ||
6 | #include "config.h" | |
7 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
8 | int BoilPower = 100; ///< Boil power 0..100% |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
9 | int LastMashStep = 0; ///< Last valid mash step |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
10 | char temp_buf[64]; ///< Temporary buffer |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
11 | char logline[128]; ///< Log line buffer |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
12 | char strftime_buf[64]; ///< Time buffer |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
13 | bool loop; ///< Loop flag |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
14 | bool CoolBeep = false; ///< Did beep during cooling |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
15 | bool Resume = false; ///< Resume brew flag |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
16 | bool pumpRest = false; ///< Pump is resting |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
17 | bool updateRuntime = false; ///< Update runtime record |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
18 | bool NewMinute = false; ///< We have a new minute |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
19 | bool TempReached = false; ///< Temperature is reached |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
20 | uint8_t MashState = MASH_NONE; ///< Mash states |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
21 | float temp_MLT; ///< MLT temperature |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
22 | float MinMash = 38.0; ///< Minimum edit value |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
23 | float MaxMash = 80.0; ///< Maximum edit value |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
24 | uint32_t power_MLT = 0; ///< MLT power |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
25 | uint32_t power_HLT = 0; ///< HLT power |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
26 | uint32_t counts = 0; ///< Counter for power average |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
27 | float stageTemp = 0.0; ///< Current stage temperature |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
28 | uint16_t stageTime = 0; ///< Current stage timer |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
29 | uint16_t TimeWhirlPool = 0; ///< Whirlpool timer |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
30 | uint32_t TimeLeft = 0; ///< Tie left in this stage |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
31 | uint32_t TimeSpent = 0; ///< Tota time spent |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
32 | uint32_t SecsCount = 0; ///< Seconds counter |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
33 | uint32_t pumpTime = 0; ///< Pump running time |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
34 | uint32_t TimeBrewing = 0; ///< Brewing time elapsed |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
35 | uint16_t Steady = 0; ///< Temperature is steady |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
36 | bool _NewMinute = false; ///< New minute slave flag |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
37 | bool _UseHLT = false; ///< Use HLT slave flag |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
38 | bool _Prompt = false; ///< Prompt display flag |
0 | 39 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
40 | extern bool System_TimeOk; ///< System time is valid |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
41 | extern sButton Buttons[MAXBUTTONS]; ///< Buttons definitions |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
42 | extern int Main_Screen; ///< Current screen |
42 | 43 | extern int Sub_Screen; ///< Sub screen during mash |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
44 | extern DS18B20_State *ds18b20_state; ///< DS18B20 state |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
45 | extern DRIVER_State *driver_state; ///< Relays driver state |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
46 | extern SemaphoreHandle_t xSemaphoreDS18B20; ///< DS18B20 lock semaphore |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
47 | extern SemaphoreHandle_t xSemaphoreDriver; ///< Relays driver lock semaphore |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
48 | extern double Output; ///< Cakculated outpout power |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
49 | extern time_t now; ///< Current time |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
50 | extern struct tm timeinfo; ///< Current time structure |
0 | 51 | |
52 | #ifdef CONFIG_TEMP_SENSORS_SIMULATOR | |
53 | extern float Fake_MLT; | |
54 | extern float Fake_HLT; | |
55 | #endif | |
56 | ||
19 | 57 | extern const char *mashTypes[]; |
58 | ||
0 | 59 | static const char *TAG = "automation"; |
60 | ||
61 | ||
62 | /* | |
63 | * Automation init function that only runs once when a | |
64 | * new screen is entered. | |
65 | */ | |
66 | bool Automation_Init(void) | |
67 | { | |
42 | 68 | char msg[64]; |
69 | ||
0 | 70 | switch (Main_Screen) { |
42 | 71 | case MAIN_AUTO_INIT1: |
0 | 72 | #ifdef CONFIG_TEMP_SENSORS_SIMULATOR |
73 | Fake_MLT = recipe.MashStep[0].Temperature - 10; | |
74 | Fake_HLT = recipe.SpargeTemp - 15; | |
75 | if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) { | |
76 | ds18b20_state->mlt_temperature = ((int)(Fake_MLT * 16)) / 16.0; | |
77 | ds18b20_state->hlt_temperature = ((int)(Fake_HLT * 16)) / 16.0; | |
78 | xSemaphoreGive(xSemaphoreDS18B20); | |
79 | } | |
80 | #endif | |
81 | for (int i = 0; i < 7; i++) { | |
82 | if (recipe.MashStep[i].Resttime) | |
83 | LastMashStep = i; | |
84 | } | |
85 | ESP_LOGI(TAG, "Last mash step %d", LastMashStep); | |
86 | ||
87 | // Check for a crashed session. | |
88 | if (runtime.AutoModeStarted) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
89 | TopMessage((char *)"Brouwen hervatten?"); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
90 | 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:
43
diff
changeset
|
91 | Buttons_Add(200, 100, 80, 40, (char *)"Nee", 1); |
0 | 92 | Buttons_Show(); |
93 | SoundPlay(SOUND_Prompt); | |
94 | loop = true; | |
95 | while (loop) { | |
96 | switch (Buttons_Scan()) { | |
97 | case 0: loop = false; | |
98 | Resume = true; | |
99 | Main_Screen = runtime.StageResume; | |
100 | TimeLeft = runtime.StageTimeLeft; | |
101 | TimeBrewing = runtime.TimeBrewing; | |
102 | _UseHLT = runtime.UseHLT; | |
103 | MashState = MASH_NONE; | |
104 | pumpTime = 0; | |
105 | pumpRest = false; | |
106 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
107 | driver_state->enable = true; | |
108 | if (_UseHLT) { | |
109 | driver_state->hlt_sp = recipe.SpargeTemp; | |
110 | driver_state->hlt_mode = HLT_MODE_BANG; | |
111 | } | |
112 | xSemaphoreGive(xSemaphoreDriver); | |
113 | } | |
114 | ESP_LOGI(TAG, "Resume brew screen %d, time left %d", Main_Screen, TimeLeft); | |
115 | log_begin((time_t)0); | |
116 | update_json(); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
117 | log_annotation(ANNOTATION_SYSTEM, (char *)"Resume"); |
0 | 118 | return true; |
119 | break; | |
120 | ||
121 | case 1: loop = false; | |
122 | Resume = false; | |
123 | break; | |
124 | ||
125 | default: | |
126 | break; | |
127 | } | |
128 | vTaskDelay(50 / portTICK_PERIOD_MS); | |
129 | } | |
130 | Buttons_Clear(); | |
131 | TFT_fillScreen(_bg); | |
132 | } | |
133 | ||
134 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
135 | driver_state->enable = true; | |
136 | xSemaphoreGive(xSemaphoreDriver); | |
137 | } | |
138 | runtime.AutoModeStarted = true; | |
139 | runtime.UseHLT = _UseHLT = false; | |
140 | runtime.TimeBrewing = 0; | |
141 | TimeBrewing = 0; | |
42 | 142 | runtime.StageResume = MAIN_AUTO_INIT1; |
0 | 143 | runtime.StageTimeLeft = 0; |
144 | runtime.HopAddition = 0; | |
145 | runtime.Logfile[0] = '\0'; | |
146 | runtime.PumpCooling = false; | |
147 | write_runtime(); | |
148 | power_MLT = power_HLT = counts = 0; | |
149 | log_clean(); | |
150 | vTaskDelay(250 / portTICK_PERIOD_MS); // Allow some time | |
151 | break; | |
152 | ||
42 | 153 | case MAIN_AUTO_INIT2: |
0 | 154 | case MAIN_AUTO_DELAYSTART: |
155 | break; | |
156 | ||
157 | case MAIN_AUTO_HEATUP: | |
158 | if (runtime.UseHLT) { | |
159 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
160 | driver_state->hlt_mode = HLT_MODE_BANG; | |
161 | xSemaphoreGive(xSemaphoreDriver); | |
162 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
163 | TopMessage((char *)"Spoelwater opwarmen"); |
0 | 164 | MLT_info(71, 26, false); |
165 | HLT_info(71,150, false, false); | |
166 | } | |
167 | break; | |
168 | ||
169 | case MAIN_AUTO_MASH_IN: | |
170 | case MAIN_AUTO_MASH_1: | |
171 | case MAIN_AUTO_MASH_2: | |
172 | case MAIN_AUTO_MASH_3: | |
173 | case MAIN_AUTO_MASH_4: | |
174 | case MAIN_AUTO_MASH_5: | |
175 | case MAIN_AUTO_MASH_6: | |
176 | case MAIN_AUTO_MASH_OUT: | |
177 | if (Main_Screen == MAIN_AUTO_MASH_IN) { | |
178 | MinMash = 38.0; | |
179 | MaxMash = recipe.MashStep[1].Temperature + 10.0; | |
180 | TimeBrewing = 0; | |
181 | runtime.TimeBrewing = 0; | |
182 | if (System_TimeOk) { | |
183 | time(&now); | |
184 | localtime_r(&now, &timeinfo); | |
185 | log_begin(now); | |
186 | runtime.BrewStart = now; | |
187 | } else { | |
188 | log_begin((time_t)0); | |
189 | runtime.BrewStart = (time_t)0; | |
190 | } | |
191 | updateRuntime = true; | |
192 | } else if (Main_Screen == MAIN_AUTO_MASH_OUT) { | |
193 | MinMash = 75.0; | |
194 | MaxMash = 80.0; | |
195 | } else { | |
196 | MinMash = recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN - 1].Temperature; | |
197 | if (recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN + 1].Resttime) { | |
198 | MaxMash = recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN + 1].Temperature; | |
199 | } else { | |
200 | MaxMash = 75.0; | |
201 | } | |
202 | } | |
42 | 203 | MashState = Sub_Screen = MASH_NONE; |
204 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
205 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 206 | pumpTime = 0; |
207 | pumpRest = false; | |
208 | runtime.StageResume = Main_Screen; | |
209 | updateRuntime = true; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
210 | TopMessage((char *)"Maischen"); |
0 | 211 | MLT_info(71, 26, false); |
212 | if (_UseHLT) { | |
213 | HLT_info(71,170, false, true); | |
214 | } | |
215 | break; | |
216 | ||
217 | case MAIN_AUTO_TOBOIL: | |
218 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
219 | driver_state->mlt_sp = stageTemp = config.BoilTemperature; | |
220 | driver_state->mlt_mode = MLT_MODE_EXT; | |
221 | driver_state->hlt_sp = 0.0; | |
222 | driver_state->hlt_mode = HLT_MODE_NONE; | |
223 | xSemaphoreGive(xSemaphoreDriver); | |
224 | } | |
225 | ||
226 | runtime.StageResume = Main_Screen; | |
227 | updateRuntime = true; | |
228 | TempReached = false; | |
229 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
230 | TopMessage((char *)"Naar koken"); |
0 | 231 | 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:
43
diff
changeset
|
232 | Buttons_Add( 5, 30, 60, 40, (char *)"+sp", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
233 | Buttons_Add(255, 30, 60, 40, (char *)"-sp", 1); |
0 | 234 | Buttons_Show(); |
235 | ESP_LOGI(TAG, "Mash done, going to boil."); | |
42 | 236 | Sub_Screen = 0; |
0 | 237 | break; |
238 | ||
239 | case MAIN_AUTO_BOILING: | |
240 | if (Resume) { | |
241 | TimeLeft = runtime.StageTimeLeft * 60; | |
242 | } else { | |
42 | 243 | // +1 minute for flameout and for a smooth transition. |
0 | 244 | runtime.StageTimeLeft = TimeLeft = (recipe.BoilTime * 60) + 60; |
245 | runtime.StageResume = Main_Screen; | |
246 | runtime.HopAddition = 0; | |
247 | } | |
248 | SecsCount = 0; | |
249 | ||
250 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
251 | driver_state->mlt_sp = stageTemp = config.BoilTemperature; | |
252 | driver_state->mlt_mode = MLT_MODE_EXT; | |
253 | xSemaphoreGive(xSemaphoreDriver); | |
254 | } | |
255 | SoundPlay(SOUND_TempReached); | |
256 | BoilPower = equipment.BoilPower; | |
257 | updateRuntime = true; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
258 | TopMessage((char *)"Koken"); |
0 | 259 | 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:
43
diff
changeset
|
260 | Buttons_Add( 3, 30, 60, 40, (char *)"+sp", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
261 | Buttons_Add(257, 30, 60, 40, (char *)"-sp", 1); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
262 | Buttons_Add( 3, 190, 60, 40, (char *)"+1m", 2); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
263 | Buttons_Add(257, 190, 60, 40, (char *)"-1m", 3); |
0 | 264 | Buttons_Show(); |
265 | ESP_LOGI(TAG, "Boil temperature reached, boil %d minutes", (TimeLeft / 60) -1); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
266 | log_annotation(ANNOTATION_STAGE, (char *)"Koken"); |
42 | 267 | Sub_Screen = 0; |
0 | 268 | break; |
269 | ||
270 | case MAIN_AUTO_COOLING_H: | |
271 | case MAIN_AUTO_COOLING_M: | |
272 | case MAIN_AUTO_COOLING_C: | |
273 | TempReached = false; | |
274 | runtime.StageResume = Main_Screen; | |
275 | runtime.StageTimeLeft = 0; | |
276 | updateRuntime = true; | |
277 | if ((Main_Screen == MAIN_AUTO_COOLING_H) && (! recipe.Whirlpool7)) { | |
278 | // Skip cooling before whirlpool 74 degrees | |
279 | Main_Screen = MAIN_AUTO_COOLING_M; | |
280 | return true; //goto startover; | |
281 | } | |
282 | if ((Main_Screen == MAIN_AUTO_COOLING_M) && (! recipe.Whirlpool6)) { | |
283 | // Skip cooling before whirlpool 63 degrees. | |
284 | Main_Screen = MAIN_AUTO_COOLING_C; | |
285 | return true; //goto startover; | |
286 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
287 | TopMessage((char *)"Start koelen?"); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
288 | Buttons_Add( 40, 100, 80, 40, (char *)"Start", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
289 | Buttons_Add(200, 100, 80, 40, (char *)"Stop", 1); |
0 | 290 | Buttons[1].dark = true; |
291 | Buttons_Show(); | |
292 | SoundPlay(SOUND_Prompt); | |
293 | _Prompt = true; | |
294 | break; | |
295 | ||
43
2079940c3989
Fixed missing whirlpool 88+ degrees. Some code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
296 | case MAIN_AUTO_WHIRLPOOL9: |
0 | 297 | case MAIN_AUTO_WHIRLPOOL7: |
298 | case MAIN_AUTO_WHIRLPOOL6: | |
299 | case MAIN_AUTO_WHIRLPOOL2: | |
300 | TempReached = true; | |
301 | runtime.StageResume = Main_Screen; | |
302 | updateRuntime = true; | |
303 | if ((Main_Screen == MAIN_AUTO_WHIRLPOOL9) && (! recipe.Whirlpool9)) { | |
304 | // Skip whirlpool 93 degrees. | |
305 | Main_Screen = MAIN_AUTO_COOLING_H; | |
306 | return true; //goto startover; | |
307 | } | |
308 | if ((Main_Screen == MAIN_AUTO_WHIRLPOOL7) && (! recipe.Whirlpool7)) { | |
309 | // Skip whirlpool 74 degrees. | |
310 | Main_Screen = MAIN_AUTO_COOLING_M; | |
311 | return true; //goto startover; | |
312 | } | |
313 | if ((Main_Screen == MAIN_AUTO_WHIRLPOOL6) && (! recipe.Whirlpool6)) { | |
314 | // Skip whirlpool 63 degrees. | |
315 | Main_Screen = MAIN_AUTO_COOLING_C; | |
316 | return true; //goto startover; | |
317 | } | |
318 | if ((Main_Screen == MAIN_AUTO_WHIRLPOOL2) && (! recipe.Whirlpool2)) { | |
319 | // Skip final whirlpool. | |
320 | Main_Screen = MAIN_AUTO_DONE; | |
321 | return true; //goto startover; | |
322 | } | |
323 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
324 | TopMessage((char *)"Start Whirlpool?"); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
325 | Buttons_Add( 40, 100, 80, 40, (char *)"Start", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
326 | Buttons_Add(200, 100, 80, 40, (char *)"Stop", 1); |
0 | 327 | Buttons[1].dark = true; |
328 | Buttons_Show(); | |
329 | SoundPlay(SOUND_Prompt); | |
330 | _Prompt = true; | |
331 | break; | |
332 | ||
333 | case MAIN_AUTO_DONE: | |
334 | case MAIN_AUTO_ABORT: | |
335 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
336 | driver_state->enable = false; | |
337 | driver_state->mlt_mode = MLT_MODE_NONE; | |
338 | driver_state->mlt_sp = 0.0; | |
339 | driver_state->hlt_mode = HLT_MODE_NONE; | |
340 | driver_state->hlt_sp = 0.0; | |
341 | driver_state->pump_run = 0; | |
342 | xSemaphoreGive(xSemaphoreDriver); | |
343 | } | |
344 | _fg = TFT_YELLOW; | |
345 | TFT_setFont(DEJAVU24_FONT, NULL); | |
346 | if (Main_Screen == MAIN_AUTO_DONE) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
347 | TFT_print((char *)"Brouwen is gereed.", CENTER, CENTER); |
0 | 348 | ESP_LOGI(TAG, "Brew is done"); |
349 | SoundPlay(SOUND_End); | |
350 | } else { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
351 | TFT_print((char *)"Brouwen is afgebroken.", CENTER, CENTER); |
0 | 352 | ESP_LOGI(TAG, "Brew is aborted"); |
353 | SoundPlay(SOUND_Warn); | |
354 | } | |
355 | log_close(); | |
356 | runtime.Logfile[0] = '\0'; | |
357 | runtime.BrewStart = (time_t)0; | |
358 | runtime.AutoModeStarted = false; | |
359 | runtime.StageResume = MAIN_MODE_FREE; | |
360 | runtime.PumpCooling = false; | |
361 | runtime.HopAddition = 0; | |
362 | runtime.TimeBrewing = 0; | |
363 | runtime.StageTimeLeft = 0; | |
364 | updateRuntime = true; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
365 | Buttons_Add(130, 200, 60, 40, (char *)"Ok", 0); |
0 | 366 | Buttons[0].dark = true; |
367 | Buttons_Show(); | |
368 | break; | |
369 | ||
370 | default: | |
371 | break; | |
372 | } | |
373 | ||
374 | return false; | |
375 | } | |
376 | ||
377 | ||
378 | ||
379 | /* | |
380 | * Automation loop screens. Mostly non-blocking. | |
381 | */ | |
382 | bool Automation_Loop(void) | |
383 | { | |
384 | static bool beeped = false; | |
42 | 385 | char tmp[32], msg[256]; |
0 | 386 | uint16_t y; |
387 | ||
388 | switch (Main_Screen) { | |
389 | ||
42 | 390 | case MAIN_AUTO_INIT1: |
0 | 391 | /* |
392 | * Present selected equipment and recipe. | |
393 | */ | |
42 | 394 | Sub_Screen = 1; |
0 | 395 | read_recipe(config.RecipeRec); |
42 | 396 | snprintf(msg, 255, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\",\"brew1\":\"%s\",\"brew2\":\"%s\"}", |
397 | Main_Screen, Sub_Screen, equipment.Name, recipe.Name); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
398 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 399 | y = 28; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
400 | TopMessage((char *)"Automaat"); |
0 | 401 | TFT_setFont(DEFAULT_FONT, NULL); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
402 | ShowText(2,y,(char *)"Installatie", equipment.Name); |
0 | 403 | y += 16; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
404 | ShowText(2,y,(char *)"Recept", recipe.Name); |
0 | 405 | y += 16; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
406 | ShowFloat(2, y, (char *)"Maisch in", (char *)" C", recipe.MashStep[0].Temperature, 2); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
407 | ShowFloat(162, y, (char *)"Spoelwater", (char *)" C", recipe.SpargeTemp, 2); |
0 | 408 | y += 16; |
409 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
410 | TFT_print((char *)"Maisch stap", 2, y); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
411 | TFT_print((char *)"T", 200, y); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
412 | TFT_print((char *)"Temp.", 220, y); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
413 | TFT_print((char *)"Rust", 280, y); |
0 | 414 | _fg = TFT_YELLOW; |
415 | y += 16; | |
416 | for (int i = 1; i < 8; i++) { | |
417 | if (recipe.MashStep[i].Resttime) { | |
418 | TFT_print(recipe.MashStep[i].Name, 2, y); | |
19 | 419 | strcpy(tmp, mashTypes[recipe.MashStep[i].Type]); |
420 | tmp[1] = '\0'; | |
0 | 421 | TFT_print(tmp, 200, y); |
19 | 422 | sprintf(tmp, "%.2f", recipe.MashStep[i].Temperature); |
423 | TFT_print(tmp, 220, y); | |
424 | sprintf(tmp, "%2d m", recipe.MashStep[i].Resttime); | |
425 | TFT_print(tmp, 280, y); | |
0 | 426 | y += 16; |
427 | } | |
428 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
429 | ShowInteger(2, y, (char *)"Kooktijd", (char *)" min", recipe.BoilTime); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
430 | ShowFloat(162, y, (char *)"Koel tot", (char *)" C", recipe.CoolTemp, 2); |
0 | 431 | y += 16; |
432 | if (recipe.Additions) { | |
433 | _fg = TFT_YELLOW; | |
434 | sprintf(tmp, "%d ", recipe.Additions); | |
435 | TFT_print(tmp, 2, y); | |
436 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
437 | TFT_print((char *)"toevoegingen om", LASTX, y); |
0 | 438 | _fg = TFT_YELLOW; |
439 | for (int i = 1; i <= recipe.Additions; i++) { | |
440 | sprintf(tmp, " %d", recipe.Addition[i-1].Time); | |
441 | TFT_print(tmp, LASTX, y); | |
442 | } | |
443 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
444 | TFT_print((char *)" minuten", LASTX, y); |
0 | 445 | } else { |
446 | _fg = TFT_WHITE; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
447 | TFT_print((char *)"Geen hop toevoegingen.", 2, y); |
0 | 448 | } |
449 | y += 16; | |
450 | if (recipe.Whirlpool9) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
451 | ShowInteger(2, y, (char *)"Whirlpool 88..100 graden", (char *)" minuten", recipe.Whirlpool9); |
0 | 452 | y += 16; |
453 | } | |
454 | if (recipe.Whirlpool7) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
455 | ShowInteger(2, y, (char *)"Whirlpool 71..77 graden", (char *)" minuten", recipe.Whirlpool7); |
0 | 456 | y += 16; |
457 | } | |
458 | if (recipe.Whirlpool6) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
459 | ShowInteger(2, y, (char *)"Whirlpool 60..66 graden", (char *)" minuten", recipe.Whirlpool6); |
0 | 460 | y += 16; |
461 | } | |
462 | if (recipe.Whirlpool2) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
463 | ShowInteger(2, y, (char *)"Whirlpool koud", (char *)" minuten", recipe.Whirlpool2); |
0 | 464 | y += 16; |
465 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
466 | Buttons_Add( 0, 210, 70, 30, (char *)"Stop" , 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
467 | Buttons_Add(250, 210, 70, 30, (char *)"Start" , 1); |
0 | 468 | Buttons[0].dark = true; |
469 | Buttons_Show(); | |
470 | loop = true; | |
471 | while (loop) { | |
472 | switch (Buttons_Scan()) { | |
473 | case 0: loop = false; | |
474 | Main_Screen = MAIN_AUTO_ABORT; | |
475 | break; | |
476 | ||
477 | case 1: loop = false; | |
42 | 478 | Main_Screen = MAIN_AUTO_INIT2; |
0 | 479 | break; |
480 | ||
481 | default: break; | |
482 | } | |
483 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
484 | } | |
42 | 485 | Buttons_Clear(); |
486 | break; | |
0 | 487 | |
42 | 488 | case MAIN_AUTO_INIT2: |
0 | 489 | _UseHLT = false; |
490 | _bg = TFT_BLACK; | |
491 | TFT_fillScreen(_bg); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
492 | TopMessage((char *)"Maisch water aanwezig?"); |
0 | 493 | Buttons_Clear(); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
494 | 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:
43
diff
changeset
|
495 | Buttons_Add(200, 100, 80, 40, (char *)"Nee", 1); |
0 | 496 | Buttons_Show(); |
497 | SoundPlay(SOUND_Prompt); | |
498 | loop = true; | |
499 | while (loop) { | |
500 | switch (Buttons_Scan()) { | |
501 | case 0: loop = false; | |
502 | break; | |
503 | ||
504 | case 1: loop = false; | |
505 | Main_Screen = MAIN_AUTO_ABORT; | |
506 | break; | |
507 | ||
508 | default: break; | |
509 | } | |
510 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
511 | } | |
512 | if (Main_Screen == MAIN_AUTO_ABORT) | |
513 | break; | |
514 | ||
515 | 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:
43
diff
changeset
|
516 | TopMessage((char *)"Spoelwater aanwezig?"); |
0 | 517 | SoundPlay(SOUND_Prompt); |
518 | loop = true; | |
519 | while (loop) { | |
520 | switch (Buttons_Scan()) { | |
521 | case 0: loop = false; | |
522 | _UseHLT = true; | |
523 | break; | |
524 | ||
525 | case 1: loop = false; | |
526 | break; | |
527 | ||
528 | default: break; | |
529 | } | |
530 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
531 | } | |
532 | runtime.UseHLT = _UseHLT; | |
533 | } else { | |
534 | runtime.UseHLT = _UseHLT = false; | |
535 | } | |
536 | updateRuntime = true; | |
537 | if (_UseHLT) { | |
538 | /* | |
539 | * Calculate HLT setpoint for pre-heat. Substract the | |
540 | * available Mash rest times, asume 0.5 degrees/minute | |
541 | * heat capacity during mash. | |
542 | */ | |
543 | int AvailableTime = 0; | |
544 | for (int i = 1; i < 6; i++) // Only normal Mash steps | |
545 | AvailableTime += recipe.MashStep[i].Resttime; | |
546 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
547 | driver_state->hlt_sp = recipe.SpargeTemp - ((AvailableTime / 2) + 2); | |
548 | ESP_LOGI(TAG, "HLT preheat set to %4.1f", driver_state->hlt_sp); | |
549 | xSemaphoreGive(xSemaphoreDriver); | |
550 | } | |
551 | } | |
552 | Buttons_Clear(); | |
553 | Main_Screen = MAIN_AUTO_DELAYSTART; | |
554 | break; | |
555 | ||
556 | case MAIN_AUTO_DELAYSTART: | |
557 | Main_Screen = MAIN_AUTO_HEATUP; | |
558 | break; | |
559 | ||
560 | case MAIN_AUTO_HEATUP: | |
561 | if (! runtime.UseHLT) { // Skip if HLT is off | |
562 | Main_Screen = MAIN_AUTO_MASH_IN; | |
563 | break; | |
564 | } | |
565 | ||
566 | MLT_info(71, 26, true); | |
567 | HLT_info(71,150, true, false); | |
568 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
569 | if (driver_state->hlt_pv >= driver_state->hlt_sp) { | |
570 | Main_Screen = MAIN_AUTO_MASH_IN; | |
571 | driver_state->hlt_sp = recipe.SpargeTemp; // Set final setpoint | |
572 | } | |
573 | xSemaphoreGive(xSemaphoreDriver); | |
574 | } | |
575 | break; | |
576 | ||
577 | case MAIN_AUTO_MASH_IN: | |
578 | case MAIN_AUTO_MASH_1: | |
579 | case MAIN_AUTO_MASH_2: | |
580 | case MAIN_AUTO_MASH_3: | |
581 | case MAIN_AUTO_MASH_4: | |
582 | case MAIN_AUTO_MASH_5: | |
583 | case MAIN_AUTO_MASH_6: | |
584 | case MAIN_AUTO_MASH_OUT: | |
585 | temp_MLT = 0.0; | |
586 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
587 | temp_MLT = driver_state->mlt_pv; | |
588 | ||
589 | if (MashState == MASH_ADD || MashState == MASH_REMOVE) { | |
590 | driver_state->pump_run = 0; | |
591 | } else if (MashState != MASH_NONE) { | |
592 | if (Main_Screen == MAIN_AUTO_MASH_IN) { | |
593 | driver_state->pump_run = (equipment.PumpPreMash && ! pumpRest) ? 1 : 0; | |
594 | } else if (Main_Screen == MAIN_AUTO_MASH_OUT) { | |
595 | driver_state->pump_run = (equipment.PumpMashOut && ! pumpRest) ? 1 : 0; | |
596 | } else { | |
597 | driver_state->pump_run = (equipment.PumpOnMash && ! pumpRest) ? 1 : 0; | |
598 | } | |
599 | } | |
600 | xSemaphoreGive(xSemaphoreDriver); | |
601 | } | |
602 | if (MashState == MASH_NONE) { | |
603 | stageTemp = recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Temperature; | |
604 | stageTime = recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Resttime; | |
605 | TempReached = false; | |
606 | if (stageTime == 0) { | |
607 | ESP_LOGI(TAG, "Mash step %d skipped", Main_Screen - MAIN_AUTO_MASH_IN); | |
608 | Main_Screen++; | |
609 | break; | |
610 | } | |
611 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
612 | driver_state->mlt_sp = stageTemp; | |
613 | driver_state->mlt_mode = MLT_MODE_PID; | |
614 | xSemaphoreGive(xSemaphoreDriver); | |
615 | } | |
42 | 616 | MashState = Sub_Screen = MASH_WAITTEMP; |
617 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
618 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
19 | 619 | ESP_LOGI(TAG, "Mash step %d type: %s time: %d temp: %4.1f min: %4.1f max: %4.1f", |
620 | Main_Screen - MAIN_AUTO_MASH_IN, mashTypes[recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Type], | |
621 | stageTime, stageTemp, MinMash, MaxMash); | |
0 | 622 | |
623 | if (Main_Screen > MAIN_AUTO_MASH_IN) { | |
624 | // Do not annotate before the log is open. | |
625 | if (Main_Screen == MAIN_AUTO_MASH_OUT) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
626 | log_annotation(ANNOTATION_STAGE, (char *)"Uitmaischen"); |
0 | 627 | } else { |
628 | sprintf(logline, "Maisch: %d", Main_Screen - MAIN_AUTO_MASH_IN); | |
629 | log_annotation(ANNOTATION_STAGE, logline); | |
630 | } | |
631 | } | |
632 | ||
633 | if (strlen(recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Name)) { | |
634 | TopMessage(recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Name); | |
635 | } else { | |
636 | sprintf(temp_buf, "Maisch stap #%d", Main_Screen - MAIN_AUTO_MASH_IN); | |
637 | TopMessage(temp_buf); | |
638 | } | |
19 | 639 | if ((Main_Screen > MAIN_AUTO_MASH_IN) && (Main_Screen < MAIN_AUTO_MASH_OUT) && |
640 | (recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Type == MASHTYPE_INFUSION)) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
641 | Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0); |
19 | 642 | Buttons[0].dark = true; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
643 | Buttons_Add(255,120, 60, 40, (char *)"Ok", 1); |
19 | 644 | Buttons_Show(); |
645 | _fg = TFT_WHITE; | |
646 | _bg = TFT_BLACK; | |
647 | TFT_setFont(DEJAVU18_FONT, NULL); | |
648 | sprintf(temp_buf, "Infuse %.1f L/%.1f C", recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Infusion_amount, | |
649 | recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Infusion_temp); | |
650 | TFT_print(temp_buf, CENTER, 135); | |
651 | SoundPlay(SOUND_Prompt); | |
42 | 652 | MashState = Sub_Screen = MASH_INFUSE; |
653 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"%s\"}", Main_Screen, Sub_Screen, temp_buf); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
654 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
19 | 655 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { |
656 | // No heating during the infusion. | |
657 | driver_state->mlt_sp = stageTemp; | |
658 | driver_state->mlt_mode = MLT_MODE_OFF; | |
659 | xSemaphoreGive(xSemaphoreDriver); | |
660 | } | |
661 | ESP_LOGI(TAG, "Mash infusion prompt"); | |
662 | } else { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
663 | Buttons_Add( 5, 30, 60, 40, (char *)"+sp", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
664 | Buttons_Add(255, 30, 60, 40, (char *)"-sp", 1); |
19 | 665 | Buttons_Show(); |
666 | } | |
0 | 667 | |
668 | } else if (MashState == MASH_WAITTEMP) { | |
669 | pumpRest = false; | |
670 | if (temp_MLT < stageTemp) { | |
671 | Steady = 0; | |
672 | } | |
673 | if ((temp_MLT >= stageTemp) && (Steady > 10)) { | |
674 | SoundPlay(SOUND_TempReached); | |
675 | TempReached = true; | |
42 | 676 | MashState = Sub_Screen = MASH_REST; |
677 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
678 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 679 | if (Main_Screen == MAIN_AUTO_MASH_IN) { |
680 | TimerSet(0); | |
681 | } else { | |
682 | if (Resume && (runtime.StageTimeLeft < stageTime)) | |
683 | TimerSet(runtime.StageTimeLeft * 60); | |
684 | else | |
685 | TimerSet(stageTime * 60); | |
686 | } | |
687 | Resume = false; | |
688 | runtime.StageTimeLeft = TimeLeft / 60; | |
689 | updateRuntime = true; | |
690 | ESP_LOGI(TAG, "Mash step %d temperature reached, rest time %d", Main_Screen - MAIN_AUTO_MASH_IN, TimeLeft / 60); | |
691 | Buttons_Clear(); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
692 | Buttons_Add( 0, 120, 60, 40, (char *)"+1m", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
693 | Buttons_Add(260, 120, 60, 40, (char *)"-1m", 1); |
0 | 694 | Buttons_Show(); |
695 | } | |
696 | switch (Buttons_Scan()) { | |
697 | case 0: if (stageTemp < MaxMash) { | |
698 | stageTemp += 0.25; | |
699 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
700 | driver_state->mlt_sp = stageTemp; | |
701 | xSemaphoreGive(xSemaphoreDriver); | |
702 | } | |
703 | } | |
704 | break; | |
705 | ||
706 | case 1: if (stageTemp > MinMash) { | |
707 | stageTemp -= 0.25; | |
708 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
709 | driver_state->mlt_sp = stageTemp; | |
710 | xSemaphoreGive(xSemaphoreDriver); | |
711 | } | |
712 | } | |
713 | break; | |
714 | ||
715 | default: | |
716 | break; | |
717 | } | |
718 | if (NewMinute) | |
719 | updateRuntime = true; | |
720 | ||
721 | } else if (MashState == MASH_REST) { | |
722 | /* | |
723 | * Mash step rest time and pump control | |
724 | */ | |
725 | if (((Main_Screen == MAIN_AUTO_MASH_OUT) && equipment.PumpMashOut) || | |
726 | ((Main_Screen != MAIN_AUTO_MASH_OUT) && equipment.PumpOnMash)) { | |
727 | float DeltaTemp = equipment.PumpRest * stageTemp / 120; // Maximum temperature drop before heating again. | |
728 | if (pumpTime >= (equipment.PumpCycle + equipment.PumpRest) || ((stageTemp - temp_MLT) > DeltaTemp)) { | |
729 | pumpTime = 0; | |
730 | } | |
731 | if (pumpTime >= equipment.PumpCycle) { | |
732 | if (! pumpRest) { | |
733 | pumpRest = true; | |
734 | ESP_LOGI(TAG, "Pump rest"); | |
735 | } | |
736 | } else { | |
737 | if (pumpRest) { | |
738 | pumpRest = false; | |
739 | ESP_LOGI(TAG, "Pump start"); | |
740 | } | |
741 | } | |
742 | } | |
743 | if (TimeLeft) { | |
744 | switch (Buttons_Scan()) { | |
745 | case 0: TimeLeft += 60; | |
746 | runtime.StageTimeLeft = TimeLeft / 60; | |
747 | updateRuntime = true; | |
748 | break; | |
749 | ||
750 | case 1: if (TimeLeft < 60) | |
751 | TimeLeft = 0; | |
752 | else | |
753 | TimeLeft -= 60; | |
754 | runtime.StageTimeLeft = TimeLeft / 60; | |
755 | updateRuntime = true; | |
756 | break; | |
757 | ||
758 | default: break; | |
759 | } | |
760 | } | |
761 | ||
762 | if (TimeLeft == 0) { | |
763 | runtime.StageTimeLeft = TimeLeft / 60; | |
764 | updateRuntime = true; | |
765 | if ((Main_Screen == MAIN_AUTO_MASH_IN) && config.AskAdd) { | |
766 | /* | |
767 | * Add Mash prompt. | |
768 | */ | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
769 | log_annotation(ANNOTATION_EVENT, (char *)"Mout storten"); |
0 | 770 | Buttons_Clear(); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
771 | Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0); |
0 | 772 | Buttons[0].dark = true; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
773 | Buttons_Add(255,120, 60, 40, (char *)"Ok", 1); |
0 | 774 | Buttons_Show(); |
775 | _fg = TFT_WHITE; | |
776 | _bg = TFT_BLACK; | |
777 | TFT_setFont(DEJAVU24_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
778 | TFT_print((char *)"Mout storten?", CENTER, 135); |
0 | 779 | SoundPlay(SOUND_Prompt); |
42 | 780 | MashState = Sub_Screen = MASH_ADD; |
781 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"Mout storten?\"}", Main_Screen, Sub_Screen); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
782 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 783 | ESP_LOGI(TAG, "Mash add prompt"); |
784 | break; | |
785 | } | |
786 | if (((Main_Screen - MAIN_AUTO_MASH_IN) == LastMashStep) && config.AskIodine) { | |
787 | /* | |
788 | * Iodone test prompt. | |
789 | */ | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
790 | log_annotation(ANNOTATION_EVENT, (char *)"Jodium test"); |
0 | 791 | TFT_fillRect(0, 120, 320, 50, TFT_BLACK); |
792 | Buttons_Clear(); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
793 | Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0); |
0 | 794 | Buttons[0].dark = true; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
795 | Buttons_Add(255,120, 60, 40, (char *)"Ok", 1); |
0 | 796 | Buttons_Show(); |
797 | _fg = TFT_WHITE; | |
798 | _bg = TFT_BLACK; | |
799 | TFT_setFont(DEJAVU24_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
800 | TFT_print((char *)"Jodium test?", CENTER, 127); |
0 | 801 | SoundPlay(SOUND_Prompt); |
802 | beeped = false; | |
803 | TimerSet(config.IodineTime * 60); | |
42 | 804 | MashState = Sub_Screen = MASH_IODINE; |
805 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"Jodium test?\"}", Main_Screen, Sub_Screen); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
806 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 807 | ESP_LOGI(TAG, "Mash iodine test prompt"); |
808 | break; | |
809 | } | |
810 | if ((Main_Screen == MAIN_AUTO_MASH_OUT) && config.AskRemove) { | |
811 | /* | |
812 | * Mash remove prompt. | |
813 | */ | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
814 | log_annotation(ANNOTATION_EVENT, (char *)"Mout verwijderen"); |
0 | 815 | TFT_fillRect(0, 120, 320, 50, TFT_BLACK); |
816 | Buttons_Clear(); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
817 | Buttons_Add( 5,120, 60, 40, (char *)"Halt", 0); |
0 | 818 | Buttons[0].dark = true; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
819 | Buttons_Add(255,120, 60, 40, (char *)"Ok", 1); |
0 | 820 | Buttons_Show(); |
821 | _fg = TFT_WHITE; | |
822 | _bg = TFT_BLACK; | |
823 | TFT_setFont(DEJAVU18_FONT, NULL); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
824 | TFT_print((char *)"Mout verwijderen?", CENTER, 135); |
0 | 825 | SoundPlay(SOUND_Prompt); |
42 | 826 | MashState = Sub_Screen = MASH_REMOVE; |
827 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"Mout verwijderen?\"}", Main_Screen, Sub_Screen); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
828 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 829 | ESP_LOGI(TAG, "Mash remove prompt"); |
830 | break; | |
831 | } | |
832 | if (Main_Screen != MAIN_AUTO_ABORT) | |
833 | Main_Screen++; | |
834 | TempReached = false; | |
835 | } else { | |
836 | TimerShow(TimeLeft, 65, 122); | |
837 | if (NewMinute) { | |
838 | runtime.StageTimeLeft = TimeLeft / 60; | |
839 | updateRuntime = true; | |
840 | } | |
841 | } | |
842 | } else if (MashState == MASH_ADD) { | |
843 | switch (Buttons_Scan()) { | |
844 | case 0: Main_Screen = MAIN_AUTO_ABORT; | |
845 | break; | |
846 | case 1: Main_Screen++; | |
847 | break; | |
848 | default: break; | |
849 | } | |
850 | } else if (MashState == MASH_IODINE) { | |
851 | if (TimeSpent % 45 == 0) { | |
852 | if (! beeped) { | |
853 | SoundPlay(SOUND_Warn); | |
854 | beeped = true; | |
855 | } | |
856 | } else { | |
857 | beeped = false; | |
858 | } | |
859 | switch (Buttons_Scan()) { | |
860 | case 0: Main_Screen = MAIN_AUTO_ABORT; | |
861 | break; | |
862 | case 1: Main_Screen++; | |
863 | break; | |
864 | default: break; | |
865 | } | |
866 | if (TimeLeft == 0) { | |
867 | Main_Screen++; | |
868 | } | |
869 | } else if (MashState == MASH_REMOVE) { | |
870 | switch (Buttons_Scan()) { | |
871 | case 0: Main_Screen = MAIN_AUTO_ABORT; | |
872 | break; | |
873 | case 1: Main_Screen++; | |
874 | break; | |
875 | default: break; | |
876 | } | |
19 | 877 | } else if (MashState == MASH_INFUSE) { |
878 | switch (Buttons_Scan()) { | |
879 | case 0: Main_Screen = MAIN_AUTO_ABORT; | |
880 | break; | |
42 | 881 | case 1: MashState = Sub_Screen = MASH_WAITTEMP; |
882 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
883 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
19 | 884 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { |
885 | // Start PID again. | |
886 | driver_state->mlt_sp = stageTemp; | |
887 | driver_state->mlt_mode = MLT_MODE_PID; | |
888 | xSemaphoreGive(xSemaphoreDriver); | |
889 | } | |
890 | Buttons_Clear(); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
891 | Buttons_Add( 5, 30, 60, 40, (char *)"+sp", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
892 | Buttons_Add(255, 30, 60, 40, (char *)"-sp", 1); |
19 | 893 | Buttons_Show(); |
894 | TFT_fillRect(65, 120, 190, 40, TFT_BLACK); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
895 | log_annotation(ANNOTATION_EVENT, (char *)"Eind infusie"); |
19 | 896 | break; |
897 | default: break; | |
898 | } | |
0 | 899 | } /* MashState */ |
900 | MLT_info(71, 26, true); | |
901 | if (_UseHLT) { | |
902 | HLT_info(71, 170, true, true); | |
903 | } | |
904 | break; | |
905 | ||
906 | case MAIN_AUTO_TOBOIL: | |
907 | Output = 255; | |
908 | /* | |
909 | * Go to the boil temperature and wait until it is steady. | |
910 | */ | |
911 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
912 | if (driver_state->mlt_pv < stageTemp) { | |
913 | Steady = 0; | |
914 | } else { | |
915 | if (Steady > 10) { | |
916 | Main_Screen = MAIN_AUTO_BOILING; | |
917 | TempReached = true; | |
918 | } | |
919 | } | |
920 | driver_state->pump_run = (equipment.PumpOnBoil && (driver_state->mlt_pv < equipment.PumpMaxTemp)) ? 1 : 0; | |
921 | xSemaphoreGive(xSemaphoreDriver); | |
922 | } | |
923 | ||
924 | MLT_info(71, 26, true); | |
925 | switch (Buttons_Scan()) { | |
926 | case 0: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
927 | driver_state->mlt_sp += 0.25; | |
928 | xSemaphoreGive(xSemaphoreDriver); | |
929 | } | |
930 | break; | |
931 | ||
932 | case 1: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
933 | driver_state->mlt_sp -= 0.25; | |
934 | xSemaphoreGive(xSemaphoreDriver); | |
935 | } | |
936 | break; | |
937 | ||
938 | default: break; | |
939 | } | |
940 | if (Resume) | |
941 | Resume = false; | |
942 | break; | |
943 | ||
944 | case MAIN_AUTO_BOILING: | |
945 | if (Resume) | |
946 | Resume = false; | |
947 | if (NewMinute) { | |
948 | if ((runtime.HopAddition < recipe.Additions) && (TimeLeft <= ((recipe.Addition[runtime.HopAddition].Time * 60) + 60))) { | |
949 | ESP_LOGI(TAG, "Hop addition %d at %d minutes", runtime.HopAddition + 1, recipe.Addition[runtime.HopAddition].Time); | |
950 | TopMessage(recipe.Addition[runtime.HopAddition].Name); | |
26
373a33699605
Graph title includes beer code. Hop additions now only display the additions themselfes.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
951 | log_annotation(ANNOTATION_EVENT, recipe.Addition[runtime.HopAddition].Name); |
0 | 952 | SoundPlay(SOUND_AddHop); |
953 | runtime.HopAddition++; | |
954 | } else { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
955 | TopMessage((char *)"Koken"); |
0 | 956 | } |
957 | runtime.StageTimeLeft = TimeLeft / 60; | |
958 | updateRuntime = true; | |
959 | } | |
960 | if (TimeLeft < 60) { | |
961 | if (Output) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
962 | log_annotation(ANNOTATION_STAGE, (char *)"Vlamuit"); |
0 | 963 | } |
964 | // Flameout | |
965 | Output = 0; | |
966 | } else if (driver_state->mlt_pv >= stageTemp) { | |
967 | Output = (int)((BoilPower * 255.0) / 100.0); | |
968 | if (Buttons[4].x == -1) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
969 | Buttons_Add( 3,110, 60, 40, (char *)"+%", 4); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
970 | Buttons_Add(257,110, 60, 40, (char *)"-%", 5); |
0 | 971 | Buttons_Show(); |
972 | } | |
973 | } else { | |
974 | Output = 255; | |
975 | if (Buttons[4].x != -1) { | |
976 | Buttons[4].x = Buttons[5].x = -1; | |
977 | Buttons_Show(); | |
978 | TFT_fillRect( 3,110, 60, 40, TFT_BLACK); | |
979 | TFT_fillRect(257,110, 60, 40, TFT_BLACK); | |
980 | } | |
981 | } | |
982 | ||
983 | MLT_info(71, 26, true); | |
984 | TimerShow(TimeLeft, 65, 190); | |
985 | ||
986 | switch (Buttons_Scan()) { | |
987 | case 0: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
988 | driver_state->mlt_sp += 0.25; | |
989 | xSemaphoreGive(xSemaphoreDriver); | |
990 | } | |
991 | break; | |
992 | ||
993 | case 1: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
994 | driver_state->mlt_sp -= 0.25; | |
995 | xSemaphoreGive(xSemaphoreDriver); | |
996 | } | |
997 | break; | |
998 | ||
999 | case 2: TimeLeft += 60; | |
1000 | break; | |
1001 | ||
1002 | case 3: if (TimeLeft > 60) | |
1003 | TimeLeft -= 60; | |
1004 | else | |
1005 | TimeLeft = 0; | |
1006 | break; | |
1007 | ||
1008 | case 4: if (BoilPower < 100) | |
1009 | BoilPower++; | |
1010 | break; | |
1011 | ||
1012 | case 5: if (BoilPower > 0) | |
1013 | BoilPower--; | |
1014 | break; | |
1015 | ||
1016 | default: break; | |
1017 | } | |
1018 | ||
1019 | if (TimeLeft == 0) { | |
1020 | Main_Screen = MAIN_AUTO_WHIRLPOOL9; | |
1021 | ESP_LOGI(TAG, "Boil is ready"); | |
1022 | } | |
1023 | break; | |
1024 | ||
1025 | case MAIN_AUTO_COOLING_H: | |
1026 | case MAIN_AUTO_COOLING_M: | |
1027 | case MAIN_AUTO_COOLING_C: | |
1028 | if (_Prompt) { | |
1029 | /* | |
1030 | * Prompt mode | |
1031 | */ | |
1032 | switch (Buttons_Scan()) { | |
1033 | case 0: _Prompt = false; | |
1034 | Buttons_Clear(); | |
1035 | break; | |
1036 | case 1: Main_Screen = MAIN_AUTO_DONE; | |
1037 | Buttons_Clear(); | |
1038 | return true; //goto startover; | |
1039 | break; | |
1040 | default: | |
1041 | break; | |
1042 | } | |
1043 | ||
1044 | if (! _Prompt) { | |
1045 | /* | |
1046 | * Starting cooling, setup the screen. | |
1047 | */ | |
1048 | Buttons_Clear(); | |
1049 | TFT_fillScreen(_bg); | |
42 | 1050 | Sub_Screen = 1; |
0 | 1051 | if (Main_Screen == MAIN_AUTO_COOLING_H) { |
1052 | stageTemp = 77.0; | |
1053 | } else if (Main_Screen == MAIN_AUTO_COOLING_M) { | |
1054 | stageTemp = 66.0; | |
1055 | } else { | |
1056 | stageTemp = recipe.CoolTemp; | |
1057 | } | |
42 | 1058 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1059 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 1060 | CoolBeep = false; |
1061 | ESP_LOGI(TAG, "Start cooling from %6.2f to %4.1f", ds18b20_state->mlt_temperature, stageTemp); | |
1062 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1063 | driver_state->mlt_mode = MLT_MODE_OFF; | |
1064 | driver_state->mlt_sp = stageTemp; | |
1065 | xSemaphoreGive(xSemaphoreDriver); | |
1066 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1067 | log_annotation(ANNOTATION_STAGE, (char *)"Koelen"); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1068 | TopMessage((char *)"Koelen"); |
0 | 1069 | 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:
43
diff
changeset
|
1070 | Buttons_Add( 5, 200, 60, 40, (char *)"Stop", 0); |
0 | 1071 | Buttons[0].dark = true; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1072 | Buttons_Add( 5, 26, 60, 40, (char *)"+1", 1); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1073 | Buttons_Add(255, 26, 60, 40, (char *)"-1", 2); |
0 | 1074 | /* |
1075 | * The next key is not a mistake, but we need a key entry which | |
1076 | * will later become the pump key. The keyscan routine will find | |
1077 | * the original key if pressed. | |
1078 | */ | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1079 | Buttons_Add(255, 26, 60, 40, (char *)"-1", 3); |
0 | 1080 | Buttons_Show(); |
1081 | } | |
1082 | } else { | |
1083 | /* | |
1084 | * Not in prompt mode. | |
1085 | */ | |
1086 | #ifdef CONFIG_TEMP_SENSORS_SIMULATOR | |
1087 | if (Fake_MLT > 12.0) { | |
1088 | if (driver_state->pump_run) | |
1089 | Fake_MLT -= 0.00025 * (Fake_MLT - 12.0); | |
1090 | else | |
1091 | Fake_MLT -= 0.00015 * (Fake_MLT - 12.0); | |
1092 | } | |
1093 | if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) { | |
1094 | ds18b20_state->mlt_temperature = ((int)(Fake_MLT * 16)) / 16.0; | |
1095 | xSemaphoreGive(xSemaphoreDS18B20); | |
1096 | } | |
1097 | #endif | |
1098 | MLT_info(71, 26, true); | |
1099 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1100 | /* | |
1101 | * If the pump safe temperature is reached, add the control button. | |
1102 | * Redefine key number 3 if it is at the position of key 2. | |
1103 | */ | |
1104 | if ((driver_state->mlt_pv < equipment.PumpMaxTemp) && (Buttons[3].x == Buttons[2].x) &&(Buttons[3].y == Buttons[2].y)) { | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1105 | Buttons_Add(255, 200, 60, 40, (char *)"Pomp", 3); |
0 | 1106 | Buttons_Show(); |
1107 | } | |
1108 | xSemaphoreGive(xSemaphoreDriver); | |
1109 | } | |
1110 | switch (Buttons_Scan()) { | |
1111 | case 1: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1112 | if (Main_Screen == MAIN_AUTO_COOLING_H) { | |
1113 | if (driver_state->mlt_sp < 77.0) | |
1114 | driver_state->mlt_sp += 1.0; | |
1115 | } else if (Main_Screen == MAIN_AUTO_COOLING_M) { | |
1116 | if (driver_state->mlt_sp < 66.0) | |
1117 | driver_state->mlt_sp += 1.0; | |
1118 | } else if (Main_Screen == MAIN_AUTO_COOLING_C) { | |
1119 | if (driver_state->mlt_sp < 30.0) | |
1120 | driver_state->mlt_sp += 1.0; | |
1121 | } | |
1122 | xSemaphoreGive(xSemaphoreDriver); | |
1123 | } | |
1124 | break; | |
1125 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1126 | case 0: Buttons_Add( 60, 150, 90, 40, (char *)"Stoppen", 4); |
0 | 1127 | Buttons[4].dark = true; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1128 | Buttons_Add(170, 150, 90, 40, (char *)"Sorry", 5); |
0 | 1129 | Buttons_Show(); |
1130 | break; | |
1131 | ||
1132 | case 2: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1133 | if (Main_Screen == MAIN_AUTO_COOLING_H) { | |
1134 | if (driver_state->mlt_sp > 71.0) | |
1135 | driver_state->mlt_sp -= 1.0; | |
1136 | } else if (Main_Screen == MAIN_AUTO_COOLING_M) { | |
1137 | if (driver_state->mlt_sp > 60.0) | |
1138 | driver_state->mlt_sp -= 1.0; | |
1139 | } else if (Main_Screen == MAIN_AUTO_COOLING_C) { | |
1140 | if (driver_state->mlt_sp > 10.0) | |
1141 | driver_state->mlt_sp -= 1.0; | |
1142 | } | |
1143 | xSemaphoreGive(xSemaphoreDriver); | |
1144 | } | |
1145 | break; | |
1146 | ||
1147 | case 3: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1148 | if (driver_state->mlt_pv < equipment.PumpMaxTemp) { | |
1149 | if (driver_state->pump_run) | |
1150 | driver_state->pump_run = 0; | |
1151 | else | |
1152 | driver_state->pump_run = 1; | |
1153 | } else { | |
1154 | driver_state->pump_run = 0; | |
1155 | } | |
1156 | runtime.PumpCooling = driver_state->pump_run; | |
1157 | updateRuntime = true; | |
1158 | xSemaphoreGive(xSemaphoreDriver); | |
1159 | } | |
1160 | break; | |
1161 | ||
1162 | case 4: Main_Screen++; | |
1163 | break; | |
1164 | ||
1165 | case 5: Buttons[4].x = Buttons[5].x = -1; | |
1166 | TFT_fillRect(60, 150, 200, 40, TFT_BLACK); | |
1167 | break; | |
1168 | ||
1169 | default: | |
1170 | break; | |
1171 | } | |
1172 | ||
1173 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1174 | if (! CoolBeep && (driver_state->mlt_pv < (driver_state->mlt_sp + 2.0))) { | |
1175 | SoundPlay(SOUND_Warn); | |
1176 | CoolBeep = true; | |
1177 | } | |
1178 | if (driver_state->mlt_pv <= driver_state->mlt_sp) { | |
1179 | SoundPlay(SOUND_TempReached); | |
1180 | Main_Screen++; | |
42 | 1181 | Sub_Screen = 0; |
0 | 1182 | } |
1183 | xSemaphoreGive(xSemaphoreDriver); | |
1184 | } | |
1185 | } | |
1186 | break; | |
1187 | ||
1188 | case MAIN_AUTO_WHIRLPOOL9: | |
1189 | case MAIN_AUTO_WHIRLPOOL7: | |
1190 | case MAIN_AUTO_WHIRLPOOL6: | |
1191 | case MAIN_AUTO_WHIRLPOOL2: | |
1192 | if (_Prompt) { | |
1193 | ||
1194 | switch (Buttons_Scan()) { | |
1195 | case 0: _Prompt = false; | |
1196 | break; | |
1197 | case 1: if (Main_Screen == MAIN_AUTO_WHIRLPOOL2) { | |
1198 | Main_Screen = MAIN_AUTO_DONE; | |
1199 | } else { | |
1200 | Main_Screen++; | |
1201 | } | |
1202 | Buttons_Clear(); | |
1203 | return true; //goto startover; | |
1204 | break; | |
1205 | default: | |
1206 | break; | |
1207 | } | |
1208 | ||
1209 | if (! _Prompt) { | |
1210 | /* | |
1211 | * Prepare the screen for the actual whirpool. | |
1212 | */ | |
1213 | Buttons_Clear(); | |
1214 | TFT_fillScreen(_bg); | |
42 | 1215 | Sub_Screen = 1; |
1216 | snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1217 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
0 | 1218 | if (Main_Screen == MAIN_AUTO_WHIRLPOOL9) { |
1219 | TimeWhirlPool = recipe.Whirlpool9; | |
1220 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1221 | driver_state->mlt_sp = 93.0; | |
1222 | driver_state->mlt_mode = MLT_MODE_PID; | |
1223 | xSemaphoreGive(xSemaphoreDriver); | |
1224 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1225 | TopMessage((char *)"Whirlpool 88..100"); |
0 | 1226 | } else if (Main_Screen == MAIN_AUTO_WHIRLPOOL7) { |
1227 | TimeWhirlPool = recipe.Whirlpool7; | |
1228 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1229 | driver_state->mlt_sp = 74.0; | |
1230 | driver_state->mlt_mode = MLT_MODE_PID; | |
1231 | xSemaphoreGive(xSemaphoreDriver); | |
1232 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1233 | TopMessage((char *)"Whirlpool 71..77"); |
0 | 1234 | } else if (Main_Screen == MAIN_AUTO_WHIRLPOOL6) { |
1235 | TimeWhirlPool = recipe.Whirlpool6; | |
1236 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1237 | driver_state->mlt_sp = 63.0; | |
1238 | driver_state->mlt_mode = MLT_MODE_PID; | |
1239 | xSemaphoreGive(xSemaphoreDriver); | |
1240 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1241 | TopMessage((char *)"Whirlpool 60..66"); |
0 | 1242 | } else { |
1243 | TimeWhirlPool = recipe.Whirlpool2; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1244 | TopMessage((char *)"Koude whirlpool"); |
0 | 1245 | } |
1246 | if (Resume) { | |
1247 | TimeWhirlPool = runtime.StageTimeLeft; | |
1248 | } | |
1249 | ||
1250 | /* | |
1251 | * If the pump is allowed at the current temperature, turn it on. | |
1252 | */ | |
1253 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1254 | driver_state->pump_run = (driver_state->mlt_pv < equipment.PumpMaxTemp) ? 1 : 0; | |
1255 | xSemaphoreGive(xSemaphoreDriver); | |
1256 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1257 | log_annotation(ANNOTATION_STAGE, (char *)"Whirlpool"); |
0 | 1258 | |
1259 | TimerSet(TimeWhirlPool * 60); | |
1260 | runtime.StageTimeLeft = TimeWhirlPool; | |
1261 | updateRuntime = true; | |
1262 | MLT_info(71, 26, false); | |
1263 | ESP_LOGI(TAG, "Whirlpool %d minutes, sp %4.1f", TimeWhirlPool, driver_state->mlt_sp); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1264 | Buttons_Add(255, 120, 60, 40, (char *)"+1m", 0); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1265 | Buttons_Add( 5, 120, 60, 40, (char *)"-1m", 1); |
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
1266 | Buttons_Add(255, 200, 60, 40, (char *)"Pomp", 2); |
0 | 1267 | Buttons_Show(); |
1268 | } | |
1269 | } else { | |
1270 | /* | |
1271 | * Not running in prompt mode, do the whirlpool. | |
1272 | */ | |
1273 | if (TimeLeft == 120) { | |
1274 | /* | |
1275 | * Drop the temperature when whirlpool is almost ready. | |
1276 | * If we are lucky the heater element will cool down so | |
1277 | * the next cooling stage will not wast too much energy. | |
1278 | */ | |
1279 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1280 | if (Main_Screen == MAIN_AUTO_WHIRLPOOL9) | |
1281 | driver_state->mlt_sp = 88.0; | |
1282 | if (Main_Screen == MAIN_AUTO_WHIRLPOOL7) | |
1283 | driver_state->mlt_sp = 71.0; | |
1284 | if (Main_Screen == MAIN_AUTO_WHIRLPOOL6) | |
1285 | driver_state->mlt_sp = 60.0; | |
1286 | xSemaphoreGive(xSemaphoreDriver); | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | MLT_info(71, 26, true); | |
1291 | TimerShow(TimeLeft, 65, 122); | |
1292 | switch (Buttons_Scan()) { | |
1293 | case 0: TimeLeft += 60; | |
1294 | break; | |
1295 | case 1: if (TimeLeft > 60) | |
1296 | TimeLeft -= 60; | |
1297 | else | |
1298 | TimeLeft = 0; | |
1299 | break; | |
1300 | case 2: if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1301 | if (driver_state->mlt_pv < equipment.PumpMaxTemp) { | |
1302 | if (driver_state->pump_run) | |
1303 | driver_state->pump_run = 0; | |
1304 | else | |
1305 | driver_state->pump_run = 1; | |
1306 | } else { | |
1307 | driver_state->pump_run = 0; | |
1308 | } | |
1309 | xSemaphoreGive(xSemaphoreDriver); | |
1310 | } | |
1311 | } | |
1312 | ||
1313 | if (NewMinute) { | |
1314 | runtime.StageTimeLeft = TimeLeft / 60; | |
1315 | updateRuntime = true; | |
1316 | } | |
1317 | ||
1318 | if ((TimeLeft == 0)) { | |
1319 | if (Main_Screen == MAIN_AUTO_WHIRLPOOL9) { | |
1320 | Main_Screen = MAIN_AUTO_COOLING_H; | |
1321 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1322 | driver_state->pump_run = runtime.PumpCooling; | |
1323 | xSemaphoreGive(xSemaphoreDriver); | |
1324 | } | |
1325 | } else if (Main_Screen == MAIN_AUTO_WHIRLPOOL7) { | |
1326 | Main_Screen = MAIN_AUTO_COOLING_M; | |
1327 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1328 | driver_state->pump_run = runtime.PumpCooling; | |
1329 | xSemaphoreGive(xSemaphoreDriver); | |
1330 | } | |
1331 | } else if (Main_Screen == MAIN_AUTO_WHIRLPOOL6) { | |
1332 | Main_Screen = MAIN_AUTO_COOLING_C; | |
1333 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
1334 | driver_state->pump_run = runtime.PumpCooling; | |
1335 | xSemaphoreGive(xSemaphoreDriver); | |
1336 | } | |
1337 | } else if (Main_Screen == MAIN_AUTO_WHIRLPOOL2) { | |
1338 | Main_Screen = MAIN_AUTO_DONE; | |
1339 | } | |
1340 | } | |
1341 | } | |
1342 | break; | |
1343 | ||
1344 | case MAIN_AUTO_DONE: | |
1345 | case MAIN_AUTO_ABORT: | |
1346 | if (Buttons_Scan() == 0) | |
1347 | Main_Screen = MAIN_MODE_FREE; | |
1348 | break; | |
1349 | ||
1350 | default: | |
1351 | break; | |
1352 | } | |
1353 | ||
1354 | return false; | |
1355 | } | |
1356 | ||
1357 |