Sun, 21 Oct 2018 13:07:50 +0200
Updated documentation
0 | 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 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
83 | #define VERSION "0.2.3" ///< Application version |
0 | 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. | |
2
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
109 | MAIN_TOOLS_FILES_DIR, ///< Main files directory listings. |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
110 | MAIN_TOOLS_FILES_RESTORE, ///< Main files restore. |
7a03d81c0e0d
Added database backup and restore.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
111 | MAIN_TOOLS_FILES_BACKUP, ///< Main files backup. |
0 | 112 | MAIN_TOOLS_UPDATES, ///< Main Updates. |
113 | MAIN_AUTO_INIT, ///< Automatic start | |
114 | MAIN_AUTO_DELAYSTART, ///< Delayed start | |
115 | MAIN_AUTO_HEATUP, ///< Heatup the system | |
116 | MAIN_AUTO_MASH_IN = 100, ///< Mash-in | |
117 | MAIN_AUTO_MASH_1, ///< Mash step 1 | |
118 | MAIN_AUTO_MASH_2, ///< Mash step 2 | |
119 | MAIN_AUTO_MASH_3, ///< Mash step 3 | |
120 | MAIN_AUTO_MASH_4, ///< Mash step 4 | |
121 | MAIN_AUTO_MASH_5, ///< Mash step 5 | |
122 | MAIN_AUTO_MASH_6, ///< Mash step 6 | |
123 | MAIN_AUTO_MASH_OUT, ///< Mash-out | |
124 | MAIN_AUTO_TOBOIL, ///< Going to boil | |
125 | MAIN_AUTO_BOILING, ///< Boiling | |
126 | MAIN_AUTO_WHIRLPOOL9, ///< Whirlpool | |
127 | MAIN_AUTO_COOLING_H, ///< Cooling hot type | |
128 | MAIN_AUTO_WHIRLPOOL7, ///< Whirlpool | |
129 | MAIN_AUTO_COOLING_M, ///< Cooling medium type | |
130 | MAIN_AUTO_WHIRLPOOL6, ///< Whirlpool | |
131 | MAIN_AUTO_COOLING_C, ///< Cooling cold type | |
132 | MAIN_AUTO_WHIRLPOOL2, ///< Whirlpool | |
133 | MAIN_AUTO_DONE, ///< Finished | |
134 | MAIN_AUTO_ABORT, ///< Aborted | |
135 | MAIN_MANUAL_INIT = 200, ///< Manual control init | |
136 | MAIN_MANUAL_MAIN, ///< Manual control main menu | |
137 | } MAIN_MODE; | |
138 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
139 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
140 | * @brief The differents stages in the mash steps. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
141 | */ |
0 | 142 | typedef enum { |
143 | MASH_NONE = 0, ///< Initial Mash state | |
144 | MASH_WAITTEMP, ///< Wait to reach temperature. | |
145 | MASH_REST, ///< Mash rest | |
146 | MASH_ADD, ///< Add mash wait | |
147 | MASH_IODINE, ///< Wait iodine test | |
148 | MASH_REMOVE, ///< Wait mash remove | |
149 | } MASH_TYPE; | |
150 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
151 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
152 | * @brief The working mode of the second heater SSR. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
153 | */ |
0 | 154 | typedef enum { |
155 | SSR2_OFF = 0, ///< SSR2 not used. | |
156 | SSR2_HLT_SHARE, ///< SSR2 for HLT shared with MLT | |
157 | SSR2_HLT_IND, ///< SSR2 for HLT independend. | |
158 | SSR2_ON_IDLE, ///< SSR2 on when NLT is idle. | |
159 | } SSR2_TYPE; | |
160 | ||
161 | ||
162 | ||
163 | /** | |
164 | * @brief Global configuration. File /spiffs/config.conf | |
165 | */ | |
166 | struct strConfig { | |
167 | uint8_t Version; ///< Record version number for updates. | |
168 | uint8_t Unit; ///< Celsius or Farenheit (not used yet). | |
169 | float BoilTemperature; ///< The temperature when water boils. | |
170 | bool AskAdd; ///< Ask to add the mash. | |
171 | bool AskRemove; ///< Ask to remove the mash. | |
172 | bool AskIodine; ///< Ask to confirm the iodine test. | |
173 | uint8_t IodineTime; ///< Continue after this time if not confirmed. | |
174 | int EquipmentRec; ///< Equipment record number. | |
175 | char obsolete1[32]; ///< Obsolete. | |
176 | char hostname[32]; ///< Our hostname. | |
177 | char ap_ssid[32]; ///< AP SSID. | |
178 | char ap_pwd[64]; ///< AP password. | |
179 | uint8_t ap_channel; ///< AP channel. | |
180 | uint8_t ap_ssid_hidden; ///< AP SSID hidden. | |
181 | wifi_bandwidth_t ap_bandwidth; ///< AP channel bandwidth. | |
182 | uint16_t ts_xleft; ///< TS calibration X left. | |
183 | uint16_t ts_xright; ///< TS calibration X right. | |
184 | uint16_t ts_ytop; ///< TS calibration Y top. | |
185 | uint16_t ts_ybottom; ///< TS calibration Y bottom. | |
186 | int RecipeRec; ///< Current recipe record. | |
187 | char uuid[37]; ///< Sort of uuid code. | |
188 | char lastSSID[32]; ///< Last connected station. | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
189 | } config; ///< Config record. |
0 | 190 | |
191 | /** | |
192 | * @brief Write configuration to disk. | |
193 | */ | |
194 | void write_config(void); | |
195 | ||
196 | /** @brief Read configuration file. If it doesn't exist create and | |
197 | * write a new configuration file with sane defaults. | |
198 | */ | |
199 | void read_config(void); | |
200 | ||
201 | ||
202 | ||
203 | /** | |
204 | * @brief Equipment configuration. File /spiffs/equipments.conf | |
205 | */ | |
206 | struct strEquipment { | |
207 | int Version; ///< Record version number for updates. | |
208 | int Record; ///< Record number. | |
209 | char Name[32]; ///< Equipment name. | |
210 | int BoilPower; ///< The power percentage needed to keep the wort boiling. | |
211 | int MashPower; ///< The power percentage needed to heat during mash. | |
212 | int PumpCycle; ///< Minutes to run the pump during mash rest. | |
213 | int PumpRest; ///< Minutes to pause the pump during mash rests. | |
214 | bool PumpPreMash; ///< Pump on before mash-in. | |
215 | bool PumpOnMash; ///< Pump on during mashing. | |
216 | bool PumpMashOut; ///< Pump on during mash remove. | |
217 | bool PumpOnBoil; ///< Pump on during the boil. | |
218 | int PumpMaxTemp; ///< Turn pump off above this temperature. | |
219 | bool PIDPipe; ///< Run PID during mash removal. | |
220 | int SSR2; ///< Use second SSR (HLT) or not. | |
221 | float TempHLT; ///< The temperature of the sparge water. | |
222 | double PID_kP; ///< PID P setting. | |
223 | double PID_kI; ///< PID I setting. | |
224 | double PID_kD; ///< PID D setting. | |
225 | bool PID_POn; ///< PID compute on Measurement or Errors. | |
226 | int SampleTime; ///< PID sample time in seconds. | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
227 | } equipment; ///< Equipment record. |
0 | 228 | |
229 | /** | |
230 | * @brief Append equipments record to disk. | |
231 | */ | |
232 | void append_equipment(void); | |
233 | ||
234 | /** | |
235 | * @brief Read equipments file. If it doesn't exist create and | |
236 | * write a new equipment file with sane defaults. | |
237 | * This is then the first and default brew equipment. | |
238 | * @param RecNo Read the record with Record is RecNo. Start at 1. | |
239 | */ | |
240 | void read_equipment(int RecNo); | |
241 | ||
242 | /** | |
243 | * @brief Write rquipment record. It should exist. | |
244 | * @param RecNo The equipment record in memory to write at record. Records start at 1. | |
245 | */ | |
246 | void write_equipment(int RecNo); | |
247 | ||
248 | /** | |
249 | * @brief Delete equipment record, renumber remaining records. | |
250 | * @param RecNo The record to remove. | |
251 | */ | |
252 | void delete_equipment(int RecNo); | |
253 | ||
254 | ||
255 | ||
256 | /** | |
257 | * @brief Records with WiFi stations we have succesfully connected. | |
258 | */ | |
259 | struct strStations { | |
260 | char SSID[32]; ///< Station SSID | |
261 | char Password[64]; ///< Station password | |
262 | bool hide; ///< Hide from AP scan. | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
263 | } wifiStation; ///< Station record. |
0 | 264 | |
265 | /** | |
266 | * @brief Add a new station record. | |
267 | * @param SSID The SSID | |
268 | * @param Password The password for this SSID | |
269 | * @return The record number, or -1 if error. | |
270 | */ | |
271 | int add_station(uint8_t *SSID, uint8_t *Password); | |
272 | ||
273 | /** | |
274 | * @brief Read station info record. | |
275 | * @param SSID Search for the SSID and load the record if found. | |
276 | * @return Return -1 if not found, else the record number and the wifiStation record is filled. | |
277 | */ | |
278 | int read_station(uint8_t *SSID); | |
279 | ||
280 | /** | |
281 | * @brief Remove station record. | |
282 | * @param SSID The SSID to remove. | |
283 | */ | |
284 | void remove_station(uint8_t *SSID); | |
285 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
286 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
287 | * @brief Blacklist station SSID |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
288 | * @param SSID The SSID to blacklist. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
289 | * @return -1 if error, else the record number. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
290 | */ |
0 | 291 | int blacklist_station(uint8_t *SSID); |
292 | ||
293 | ||
294 | ||
295 | /** | |
296 | * @brief Runtime configuration. File /spiffs/runtime.conf | |
297 | */ | |
298 | struct strRuntime { | |
299 | uint8_t Version; ///< Record version number for updates. | |
300 | bool AutoModeStarted; ///< Running automode. | |
301 | int StageResume; ///< Current Resume Stage. | |
302 | int StageTimeLeft; ///< Current Stage Time left. | |
303 | uint8_t HopAddition; ///< Current Hop Addition. | |
304 | float ManualMLT; ///< Last used MLT temperature. | |
305 | float ManualHLT; ///< Last used HLT temperature. | |
306 | time_t BrewStart; ///< Brew start time. | |
307 | char Logfile[64]; ///< Brew logfile. | |
308 | bool UseHLT; ///< Use HLT during brew. | |
309 | bool PumpCooling; ///< Pump during cooling. | |
310 | uint32_t TimeBrewing; ///< Time we are brewing. | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
311 | } runtime; ///< Runtime record. |
0 | 312 | |
313 | ||
314 | /** | |
315 | * @brief Write runtime information to disk. | |
316 | */ | |
317 | void write_runtime(void); | |
318 | ||
319 | /** | |
320 | * @brief Read runtime information file. If it doesn't exist create and | |
321 | * write a new runtime file with sane defaults. | |
322 | */ | |
323 | void read_runtime(void); | |
324 | ||
325 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
326 | |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
327 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
328 | * @brief Addition types |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
329 | */ |
0 | 330 | typedef enum { |
331 | ADDITION_HOP = 0, | |
332 | ADDITION_FERMENTABLE = 1, | |
333 | ADDITION_SPICE = 2, | |
334 | ADDITION_FINING = 3, | |
335 | ADDITION_WATER_AGENT = 4, | |
336 | ADDITION_HERB = 5, | |
337 | ADDITION_FLAVOR = 6, | |
338 | ADDITION_OTHER = 7, | |
339 | } ADDITION_TYPE; | |
340 | ||
341 | /** | |
342 | * @brief Mash steps | |
343 | */ | |
344 | typedef struct strMashStep { | |
345 | char Name[32]; ///< Step name. | |
346 | float Temperature; ///< Step temperature. | |
347 | uint16_t Resttime; ///< Step resttime. | |
348 | uint16_t Steptime; ///< Step time to reach temp. | |
349 | } mashstep_t; | |
350 | ||
351 | /** | |
352 | * @brief Hop and other additions | |
353 | */ | |
354 | typedef struct strAddition { | |
355 | uint16_t Time; ///< Time for addition. | |
356 | uint8_t Type; ///< Addition type, Hop, Syrop ... | |
357 | char Name[64]; ///< Addition name. | |
358 | } addition_t; | |
359 | ||
360 | /** | |
361 | * @brief Current recipe | |
362 | */ | |
363 | struct strRecipe { | |
364 | uint8_t Version; ///< Record version number. | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
365 | int Record; ///< Record number |
0 | 366 | char Name[128]; ///< Recipe name. |
367 | char Code[32]; ///< Recipe code. | |
368 | mashstep_t MashStep[8]; ///< Mash steps. | |
369 | uint16_t BoilTime; ///< Boil time. | |
370 | uint8_t Additions; ///< Number of additions. | |
371 | addition_t Addition[10]; ///< Additions | |
372 | float CoolTemp; ///< Cool temperature. | |
373 | uint16_t Whirlpool9; ///< Zero or the Hot Whirlpool time 88..100 ° | |
374 | uint16_t Whirlpool7; ///< Zero or the Sub Isomerization Whirlpool time 71..77 ° | |
375 | uint16_t Whirlpool6; ///< Zero or the "Tepid" Whirlpool time 60..66 ° | |
376 | uint16_t Whirlpool2; ///< Zero or the Cold Whirlpool time < 30 ° | |
377 | float SpargeTemp; ///< Sparge water temperature. | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
378 | } recipe; ///< Recipe record. |
0 | 379 | |
380 | /** | |
381 | * @brief Append a recipe record. Create file if it doesn't exist. | |
382 | */ | |
383 | void append_recipe(void); | |
384 | ||
385 | /** | |
386 | * @brief Write current recipe | |
387 | * @param RecNo Record number starting at 1. | |
388 | */ | |
389 | void write_recipe(int RecNo); | |
390 | ||
391 | /** | |
392 | * @brief Read current recipe | |
393 | * @param RecNo The record to read, start at 1. | |
394 | */ | |
395 | void read_recipe(int RecNo); | |
396 | ||
397 | /** | |
398 | * @brief Delete recipe record, renumber remaining records. | |
399 | * @param RecNo The record to remove. | |
400 | */ | |
401 | void delete_recipe(int RecNo); | |
402 | ||
403 | #endif |