main/co2meter.c

Fri, 01 Nov 2019 14:23:48 +0100

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

Added code comments.

17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
1 /**
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
2 * @file co2meter.c
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
3 * @brief co2meter project.
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 */
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 #include "config.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 static const char *TAG = "co2meter";
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 #define PIN_SDA (CONFIG_I2C_MASTER_SDA)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 #define PIN_SCL (CONFIG_I2C_MASTER_SCL)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 #define ROT_ENC_A_GPIO (CONFIG_ROT_ENC_A_GPIO)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 #define ROT_ENC_B_GPIO (CONFIG_ROT_ENC_B_GPIO)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 #define ROT_ENC_SW_GPIO (CONFIG_ROT_ENC_SW_GPIO)
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: 14
diff changeset
15 #define INACTIVITY 480 ///< Time in 250 mSec units.
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: 14
diff changeset
16
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17
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: 14
diff changeset
18 int Main_Loop1 = ML1_INIT; ///< Loop 1 init
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 int Main_Loop2 = -1; ///< Loop 2 invalid
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: 14
diff changeset
20 int New_Loop2 = ML2_DONE; ///< Loop 2 new state
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 bool System_TimeOk = false; ///< System time status
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 time_t now; ///< Current time
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 struct tm timeinfo; ///< Current time structure
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 char strftime_buf[64]; ///< Time buffer
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 static RTC_DATA_ATTR struct timeval sleep_enter_time;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 static TaskHandle_t xTaskDS18B20 = NULL;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 static TaskHandle_t xTaskADC = NULL;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 static TaskHandle_t xTaskWifi = NULL;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 static TaskHandle_t xTaskMQTT = NULL;
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: 14
diff changeset
30 const esp_app_desc_t *app_desc = NULL; ///< Application description
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: 14
diff changeset
31 u8g2_t u8g2; ///< A structure which will contain all the data for one display
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: 14
diff changeset
32 rotary_encoder_info_t rinfo = { 0 }; ///< Rotary encoder record
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: 14
diff changeset
33 static int PushDuration = 0; ///< Duration of the pushed button
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
4
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
35 extern unit_t units[3]; ///< Pressure test units
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
36 extern SemaphoreHandle_t xSemaphoreUnits; ///< Units lock semaphore
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 extern DS18B20_State *ds18b20_state; ///< DS18B20 state
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 extern SemaphoreHandle_t xSemaphoreDS18B20; ///< DS18B20 lock semaphore
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 extern ADC_State *adc_state; ///< ADC state
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 extern SemaphoreHandle_t xSemaphoreADC; ///< ADC lock semaphore
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: 14
diff changeset
41 extern int count_pub; ///< Published MQTT messages in transit
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: 14
diff changeset
42 static xQueueHandle gpio_evt_queue = NULL; ///< Rotary pushbutton queue
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: 14
diff changeset
43 static int usertimer = 0; ///< User inactive timeout
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45
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: 14
diff changeset
46
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
47 /**
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
48 * @brief Write a menu line on the display.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
49 * @param bright Display the line with a bold or normal font.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
50 * @param x The horizontal start position of the line.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
51 * @param y The vertical bottom of the line position.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
52 * @param format The formatted data to display.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
53 */
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
54 void menu_line(int bright, int x, int y, const char *format, ...)
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
55 {
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
56 char buf[65];
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
57 va_list va_ptr;
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
58
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
59 if (bright)
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
60 u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
61 else
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
62 u8g2_SetFont(&u8g2, u8g2_font_t0_12_tr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
63
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
64 va_start(va_ptr, format);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
65 vsnprintf(buf, 65, format, va_ptr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
66 va_end(va_ptr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
67
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
68 u8g2_DrawStr(&u8g2, x, y, buf);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
69 }
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
70
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
71
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
72
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
73 /**
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
74 * @brief Clear the display and prepare the top of the display.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
75 * @format The formatted data to display at the top.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
76 */
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
77 void screen_top(const char *format, ...)
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
78 {
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
79 char buf[65];
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
80 va_list va_ptr;
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
81
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
82 va_start(va_ptr, format);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
83 vsnprintf(buf, 65, format, va_ptr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
84 va_end(va_ptr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
85
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
86 u8g2_ClearBuffer(&u8g2);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
87 u8g2_DrawHLine(&u8g2, 0, 14, 128);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
88
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
89 u8g2_SetFont(&u8g2, u8g2_font_t0_15_tr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
90 u8g2_uint_t w = u8g2_GetStrWidth(&u8g2, buf);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
91 u8g2_DrawStr(&u8g2, (128 - w) / 2,12, buf);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
92 }
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
93
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
94
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
95
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
96 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
97 * @brief The splash screen shown during cold boot or user wakeup.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
98 */
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
99 void screen_splash()
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
100 {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
101 screen_top("CO2 meter %s", app_desc->version);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
102
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
103 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
104 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, "START");
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
105 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,50, "START");
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
106
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
107 u8g2_SendBuffer(&u8g2);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
108 u8g2_SetPowerSave(&u8g2, 0); // wake up display
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
109 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
110
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
111
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
112
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
113 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
114 * @brief The main overview screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
115 */
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: 14
diff changeset
116 void screen_main()
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
117 {
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
118 char buf[65];
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: 14
diff changeset
119 int i;
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
120
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
121 screen_top("CO2 meter %s", app_desc->version);
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
122
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: 14
diff changeset
123 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
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: 14
diff changeset
124
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: 14
diff changeset
125 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
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: 14
diff changeset
126 sprintf(buf, "%.1f °C", units[0].temperature / 1000.0);
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
127 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, buf);
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: 14
diff changeset
128 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf);
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: 14
diff changeset
129 u8g2_SetFont(&u8g2, u8g2_font_t0_18b_tf);
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: 14
diff changeset
130
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: 14
diff changeset
131 for (i = 0; i < 3; i++) {
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: 14
diff changeset
132 sprintf(buf, "%.1f", units[i].pressure / 1000.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: 14
diff changeset
133 w = u8g2_GetUTF8Width(&u8g2, buf);
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: 14
diff changeset
134 u8g2_DrawUTF8(&u8g2, ((42 - w) / 2) + i * 43,63, buf);
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: 14
diff changeset
135 }
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: 14
diff changeset
136 xSemaphoreGive(xSemaphoreUnits);
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: 14
diff changeset
137 }
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: 14
diff changeset
138 u8g2_SendBuffer(&u8g2);
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: 14
diff changeset
139 u8g2_SetPowerSave(&u8g2, 0); // wake up display
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: 14
diff changeset
140 }
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: 14
diff changeset
141
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: 14
diff changeset
142
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: 14
diff changeset
143
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
144 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
145 * @brief The unit display screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
146 * @param no The unit index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
147 */
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: 14
diff changeset
148 void screen_unit(int no)
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: 14
diff changeset
149 {
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: 14
diff changeset
150 char buf[65];
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: 14
diff changeset
151
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
152 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
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: 14
diff changeset
153
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
154 screen_top("Unit %d %s", no + 1, units[no].mode ? "On":"Off");
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: 14
diff changeset
155
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: 14
diff changeset
156 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
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: 14
diff changeset
157 sprintf(buf, "%.1f °C", units[no].temperature / 1000.0);
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
158 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, buf);
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: 14
diff changeset
159 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf);
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: 14
diff changeset
160
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: 14
diff changeset
161 sprintf(buf, "%.2f bar", units[no].pressure / 1000.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: 14
diff changeset
162 w = u8g2_GetUTF8Width(&u8g2, buf);
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: 14
diff changeset
163 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,63, buf);
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
164
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: 14
diff changeset
165 xSemaphoreGive(xSemaphoreUnits);
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: 14
diff changeset
166 }
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: 14
diff changeset
167 u8g2_SendBuffer(&u8g2);
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: 14
diff changeset
168 u8g2_SetPowerSave(&u8g2, 0); // wake up display
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: 14
diff changeset
169 }
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: 14
diff changeset
170
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: 14
diff changeset
171
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: 14
diff changeset
172
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
173 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
174 * @brief The unit zero setup screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
175 * @param no The unit index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
176 * @param sub The submenu index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
177 */
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
178 void screen_unit_zero(int no, int sub)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
179 {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
180 screen_top("Unit %d zero mV", no + 1);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
181 menu_line( 0, 2, 25, "Current %d", units[no].pressure_zero);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
182 menu_line(sub == 0, 2, 37, "New value %d", units[no].pressure_voltage / (adc_state->Batt_voltage / 1000));
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
183 menu_line(sub == 1, 2, 49, "Return");
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
184 printf("current %d p_voltage %d batt %d\n", units[no].pressure_zero, units[no].pressure_voltage, adc_state->Batt_voltage);
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
185 u8g2_SendBuffer(&u8g2);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
186 u8g2_SetPowerSave(&u8g2, 0);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
187 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
188
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
189
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
190
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
191 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
192 * @brief The unit setup screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
193 * @param no The unit index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
194 * @param sub The submenu index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
195 */
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: 14
diff changeset
196 void screen_unit_setup(int no, int sub)
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: 14
diff changeset
197 {
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
198 screen_top("Unit %d setup", no + 1);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
199 menu_line(sub == 0, 2, 25, "Mode %s", units[no].mode ? "ON":"OFF");
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
200 menu_line(sub == 1, 2, 37, "Zero mV %d", units[no].pressure_zero);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
201 menu_line(sub == 2, 2, 49, "DS18B20 %s", units[no].temperature_rom_code);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
202 menu_line(sub == 3, 2, 61, "Return");
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
203 u8g2_SendBuffer(&u8g2);
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: 14
diff changeset
204 u8g2_SetPowerSave(&u8g2, 0);
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
205 }
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
206
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
207
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
208
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
209 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
210 * @brief Fatal messages on the screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
211 * @param e1 The first line.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
212 * @param e2 The second line.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
213 */
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
214 void screen_fatal(char *e1, char *e2)
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
215 {
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
216 u8g2_SetFont(&u8g2, u8g2_font_t0_15_tr);
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
217 u8g2_DrawStr(&u8g2,2,12,e1);
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
218 u8g2_DrawStr(&u8g2,2,24,e2);
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
219 u8g2_SendBuffer(&u8g2);
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
220 u8g2_SetPowerSave(&u8g2, 0);
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: 14
diff changeset
221 }
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
222
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: 14
diff changeset
223
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: 14
diff changeset
224
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
225 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
226 * @brief Interrupt service routine for the rotary pushbutton.
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: 14
diff changeset
227 */
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: 14
diff changeset
228 static void IRAM_ATTR gpio_isr_handler(void* arg)
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: 14
diff changeset
229 {
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: 14
diff changeset
230 uint32_t gpio_num = (uint32_t) arg;
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: 14
diff changeset
231 xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
232 }
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
233
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
234
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
235
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
236 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
237 * @brief GPIO queue task. See if there is a rotary pushbutton event on the queue.
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: 14
diff changeset
238 */
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: 14
diff changeset
239 static void gpio_task(void* arg)
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: 14
diff changeset
240 {
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: 14
diff changeset
241 uint32_t io_num;
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: 14
diff changeset
242 static int64_t pushed = 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: 14
diff changeset
243
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: 14
diff changeset
244 for(;;) {
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: 14
diff changeset
245 if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
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: 14
diff changeset
246 if (io_num == ROT_ENC_SW_GPIO) {
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: 14
diff changeset
247 if (gpio_get_level(io_num) == 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: 14
diff changeset
248 pushed = esp_timer_get_time();
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: 14
diff changeset
249 PushDuration = 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: 14
diff changeset
250 } else if (gpio_get_level(io_num) == 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: 14
diff changeset
251 PushDuration = (esp_timer_get_time() - pushed) / 1000;
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: 14
diff changeset
252 ESP_LOGI(TAG, "GPIO rotary button intr, val: %d time: %d", gpio_get_level(io_num), PushDuration);
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: 14
diff changeset
253 }
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: 14
diff changeset
254 } else {
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: 14
diff changeset
255 ESP_LOGE(TAG, "GPIO[%d] unknown intr, val: %d", io_num, gpio_get_level(io_num));
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: 14
diff changeset
256 }
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: 14
diff changeset
257 usertimer = INACTIVITY;
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: 14
diff changeset
258 }
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: 14
diff changeset
259 }
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: 14
diff changeset
260 }
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: 14
diff changeset
261
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: 14
diff changeset
262
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: 14
diff changeset
263
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
264 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
265 * @brief Select new menu number on a postitive or negative rotary position.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
266 * @param pos The new position, positive, negative or zero.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
267 * @param next_menu The selected menu if rotated clockwise.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
268 * @param prev_menu The selected menu if rotated counter-clockwise.
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: 14
diff changeset
269 */
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: 14
diff changeset
270 static void rotate_to_menu(rotary_encoder_position_t pos, int next_menu, int prev_menu)
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: 14
diff changeset
271 {
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: 14
diff changeset
272 if (pos > 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: 14
diff changeset
273 New_Loop2 = next_menu;
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: 14
diff changeset
274 else if (pos < 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: 14
diff changeset
275 New_Loop2 = prev_menu;
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: 14
diff changeset
276 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
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: 14
diff changeset
277 }
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: 14
diff changeset
278
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: 14
diff changeset
279
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
280
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
281 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
282 * @brief Rotate subscreens numbers.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
283 * @param pos The new position, positive, negative or zero.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
284 * @param min The lowest number. If already at the lowest, select the highest.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
285 * @param max The highest number. If already at the highest, select the lowest.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
286 * @param cursub The subscreen number by reference. This is updated with the new number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
287 * @return Returns true if a new number is selected, false if nothing changed.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
288 */
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
289 bool rotate_to_sub(rotary_encoder_position_t pos, int min, int max, int *cursub)
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
290 {
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
291 int sub = *cursub;
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
292 bool rc = false;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
293
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
294 if (pos > 0) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
295 if (sub < max)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
296 sub++;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
297 else
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
298 sub = min;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
299 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
300 rc = true;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
301 } else if (pos < 0) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
302 if (sub > min)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
303 sub--;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
304 else
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
305 sub = max;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
306 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
307 rc = true;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
308 }
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
309
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
310 *cursub = sub;
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
311 return rc;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
312 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
313
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
314
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
315
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 void app_main()
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 struct timeval now;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 gettimeofday(&now, NULL);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320 int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 esp_err_t ret;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322
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: 14
diff changeset
323 Main_Loop1 = ML1_INIT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324 Main_Loop2 = -1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
326 /*
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
327 * Setup the OLED display.
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
328 * See: https://github.com/nkolban/esp32-snippets/blob/master/hardware/displays/U8G2/
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
329 */
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
330 u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
331 u8g2_esp32_hal.sda = PIN_SDA;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
332 u8g2_esp32_hal.scl = PIN_SCL;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
333 u8g2_esp32_hal_init(u8g2_esp32_hal);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
334
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
335 u8g2_Setup_sh1106_i2c_128x64_noname_f(&u8g2, U8G2_R0, u8g2_esp32_i2c_byte_cb, u8g2_esp32_gpio_and_delay_cb); // init u8g2 structure
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
336 u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
337 u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
338
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
339 app_desc = esp_ota_get_app_description();
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
340
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 switch (esp_sleep_get_wakeup_cause()) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 case ESP_SLEEP_WAKEUP_EXT1: {
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: 14
diff changeset
343 ESP_LOGI(TAG, "Starting from deep sleep, Rotary switch pressed");
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: 14
diff changeset
344 New_Loop2 = ML2_INIT;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
345 screen_splash();
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 case ESP_SLEEP_WAKEUP_TIMER: {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 ESP_LOGI(TAG, "Starting from deep sleep, timer wakeup after %dms", sleep_time_ms);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 case ESP_SLEEP_WAKEUP_UNDEFINED:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 default:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 ESP_LOGI(TAG, "Starting from hard reset");
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
355 screen_splash();
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357
7
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
358 const int wakeup_time_sec = 55;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 ESP_LOGI(TAG, "Enabling timer wakeup, %ds", wakeup_time_sec);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 esp_sleep_enable_timer_wakeup(wakeup_time_sec * 1000000);
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: 14
diff changeset
361 const uint64_t ext_wakeup_pin_1_mask = 1ULL << ROT_ENC_SW_GPIO;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362
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: 14
diff changeset
363 ESP_LOGI(TAG, "Enabling EXT1 wakeup on pin GPIO%d", ROT_ENC_SW_GPIO);
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: 14
diff changeset
364 esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ALL_LOW);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 // Isolate GPIO12 pin from external circuits. This is needed for modules
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367 // which have an external pull-up resistor on GPIO12 (such as ESP32-WROVER)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368 // to minimize current consumption.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 // rtc_gpio_isolate(GPIO_NUM_12);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
372 * Initialize NVS
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
373 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374 ret = nvs_flash_init();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375 if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 ESP_ERROR_CHECK(nvs_flash_erase());
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377 ret = nvs_flash_init();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379 ESP_ERROR_CHECK(ret);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 /*
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
382 * Setup SPIFFS filesystem
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
383 */
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 ESP_LOGI(TAG, "Initializing SPIFFS");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 esp_vfs_spiffs_conf_t conf = {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 .base_path = "/spiffs",
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 .partition_label = NULL,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 .max_files = 5,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 .format_if_mount_failed = true
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 };
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
392 /*
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
393 * Use settings defined above to initialize and mount SPIFFS filesystem.
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
394 * Note: esp_vfs_spiffs_register is an all-in-one convenience function.
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
395 */
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 ret = esp_vfs_spiffs_register(&conf);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 if (ret != ESP_OK) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 if (ret == ESP_FAIL) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 ESP_LOGE(TAG, "Failed to mount or format filesystem");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 } else if (ret == ESP_ERR_NOT_FOUND) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 ESP_LOGE(TAG, "Failed to find SPIFFS partition");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 } else {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404 ESP_LOGE(TAG, "Failed to initialize SPIFFS (%d)", ret);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 }
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
406 screen_fatal("SPIFFS:", "init error");
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 return; // Stop application.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410 size_t total = 0, used = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 ret = esp_spiffs_info(NULL, &total, &used);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 if (ret != ESP_OK) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 ESP_LOGE(TAG, "Failed to get SPIFFS partition information");
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
414 screen_fatal("SPIFFS:", "partition error");
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 return; // Stop application.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 } else {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417 ESP_LOGI(TAG, "Partition size: %d, used: %d - %d%%", total, used, (used * 100) / total);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 // Just to debug, list the /spiffs filesystem.
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
421 #if 0
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422 DIR *dir = opendir("/spiffs");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423 struct dirent* de = readdir(dir);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424 while (de) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
425 if (de->d_type == DT_REG) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 printf("F ");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
427 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 if (de->d_type == DT_DIR) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429 printf("D ");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 printf("%s\n", de->d_name);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
432 de = readdir(dir);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
433 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 closedir(dir);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435 #endif
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
438 * Read or create configuration
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440 read_config();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441 read_units();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443 //add_station((uint8_t *)"MBSE_WLR", (uint8_t *)"abcjkltuv");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 //remove_station((uint8_t *)"MBSE_WLP");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
446 /*
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
447 * Create FreeRTOS tasks
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
448 */
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 xSemaphoreDS18B20 = xSemaphoreCreateMutex();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
450 xSemaphoreADC = xSemaphoreCreateMutex();
4
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
451 xSemaphoreUnits = xSemaphoreCreateMutex();
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
452
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 xTaskCreate(&task_ds18b20, "task_ds18b20", 2560, NULL, 8, &xTaskDS18B20);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
454 xTaskCreate(&task_adc, "task_adc", 2560, NULL, 8, &xTaskADC);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455 esp_log_level_set("wifi", ESP_LOG_ERROR);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456 xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi);
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
457 vTaskDelay(10 / portTICK_PERIOD_MS);
7
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
458 esp_log_level_set("MQTT_CLIENT", ESP_LOG_ERROR);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 xTaskCreate(&task_mqtt, "task_mqtt", 4096, NULL, 5, &xTaskMQTT);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460
7
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
461 /*
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
462 * Setup the Rotary Encoder.
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
463 * esp32-rotary-encoder requires that the GPIO ISR service is
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
464 * installed before calling rotary_encoder_register()
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
465 */
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
466 ESP_ERROR_CHECK(gpio_install_isr_service(0));
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
467 ESP_ERROR_CHECK(rotary_encoder_init(&rinfo, ROT_ENC_A_GPIO, ROT_ENC_B_GPIO));
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: 14
diff changeset
468 ESP_ERROR_CHECK(rotary_encoder_enable_half_steps(&rinfo, false));
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: 14
diff changeset
469
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: 14
diff changeset
470 gpio_config_t io_conf;
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: 14
diff changeset
471 io_conf.intr_type = GPIO_PIN_INTR_ANYEDGE;
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: 14
diff changeset
472 io_conf.pin_bit_mask = (1ULL << ROT_ENC_SW_GPIO);
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: 14
diff changeset
473 io_conf.mode = GPIO_MODE_INPUT;
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: 14
diff changeset
474 gpio_config(&io_conf);
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: 14
diff changeset
475
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: 14
diff changeset
476 gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
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: 14
diff changeset
477 xTaskCreate(gpio_task, "gpio_task", 2048, NULL, 10, NULL);
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: 14
diff changeset
478
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: 14
diff changeset
479 gpio_isr_handler_add(ROT_ENC_SW_GPIO, gpio_isr_handler, (void*) ROT_ENC_SW_GPIO);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 // Create a queue for events from the rotary encoder driver.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 // Tasks can read from this queue to receive up to date position information.
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: 14
diff changeset
483 QueueHandle_t event_queue = rotary_encoder_create_queue();
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: 14
diff changeset
484 ESP_ERROR_CHECK(rotary_encoder_set_queue(&rinfo, event_queue));
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487 * Main application loop.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489 while (1) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
491 ESP_LOGI(TAG, "Entered app loop");
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: 14
diff changeset
492 rotary_encoder_event_t event = { 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: 14
diff changeset
493 int sub = 0;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
494 u8g2_SetPowerSave(&u8g2, 1);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
495
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496 /* Measure process or user input via rotary switch */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497 while (1) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498 switch (Main_Loop1) {
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: 14
diff changeset
499 case ML1_INIT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
500 ESP_LOGI(TAG, "Loop timer: Init");
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: 14
diff changeset
501 // If configured do ML1_CONNECT
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: 14
diff changeset
502 Main_Loop1 = ML1_CONNECT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 requestWiFi_system(true);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504 request_ds18b20();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505 request_adc();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
506 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507
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: 14
diff changeset
508 case ML1_CONNECT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509 if (ready_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: 14
diff changeset
510 Main_Loop1 = ML1_MQTT_CONNECT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512
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: 14
diff changeset
513 case ML1_MQTT_CONNECT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514 if (ready_ds18b20() && ready_adc()) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515 connect_mqtt(true);
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: 14
diff changeset
516 Main_Loop1 = ML1_WAITCON;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
517 ESP_LOGI(TAG, "Loop timer: Wait MQTT");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519 /* Get global temperature, use for all units. */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520 uint32_t temp = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
521 int state = 0;
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
522 char rom_code[17];
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523 if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) {
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
524 temp = (ds18b20_state->sensor[0].temperature * 1000);
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
525 state = (ds18b20_state->sensor[0].error == 0) ? 0:1;
9
a85995941d0d Added publish logs. Another fix for DS18B20 rom address copy.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
526 strncpy(rom_code, ds18b20_state->sensor[0].rom_code, 17);
a85995941d0d Added publish logs. Another fix for DS18B20 rom address copy.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
527 rom_code[16] = '\0';
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528 xSemaphoreGive(xSemaphoreDS18B20);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529 }
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
530
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
531 /* Copy measured data and calculate results */
4
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
532 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
533 for (int i = 0; i < 3; i++) {
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
534 units[i].temperature = temp;
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
535 units[i].temperature_state = state;
8
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
536 units[i].alarm = 0;
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
537 if (state)
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
538 units[i].alarm |= ALARM_SYS_TEMPERATURE & ALARM_UNIT_TEMPERATURE;
4
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
539 strncpy(units[i].temperature_rom_code, rom_code, 17);
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
540 if (xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE) {
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
541 units[i].pressure_state = adc_state->Pressure[i].error;
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
542 units[i].pressure_channel = adc_state->Pressure[i].channel;
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
543 units[i].pressure_voltage = adc_state->Pressure[i].voltage;
8
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
544 if (units[i].pressure_state || units[i].pressure_voltage < 80)
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
545 units[i].alarm |= ALARM_UNIT_PRESSURE;
4
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
546 int P = (units[i].pressure_voltage / (adc_state->Batt_voltage / 1000) - units[i].pressure_zero) * 14; // in bar
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
547 if (P < 0)
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
548 P = 0;
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
549 units[i].pressure = P;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
550 printf("%d volt: %d batt: %d scale: %d mbar: %d\n", i, units[i].pressure_voltage, adc_state->Batt_voltage,
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551 units[i].pressure_voltage / (adc_state->Batt_voltage / 1000) - units[i].pressure_zero, P);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
552 // Moet die echt op 5 volt?
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 // Verbruik 10 mA
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554 // Setup tijd max 2 mS
4
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
555 xSemaphoreGive(xSemaphoreADC);
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
556 }
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557 }
4
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
558 write_units();
2a57c466bf45 FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
559 xSemaphoreGive(xSemaphoreUnits);
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: 14
diff changeset
560 switch (Main_Loop2) {
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: 14
diff changeset
561 case ML2_USER: screen_main(); break;
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: 14
diff changeset
562 case ML2_UNIT1: screen_unit(0); break;
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: 14
diff changeset
563 case ML2_UNIT2: screen_unit(1); break;
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: 14
diff changeset
564 case ML2_UNIT3: screen_unit(2); break;
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: 14
diff changeset
565 }
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569
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: 14
diff changeset
570 case ML1_WAITCON:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571 if (ready_mqtt())
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: 14
diff changeset
572 Main_Loop1 = ML1_SEND;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574
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: 14
diff changeset
575 case ML1_SEND:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576 ESP_LOGI(TAG, "Loop timer: Send MQTT");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
577 publishNode();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
578 publishUnits();
9
a85995941d0d Added publish logs. Another fix for DS18B20 rom address copy.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
579 publishLogs();
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: 14
diff changeset
580 Main_Loop1 = ML1_WAITACK;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582
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: 14
diff changeset
583 case ML1_WAITACK:
11
e33f2d325d15 Experimental mqtt published messages state counter
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
584 if (count_pub == 0) // Wait until all published messages are sent.
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: 14
diff changeset
585 Main_Loop1 = ML1_MQTT_DISCONNECT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587
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: 14
diff changeset
588 case ML1_MQTT_DISCONNECT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 ESP_LOGI(TAG, "Loop timer: Disconnect MQTT");
11
e33f2d325d15 Experimental mqtt published messages state counter
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
590 connect_mqtt(false); // Doesn't really 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: 14
diff changeset
591 Main_Loop1 = ML1_DISCONNECT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
592 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593
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: 14
diff changeset
594 case ML1_DISCONNECT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595 if (! ready_mqtt()) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596 ESP_LOGI(TAG, "Loop timer: WiFi off");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
597 requestWiFi_system(false);
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: 14
diff changeset
598 Main_Loop1 = ML1_WIFI_OFF;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
601
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: 14
diff changeset
602 case ML1_WIFI_OFF:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603 if (! ready_WiFi()) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604 ESP_LOGI(TAG, "Loop timer: Done");
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: 14
diff changeset
605 Main_Loop1 = ML1_DONE;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
608
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: 14
diff changeset
609 case ML1_DONE:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
612
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
613 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
614 * One time actions
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
615 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
616 if (New_Loop2 != Main_Loop2) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
617
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
618 Main_Loop2 = New_Loop2;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
619
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
620 switch (Main_Loop2) {
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: 14
diff changeset
621 case ML2_INIT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
622 ESP_LOGI(TAG, "Loop user: Init");
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: 14
diff changeset
623 New_Loop2 = ML2_USER;
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: 14
diff changeset
624 usertimer = INACTIVITY;
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: 14
diff changeset
625 break;
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: 14
diff changeset
626
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: 14
diff changeset
627 case ML2_USER:
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: 14
diff changeset
628 ESP_LOGI(TAG, "Loop 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: 14
diff changeset
629 screen_main();
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: 14
diff changeset
630 break;
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: 14
diff changeset
631
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: 14
diff changeset
632 case ML2_UNIT1:
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: 14
diff changeset
633 case ML2_UNIT2:
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: 14
diff changeset
634 case ML2_UNIT3:
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: 14
diff changeset
635 ESP_LOGI(TAG, "Loop user: Unit %d", Main_Loop2 - ML2_UNIT1);
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: 14
diff changeset
636 screen_unit(Main_Loop2 - ML2_UNIT1);
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: 14
diff changeset
637 break;
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: 14
diff changeset
638
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: 14
diff changeset
639 case ML2_SET_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: 14
diff changeset
640 ESP_LOGI(TAG, "Loop user: Setup WiFi");
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642
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: 14
diff changeset
643 case ML2_SET_NETWORK:
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: 14
diff changeset
644 ESP_LOGI(TAG, "Loop user: Setup Network");
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: 14
diff changeset
645 break;
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: 14
diff changeset
646
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: 14
diff changeset
647 case ML2_SET_MQTT:
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: 14
diff changeset
648 ESP_LOGI(TAG, "Loop user: Setup MQTT");
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: 14
diff changeset
649 break;
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: 14
diff changeset
650
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: 14
diff changeset
651 case ML2_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: 14
diff changeset
652 ESP_LOGI(TAG, "Loop user: 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: 14
diff changeset
653 break;
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: 14
diff changeset
654
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: 14
diff changeset
655 case ML2_SETUP_UNIT1:
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: 14
diff changeset
656 case ML2_SETUP_UNIT2:
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: 14
diff changeset
657 case ML2_SETUP_UNIT3:
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: 14
diff changeset
658 ESP_LOGI(TAG, "Loop user: Setup Unit %d", Main_Loop2 - ML2_SETUP_UNIT1);
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: 14
diff changeset
659 sub = 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: 14
diff changeset
660 screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, sub);
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: 14
diff changeset
661 break;
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: 14
diff changeset
662
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
663 case ML2_ZERO_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
664 case ML2_ZERO_UNIT2:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
665 case ML2_ZERO_UNIT3:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
666 ESP_LOGI(TAG, "Loop user: Zero Unit %d", Main_Loop2 - ML2_ZERO_UNIT1);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
667 sub = 0;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
668 screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, sub);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
669 break;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
670
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: 14
diff changeset
671 case ML2_INACTIVE:
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: 14
diff changeset
672 ESP_LOGI(TAG, "Loop user: Inactive");
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: 14
diff changeset
673 u8g2_SetPowerSave(&u8g2, 1); // powersave display
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: 14
diff changeset
674 New_Loop2 = ML2_DONE;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
675 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
676
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
677 default:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
678 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
679 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
680 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
681
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
682 /*
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
683 * Handle rotationg the rotary encoder.
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
684 */
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: 14
diff changeset
685 if (Main_Loop2 < ML2_INACTIVE) {
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
686 // If not configured, start configure
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
687 // If configured select first unit
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
688 // Handle screen (first is show measured values)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
689
14
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
690 // Display per unit. Temp + Pressure + state. Press is setup this sensor.
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
691 // Setup menu: Sensors
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
692 // WiFi
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
693 // MQTT
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
694 // System (timers etc)
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
695 // Update OTA
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
696 // Return
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
697
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
698 // Sensors menu: Assignments, turn to choose one.
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
699 // Sensors setup menu: DS18B20 addr Press is assign
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
700 // DS18B20 addr
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
701
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: 14
diff changeset
702 if (xQueueReceive(event_queue, &event, 250 / portTICK_PERIOD_MS) == pdTRUE) {
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: 14
diff changeset
703 usertimer = INACTIVITY;
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: 14
diff changeset
704 switch (Main_Loop2) {
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: 14
diff changeset
705 case ML2_USER: rotate_to_menu(event.state.position, ML2_UNIT1, ML2_USER); break;
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: 14
diff changeset
706 case ML2_UNIT1: rotate_to_menu(event.state.position, ML2_UNIT2, ML2_USER); break;
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: 14
diff changeset
707 case ML2_UNIT2: rotate_to_menu(event.state.position, ML2_UNIT3, ML2_UNIT1); break;
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: 14
diff changeset
708 case ML2_UNIT3: rotate_to_menu(event.state.position, ML2_SET_WIFI, ML2_UNIT2); break;
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: 14
diff changeset
709 case ML2_SET_WIFI: rotate_to_menu(event.state.position, ML2_SET_NETWORK, ML2_UNIT3); break;
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: 14
diff changeset
710 case ML2_SET_NETWORK: rotate_to_menu(event.state.position, ML2_SET_MQTT, ML2_SET_WIFI); break;
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: 14
diff changeset
711 case ML2_SET_MQTT: rotate_to_menu(event.state.position, ML2_UPDATE, ML2_SET_NETWORK); break;
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: 14
diff changeset
712 case ML2_UPDATE: rotate_to_menu(event.state.position, ML2_UPDATE, ML2_SET_MQTT); break;
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: 14
diff changeset
713 case ML2_SETUP_UNIT1:
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: 14
diff changeset
714 case ML2_SETUP_UNIT2:
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
715 case ML2_SETUP_UNIT3: if (rotate_to_sub(event.state.position, 0, 3, &sub))
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
716 screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, sub);
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
717 break;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
718 case ML2_ZERO_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
719 case ML2_ZERO_UNIT2:
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
720 case ML2_ZERO_UNIT3: if (rotate_to_sub(event.state.position, 0, 1, &sub))
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
721 screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, sub);
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: 14
diff changeset
722 break;
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: 14
diff changeset
723 default:
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: 14
diff changeset
724 ESP_LOGI(TAG, "Event: position %d, direction %s", event.state.position,
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: 14
diff changeset
725 event.state.direction ? (event.state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW":"CCW"):"NOT_SET");
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: 14
diff changeset
726 }
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: 14
diff changeset
727 } else {
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: 14
diff changeset
728 // Poll current position and direction
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
729 // rotary_encoder_state_t state = { 0 };
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
730 // ESP_ERROR_CHECK(rotary_encoder_get_state(&rinfo, &state));
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: 14
diff changeset
731
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: 14
diff changeset
732 // ESP_LOGI(TAG, "Poll: position %d, direction %s timer %d", state.position,
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: 14
diff changeset
733 // state.direction ? (state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW" : "CCW") : "NOT_SET", usertimer);
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
734 if (usertimer) {
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: 14
diff changeset
735 usertimer--;
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
736 if ((usertimer % 240) == 0) { // Each minute
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
737 ESP_LOGI(TAG, "usertimer %d", usertimer);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
738 if (Main_Loop1 == ML1_DONE)
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
739 Main_Loop1 = ML1_INIT;
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
740 }
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
741 } else
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: 14
diff changeset
742 New_Loop2 = ML2_INACTIVE;
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: 14
diff changeset
743 }
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
746 /*
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
747 * Handle pressed rotary button.
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
748 */
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
749 if (PushDuration) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
750 int idx = 0;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
751 switch (Main_Loop2) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
752 case ML2_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
753 case ML2_UNIT2:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
754 case ML2_UNIT3:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
755 New_Loop2 = ML2_SETUP_UNIT1 + (Main_Loop2 - ML2_UNIT1);
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: 14
diff changeset
756 break;
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: 14
diff changeset
757
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
758 case ML2_SETUP_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
759 case ML2_SETUP_UNIT2:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
760 case ML2_SETUP_UNIT3:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
761 idx = Main_Loop2 - ML2_SETUP_UNIT1;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
762 if (sub == 0) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
763 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
764 if (units[idx].mode)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
765 units[idx].mode = 0;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
766 else
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
767 units[idx].mode = 1;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
768 write_units();
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
769 xSemaphoreGive(xSemaphoreUnits);
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: 14
diff changeset
770 }
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
771 screen_unit_setup(idx, sub);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
772 if (Main_Loop1 == ML1_DONE)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
773 Main_Loop1 = ML1_INIT;
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: 14
diff changeset
774 }
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
775 if (sub == 1)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
776 New_Loop2 = ML2_ZERO_UNIT1 + idx;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
777 if (sub == 3)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
778 New_Loop2 = ML2_UNIT1 + idx;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
779 printf("unit setup sub %d new %d idx %d\n", sub, New_Loop2, idx);
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: 14
diff changeset
780 break;
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: 14
diff changeset
781
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
782 case ML2_ZERO_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
783 case ML2_ZERO_UNIT2:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
784 case ML2_ZERO_UNIT3:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
785 idx = Main_Loop2 - ML2_ZERO_UNIT1;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
786 if (sub == 0) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
787 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE &&
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
788 xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE &&
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
789 adc_state->Pressure[idx].voltage > 165 &&
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
790 adc_state->Pressure[idx].voltage < 660) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
791 units[idx].pressure_zero = adc_state->Pressure[idx].voltage / (adc_state->Batt_voltage / 1000);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
792 write_units();
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
793 xSemaphoreGive(xSemaphoreADC);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
794 xSemaphoreGive(xSemaphoreUnits);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
795 screen_unit_zero(idx, sub);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
796 if (Main_Loop1 == ML1_DONE)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
797 Main_Loop1 = ML1_INIT;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
798 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
799 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
800 if (sub == 1) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
801 New_Loop2 = ML2_SETUP_UNIT1 + idx;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
802 sub = 1;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
803 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
804 printf("unit zero sub %d new %d idx %d\n", sub, New_Loop2, idx);
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: 14
diff changeset
805 break;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
806
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
807 default:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
808 break;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
809 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
810 PushDuration = 0;
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: 14
diff changeset
811 }
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: 14
diff changeset
812
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: 14
diff changeset
813 if (Main_Loop1 == ML1_DONE && Main_Loop2 == ML2_DONE)
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
816 vTaskDelay(10 / portTICK_PERIOD_MS);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
817 }
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
818
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
819 ESP_LOGI(TAG, "Entering deep sleep");
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
820 gettimeofday(&sleep_enter_time, NULL);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
821 esp_deep_sleep_start();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
822
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: 14
diff changeset
823 Main_Loop1 = ML1_INIT;
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: 14
diff changeset
824 New_Loop2 = ML2_INIT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
825 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
826
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
827 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
828

mercurial