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