main/co2meter.c

Mon, 04 Nov 2019 19:35:05 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 04 Nov 2019 19:35:05 +0100
changeset 20
7c1dacafed03
parent 19
4fb9ed228a23
child 21
043ae27633f8
permissions
-rw-r--r--

Attempt to create a rotary editor

17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
1 /**
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
2 * @file co2meter.c
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
3 * @brief co2meter project.
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 #include "config.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 static const char *TAG = "co2meter";
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 #define PIN_SDA (CONFIG_I2C_MASTER_SDA)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 #define PIN_SCL (CONFIG_I2C_MASTER_SCL)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 #define ROT_ENC_A_GPIO (CONFIG_ROT_ENC_A_GPIO)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 #define ROT_ENC_B_GPIO (CONFIG_ROT_ENC_B_GPIO)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 #define ROT_ENC_SW_GPIO (CONFIG_ROT_ENC_SW_GPIO)
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
15 #define INACTIVITY 480 ///< Time in 250 mSec units.
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
16
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
17 #define EDIT_TYPE_TEXT 0 ///< Editor type is text
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
18 #define EDIT_TYPE_INT 1 ///< Editor type is integer
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
19 #define EDIT_TYPE_FLOAT 2 ///< Editor type is float
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
20
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
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
22 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
23 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
24 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
25 bool System_TimeOk = false; ///< System time status
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 time_t now; ///< Current time
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 struct tm timeinfo; ///< Current time structure
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 char strftime_buf[64]; ///< Time buffer
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 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
30 static TaskHandle_t xTaskDS18B20 = NULL;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 static TaskHandle_t xTaskADC = NULL;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 static TaskHandle_t xTaskWifi = NULL;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 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
34 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
35 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
36 rotary_encoder_info_t rinfo = { 0 }; ///< Rotary encoder record
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
37 rotary_encoder_event_t event = { 0 };
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
38 QueueHandle_t event_queue;
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
39 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
40
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
41 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
42 extern SemaphoreHandle_t xSemaphoreUnits; ///< Units lock semaphore
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 extern DS18B20_State *ds18b20_state; ///< DS18B20 state
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 extern SemaphoreHandle_t xSemaphoreDS18B20; ///< DS18B20 lock semaphore
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 extern ADC_State *adc_state; ///< ADC state
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 extern SemaphoreHandle_t xSemaphoreADC; ///< ADC lock semaphore
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
47 extern WIFI_State *wifi_state; ///< WiFi 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
48 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
49 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
50 static int usertimer = 0; ///< User inactive timeout
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52
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
53
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
54 /**
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
55 * @brief Get a keyboard character from the rotary encoder.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
56 * @param curkey The referenced value if the key being edited. NOTE, start at 0 for a new char??
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
57 * @param type The edittype, all values, integer or float.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
58 * @param x The x position on the screen.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
59 * @param y The y position on the screen.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
60 * @return 1 if short keypress, meaning enter key. 2 if long press, enter key and editing is ready.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
61 */
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
62 int getkey(int *curkey, int type, int x, int y)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
63 {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
64 int key = *curkey;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
65 int rc = 0;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
66
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
67 u8g2_DrawHLine(&u8g2, x, y+3, 12);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
68 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
69
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
70 for (;;) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
71 if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
72 usertimer = INACTIVITY;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
73 if (event.state.position != 0) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
74
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
75 u8g2_SetDrawColor(&u8g2, 0);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
76 u8g2_DrawGlyph(&u8g2, x, y, key);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
77 u8g2_SetDrawColor(&u8g2, 1);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
78 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
79
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
80 if (event.state.position > 0) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
81 if (key == 126)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
82 key = 171;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
83 else if (key < 126)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
84 key++;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
85 } else if (event.state.position < 0) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
86 if (key == 171)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
87 key = 126;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
88 else if (key > 32)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
89 key--;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
90 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
91
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
92 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
93 u8g2_DrawGlyph(&u8g2, x, y, key);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
94 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
95 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
96 } else {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
97 if (PushDuration) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
98 if (PushDuration > 500)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
99 rc = 2;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
100 else
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
101 rc = 1;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
102 PushDuration = 0;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
103 break;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
104 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
105 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
106 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
107 u8g2_SetDrawColor(&u8g2, 0);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
108 u8g2_DrawHLine(&u8g2, x, y+3, 12);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
109 u8g2_SetDrawColor(&u8g2, 1);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
110 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
111
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
112 *curkey = key;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
113 return rc;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
114 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
115
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
116
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
117
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
118 /**
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
119 * @brief Editor using the rotary switch.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
120 * @param label The label of the edit field.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
121 * @param txt The string to edit.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
122 * @param errmsg The error message if needed.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
123 * @param len The maximum length for the string.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
124 * @param type The edit type.
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
125 */
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
126 void rotary_editer(char *label, char *txt, char *errmsg, int len, int type)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
127 {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
128 char buf[65];
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
129 int key, x, y, rc;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
130
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
131 u8g2_ClearBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
132 u8g2_DrawHLine(&u8g2, 0, 14, 128);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
133 u8g2_DrawHLine(&u8g2, 0, 49, 128);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
134 u8g2_SetFont(&u8g2, u8g2_font_t0_15_tf);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
135 sprintf(buf, "Edit %s", label);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
136 u8g2_DrawStr(&u8g2,0,12,buf);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
137
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
138 if (strlen(errmsg)) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
139 u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tf);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
140 u8g2_DrawStr(&u8g2, 0, 61, errmsg);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
141 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
142 u8g2_SetFont(&u8g2, u8g2_font_t0_12_tf);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
143 y = 36;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
144 u8g2_DrawStr(&u8g2, 0, y, txt);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
145 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
146
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
147 for (;;) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
148 x = u8g2_GetUTF8Width(&u8g2, txt);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
149 key = 'a';
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
150 rc = getkey(&key, type, x, y);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
151 if (rc == 1) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
152 if (key >= 32 && key <= 126 && strlen(txt) < len) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
153 txt[strlen(txt) + 1] = '\0';
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
154 txt[strlen(txt)] = key;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
155 } else if (key == 171 && strlen(txt)) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
156 // delete key
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
157 txt[strlen(txt) - 1] = '\0';
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
158 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
159 printf("strlen %d x %d key %d\n", strlen(txt), x, key);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
160 } else if (rc == 2) {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
161 break;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
162 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
163 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
164 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
165
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
166
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
167
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
168 /**
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
169 * @brief Write a menu line on the display.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
170 * @param bright Display the line with a bold or normal font.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
171 * @param x The horizontal start position of the line.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
172 * @param y The vertical bottom of the line position.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
173 * @param format The formatted data to display.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
174 */
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
175 void menu_line(int bright, int x, int y, const char *format, ...)
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
176 {
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
177 char buf[65];
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
178 va_list va_ptr;
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
179
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
180 if (bright)
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
181 u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
182 else
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
183 u8g2_SetFont(&u8g2, u8g2_font_t0_12_tr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
184
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
185 va_start(va_ptr, format);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
186 vsnprintf(buf, 65, format, va_ptr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
187 va_end(va_ptr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
188
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
189 u8g2_DrawStr(&u8g2, x, y, buf);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
190 }
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
191
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
192
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
193
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
194 /**
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
195 * @brief Clear the display and prepare the top of the display.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
196 * @format The formatted data to display at the top.
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
197 */
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
198 void screen_top(const char *format, ...)
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
199 {
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
200 char buf[65];
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
201 va_list va_ptr;
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
202
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
203 va_start(va_ptr, format);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
204 vsnprintf(buf, 65, format, va_ptr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
205 va_end(va_ptr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
206
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
207 u8g2_ClearBuffer(&u8g2);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
208 u8g2_DrawHLine(&u8g2, 0, 14, 128);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
209
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
210 u8g2_SetFont(&u8g2, u8g2_font_t0_15_tr);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
211 u8g2_uint_t w = u8g2_GetStrWidth(&u8g2, buf);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
212 u8g2_DrawStr(&u8g2, (128 - w) / 2,12, buf);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
213 }
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
214
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
215
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
216
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
217 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
218 * @brief The splash screen shown during cold boot or user wakeup.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
219 */
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
220 void screen_splash()
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
221 {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
222 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
223
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
224 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
225 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
226 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
227
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
228 u8g2_SendBuffer(&u8g2);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
229 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
230 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
231
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
232
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
233
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
234 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
235 * @brief The main overview screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
236 */
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
237 void screen_main()
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
238 {
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
239 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
240 int i;
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
241
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
242 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
243
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
244 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
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 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
247 sprintf(buf, "%.1f °C", units[0].temperature / 1000.0);
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
248 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
249 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
250 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
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 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
253 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
254 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
255 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
256 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
257 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
258 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
259 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
260 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
261 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
262
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
263
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
264
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
265 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
266 * @brief The unit display screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
267 * @param no The unit index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
268 */
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
269 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
270 {
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
271 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
272
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
273 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
274
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
275 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
276
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
277 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
278 sprintf(buf, "%.1f °C", units[no].temperature / 1000.0);
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
279 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
280 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
281
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
282 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
283 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
284 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
285
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
286 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
287 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
288 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
289 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
290 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
291
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
292
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
293
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
294 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
295 * @brief The unit zero setup screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
296 * @param no The unit index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
297 * @param sub The submenu index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
298 */
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
299 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
300 {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
301 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
302 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
303 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
304 menu_line(sub == 1, 2, 49, "Return");
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
305 printf("current %d p_voltage %d batt %d\n", units[no].pressure_zero, units[no].pressure_voltage, adc_state->Batt_voltage);
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
306 u8g2_SendBuffer(&u8g2);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
307 u8g2_SetPowerSave(&u8g2, 0);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
308 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
309
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
310
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
311
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
312 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
313 * @brief The unit setup screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
314 * @param no The unit index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
315 * @param sub The submenu index number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
316 */
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
317 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
318 {
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
319 screen_top("Unit %d setup", no + 1);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
320 menu_line(sub == 0, 2, 25, "Mode %s", units[no].mode ? "ON":"OFF");
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
321 menu_line(sub == 1, 2, 37, "Zero mV %d", units[no].pressure_zero);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
322 menu_line(sub == 2, 2, 49, "DS18B20 %s", units[no].temperature_rom_code);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
323 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
324 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
325 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
326 }
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
327
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
328
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
329
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
330 void screen_wifi()
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
331 {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
332 char buf[65];
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
333
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
334 screen_top("WiFi Status");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
335 snprintf(buf, 65, "SSID %s", wifi_state->STA_ssid);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
336 u8g2_DrawStr(&u8g2, 1, 28, buf);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
337 snprintf(buf, 65, "Online %s", wifi_state->STA_online ? "Yes":"No");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
338 u8g2_DrawStr(&u8g2, 1, 43, buf);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
339 snprintf(buf, 65, "RSSI %d", wifi_state->STA_rssi);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
340 u8g2_DrawStr(&u8g2, 1, 59, buf);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
341 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
342 u8g2_SetPowerSave(&u8g2, 0);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
343 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
344
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
345
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
346
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
347 void screen_wifi_setup(int sub)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
348 {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
349 screen_top("WiFi Setup");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
350 menu_line(sub == 0, 2, 25, "Connect");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
351 menu_line(sub == 1, 2, 37, "New");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
352 menu_line(sub == 2, 2, 49, "Delete");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
353 menu_line(sub == 3, 2, 61, "Return");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
354 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
355 u8g2_SetPowerSave(&u8g2, 0);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
356 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
357
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
358
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
359
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
360 void screen_network()
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
361 {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
362 screen_top("Network Status");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
363 menu_line(0, 1, 25, "IP %s", wifi_state->STA_ip);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
364 menu_line(0, 1, 37, "Mask %s", wifi_state->STA_nm);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
365 menu_line(0, 1, 49, "GW %s", wifi_state->STA_gw);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
366 menu_line(0, 1, 61, "Name %s", config.hostname);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
367 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
368 u8g2_SetPowerSave(&u8g2, 0);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
369 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
370
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
371
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
372
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
373 void screen_mqtt()
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
374 {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
375 screen_top("MQTT Status");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
376 menu_line(0, 1, 25, "serv %s", config.mqtt_server);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
377 menu_line(0, 1, 37, "port %d", config.mqtt_port);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
378 menu_line(0, 1, 49, "user %s", config.mqtt_user);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
379 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
380 u8g2_SetPowerSave(&u8g2, 0);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
381 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
382
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
383
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
384
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
385 void screen_update()
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
386 {
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
387 screen_top("Update firmware");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
388 menu_line(0, 1, 43, "Push to update");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
389 u8g2_SendBuffer(&u8g2);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
390 u8g2_SetPowerSave(&u8g2, 0);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
391 }
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
392
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
393
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
394
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
395 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
396 * @brief Fatal messages on the screen.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
397 * @param e1 The first line.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
398 * @param e2 The second line.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
399 */
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
400 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
401 {
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
402 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
403 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
404 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
405 u8g2_SendBuffer(&u8g2);
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
406 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
407 }
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
408
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
409
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
410
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
411 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
412 * @brief Interrupt service routine for the rotary pushbutton.
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
413 */
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
414 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
415 {
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
416 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
417 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
418 }
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
419
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
420
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
421
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
422 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
423 * @brief GPIO queue task. See if there is a rotary pushbutton event on the queue.
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
424 */
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
425 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
426 {
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
427 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
428 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
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 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
431 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
432 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
433 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
434 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
435 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
436 } 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
437 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
438 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
439 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
440 } 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
441 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
442 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. 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 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
444 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
445 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
446 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
447
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
448
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
449
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
450 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
451 * @brief Select new menu number on a postitive or negative rotary position.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
452 * @param pos The new position, positive, negative or zero.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
453 * @param next_menu The selected menu if rotated clockwise.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
454 * @param prev_menu The selected menu if rotated counter-clockwise.
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
455 */
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
456 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
457 {
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
458 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
459 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
460 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
461 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
462 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
463 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
464
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
465
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
466
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
467 /**
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
468 * @brief Rotate subscreens numbers.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
469 * @param pos The new position, positive, negative or zero.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
470 * @param min The lowest number. If already at the lowest, select the highest.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
471 * @param max The highest number. If already at the highest, select the lowest.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
472 * @param cursub The subscreen number by reference. This is updated with the new number.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
473 * @return Returns true if a new number is selected, false if nothing changed.
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
474 */
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
475 bool rotate_to_sub(rotary_encoder_position_t pos, int min, int max, int *cursub)
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
476 {
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
477 int sub = *cursub;
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
478 bool rc = false;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
479
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
480 if (pos > 0) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
481 if (sub < max)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
482 sub++;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
483 else
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
484 sub = min;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
485 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
486 rc = true;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
487 } else if (pos < 0) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
488 if (sub > min)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
489 sub--;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
490 else
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
491 sub = max;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
492 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
493 rc = true;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
494 }
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
495
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
496 *cursub = sub;
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
497 return rc;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
498 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
499
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
500
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
501
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
502 void app_main()
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504 struct timeval now;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505 gettimeofday(&now, NULL);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
506 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
507 esp_err_t ret;
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
508 char txt[65];
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
510 Main_Loop1 = ML1_INIT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511 Main_Loop2 = -1;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
513 /*
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
514 * Setup the OLED display.
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
515 * 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
516 */
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
517 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
518 u8g2_esp32_hal.sda = PIN_SDA;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
519 u8g2_esp32_hal.scl = PIN_SCL;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
520 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
521
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
522 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
523 u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
524 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
525
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
526 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
527
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528 switch (esp_sleep_get_wakeup_cause()) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529 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
530 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
531 New_Loop2 = ML2_INIT;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
532 screen_splash();
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 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535 case ESP_SLEEP_WAKEUP_TIMER: {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536 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
537 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
539 case ESP_SLEEP_WAKEUP_UNDEFINED:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540 default:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
541 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
542 screen_splash();
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
543 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
544
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
545 const int wakeup_time_sec = 55;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546 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
547 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
548 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
549
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
550 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
551 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
552
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 // 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
554 // 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
555 // to minimize current consumption.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556 // rtc_gpio_isolate(GPIO_NUM_12);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 * Initialize NVS
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561 ret = nvs_flash_init();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
563 ESP_ERROR_CHECK(nvs_flash_erase());
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
564 ret = nvs_flash_init();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 ESP_ERROR_CHECK(ret);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 /*
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
569 * Setup SPIFFS filesystem
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
570 */
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571 ESP_LOGI(TAG, "Initializing SPIFFS");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 esp_vfs_spiffs_conf_t conf = {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 .base_path = "/spiffs",
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 .partition_label = NULL,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 .max_files = 5,
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576 .format_if_mount_failed = true
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
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
579 /*
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
580 * 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
581 * 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
582 */
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583 ret = esp_vfs_spiffs_register(&conf);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 if (ret != ESP_OK) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 if (ret == ESP_FAIL) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 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
588 } else if (ret == ESP_ERR_NOT_FOUND) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 ESP_LOGE(TAG, "Failed to find SPIFFS partition");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 } else {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591 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
592 }
13
7de246feba5f Updated esp-idf. The first two global screen functions created.
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
593 screen_fatal("SPIFFS:", "init error");
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
594 return; // Stop application.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
597 size_t total = 0, used = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 ret = esp_spiffs_info(NULL, &total, &used);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 if (ret != ESP_OK) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600 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
601 screen_fatal("SPIFFS:", "partition error");
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
602 return; // Stop application.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603 } else {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604 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
605 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607 // 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
608 #if 0
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
609 DIR *dir = opendir("/spiffs");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610 struct dirent* de = readdir(dir);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611 while (de) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
612 if (de->d_type == DT_REG) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
613 printf("F ");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
614 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
615 if (de->d_type == DT_DIR) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
616 printf("D ");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
617 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
618 printf("%s\n", de->d_name);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
619 de = readdir(dir);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
620 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
621 closedir(dir);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
622 #endif
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
623
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
624 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
625 * Read or create configuration
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
626 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
627 read_config();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
628 read_units();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
629
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
630 //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
631 //remove_station((uint8_t *)"MBSE_WLP");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
632
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
633 /*
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
634 * Create FreeRTOS tasks
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
635 */
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
636 xSemaphoreDS18B20 = xSemaphoreCreateMutex();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
637 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
638 xSemaphoreUnits = xSemaphoreCreateMutex();
0
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 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
641 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
642 esp_log_level_set("wifi", ESP_LOG_ERROR);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643 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
644 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
645 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
646 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
647
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
648 /*
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
649 * 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
650 * 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
651 * 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
652 */
6eafc4c2bf3d Sleep time is now 55 seconds. Code cleanup. Decrease MQTT library logging to Error.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
653 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
654 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
655 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
656
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
657 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
658 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
659 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
660 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
661 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
662
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. 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 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
664 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
665
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. 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 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
667
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
668 // 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
669 // Tasks can read from this queue to receive up to date position information.
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
670 event_queue = rotary_encoder_create_queue();
16
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
671 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
672
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
673 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
674 * Main application loop.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
675 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
676 while (1) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
677
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
678 ESP_LOGI(TAG, "Entered app loop");
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
679 //event = { 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
680 int sub = 0;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
681 u8g2_SetPowerSave(&u8g2, 1);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
682
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
683 /* Measure process or user input via rotary switch */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
684 while (1) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
685 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
686 case ML1_INIT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
687 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
688 // 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
689 Main_Loop1 = ML1_CONNECT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
690 requestWiFi_system(true);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
691 request_ds18b20();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
692 request_adc();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
693 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
694
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 case ML1_CONNECT:
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
696 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
697 Main_Loop1 = ML1_MQTT_CONNECT;
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
698 if (Main_Loop2 == ML2_WIFI)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
699 screen_wifi();
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
700 }
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
701 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
702
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
703 case ML1_MQTT_CONNECT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
704 if (ready_ds18b20() && ready_adc()) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
705 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
706 Main_Loop1 = ML1_WAITCON;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
707 ESP_LOGI(TAG, "Loop timer: Wait MQTT");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
708
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709 /* Get global temperature, use for all units. */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
710 uint32_t temp = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
711 int state = 0;
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
712 char rom_code[17];
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713 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
714 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
715 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
716 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
717 rom_code[16] = '\0';
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
718 xSemaphoreGive(xSemaphoreDS18B20);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
719 }
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
720
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
721 /* 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
722 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
723 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
724 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
725 units[i].temperature_state = state;
8
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
726 units[i].alarm = 0;
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
727 if (state)
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
728 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
729 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
730 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
731 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
732 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
733 units[i].pressure_voltage = adc_state->Pressure[i].voltage;
8
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
734 if (units[i].pressure_state || units[i].pressure_voltage < 80)
c6bbd1380f22 Added alarm flag for units.
Michiel Broek <mbroek@mbse.eu>
parents: 7
diff changeset
735 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
736 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
737 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
738 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
739 units[i].pressure = P;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
740 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
741 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
742 // Moet die echt op 5 volt?
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
743 // Verbruik 10 mA
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 // 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
745 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
746 }
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
747 }
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
748 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
749 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
750 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
751 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
752 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
753 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
754 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
755 }
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
756 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
757 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
759
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
760 case ML1_WAITCON:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
761 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
762 Main_Loop1 = ML1_SEND;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
763 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
764
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 case ML1_SEND:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766 ESP_LOGI(TAG, "Loop timer: Send MQTT");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767 publishNode();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 publishUnits();
9
a85995941d0d Added publish logs. Another fix for DS18B20 rom address copy.
Michiel Broek <mbroek@mbse.eu>
parents: 8
diff changeset
769 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
770 Main_Loop1 = ML1_WAITACK;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
772
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
773 case ML1_WAITACK:
11
e33f2d325d15 Experimental mqtt published messages state counter
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
774 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
775 Main_Loop1 = ML1_MQTT_DISCONNECT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
777
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
778 case ML1_MQTT_DISCONNECT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
779 ESP_LOGI(TAG, "Loop timer: Disconnect MQTT");
11
e33f2d325d15 Experimental mqtt published messages state counter
Michiel Broek <mbroek@mbse.eu>
parents: 9
diff changeset
780 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
781 Main_Loop1 = ML1_DISCONNECT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
783
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
784 case ML1_DISCONNECT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 if (! ready_mqtt()) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
786 ESP_LOGI(TAG, "Loop timer: WiFi off");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
787 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
788 Main_Loop1 = ML1_WIFI_OFF;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
789 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
790 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
791
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
792 case ML1_WIFI_OFF:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
793 if (! ready_WiFi()) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
794 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
795 Main_Loop1 = ML1_DONE;
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
796 if (Main_Loop2 == ML2_WIFI)
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
797 screen_wifi();
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
798 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800
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
801 case ML1_DONE:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
804
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806 * One time actions
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808 if (New_Loop2 != Main_Loop2) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
810 Main_Loop2 = New_Loop2;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
811
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
812 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
813 case ML2_INIT:
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814 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
815 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
816 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
817 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
818
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
819 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
820 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
821 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
822 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
823
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
824 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
825 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
826 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
827 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
828 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
829 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
830
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
831 case ML2_WIFI:
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
832 ESP_LOGI(TAG, "Loop user: WiFi");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
833 screen_wifi();
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
834 break;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
835
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
836 case ML2_NETWORK:
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
837 ESP_LOGI(TAG, "Loop user: Network");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
838 screen_network();
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
839 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
841 case ML2_MQTT:
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
842 ESP_LOGI(TAG, "Loop user: MQTT");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
843 screen_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
844 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
845
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
846 case ML2_SETUP_MQTT:
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
847 ESP_LOGI(TAG, "Loop user: MQTT setup");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
848 sprintf(txt, "EDtXt");
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
849 rotary_editer("MQTT demo", txt, "", 16, EDIT_TYPE_TEXT);
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
850 New_Loop2 = ML2_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
851 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
852
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
853 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
854 ESP_LOGI(TAG, "Loop user: Update");
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
855 screen_update();
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
856 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
857
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
858 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
859 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
860 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
861 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
862 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
863 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
864 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
865
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
866 case ML2_ZERO_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
867 case ML2_ZERO_UNIT2:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
868 case ML2_ZERO_UNIT3:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
869 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
870 sub = 0;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
871 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
872 break;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
873
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
874 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
875 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
876 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
877 New_Loop2 = ML2_DONE;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
878 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
879
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
880 default:
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
881 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
882 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
883 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
884
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
885 /*
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
886 * Handle rotationg the rotary encoder.
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
887 */
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
888 if (Main_Loop2 < ML2_INACTIVE) {
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
889 // If not configured, start configure
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
890 // If configured select first unit
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
891 // Handle screen (first is show measured values)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
892
14
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
893 // Display per unit. Temp + Pressure + state. Press is setup this sensor.
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
894 // Setup menu: Sensors
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
895 // WiFi
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
896 // MQTT
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
897 // System (timers etc)
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
898 // Update OTA
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
899 // Return
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
900
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
901 // Sensors menu: Assignments, turn to choose one.
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
902 // Sensors setup menu: DS18B20 addr Press is assign
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
903 // DS18B20 addr
deaca7606e23 Added some menu ideas
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
904
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
905 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
906 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
907 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
908 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
909 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
910 case ML2_UNIT2: rotate_to_menu(event.state.position, ML2_UNIT3, ML2_UNIT1); break;
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
911 case ML2_UNIT3: rotate_to_menu(event.state.position, ML2_WIFI, ML2_UNIT2); break;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
912 case ML2_WIFI: rotate_to_menu(event.state.position, ML2_NETWORK, ML2_UNIT3); break;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
913 case ML2_NETWORK: rotate_to_menu(event.state.position, ML2_MQTT, ML2_WIFI); break;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
914 case ML2_MQTT: rotate_to_menu(event.state.position, ML2_UPDATE, ML2_NETWORK); break;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
915 case ML2_UPDATE: rotate_to_menu(event.state.position, ML2_UPDATE, ML2_MQTT); break;
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
916 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
917 case ML2_SETUP_UNIT2:
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
918 case ML2_SETUP_UNIT3: if (rotate_to_sub(event.state.position, 0, 3, &sub))
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
919 screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, sub);
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
920 break;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
921 case ML2_ZERO_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
922 case ML2_ZERO_UNIT2:
19
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
923 case ML2_ZERO_UNIT3: if (rotate_to_sub(event.state.position, 0, 1, &sub))
4fb9ed228a23 Added code comments.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
924 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
925 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
926 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
927 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
928 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
929 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
930 } 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
931 // Poll current position and direction
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
932 // rotary_encoder_state_t state = { 0 };
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
933 // 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
934
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
935 // 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
936 // state.direction ? (state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW" : "CCW") : "NOT_SET", usertimer);
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
937 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
938 usertimer--;
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
939 if ((usertimer % 240) == 0) { // Each minute
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
940 ESP_LOGI(TAG, "usertimer %d", usertimer);
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
941 if (Main_Loop1 == ML1_DONE)
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
942 Main_Loop1 = ML1_INIT;
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
943 }
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
944 } 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
945 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
946 }
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
947 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
948
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
949 /*
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
950 * Handle pressed rotary button.
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
951 */
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
952 if (PushDuration) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
953 int idx = 0;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
954 switch (Main_Loop2) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
955 case ML2_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
956 case ML2_UNIT2:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
957 case ML2_UNIT3:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
958 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
959 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
960
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
961 case ML2_SETUP_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
962 case ML2_SETUP_UNIT2:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
963 case ML2_SETUP_UNIT3:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
964 idx = Main_Loop2 - ML2_SETUP_UNIT1;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
965 if (sub == 0) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
966 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
967 if (units[idx].mode)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
968 units[idx].mode = 0;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
969 else
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
970 units[idx].mode = 1;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
971 write_units();
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
972 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
973 }
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
974 screen_unit_setup(idx, sub);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
975 if (Main_Loop1 == ML1_DONE)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
976 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
977 }
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
978 if (sub == 1)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
979 New_Loop2 = ML2_ZERO_UNIT1 + idx;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
980 if (sub == 3)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
981 New_Loop2 = ML2_UNIT1 + idx;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
982 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
983 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
984
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
985 case ML2_ZERO_UNIT1:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
986 case ML2_ZERO_UNIT2:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
987 case ML2_ZERO_UNIT3:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
988 idx = Main_Loop2 - ML2_ZERO_UNIT1;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
989 if (sub == 0) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
990 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE &&
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
991 xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE &&
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
992 adc_state->Pressure[idx].voltage > 165 &&
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
993 adc_state->Pressure[idx].voltage < 660) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
994 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
995 write_units();
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
996 xSemaphoreGive(xSemaphoreADC);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
997 xSemaphoreGive(xSemaphoreUnits);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
998 screen_unit_zero(idx, sub);
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
999 if (Main_Loop1 == ML1_DONE)
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1000 Main_Loop1 = ML1_INIT;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1001 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1002 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1003 if (sub == 1) {
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1004 New_Loop2 = ML2_SETUP_UNIT1 + idx;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1005 sub = 1;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1006 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1007 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
1008 break;
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1009
20
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
1010 case ML2_MQTT:
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
1011 New_Loop2 = ML2_SETUP_MQTT;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
1012 break;
7c1dacafed03 Attempt to create a rotary editor
Michiel Broek <mbroek@mbse.eu>
parents: 19
diff changeset
1013
18
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1014 default:
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1015 break;
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1016 }
d969e0fe05dc Added splash screen and unit zero set menu.
Michiel Broek <mbroek@mbse.eu>
parents: 17
diff changeset
1017 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
1018 }
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
1019
e38ffa806e84 Initial code for the rotary switch and some menus. Changed default pushbutton pin from 12 to 14 and swapped the rotary pins. Disabled always create a new units file, it should be safe to keep it now.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
1020 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
1021 break;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1022
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1023 vTaskDelay(10 / portTICK_PERIOD_MS);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1024 }
6
06a5028dbcdf Hookup OLED I2C display to temorary display some data.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
1025
17
f9eca4a55911 More menus development.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
1026 ESP_LOGI(TAG, "Entering deep sleep");
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1027 gettimeofday(&sleep_enter_time, NULL);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1028 esp_deep_sleep_start();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1029
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
1030 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
1031 New_Loop2 = ML2_INIT;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1032 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1033
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1034 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1035

mercurial