Fri, 01 Nov 2019 13:13:14 +0100
Added splash screen and unit zero set menu.
17 | 1 | /** |
2 | * @file co2meter.c | |
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 | 47 | /** |
48 | * @brief Write a menu line on the display. | |
49 | * @param bright Display the line with a bold or normal font. | |
50 | * @param x The horizontal start position of the line. | |
51 | * @param y The vertical bottom of the line position. | |
52 | * @param format The formatted data to display. | |
53 | */ | |
54 | void menu_line(int bright, int x, int y, const char *format, ...) | |
55 | { | |
56 | char buf[65]; | |
57 | va_list va_ptr; | |
58 | ||
59 | if (bright) | |
60 | u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tr); | |
61 | else | |
62 | u8g2_SetFont(&u8g2, u8g2_font_t0_12_tr); | |
63 | ||
64 | va_start(va_ptr, format); | |
65 | vsnprintf(buf, 65, format, va_ptr); | |
66 | va_end(va_ptr); | |
67 | ||
68 | u8g2_DrawStr(&u8g2, x, y, buf); | |
69 | } | |
70 | ||
71 | ||
72 | ||
73 | /** | |
74 | * @brief Clear the display and prepare the top of the display. | |
75 | * @format The formatted data to display at the top. | |
76 | */ | |
77 | void screen_top(const char *format, ...) | |
78 | { | |
79 | char buf[65]; | |
80 | va_list va_ptr; | |
81 | ||
82 | va_start(va_ptr, format); | |
83 | vsnprintf(buf, 65, format, va_ptr); | |
84 | va_end(va_ptr); | |
85 | ||
86 | u8g2_ClearBuffer(&u8g2); | |
87 | u8g2_DrawHLine(&u8g2, 0, 14, 128); | |
88 | ||
89 | u8g2_SetFont(&u8g2, u8g2_font_t0_15_tr); | |
90 | u8g2_uint_t w = u8g2_GetStrWidth(&u8g2, buf); | |
91 | u8g2_DrawStr(&u8g2, (128 - w) / 2,12, buf); | |
92 | } | |
93 | ||
94 | ||
95 | ||
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
96 | void screen_splash() |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
97 | { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
98 | 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
|
99 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
100 | 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
|
101 | 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
|
102 | 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
|
103 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
104 | u8g2_SendBuffer(&u8g2); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
105 | 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
|
106 | } |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
107 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
108 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
109 | |
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
|
110 | void screen_main() |
13
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
111 | { |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
112 | 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
|
113 | int i; |
13
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
114 | |
17 | 115 | 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
|
116 | |
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
|
117 | 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
|
118 | |
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 | 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
|
120 | sprintf(buf, "%.1f °C", units[0].temperature / 1000.0); |
17 | 121 | 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
|
122 | 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
|
123 | 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
|
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 | 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
|
126 | 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
|
127 | 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
|
128 | 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
|
129 | } |
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 | 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
|
131 | } |
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 | 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
|
133 | 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
|
134 | } |
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 | |
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 | 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
|
139 | { |
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 | 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
|
141 | |
17 | 142 | 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
|
143 | |
17 | 144 | 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
|
145 | |
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
|
146 | 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
|
147 | sprintf(buf, "%.1f °C", units[no].temperature / 1000.0); |
17 | 148 | 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
|
149 | 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
|
150 | |
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 | 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
|
152 | 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
|
153 | 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
|
154 | |
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 | 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
|
156 | } |
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 | 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
|
158 | 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
|
159 | } |
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 | |
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 | |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
163 | 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
|
164 | { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
165 | 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
|
166 | 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
|
167 | 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
|
168 | menu_line(sub == 1, 2, 49, "Return"); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
169 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
170 | u8g2_SendBuffer(&u8g2); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
171 | u8g2_SetPowerSave(&u8g2, 0); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
172 | } |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
173 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
174 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
175 | |
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
|
176 | 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
|
177 | { |
17 | 178 | screen_top("Unit %d setup", no + 1); |
179 | menu_line(sub == 0, 2, 25, "Mode %s", units[no].mode ? "ON":"OFF"); | |
180 | menu_line(sub == 1, 2, 37, "Zero mV %d", units[no].pressure_zero); | |
181 | menu_line(sub == 2, 2, 49, "DS18B20 %s", units[no].temperature_rom_code); | |
182 | 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
|
183 | |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
184 | 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
|
185 | 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
|
186 | } |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
187 | |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
188 | |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
189 | |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
190 | 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
|
191 | { |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
192 | 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
|
193 | 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
|
194 | 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
|
195 | u8g2_SendBuffer(&u8g2); |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
196 | 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
|
197 | } |
13
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
198 | |
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
|
199 | |
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
|
200 | |
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
|
201 | /* |
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
|
202 | * Interrupt service routine for the rotary pushbutton. |
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
|
203 | */ |
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 | 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
|
205 | { |
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
|
206 | 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
|
207 | 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
|
208 | } |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
209 | |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
210 | |
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
211 | |
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
|
212 | /* |
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
|
213 | * GPIO queue task. See if there is a rotary pushbutton event in the 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
|
214 | */ |
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
|
215 | 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
|
216 | { |
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
|
217 | 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
|
218 | 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
|
219 | |
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
|
220 | 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
|
221 | 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
|
222 | 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
|
223 | 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
|
224 | 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
|
225 | 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
|
226 | } 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
|
227 | 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
|
228 | 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
|
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 | } 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
|
231 | 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
|
232 | } |
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
|
233 | 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
|
234 | } |
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
|
235 | } |
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
|
236 | } |
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
|
237 | |
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 | |
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 | * Select new menu number on a postitive or negative rotary 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
|
242 | * Then reset the rotary 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
|
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 | 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
|
245 | { |
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 (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
|
247 | 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
|
248 | 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
|
249 | 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
|
250 | 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
|
251 | } |
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 | |
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 | |
13
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
254 | |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
255 | int rotate_to_sub(rotary_encoder_position_t pos, int min, int max, int cursub) |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
256 | { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
257 | int sub = cursub; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
258 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
259 | if (pos > 0) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
260 | if (sub < max) |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
261 | sub++; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
262 | else |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
263 | sub = min; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
264 | ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo)); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
265 | } else if (pos < 0) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
266 | if (sub > min) |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
267 | sub--; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
268 | else |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
269 | sub = max; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
270 | ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo)); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
271 | } |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
272 | return sub; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
273 | } |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
274 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
275 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
276 | void app_main() |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
277 | { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
278 | struct timeval now; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | gettimeofday(&now, NULL); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
280 | 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
|
281 | esp_err_t ret; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
282 | |
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
|
283 | Main_Loop1 = ML1_INIT; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
284 | Main_Loop2 = -1; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
285 | |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
286 | /* |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
287 | * Setup the OLED display. |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
288 | * 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
|
289 | */ |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
290 | 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
|
291 | u8g2_esp32_hal.sda = PIN_SDA; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
292 | u8g2_esp32_hal.scl = PIN_SCL; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
293 | 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
|
294 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
295 | 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
|
296 | u8x8_SetI2CAddress(&u8g2.u8x8, 0x78); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
297 | 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
|
298 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
299 | 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
|
300 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
301 | switch (esp_sleep_get_wakeup_cause()) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
302 | 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
|
303 | 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
|
304 | New_Loop2 = ML2_INIT; |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
305 | screen_splash(); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
306 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
307 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | case ESP_SLEEP_WAKEUP_TIMER: { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | 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
|
310 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
312 | case ESP_SLEEP_WAKEUP_UNDEFINED: |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
313 | default: |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
314 | 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
|
315 | screen_splash(); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
316 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | |
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
|
318 | const int wakeup_time_sec = 55; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | 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
|
320 | 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
|
321 | 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
|
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 | 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
|
324 | 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
|
325 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
326 | // 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
|
327 | // 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
|
328 | // to minimize current consumption. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
329 | // rtc_gpio_isolate(GPIO_NUM_12); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
330 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
331 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
332 | * Initialize NVS |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
333 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
334 | ret = nvs_flash_init(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
335 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
336 | ESP_ERROR_CHECK(nvs_flash_erase()); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
337 | ret = nvs_flash_init(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
338 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
339 | ESP_ERROR_CHECK(ret); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
340 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
341 | /* |
6
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
342 | * Setup SPIFFS filesystem |
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
343 | */ |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
344 | ESP_LOGI(TAG, "Initializing SPIFFS"); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
345 | esp_vfs_spiffs_conf_t conf = { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
346 | .base_path = "/spiffs", |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
347 | .partition_label = NULL, |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
348 | .max_files = 5, |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
349 | .format_if_mount_failed = true |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
350 | }; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
351 | |
6
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
352 | /* |
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
353 | * 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
|
354 | * 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
|
355 | */ |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
356 | ret = esp_vfs_spiffs_register(&conf); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
357 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | if (ret != ESP_OK) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
359 | if (ret == ESP_FAIL) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
360 | 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
|
361 | } else if (ret == ESP_ERR_NOT_FOUND) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
362 | ESP_LOGE(TAG, "Failed to find SPIFFS partition"); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
363 | } else { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
364 | 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
|
365 | } |
13
7de246feba5f
Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
366 | screen_fatal("SPIFFS:", "init error"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
367 | return; // Stop application. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
368 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
369 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
370 | size_t total = 0, used = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
371 | ret = esp_spiffs_info(NULL, &total, &used); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
372 | if (ret != ESP_OK) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
373 | 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
|
374 | screen_fatal("SPIFFS:", "partition error"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
375 | return; // Stop application. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
376 | } else { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
377 | 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
|
378 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
379 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
380 | // 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
|
381 | #if 0 |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
382 | DIR *dir = opendir("/spiffs"); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
383 | struct dirent* de = readdir(dir); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
384 | while (de) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
385 | if (de->d_type == DT_REG) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
386 | printf("F "); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
387 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
388 | if (de->d_type == DT_DIR) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
389 | printf("D "); |
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 | printf("%s\n", de->d_name); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
392 | de = readdir(dir); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
393 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
394 | closedir(dir); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
395 | #endif |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
396 | |
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 | * Read or create configuration |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
399 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
400 | read_config(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
401 | read_units(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
402 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
403 | //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
|
404 | //remove_station((uint8_t *)"MBSE_WLP"); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
405 | |
6
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
406 | /* |
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
407 | * Create FreeRTOS tasks |
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
408 | */ |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
409 | xSemaphoreDS18B20 = xSemaphoreCreateMutex(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
410 | 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
|
411 | xSemaphoreUnits = xSemaphoreCreateMutex(); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
412 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
413 | 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
|
414 | 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
|
415 | esp_log_level_set("wifi", ESP_LOG_ERROR); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
416 | 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
|
417 | 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
|
418 | 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
|
419 | 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
|
420 | |
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
|
421 | /* |
6eafc4c2bf3d
Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
422 | * 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
|
423 | * 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
|
424 | * 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
|
425 | */ |
6eafc4c2bf3d
Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
426 | 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
|
427 | 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
|
428 | 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
|
429 | |
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
|
430 | 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
|
431 | 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
|
432 | 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
|
433 | 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
|
434 | 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
|
435 | |
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
|
436 | 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
|
437 | 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
|
438 | |
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
|
439 | 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
|
440 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
441 | // 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
|
442 | // 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
|
443 | 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
|
444 | 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
|
445 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
446 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
447 | * Main application loop. |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
448 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
449 | while (1) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
450 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
451 | 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
|
452 | 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
|
453 | int sub = 0; |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
454 | u8g2_SetPowerSave(&u8g2, 1); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
455 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
456 | /* Measure process or user input via rotary switch */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
457 | while (1) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
458 | 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
|
459 | case ML1_INIT: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
460 | 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
|
461 | // 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
|
462 | Main_Loop1 = ML1_CONNECT; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
463 | requestWiFi_system(true); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
464 | request_ds18b20(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
465 | request_adc(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
466 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
467 | |
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 | case ML1_CONNECT: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
469 | 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
|
470 | Main_Loop1 = ML1_MQTT_CONNECT; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
471 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
472 | |
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
|
473 | case ML1_MQTT_CONNECT: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
474 | if (ready_ds18b20() && ready_adc()) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
475 | 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
|
476 | Main_Loop1 = ML1_WAITCON; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
477 | ESP_LOGI(TAG, "Loop timer: Wait MQTT"); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
478 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
479 | /* Get global temperature, use for all units. */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
480 | uint32_t temp = 0; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
481 | int state = 0; |
2
c0184362d48c
Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
482 | char rom_code[17]; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
483 | 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
|
484 | 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
|
485 | 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
|
486 | 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
|
487 | rom_code[16] = '\0'; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
488 | xSemaphoreGive(xSemaphoreDS18B20); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
489 | } |
6
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
490 | |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
491 | /* 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
|
492 | 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
|
493 | 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
|
494 | 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
|
495 | units[i].temperature_state = state; |
8 | 496 | units[i].alarm = 0; |
497 | if (state) | |
498 | 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
|
499 | 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
|
500 | 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
|
501 | 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
|
502 | 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
|
503 | units[i].pressure_voltage = adc_state->Pressure[i].voltage; |
8 | 504 | if (units[i].pressure_state || units[i].pressure_voltage < 80) |
505 | 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
|
506 | 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
|
507 | 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
|
508 | 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
|
509 | units[i].pressure = P; |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
510 | 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
|
511 | 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
|
512 | // Moet die echt op 5 volt? |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
513 | // Verbruik 10 mA |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
514 | // 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
|
515 | 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
|
516 | } |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
517 | } |
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
|
518 | 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
|
519 | 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
|
520 | 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
|
521 | 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
|
522 | 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
|
523 | 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
|
524 | 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
|
525 | } |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
526 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
527 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
528 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
529 | |
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
|
530 | case ML1_WAITCON: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
531 | 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
|
532 | Main_Loop1 = ML1_SEND; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
533 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
534 | |
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
|
535 | case ML1_SEND: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
536 | ESP_LOGI(TAG, "Loop timer: Send MQTT"); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
537 | publishNode(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
538 | publishUnits(); |
9
a85995941d0d
Added publish logs. Another fix for DS18B20 rom address copy.
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
539 | 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
|
540 | Main_Loop1 = ML1_WAITACK; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
541 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
542 | |
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
|
543 | case ML1_WAITACK: |
11
e33f2d325d15
Experimental mqtt published messages state counter
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
544 | 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
|
545 | Main_Loop1 = ML1_MQTT_DISCONNECT; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
546 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
547 | |
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
|
548 | case ML1_MQTT_DISCONNECT: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
549 | ESP_LOGI(TAG, "Loop timer: Disconnect MQTT"); |
11
e33f2d325d15
Experimental mqtt published messages state counter
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
550 | 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
|
551 | Main_Loop1 = ML1_DISCONNECT; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
552 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
553 | |
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
|
554 | case ML1_DISCONNECT: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
555 | if (! ready_mqtt()) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
556 | ESP_LOGI(TAG, "Loop timer: WiFi off"); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
557 | 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
|
558 | Main_Loop1 = ML1_WIFI_OFF; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
559 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
560 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
561 | |
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
|
562 | case ML1_WIFI_OFF: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
563 | if (! ready_WiFi()) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
564 | 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
|
565 | Main_Loop1 = ML1_DONE; |
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 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
568 | |
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
|
569 | case ML1_DONE: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
570 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
571 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
572 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
573 | /* |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
574 | * One time actions |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
575 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
576 | if (New_Loop2 != Main_Loop2) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
577 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
578 | Main_Loop2 = New_Loop2; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
579 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
580 | 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
|
581 | case ML2_INIT: |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
582 | 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
|
583 | 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
|
584 | 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
|
585 | 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
|
586 | |
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
|
587 | 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
|
588 | 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
|
589 | 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
|
590 | 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
|
591 | |
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
|
592 | 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
|
593 | 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
|
594 | 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
|
595 | 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
|
596 | 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
|
597 | 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
|
598 | |
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
|
599 | 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
|
600 | ESP_LOGI(TAG, "Loop user: Setup WiFi"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
601 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
602 | |
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
|
603 | 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
|
604 | 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
|
605 | 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
|
606 | |
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
|
607 | 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
|
608 | 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
|
609 | 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
|
610 | |
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
|
611 | 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
|
612 | 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
|
613 | 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
|
614 | |
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
|
615 | 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
|
616 | 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
|
617 | 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
|
618 | 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
|
619 | 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
|
620 | 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
|
621 | 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
|
622 | |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
623 | case ML2_ZERO_UNIT1: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
624 | case ML2_ZERO_UNIT2: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
625 | case ML2_ZERO_UNIT3: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
626 | 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
|
627 | sub = 0; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
628 | 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
|
629 | break; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
630 | |
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
|
631 | 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
|
632 | 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
|
633 | 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
|
634 | New_Loop2 = ML2_DONE; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
635 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
636 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
637 | default: |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
638 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
639 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
640 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
641 | |
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 | * Main user processing. Handle the rotary encoder and pushbutton. |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
644 | */ |
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
|
645 | if (Main_Loop2 < ML2_INACTIVE) { |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
646 | // If not configured, start configure |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
647 | // If configured select first unit |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
648 | // Handle screen (first is show measured values) |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
649 | |
14 | 650 | // Display per unit. Temp + Pressure + state. Press is setup this sensor. |
651 | // Setup menu: Sensors | |
652 | // WiFi | |
653 | // MQTT | |
654 | // System (timers etc) | |
655 | // Update OTA | |
656 | // Return | |
657 | ||
658 | // Sensors menu: Assignments, turn to choose one. | |
659 | // Sensors setup menu: DS18B20 addr Press is assign | |
660 | // DS18B20 addr | |
661 | ||
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
|
662 | 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
|
663 | 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
|
664 | 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
|
665 | 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
|
666 | 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
|
667 | 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
|
668 | 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
|
669 | 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
|
670 | 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
|
671 | 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
|
672 | 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
|
673 | 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
|
674 | case ML2_SETUP_UNIT2: |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
675 | case ML2_SETUP_UNIT3: sub = rotate_to_sub(event.state.position, 0, 3, sub); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
676 | screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, sub); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
677 | break; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
678 | case ML2_ZERO_UNIT1: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
679 | case ML2_ZERO_UNIT2: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
680 | case ML2_ZERO_UNIT3: sub = rotate_to_sub(event.state.position, 0, 1, sub); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
681 | 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
|
682 | 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
|
683 | 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
|
684 | 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
|
685 | 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
|
686 | } |
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
|
687 | } 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
|
688 | // Poll current position and direction |
17 | 689 | // rotary_encoder_state_t state = { 0 }; |
690 | // 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
|
691 | |
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
|
692 | // 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
|
693 | // state.direction ? (state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW" : "CCW") : "NOT_SET", usertimer); |
17 | 694 | 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
|
695 | usertimer--; |
17 | 696 | if ((usertimer % 240) == 0) { // Each minute |
697 | ESP_LOGI(TAG, "usertimer %d", usertimer); | |
698 | if (Main_Loop1 == ML1_DONE) | |
699 | Main_Loop1 = ML1_INIT; | |
700 | } | |
701 | } 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
|
702 | 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
|
703 | } |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
704 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
705 | |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
706 | /* |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
707 | * Handle pressed rotary button. |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
708 | */ |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
709 | if (PushDuration) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
710 | int idx = 0; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
711 | switch (Main_Loop2) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
712 | case ML2_UNIT1: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
713 | case ML2_UNIT2: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
714 | case ML2_UNIT3: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
715 | 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
|
716 | 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
|
717 | |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
718 | case ML2_SETUP_UNIT1: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
719 | case ML2_SETUP_UNIT2: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
720 | case ML2_SETUP_UNIT3: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
721 | idx = Main_Loop2 - ML2_SETUP_UNIT1; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
722 | if (sub == 0) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
723 | if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
724 | if (units[idx].mode) |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
725 | units[idx].mode = 0; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
726 | else |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
727 | units[idx].mode = 1; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
728 | write_units(); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
729 | 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
|
730 | } |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
731 | screen_unit_setup(idx, sub); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
732 | if (Main_Loop1 == ML1_DONE) |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
733 | 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
|
734 | } |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
735 | if (sub == 1) |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
736 | New_Loop2 = ML2_ZERO_UNIT1 + idx; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
737 | if (sub == 3) |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
738 | New_Loop2 = ML2_UNIT1 + idx; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
739 | 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
|
740 | 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
|
741 | |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
742 | case ML2_ZERO_UNIT1: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
743 | case ML2_ZERO_UNIT2: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
744 | case ML2_ZERO_UNIT3: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
745 | idx = Main_Loop2 - ML2_ZERO_UNIT1; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
746 | if (sub == 0) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
747 | if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE && |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
748 | xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE && |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
749 | adc_state->Pressure[idx].voltage > 165 && |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
750 | adc_state->Pressure[idx].voltage < 660) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
751 | 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
|
752 | write_units(); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
753 | xSemaphoreGive(xSemaphoreADC); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
754 | xSemaphoreGive(xSemaphoreUnits); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
755 | screen_unit_zero(idx, sub); |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
756 | if (Main_Loop1 == ML1_DONE) |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
757 | Main_Loop1 = ML1_INIT; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
758 | } |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
759 | } |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
760 | if (sub == 1) { |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
761 | New_Loop2 = ML2_SETUP_UNIT1 + idx; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
762 | sub = 1; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
763 | } |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
764 | 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
|
765 | break; |
18
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
766 | |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
767 | default: |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
768 | break; |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
769 | } |
d969e0fe05dc
Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
770 | 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
|
771 | } |
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
|
772 | |
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
|
773 | 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
|
774 | break; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
775 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
776 | vTaskDelay(10 / portTICK_PERIOD_MS); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
777 | } |
6
06a5028dbcdf
Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
778 | |
17 | 779 | ESP_LOGI(TAG, "Entering deep sleep"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
780 | gettimeofday(&sleep_enter_time, NULL); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
781 | esp_deep_sleep_start(); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
782 | |
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
|
783 | 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
|
784 | New_Loop2 = ML2_INIT; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
785 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
786 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
787 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
788 |