main/config.h

branch
idf 5.1
changeset 129
31f9d3e4a85f
parent 121
30aca5888d2b
child 136
89fc3c57282e
equal deleted inserted replaced
128:64886971967b 129:31f9d3e4a85f
2 * @file config.h 2 * @file config.h
3 * @brief The BrewBoard configuration data. These are stored in the 3 * @brief The BrewBoard configuration data. These are stored in the
4 * spiffs filesystem in a flash partition. 4 * spiffs filesystem in a flash partition.
5 */ 5 */
6 6
7 #ifndef _CONFIG_H 7 #ifndef _G_CONFIG_H
8 #define _CONFIG_H 8 #define _G_CONFIG_H
9 9
10 // Global includes for the project 10 // Global includes for the project
11 11
12 #include <stdio.h> 12 #include <stdio.h>
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <string.h> 14 #include <string.h>
15 #include <stdbool.h> 15 #include <stdbool.h>
16 #include <time.h> 16 #include <time.h>
17 #include <inttypes.h>
17 #include <errno.h> 18 #include <errno.h>
18 #include <sys/unistd.h> 19 #include <sys/unistd.h>
19 #include <sys/fcntl.h> 20 #include <sys/fcntl.h>
20 #include <sys/time.h> 21 #include <sys/time.h>
21 22
22 #include "freertos/FreeRTOS.h" 23 #include "freertos/FreeRTOS.h"
23 #include "freertos/task.h" 24 #include "freertos/task.h"
24 #include "freertos/semphr.h" 25 #include "freertos/semphr.h"
25 #include "freertos/event_groups.h" 26 #include "freertos/event_groups.h"
26 #include "freertos/queue.h" 27 #include "freertos/queue.h"
28 #include "driver/gpio.h"
27 #include "driver/i2c.h" 29 #include "driver/i2c.h"
28 #include "driver/ledc.h" 30 #include "driver/ledc.h"
29 #include "esp_log.h" 31 #include "esp_log.h"
30 #include "esp_spiffs.h" 32 #include "esp_spiffs.h"
33 #include "esp_vfs.h"
34 #include "esp_system.h"
35 #include "esp_chip_info.h"
36 #include "esp_netif.h"
37 #include "esp_mac.h"
38 #include "esp_wifi.h"
39 #include "esp_wpa2.h"
31 #include "esp_event.h" 40 #include "esp_event.h"
32 #include "esp_wifi.h" 41 #include "esp_timer.h"
33 #include "esp_wifi_types.h"
34 #include "esp_system.h"
35
36 #include "esp_ota_ops.h" 42 #include "esp_ota_ops.h"
37 #include "esp_http_client.h" 43 #include "esp_http_client.h"
38 #include "esp_https_ota.h" 44 #include "esp_app_format.h"
39 45 #include "esp_sntp.h"
40 #include "esp_vfs.h"
41 #include "esp_vfs_fat.h"
42 #include "nvs.h"
43 #include "nvs_flash.h" 46 #include "nvs_flash.h"
47 #include "lwip/sockets.h"
48 #include "lwip/dns.h"
49 #include "lwip/netdb.h"
50
51 #include <expat.h>
52
44 #include "esp32/rom/crc.h" 53 #include "esp32/rom/crc.h"
45 #include "mdns.h"
46 #include "lwip/sockets.h"
47 #include "lwip/api.h"
48 #include "lwip/err.h"
49 #include "lwip/netdb.h"
50 #include "lwip/dns.h"
51 #include "lwip/opt.h"
52 #include "lwip/memp.h"
53 #include "lwip/ip.h"
54 #include "lwip/raw.h"
55 #include "lwip/udp.h"
56 #include "sdkconfig.h"
57 #include "esp_sntp.h"
58 #include "expat.h"
59 54
60 #include "tftspi.h" 55 #include "tftspi.h"
61 #include "tft.h" 56 #include "tft.h"
62 #include "PID_v1.h" 57 #include "PID_v1.h"
63 #include "websocket_server.h" 58 #include "websocket_server.h"
155 150
156 151
157 /** 152 /**
158 * @brief Global configuration. File /spiffs/config.conf 153 * @brief Global configuration. File /spiffs/config.conf
159 */ 154 */
160 struct strConfig { 155 typedef struct {
161 uint8_t Version; ///< Record version number for updates. 156 uint8_t Version; ///< Record version number for updates.
162 uint8_t Unit; ///< Celsius or Farenheit (not used yet). 157 uint8_t Unit; ///< Celsius or Farenheit (not used yet).
163 float BoilTemperature; ///< The temperature when water boils. 158 float BoilTemperature; ///< The temperature when water boils.
164 bool AskAdd; ///< Ask to add the mash. 159 bool AskAdd; ///< Ask to add the mash.
165 bool AskRemove; ///< Ask to remove the mash. 160 bool AskRemove; ///< Ask to remove the mash.
178 uint16_t ts_ytop; ///< TS calibration Y top. 173 uint16_t ts_ytop; ///< TS calibration Y top.
179 uint16_t ts_ybottom; ///< TS calibration Y bottom. 174 uint16_t ts_ybottom; ///< TS calibration Y bottom.
180 int RecipeRec; ///< Current recipe record. 175 int RecipeRec; ///< Current recipe record.
181 char uuid[37]; ///< Sort of uuid code. 176 char uuid[37]; ///< Sort of uuid code.
182 char lastSSID[32]; ///< Last connected station. 177 char lastSSID[32]; ///< Last connected station.
183 } config; ///< Config record. 178 } my_config_t;
184 179
185 /** 180 /**
186 * @brief Write configuration to disk. 181 * @brief Write configuration to disk.
187 */ 182 */
188 void write_config(void); 183 void write_config(void);
196 #define EQUIPMENT_VERSION 3 ///< Equipment file version 191 #define EQUIPMENT_VERSION 3 ///< Equipment file version
197 192
198 /** 193 /**
199 * @brief Equipment configuration. File /spiffs/equipments.conf 194 * @brief Equipment configuration. File /spiffs/equipments.conf
200 */ 195 */
201 struct hdrEquipment { 196 typedef struct {
202 uint32_t version; ///< Structure version. 197 uint32_t version; ///< Structure version.
203 uint32_t hdrsize; ///< Size of this header. 198 uint32_t hdrsize; ///< Size of this header.
204 uint32_t recsize; ///< Size of a record. 199 uint32_t recsize; ///< Size of a record.
205 } equipment_hdr; 200 } my_equipment_hdr_t;
206 201
207 struct strEquipment { 202 typedef struct {
208 int MLT_watt; ///< MLT watts. 203 int MLT_watt; ///< MLT watts.
209 int HLT_watt; ///< HLT watts. 204 int HLT_watt; ///< HLT watts.
210 char Name[32]; ///< Equipment name. 205 char Name[32]; ///< Equipment name.
211 int BoilPower; ///< The power percentage needed to keep the wort boiling. 206 int BoilPower; ///< The power percentage needed to keep the wort boiling.
212 int MashPower; ///< The power percentage needed to heat during mash. 207 int MashPower; ///< The power percentage needed to heat during mash.
226 bool xPID_POn; 221 bool xPID_POn;
227 int SampleTime; ///< PID sample time in seconds. 222 int SampleTime; ///< PID sample time in seconds.
228 bool Hendi; ///< HendiControl in use. 223 bool Hendi; ///< HendiControl in use.
229 int RampPower; ///< The power percentage to ramp to boil. 224 int RampPower; ///< The power percentage to ramp to boil.
230 int Max_watt; ///< MLT plus HLT peak, shut off HLT if higher. 225 int Max_watt; ///< MLT plus HLT peak, shut off HLT if higher.
231 } equipment; ///< Equipment record. 226 } my_equipment_t; ///< Equipment record.
232 227
233 /** 228 /**
234 * @brief Append equipments record to disk. 229 * @brief Append equipments record to disk.
235 */ 230 */
236 void append_equipment(void); 231 void append_equipment(void);
258 253
259 254
260 /** 255 /**
261 * @brief Records with WiFi stations we have succesfully connected. 256 * @brief Records with WiFi stations we have succesfully connected.
262 */ 257 */
263 struct strStations { 258 typedef struct {
264 char SSID[32]; ///< Station SSID 259 char SSID[32]; ///< Station SSID
265 char Password[64]; ///< Station password 260 char Password[64]; ///< Station password
266 bool hide; ///< Hide from AP scan. 261 bool hide; ///< Hide from AP scan.
267 } wifiStation; ///< Station record. 262 } my_wifiStation_t; ///< Station record.
268 263
269 /** 264 /**
270 * @brief Add a new station record. 265 * @brief Add a new station record.
271 * @param SSID The SSID 266 * @param SSID The SSID
272 * @param Password The password for this SSID 267 * @param Password The password for this SSID
290 285
291 286
292 /** 287 /**
293 * @brief Runtime configuration. File /spiffs/runtime.conf 288 * @brief Runtime configuration. File /spiffs/runtime.conf
294 */ 289 */
295 struct strRuntime { 290 typedef struct {
296 uint8_t Version; ///< Record version number for updates. 291 uint8_t Version; ///< Record version number for updates.
297 bool AutoModeStarted; ///< Running automode. 292 bool AutoModeStarted; ///< Running automode.
298 int StageResume; ///< Current Resume Stage. 293 int StageResume; ///< Current Resume Stage.
299 int StageTimeLeft; ///< Current Stage Time left. 294 int StageTimeLeft; ///< Current Stage Time left.
300 uint8_t HopAddition; ///< Current Hop Addition. 295 uint8_t HopAddition; ///< Current Hop Addition.
307 uint32_t TimeBrewing; ///< Time we are brewing. 302 uint32_t TimeBrewing; ///< Time we are brewing.
308 uint8_t MashStep; ///< Current mash step. 303 uint8_t MashStep; ///< Current mash step.
309 bool MaltAdded; ///< If malt was added. 304 bool MaltAdded; ///< If malt was added.
310 TickType_t MLT_usage; ///< MLT usage counter. 305 TickType_t MLT_usage; ///< MLT usage counter.
311 TickType_t HLT_usage; ///< HLT usage counter. 306 TickType_t HLT_usage; ///< HLT usage counter.
312 } runtime; ///< Runtime record. 307 } my_runtime_t; ///< Runtime record.
313 308
314 309
315 /** 310 /**
316 * @brief Write runtime information to disk. 311 * @brief Write runtime information to disk.
317 */ 312 */
354 } ADDITION_TYPE; 349 } ADDITION_TYPE;
355 350
356 /** 351 /**
357 * @brief Mash steps 352 * @brief Mash steps
358 */ 353 */
359 typedef struct strMashStep { 354 typedef struct {
360 char Name[32]; ///< Step name. 355 char Name[32]; ///< Step name.
361 uint8_t Type; ///< Step Type. 356 uint8_t Type; ///< Step Type.
362 float Step_temp; ///< Step start temperature. 357 float Step_temp; ///< Step start temperature.
363 uint16_t Step_time; ///< Step rest time. 358 uint16_t Step_time; ///< Step rest time.
364 uint16_t Ramp_time; ///< Step time to reach temp. 359 uint16_t Ramp_time; ///< Step time to reach temp.
368 } mashstep_t; 363 } mashstep_t;
369 364
370 /** 365 /**
371 * @brief Hop and other additions 366 * @brief Hop and other additions
372 */ 367 */
373 typedef struct strAddition { 368 typedef struct {
374 uint16_t Time; ///< Time for addition. 369 uint16_t Time; ///< Time for addition.
375 uint8_t Type; ///< Addition type, Hop, Syrop ... 370 uint8_t Type; ///< Addition type, Hop, Syrop ...
376 char Name[64]; ///< Addition name. 371 char Name[64]; ///< Addition name.
377 } addition_t; 372 } addition_t;
378 373
379 /** 374 /**
380 * @brief Recipes database. Starts with a header block for future upgrades, 375 * @brief Recipes database. Starts with a header block for future upgrades,
381 * followed by the actual recpie records. 376 * followed by the actual recpie records.
382 */ 377 */
383 struct hdrRecipe { 378 typedef struct {
384 uint32_t version; ///< Structure version. 379 uint32_t version; ///< Structure version.
385 uint32_t hdrsize; ///< Size of this header. 380 uint32_t hdrsize; ///< Size of this header.
386 uint32_t recsize; ///< Size of a record. 381 uint32_t recsize; ///< Size of a record.
387 uint8_t mashmax; ///< Maximum mash steps. 382 uint8_t mashmax; ///< Maximum mash steps.
388 uint8_t additionmax; ///< Maximum additions. 383 uint8_t additionmax; ///< Maximum additions.
389 } recipe_hdr; 384 } my_recipe_hdr_t;
390 385
391 struct strRecipe { 386 typedef struct {
392 char Name[128]; ///< Recipe name. 387 char Name[128]; ///< Recipe name.
393 char Code[32]; ///< Recipe code. 388 char Code[32]; ///< Recipe code.
394 uint16_t BoilTime; ///< Boil time. 389 uint16_t BoilTime; ///< Boil time.
395 uint8_t Mashsteps; ///< Number of mashsteps. 390 uint8_t Mashsteps; ///< Number of mashsteps.
396 uint8_t Additions; ///< Number of additions. 391 uint8_t Additions; ///< Number of additions.
400 uint16_t Whirlpool6; ///< Zero or the "Tepid" Whirlpool time 60..66 ° 395 uint16_t Whirlpool6; ///< Zero or the "Tepid" Whirlpool time 60..66 °
401 uint16_t Whirlpool2; ///< Zero or the Cold Whirlpool time < 30 ° 396 uint16_t Whirlpool2; ///< Zero or the Cold Whirlpool time < 30 °
402 float SpargeTemp; ///< Sparge water temperature. 397 float SpargeTemp; ///< Sparge water temperature.
403 mashstep_t MashStep[MASH_MAX]; ///< Mash steps. 398 mashstep_t MashStep[MASH_MAX]; ///< Mash steps.
404 addition_t Addition[ADDITION_MAX]; ///< Additions. 399 addition_t Addition[ADDITION_MAX]; ///< Additions.
405 } recipe; ///< Recipe record. 400 } my_recipe_t; ///< Recipe record.
406 401
407 /** 402 /**
408 * @brief Append a recipe record. Create file if it doesn't exist. 403 * @brief Append a recipe record. Create file if it doesn't exist.
409 */ 404 */
410 void append_recipe(void); 405 void append_recipe(void);

mercurial