|
1 /** |
|
2 * @file config.h |
|
3 * @brief The BrewBoard configuration data. These are stored in the |
|
4 * spiffs filesystem in a flash partition. |
|
5 */ |
|
6 |
|
7 #ifndef _CONFIG_H |
|
8 #define _CONFIG_H |
|
9 |
|
10 // Global includes for the project |
|
11 |
|
12 #include <stdio.h> |
|
13 #include <stdlib.h> |
|
14 #include <string.h> |
|
15 #include <stdbool.h> |
|
16 #include <time.h> |
|
17 #include <errno.h> |
|
18 #include <sys/unistd.h> |
|
19 #include <sys/fcntl.h> |
|
20 #include <sys/time.h> |
|
21 |
|
22 #include "freertos/FreeRTOS.h" |
|
23 #include "freertos/task.h" |
|
24 #include "freertos/semphr.h" |
|
25 #include "freertos/event_groups.h" |
|
26 #include "freertos/queue.h" |
|
27 #include "driver/i2c.h" |
|
28 #include "esp_log.h" |
|
29 #include "esp_spiffs.h" |
|
30 #include "esp_event_loop.h" |
|
31 #include "esp_wifi.h" |
|
32 #include "esp_wifi_types.h" |
|
33 #include "esp_system.h" |
|
34 |
|
35 #include "esp_ota_ops.h" |
|
36 #include "esp_http_client.h" |
|
37 #include "esp_https_ota.h" |
|
38 |
|
39 #include "esp_vfs.h" |
|
40 #include "esp_vfs_fat.h" |
|
41 #include "nvs.h" |
|
42 #include "nvs_flash.h" |
|
43 #include "rom/crc.h" |
|
44 #include "mdns.h" |
|
45 #include "lwip/sockets.h" |
|
46 #include "lwip/api.h" |
|
47 #include "lwip/err.h" |
|
48 #include "lwip/netdb.h" |
|
49 #include "lwip/dns.h" |
|
50 #include "lwip/opt.h" |
|
51 #include "lwip/memp.h" |
|
52 #include "lwip/ip.h" |
|
53 #include "lwip/raw.h" |
|
54 #include "lwip/udp.h" |
|
55 #include "sdkconfig.h" |
|
56 #include "lwip/apps/sntp.h" |
|
57 #include "expat.h" |
|
58 |
|
59 #include "tftspi.h" |
|
60 #include "tft.h" |
|
61 #include "PID_v1.h" |
|
62 #include "vnc-server.h" |
|
63 #include "websocket_server.h" |
|
64 |
|
65 #include "buttons.h" |
|
66 #include "calibration.h" |
|
67 #include "automation.h" |
|
68 #include "manual.h" |
|
69 #include "setup.h" |
|
70 #include "recipes.h" |
|
71 #include "files.h" |
|
72 #include "updates.h" |
|
73 |
|
74 #include "task_tft.h" |
|
75 #include "task_ds18b20.h" |
|
76 #include "task_sdcard.h" |
|
77 #include "task_driver.h" |
|
78 #include "task_wifi.h" |
|
79 #include "task_sound.h" |
|
80 #include "task_http.h" |
|
81 |
|
82 |
|
83 #define VERSION "0.2.2" |
|
84 |
|
85 |
|
86 /** |
|
87 * @brief Main mode different screens |
|
88 */ |
|
89 typedef enum |
|
90 { |
|
91 MAIN_MODE_UNKNOWN = -1, ///< During system startup |
|
92 MAIN_MODE_FREE = 0, ///< Main menu, do nothing |
|
93 MAIN_MODE_CALIBRATION, ///< TFT calibration |
|
94 MAIN_INFO, ///< Info/about screen |
|
95 MAIN_TOOLS, ///< Main tools screen |
|
96 MAIN_TOOLS_SETUP, ///< Main setup screen |
|
97 MAIN_TOOLS_SETUP_CONFIG, ///< Main setup configuration |
|
98 MAIN_TOOLS_SETUP_CO_EDIT, ///< Main setup confguration editor |
|
99 MAIN_TOOLS_SETUP_EQUIPMENT, ///< Main setup equipment |
|
100 MAIN_TOOLS_SETUP_EQ_EDIT, ///< Main setup edit equipment |
|
101 MAIN_TOOLS_SETUP_WIFI, ///< Main setup WiFi |
|
102 MAIN_TOOLS_SETUP_WIFI_CUR, ///< Main setup WiFi current connection. |
|
103 MAIN_TOOLS_SETUP_WIFI_CON, ///< Main setup WiFi connect. |
|
104 MAIN_TOOLS_SETUP_WIFI_NEW, ///< Main setup WiFi new connection. |
|
105 MAIN_TOOLS_SETUP_CALIBRATION, ///< Main setup TFT calibration |
|
106 MAIN_TOOLS_RECIPE, ///< Main recipes screen. |
|
107 MAIN_TOOLS_RECIPE_EDIT, ///< Main recipes editor. |
|
108 MAIN_TOOLS_FILES, ///< Main files. |
|
109 MAIN_TOOLS_UPDATES, ///< Main Updates. |
|
110 MAIN_AUTO_INIT, ///< Automatic start |
|
111 MAIN_AUTO_DELAYSTART, ///< Delayed start |
|
112 MAIN_AUTO_HEATUP, ///< Heatup the system |
|
113 MAIN_AUTO_MASH_IN = 100, ///< Mash-in |
|
114 MAIN_AUTO_MASH_1, ///< Mash step 1 |
|
115 MAIN_AUTO_MASH_2, ///< Mash step 2 |
|
116 MAIN_AUTO_MASH_3, ///< Mash step 3 |
|
117 MAIN_AUTO_MASH_4, ///< Mash step 4 |
|
118 MAIN_AUTO_MASH_5, ///< Mash step 5 |
|
119 MAIN_AUTO_MASH_6, ///< Mash step 6 |
|
120 MAIN_AUTO_MASH_OUT, ///< Mash-out |
|
121 MAIN_AUTO_TOBOIL, ///< Going to boil |
|
122 MAIN_AUTO_BOILING, ///< Boiling |
|
123 MAIN_AUTO_WHIRLPOOL9, ///< Whirlpool |
|
124 MAIN_AUTO_COOLING_H, ///< Cooling hot type |
|
125 MAIN_AUTO_WHIRLPOOL7, ///< Whirlpool |
|
126 MAIN_AUTO_COOLING_M, ///< Cooling medium type |
|
127 MAIN_AUTO_WHIRLPOOL6, ///< Whirlpool |
|
128 MAIN_AUTO_COOLING_C, ///< Cooling cold type |
|
129 MAIN_AUTO_WHIRLPOOL2, ///< Whirlpool |
|
130 MAIN_AUTO_DONE, ///< Finished |
|
131 MAIN_AUTO_ABORT, ///< Aborted |
|
132 MAIN_MANUAL_INIT = 200, ///< Manual control init |
|
133 MAIN_MANUAL_MAIN, ///< Manual control main menu |
|
134 } MAIN_MODE; |
|
135 |
|
136 typedef enum { |
|
137 MASH_NONE = 0, ///< Initial Mash state |
|
138 MASH_WAITTEMP, ///< Wait to reach temperature. |
|
139 MASH_REST, ///< Mash rest |
|
140 MASH_ADD, ///< Add mash wait |
|
141 MASH_IODINE, ///< Wait iodine test |
|
142 MASH_REMOVE, ///< Wait mash remove |
|
143 } MASH_TYPE; |
|
144 |
|
145 typedef enum { |
|
146 SSR2_OFF = 0, ///< SSR2 not used. |
|
147 SSR2_HLT_SHARE, ///< SSR2 for HLT shared with MLT |
|
148 SSR2_HLT_IND, ///< SSR2 for HLT independend. |
|
149 SSR2_ON_IDLE, ///< SSR2 on when NLT is idle. |
|
150 } SSR2_TYPE; |
|
151 |
|
152 |
|
153 |
|
154 /** |
|
155 * @brief Global configuration. File /spiffs/config.conf |
|
156 */ |
|
157 struct strConfig { |
|
158 uint8_t Version; ///< Record version number for updates. |
|
159 uint8_t Unit; ///< Celsius or Farenheit (not used yet). |
|
160 float BoilTemperature; ///< The temperature when water boils. |
|
161 bool AskAdd; ///< Ask to add the mash. |
|
162 bool AskRemove; ///< Ask to remove the mash. |
|
163 bool AskIodine; ///< Ask to confirm the iodine test. |
|
164 uint8_t IodineTime; ///< Continue after this time if not confirmed. |
|
165 int EquipmentRec; ///< Equipment record number. |
|
166 char obsolete1[32]; ///< Obsolete. |
|
167 char hostname[32]; ///< Our hostname. |
|
168 char ap_ssid[32]; ///< AP SSID. |
|
169 char ap_pwd[64]; ///< AP password. |
|
170 uint8_t ap_channel; ///< AP channel. |
|
171 uint8_t ap_ssid_hidden; ///< AP SSID hidden. |
|
172 wifi_bandwidth_t ap_bandwidth; ///< AP channel bandwidth. |
|
173 uint16_t ts_xleft; ///< TS calibration X left. |
|
174 uint16_t ts_xright; ///< TS calibration X right. |
|
175 uint16_t ts_ytop; ///< TS calibration Y top. |
|
176 uint16_t ts_ybottom; ///< TS calibration Y bottom. |
|
177 int RecipeRec; ///< Current recipe record. |
|
178 char uuid[37]; ///< Sort of uuid code. |
|
179 char lastSSID[32]; ///< Last connected station. |
|
180 } config; |
|
181 |
|
182 /** |
|
183 * @brief Write configuration to disk. |
|
184 */ |
|
185 void write_config(void); |
|
186 |
|
187 /** @brief Read configuration file. If it doesn't exist create and |
|
188 * write a new configuration file with sane defaults. |
|
189 */ |
|
190 void read_config(void); |
|
191 |
|
192 |
|
193 |
|
194 /** |
|
195 * @brief Equipment configuration. File /spiffs/equipments.conf |
|
196 */ |
|
197 struct strEquipment { |
|
198 int Version; ///< Record version number for updates. |
|
199 int Record; ///< Record number. |
|
200 char Name[32]; ///< Equipment name. |
|
201 int BoilPower; ///< The power percentage needed to keep the wort boiling. |
|
202 int MashPower; ///< The power percentage needed to heat during mash. |
|
203 int PumpCycle; ///< Minutes to run the pump during mash rest. |
|
204 int PumpRest; ///< Minutes to pause the pump during mash rests. |
|
205 bool PumpPreMash; ///< Pump on before mash-in. |
|
206 bool PumpOnMash; ///< Pump on during mashing. |
|
207 bool PumpMashOut; ///< Pump on during mash remove. |
|
208 bool PumpOnBoil; ///< Pump on during the boil. |
|
209 int PumpMaxTemp; ///< Turn pump off above this temperature. |
|
210 bool PIDPipe; ///< Run PID during mash removal. |
|
211 int SSR2; ///< Use second SSR (HLT) or not. |
|
212 float TempHLT; ///< The temperature of the sparge water. |
|
213 double PID_kP; ///< PID P setting. |
|
214 double PID_kI; ///< PID I setting. |
|
215 double PID_kD; ///< PID D setting. |
|
216 bool PID_POn; ///< PID compute on Measurement or Errors. |
|
217 int SampleTime; ///< PID sample time in seconds. |
|
218 } equipment; |
|
219 |
|
220 /** |
|
221 * @brief Append equipments record to disk. |
|
222 */ |
|
223 void append_equipment(void); |
|
224 |
|
225 /** |
|
226 * @brief Read equipments file. If it doesn't exist create and |
|
227 * write a new equipment file with sane defaults. |
|
228 * This is then the first and default brew equipment. |
|
229 * @param RecNo Read the record with Record is RecNo. Start at 1. |
|
230 */ |
|
231 void read_equipment(int RecNo); |
|
232 |
|
233 /** |
|
234 * @brief Write rquipment record. It should exist. |
|
235 * @param RecNo The equipment record in memory to write at record. Records start at 1. |
|
236 */ |
|
237 void write_equipment(int RecNo); |
|
238 |
|
239 /** |
|
240 * @brief Delete equipment record, renumber remaining records. |
|
241 * @param RecNo The record to remove. |
|
242 */ |
|
243 void delete_equipment(int RecNo); |
|
244 |
|
245 |
|
246 |
|
247 /** |
|
248 * @brief Records with WiFi stations we have succesfully connected. |
|
249 */ |
|
250 struct strStations { |
|
251 char SSID[32]; ///< Station SSID |
|
252 char Password[64]; ///< Station password |
|
253 bool hide; ///< Hide from AP scan. |
|
254 } wifiStation; |
|
255 |
|
256 /** |
|
257 * @brief Add a new station record. |
|
258 * @param SSID The SSID |
|
259 * @param Password The password for this SSID |
|
260 * @return The record number, or -1 if error. |
|
261 */ |
|
262 int add_station(uint8_t *SSID, uint8_t *Password); |
|
263 |
|
264 /** |
|
265 * @brief Read station info record. |
|
266 * @param SSID Search for the SSID and load the record if found. |
|
267 * @return Return -1 if not found, else the record number and the wifiStation record is filled. |
|
268 */ |
|
269 int read_station(uint8_t *SSID); |
|
270 |
|
271 /** |
|
272 * @brief Remove station record. |
|
273 * @param SSID The SSID to remove. |
|
274 */ |
|
275 void remove_station(uint8_t *SSID); |
|
276 |
|
277 int blacklist_station(uint8_t *SSID); |
|
278 |
|
279 |
|
280 |
|
281 /** |
|
282 * @brief Runtime configuration. File /spiffs/runtime.conf |
|
283 */ |
|
284 struct strRuntime { |
|
285 uint8_t Version; ///< Record version number for updates. |
|
286 bool AutoModeStarted; ///< Running automode. |
|
287 int StageResume; ///< Current Resume Stage. |
|
288 int StageTimeLeft; ///< Current Stage Time left. |
|
289 uint8_t HopAddition; ///< Current Hop Addition. |
|
290 float ManualMLT; ///< Last used MLT temperature. |
|
291 float ManualHLT; ///< Last used HLT temperature. |
|
292 time_t BrewStart; ///< Brew start time. |
|
293 char Logfile[64]; ///< Brew logfile. |
|
294 bool UseHLT; ///< Use HLT during brew. |
|
295 bool PumpCooling; ///< Pump during cooling. |
|
296 uint32_t TimeBrewing; ///< Time we are brewing. |
|
297 } runtime; |
|
298 |
|
299 |
|
300 /** |
|
301 * @brief Write runtime information to disk. |
|
302 */ |
|
303 void write_runtime(void); |
|
304 |
|
305 /** |
|
306 * @brief Read runtime information file. If it doesn't exist create and |
|
307 * write a new runtime file with sane defaults. |
|
308 */ |
|
309 void read_runtime(void); |
|
310 |
|
311 |
|
312 typedef enum { |
|
313 ADDITION_HOP = 0, |
|
314 ADDITION_FERMENTABLE = 1, |
|
315 ADDITION_SPICE = 2, |
|
316 ADDITION_FINING = 3, |
|
317 ADDITION_WATER_AGENT = 4, |
|
318 ADDITION_HERB = 5, |
|
319 ADDITION_FLAVOR = 6, |
|
320 ADDITION_OTHER = 7, |
|
321 } ADDITION_TYPE; |
|
322 |
|
323 /** |
|
324 * @brief Mash steps |
|
325 */ |
|
326 typedef struct strMashStep { |
|
327 char Name[32]; ///< Step name. |
|
328 float Temperature; ///< Step temperature. |
|
329 uint16_t Resttime; ///< Step resttime. |
|
330 uint16_t Steptime; ///< Step time to reach temp. |
|
331 } mashstep_t; |
|
332 |
|
333 /** |
|
334 * @brief Hop and other additions |
|
335 */ |
|
336 typedef struct strAddition { |
|
337 uint16_t Time; ///< Time for addition. |
|
338 uint8_t Type; ///< Addition type, Hop, Syrop ... |
|
339 char Name[64]; ///< Addition name. |
|
340 } addition_t; |
|
341 |
|
342 /** |
|
343 * @brief Current recipe |
|
344 */ |
|
345 struct strRecipe { |
|
346 uint8_t Version; ///< Record version number. |
|
347 int Record; |
|
348 char Name[128]; ///< Recipe name. |
|
349 char Code[32]; ///< Recipe code. |
|
350 mashstep_t MashStep[8]; ///< Mash steps. |
|
351 uint16_t BoilTime; ///< Boil time. |
|
352 uint8_t Additions; ///< Number of additions. |
|
353 addition_t Addition[10]; ///< Additions |
|
354 float CoolTemp; ///< Cool temperature. |
|
355 uint16_t Whirlpool9; ///< Zero or the Hot Whirlpool time 88..100 ° |
|
356 uint16_t Whirlpool7; ///< Zero or the Sub Isomerization Whirlpool time 71..77 ° |
|
357 uint16_t Whirlpool6; ///< Zero or the "Tepid" Whirlpool time 60..66 ° |
|
358 uint16_t Whirlpool2; ///< Zero or the Cold Whirlpool time < 30 ° |
|
359 float SpargeTemp; ///< Sparge water temperature. |
|
360 } recipe; |
|
361 |
|
362 /** |
|
363 * @brief Append a recipe record. Create file if it doesn't exist. |
|
364 */ |
|
365 void append_recipe(void); |
|
366 |
|
367 /** |
|
368 * @brief Write current recipe |
|
369 * @param RecNo Record number starting at 1. |
|
370 */ |
|
371 void write_recipe(int RecNo); |
|
372 |
|
373 /** |
|
374 * @brief Read current recipe |
|
375 * @param RecNo The record to read, start at 1. |
|
376 */ |
|
377 void read_recipe(int RecNo); |
|
378 |
|
379 /** |
|
380 * @brief Delete recipe record, renumber remaining records. |
|
381 * @param RecNo The record to remove. |
|
382 */ |
|
383 void delete_recipe(int RecNo); |
|
384 |
|
385 #endif |