main/config.h

Fri, 01 Nov 2019 13:13:14 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 01 Nov 2019 13:13:14 +0100
changeset 18
d969e0fe05dc
parent 17
f9eca4a55911
child 20
7c1dacafed03
permissions
-rw-r--r--

Added splash screen and unit zero set menu.

0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file config.h
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief The 'co2meter' configuration data. These are stored in the
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * spiffs filesystem in a flash partition.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 #ifndef _CONFIG_H
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 #define _CONFIG_H
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 // Global includes for the project
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 #include <stdio.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 #include <stdlib.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 #include <string.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 #include <stdbool.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 #include <time.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include <errno.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include <sys/unistd.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include <sys/fcntl.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include <sys/time.h>
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 #include "freertos/FreeRTOS.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include "freertos/task.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 #include "freertos/semphr.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 #include "freertos/event_groups.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 #include "freertos/queue.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "driver/gpio.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #include "driver/adc.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 #include "driver/rtc_io.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 #include "soc/sens_periph.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 #include "soc/rtc.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 #include "esp_adc_cal.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 #include "esp_sleep.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 #include "esp_log.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 #include "esp_spiffs.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #include "esp_vfs.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 #include "esp_system.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #include "esp_wifi.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 //#include "esp_wifi_types.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 #include "esp_wpa2.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 #include "esp_event.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 #include "esp_spi_flash.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 #include "esp_ota_ops.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 #include "esp_http_client.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 #include "nvs.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 #include "nvs_flash.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 #include "lwip/apps/sntp.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 #include "lwip/sockets.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 #include "lwip/dns.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 #include "lwip/netdb.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 #include "tcpip_adapter.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 #include "mqtt_client.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 #include "rotary_encoder.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 #include "u8g2_esp32_hal.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 #include "task_ds18b20.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 #include "task_adc.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 #include "task_wifi.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 #include "task_mqtt.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 #include "xutil.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 * @brief Mainloop 1 timed actions.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 typedef enum
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 {
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
69 ML1_INIT = 0, ///< Init fase
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
70 ML1_CONNECT, ///< Connect WiFi
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
71 ML1_MQTT_CONNECT, ///< Connect MQTT if WiFi
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
72 ML1_WAITCON, ///< Wait for connection and measurements
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
73 ML1_SEND, ///< Send MQTT node and units messages
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
74 ML1_WAITACK, ///< MQTT messages received
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
75 ML1_MQTT_DISCONNECT, ///< MQTT disconnect
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
76 ML1_DISCONNECT, ///< Disconnect WiFi
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
77 ML1_WIFI_OFF, ///< WiFi power off
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
78 ML1_DONE ///< All done
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
79 } ML1;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 * @brief Mainloop 2 user actions.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 typedef enum
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 {
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
88 ML2_INIT = 0,
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
89 ML2_USER, ///< User mainmenu
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
90 ML2_UNIT1, ///< Unit 1
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
91 ML2_UNIT2, ///< Unit 2
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
92 ML2_UNIT3, ///< Unit 3
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
93 ML2_SET_WIFI, ///< WiFi stations setup
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
94 ML2_SET_NETWORK, ///< Network setup
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
95 ML2_SET_MQTT, ///< MQTT setup
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
96 ML2_UPDATE, ///< Update
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
97 ML2_SETUP_UNIT1, ///< Unit 1 setup
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
98 ML2_SETUP_UNIT2, ///< Unit 2 setup
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
99 ML2_SETUP_UNIT3, ///< Unit 3 setup
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
100 ML2_ZERO_UNIT1, ///< Unit 1 set zero
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
101 ML2_ZERO_UNIT2, ///< Unit 2 set zero
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
102 ML2_ZERO_UNIT3, ///< Unit 3 set zero
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
103 ML2_INACTIVE, ///< Inactive reached, cleanup
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
104 ML2_DONE ///< All done
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
105 } ML2;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 * @brief Global configuration. File /spiffs/config.conf
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 struct strConfig {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 uint8_t Version; ///< Record version number for updates.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 char ntp_server[32]; ///< Preffered NTP server.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 char hostname[32]; ///< Our hostname.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 char uuid[37]; ///< Sort of uuid code.
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
117 char xlastSSID[32]; ///< Not used anymore.
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 char mqtt_server[32]; ///< MQTT server.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 uint16_t mqtt_port; ///< MQTT TCP port.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 char mqtt_user[32]; ///< MQTT user name if needed.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 char mqtt_pwd[62]; ///< MQTT password.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 } config; ///< Config record.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 * @brief Write configuration to disk.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 void write_config(void);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
130 /**
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
131 * @brief Read configuration file. If it doesn't exist create and
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
132 * write a new configuration file with sane defaults.
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 void read_config(void);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 * @brief Records with WiFi stations we have succesfully connected.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 struct strStations {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 char SSID[32]; ///< Station SSID
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 char Password[64]; ///< Station password
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 bool hide; ///< Hide from AP scan.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 } wifiStation; ///< Station record.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 * @brief Add a new station record.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 * @param SSID The SSID
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 * @param Password The password for this SSID
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 * @return The record number, or -1 if error.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 int add_station(uint8_t *SSID, uint8_t *Password);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 * @brief Read station info record.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 * @param SSID Search for the SSID and load the record if found.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 * @return Return -1 if not found, else the record number and the wifiStation record is filled.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 int read_station(uint8_t *SSID);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 * @brief Remove station record.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 * @param SSID The SSID to remove.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 void remove_station(uint8_t *SSID);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 * @brief Records that describes the carbonation units,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 typedef struct strUnit {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 char uuid[37]; ///< Unit uuid
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 char alias[33]; ///< Alias name 'unit1'
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 int temperature_state; ///< Reading status
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
177 char temperature_rom_code[17]; ///< DS18B20 address
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 uint32_t temperature; ///< Temperature in C * 1000
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 int pressure_state; ///< Reading status
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 uint8_t pressure_channel; ///< ADC channel
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 uint32_t pressure_voltage; ///< Measured voltage in mV.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 uint32_t pressure_zero; ///< Zero offset in mV.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 uint32_t pressure; ///< Pressure in bar * 1000;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 int mode; ///< Unit mode
8
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
185 uint32_t alarm; ///< Alarm bits
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 } unit_t;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187
8
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
188 #define ALARM_UNIT_PRESSURE 0x0001 ///< Unit pressure sensor error
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
189 #define ALARM_UNIT_TEMPERATURE 0x0002 ///< Unit temperature sensor error
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
190 #define ALARM_SYS_TEMPERATURE 0x0004 ///< System temperature sensor error
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
191
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
192
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 * @brief Write units to disk.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 void write_units(void);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 /** @brief Read units file. If it doesn't exist create and
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 * write a new units file with sane defaults.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 void read_units(void);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 #endif

mercurial