main/task_user.c

Fri, 29 Nov 2019 14:26:37 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 29 Nov 2019 14:26:37 +0100
changeset 44
e52d11b8f252
parent 43
70c99c2084dc
child 51
5035385299f6
permissions
-rw-r--r--

Removed dead code. Added more doxygen documentation.

21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file task_user.c
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief co2meter project.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 #include "config.h"
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 static const char *TAG = "task_user";
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 EventGroupHandle_t xEventGroupUser; ///< Events User task
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 esp_timer_handle_t timerHandle; ///< Seconds timer
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 uint32_t SecsCount = 0; ///< Seconds counter
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 uint32_t UserTimer = 0; ///< User inactive timeout
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 int Main_Loop2 = -1; ///< Effective menu
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 int New_Loop2 = ML2_INIT; ///< New menu
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 int SubMenu = 0; ///< Submenu number
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
18 int SubOffset = 0; ///< Submenu offset
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 u8g2_t u8g2; ///< A structure which will contain all the data for one display
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 rotary_encoder_info_t rinfo = { 0 }; ///< Rotary encoder record
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
21 rotary_encoder_event_t event = { 0 }; ///< Rotary encoder events
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
22 QueueHandle_t event_queue; ///< Events queue
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
23 static xQueueHandle gpio_evt_queue = NULL; ///< Rotary pushbutton queue
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 static int PushDuration = 0; ///< Duration of the pushed button
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
25 struct strStations APs[10]; ///< List of APs we know
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
26 int edit_ssid = 0; ///< SSID being edited
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
27 int num_ssids = 0; ///< Number of SSIDs we know
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
28 struct strStations editAP; ///< Data of station to edit
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
29 char sensors[DS18B20_MAX][17]; ///< Sensors to select
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
31 extern const esp_app_desc_t *app_desc; ///< App description
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 extern unit_t units[3]; ///< Pressure test units
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 extern SemaphoreHandle_t xSemaphoreUnits; ///< Units lock semaphore
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 extern DS18B20_State *ds18b20_state; ///< DS18B20 state
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 extern SemaphoreHandle_t xSemaphoreDS18B20; ///< DS18B20 lock semaphore
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 extern ADC_State *adc_state; ///< ADC state
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 extern SemaphoreHandle_t xSemaphoreADC; ///< ADC lock semaphore
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 extern WIFI_State *wifi_state; ///< WiFi state
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
39 extern SemaphoreHandle_t xSemaphoreWiFi; ///< WiFi lock semaphore
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 extern int count_pub; ///< Published MQTT messages in transit
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 extern int Main_Loop1; ///< Main measure loop
26
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
42 extern int update_running; ///< If update is running
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
43 extern int num_sensors; ///< Detected DS18B20 sensors
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 const int TASK_USER_COLD = BIT0; ///< System cold start
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 const int TASK_USER_WAKEUP = BIT1; ///< System wakeup from deepsleep
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 const int TASK_USER_BUSY = BIT2; ///< User interface is busy doing something.
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
48 const int TASK_USER_REFRESH = BIT3; ///< Refresh requested
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 * @brief Seconds timer callback.
44
e52d11b8f252 Removed dead code. Added more doxygen documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
53 * @param arg Arguments for the timer.
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 void TimerCallback(void *arg);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 /***************************************************************************/
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 void TimerCallback(void *arg)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 SecsCount++;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 if ((SecsCount % 60) == 0) {
26
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
66 if (Main_Loop1 == ML1_DONE && update_running == 0)
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 Main_Loop1 = ML1_INIT;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 if (UserTimer == 1) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 ESP_LOGI(TAG, "User inactivity timeout");
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 xEventGroupClearBits(xEventGroupUser, TASK_USER_BUSY);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 u8g2_SetPowerSave(&u8g2, 1);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 if (UserTimer) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 UserTimer--;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 void user_cold()
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 xEventGroupSetBits(xEventGroupUser, TASK_USER_COLD);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 bool user_busy(void)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 if (xEventGroupGetBits(xEventGroupUser) & TASK_USER_BUSY)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 return true;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 return false;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 * @brief Get a keyboard character from the rotary encoder.
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
100 * @param curkey The referenced value if the key being edited.
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 * @param type The edittype, all values, integer or float.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 * @param x The x position on the screen.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 * @param y The y position on the screen.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 * @return 1 if short keypress, meaning enter key. 2 if long press, enter key and editing is ready.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 int getkey(int *curkey, int type, int x, int y)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 {
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
108 int key = *curkey;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
109 int rc = 0;
23
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
110 int8_t ascent = u8g2_GetAscent(&u8g2);
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
111 int8_t descent = u8g2_GetDescent(&u8g2);
23
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
112 int8_t charheight = u8g2_GetMaxCharHeight(&u8g2);
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
113 int8_t charwidth = u8g2_GetMaxCharWidth(&u8g2);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
115 u8g2_DrawGlyph(&u8g2, x, y, key);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 u8g2_DrawHLine(&u8g2, x, y+3, 12);
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
117 u8g2_UpdateDisplay(&u8g2);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
119 ESP_LOGI(TAG, "getkey(%c, %d, %d, %d) a %d d %d h %d w %d", key, type, x, y, ascent, descent, charheight, charwidth);
23
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
120
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 for (;;) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 UserTimer = INACTIVITY;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 if (event.state.position != 0) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
126 u8g2_SetDrawColor(&u8g2, 0);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
127 u8g2_DrawBox(&u8g2, x, y - 12, charwidth, charheight);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
128 u8g2_SetDrawColor(&u8g2, 1);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
129 u8g2_DrawHLine(&u8g2, x, y+3, charwidth);
23
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
130
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
131 if (event.state.position > 0) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
132 /*
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
133 * If turned fast, the encoder registers multiple steps.
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
134 * So follow these steps.
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
135 */
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
136 for (int i = 0; i < event.state.position; i++) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
137 if (type == EDIT_TYPE_CAPS) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
138 if (key < 127)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
139 key++;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
140 if (key > 96 && key < 123)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
141 key = 123;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
142 } else if (type == EDIT_TYPE_INT) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
143 if (key < 127)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
144 key++;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
145 if (key < 45)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
146 key = 45;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
147 if (key == 46 || key == 47)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
148 key = 48;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
149 if (key > 57)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
150 key = 127;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
151 } else if (type == EDIT_TYPE_FLOAT) {
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
153 } else { // EDIT_TYPE_TEXT
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
154 if (key < 127)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
155 key++;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
156 }
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
157 }
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
158 } else if (event.state.position < 0) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
159 for (int i = 0; i > event.state.position; i--) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
160 if (type == EDIT_TYPE_CAPS) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
161 if (key > 32)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
162 key--;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
163 if (key > 96 && key < 123)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
164 key = 96;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
165 } else if (type == EDIT_TYPE_INT) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
166 if (key > 45)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
167 key--;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
168 if (key > 57)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
169 key = 57;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
170 if (key == 46 || key == 47)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
171 key = 45;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
172 } else if (type == EDIT_TYPE_FLOAT) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
173
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
174 } else { // EDIT_TYPE_TEXT
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
175 if (key > 32)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
176 key--;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
177 }
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
178 }
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 u8g2_DrawGlyph(&u8g2, x, y, key);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 u8g2_SendBuffer(&u8g2);
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
184 u8g2_UpdateDisplay(&u8g2);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 } else {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 if (PushDuration) {
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
188 UserTimer = INACTIVITY;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 if (PushDuration > 500)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 rc = 2;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 else
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 rc = 1;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 PushDuration = 0;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 u8g2_SetDrawColor(&u8g2, 0);
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
199 if (key == 127)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
200 u8g2_DrawBox(&u8g2, x, y - 12, charwidth, charheight); // Erase DEL character
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
201 u8g2_DrawHLine(&u8g2, x, y+3, charwidth);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 u8g2_SetDrawColor(&u8g2, 1);
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
203 u8g2_UpdateDisplay(&u8g2);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 *curkey = key;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 return rc;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 * @brief Editor using the rotary switch.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 * @param label The label of the edit field.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 * @param txt The string to edit.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 * @param errmsg The error message if needed.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 * @param len The maximum length for the string.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 * @param type The edit type.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 void rotary_editer(char *label, char *txt, char *errmsg, int len, int type)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 char buf[65];
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 int key, x, y, rc;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 u8g2_ClearBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 u8g2_DrawHLine(&u8g2, 0, 14, 128);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 u8g2_DrawHLine(&u8g2, 0, 49, 128);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 u8g2_SetFont(&u8g2, u8g2_font_t0_15_tf);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 sprintf(buf, "Edit %s", label);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 u8g2_DrawStr(&u8g2,0,12,buf);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 if (strlen(errmsg)) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tf);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 u8g2_DrawStr(&u8g2, 0, 61, errmsg);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 }
23
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
235 u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 y = 36;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 u8g2_DrawStr(&u8g2, 0, y, txt);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 u8g2_SendBuffer(&u8g2);
23
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
239 ESP_LOGI(TAG, "rotary_editer(%s, %s, %s, %d, %d)", label, txt, errmsg, len, type);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
241 /*
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
242 * Choose initial edit key
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
243 */
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
244 if (type == EDIT_TYPE_CAPS)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
245 key = 'A';
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
246 else if (type == EDIT_TYPE_INT || type == EDIT_TYPE_FLOAT)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
247 key = '0';
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
248 else
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
249 key = 'a';
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
250
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 for (;;) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 x = u8g2_GetUTF8Width(&u8g2, txt);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 rc = getkey(&key, type, x, y);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 if (rc == 1) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 if (key >= 32 && key <= 126 && strlen(txt) < len) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 txt[strlen(txt) + 1] = '\0';
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 txt[strlen(txt)] = key;
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
258 } else if (key == 127 && strlen(txt)) {
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 // delete key
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 txt[strlen(txt) - 1] = '\0';
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
261 if (strlen(txt))
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
262 key = txt[strlen(txt) - 1];
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 }
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
264 ESP_LOGI(TAG, " strlen %d x %d key %d `%s`", strlen(txt), x, key, txt);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 } else if (rc == 2) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 }
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
269 ESP_LOGI(TAG, "rotary_editer() `%s`", txt);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 * @brief Write a menu line on the display.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 * @param bright Display the line with a bold or normal font.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 * @param x The horizontal start position of the line.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 * @param y The vertical bottom of the line position.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 * @param format The formatted data to display.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 void menu_line(int bright, int x, int y, const char *format, ...)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 char buf[65];
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 va_list va_ptr;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 if (bright)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tr);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 else
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 u8g2_SetFont(&u8g2, u8g2_font_t0_12_tr);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 va_start(va_ptr, format);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 vsnprintf(buf, 65, format, va_ptr);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 va_end(va_ptr);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 u8g2_DrawStr(&u8g2, x, y, buf);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 * @brief Clear the display and prepare the top of the display.
44
e52d11b8f252 Removed dead code. Added more doxygen documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
302 * @param format The formatted data to display at the top.
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304 void screen_top(const char *format, ...)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 char buf[65];
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 va_list va_ptr;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 va_start(va_ptr, format);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 vsnprintf(buf, 65, format, va_ptr);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 va_end(va_ptr);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313 u8g2_ClearBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 u8g2_DrawHLine(&u8g2, 0, 14, 128);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 u8g2_SetFont(&u8g2, u8g2_font_t0_15_tr);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 u8g2_uint_t w = u8g2_GetStrWidth(&u8g2, buf);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 u8g2_DrawStr(&u8g2, (128 - w) / 2,12, buf);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324 * @brief The splash screen shown during cold boot or user wakeup.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 void screen_splash()
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 {
36
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
328 screen_top("CO2 meter %s", app_desc->version);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329
36
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
330 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
331 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, "Welkom");
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
332 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,50, "Welkom");
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 u8g2_SendBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 u8g2_SetPowerSave(&u8g2, 0); // wake up display
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 * @brief The main overview screen.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 void screen_main()
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 char buf[65];
42
22a0f9810561 In the main screen dim the not active units.
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
345 int i, mode[3];
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
346 uint32_t temperature = 0, pressure[3];
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
349 temperature = units[0].temperature;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 for (i = 0; i < 3; i++) {
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
351 pressure[i] = units[i].pressure;
42
22a0f9810561 In the main screen dim the not active units.
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
352 mode[i] = units[i].mode;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 xSemaphoreGive(xSemaphoreUnits);
23
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
355 } else {
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
356 ESP_LOGE(TAG, "screen_main() lock error");
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 }
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
358
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
359 screen_top("CO2 meter %s", app_desc->version);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
360 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
361 sprintf(buf, "%.1f °C", temperature / 1000.0);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
362 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
363 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
364
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
365 for (i = 0; i < 3; i++) {
42
22a0f9810561 In the main screen dim the not active units.
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
366 if (mode[i])
22a0f9810561 In the main screen dim the not active units.
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
367 u8g2_SetFont(&u8g2, u8g2_font_t0_18b_tf);
22a0f9810561 In the main screen dim the not active units.
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
368 else
22a0f9810561 In the main screen dim the not active units.
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
369 u8g2_SetFont(&u8g2, u8g2_font_t0_18_tf);
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
370 sprintf(buf, "%.1f", pressure[i] / 1000.0);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
371 w = u8g2_GetUTF8Width(&u8g2, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
372 u8g2_DrawUTF8(&u8g2, ((42 - w) / 2) + i * 43,63, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
373 }
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
374
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375 u8g2_SendBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 u8g2_SetPowerSave(&u8g2, 0); // wake up display
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 * @brief The unit display screen.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 * @param no The unit index number.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 void screen_unit(int no)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 char buf[65];
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
388 int mode = 0;
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
389 uint32_t temperature = 0, pressure = 0;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
391 if (xSemaphoreTake(xSemaphoreUnits, 35) == pdTRUE) {
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
392 mode = units[no].mode;
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
393 temperature = units[no].temperature;
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
394 pressure = units[no].pressure;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 xSemaphoreGive(xSemaphoreUnits);
23
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
396 } else {
58a328e91881 Added error logging for failed locks
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
397 ESP_LOGE(TAG, "screen_unit(%d) lock error", no);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 }
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
399
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
400 screen_top("Meter %d %s", no + 1, mode ? "Aan":"Uit");
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
401
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
402 u8g2_SetFont(&u8g2, u8g2_font_t0_22b_tf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
403 sprintf(buf, "%.1f °C", temperature / 1000.0);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
404 u8g2_uint_t w = u8g2_GetUTF8Width(&u8g2, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
405 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,40, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
406
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
407 sprintf(buf, "%.2f bar", pressure / 1000.0);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
408 w = u8g2_GetUTF8Width(&u8g2, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
409 u8g2_DrawUTF8(&u8g2, (128 - w) / 2,63, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
410 u8g2_SendBuffer(&u8g2);
43
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
411 u8g2_SetPowerSave(&u8g2, 0); // wake up display
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417 * @brief The unit zero setup screen.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418 * @param no The unit index number.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 * @param sub The submenu index number.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 void screen_unit_zero(int no, int sub)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422 {
29
106464d4c727 Dutch translation on the screens.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
423 screen_top("Meter %d nulpunt", no + 1);
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
424 menu_line( 0, 1, 25, "Huidig %d", units[no].pressure_zero);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
425 menu_line(sub == 0, 1, 37, "Nieuw %d", units[no].pressure_voltage / (adc_state->Batt_voltage / 1000));
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
426 menu_line(sub == 1, 1, 49, "Terug");
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
427 u8g2_SendBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
432 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
433 * @brief The list of detected DS18B20 sensors.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
434 * @param no The unit index number.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
435 * @param sub The submenu index number.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
436 * @param offset The offset in the list.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
437 */
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
438
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
439 void screen_list_sensors(int no, int sub, int offset)
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
440 {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
441 int i;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
442
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
443 if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
444 for (i = 0; i < ds18b20_state->num_sensors; i++) {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
445 strncpy(sensors[i], ds18b20_state->sensor[i].rom_code, 17);
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
446 sensors[i][16] = '\0';
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
447 }
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
448 xSemaphoreGive(xSemaphoreDS18B20);
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
449 } else {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
450 ESP_LOGE(TAG, "screen_list_sensors() DS18B20 lock error");
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
451 }
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
452
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
453 screen_top("DS18B20 lijst");
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
454 if (num_sensors == 0) {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
455 menu_line(0, 1, 25, "Geen sensors");
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
456 } else {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
457 for (i = 0; i < num_sensors; i++) {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
458 menu_line(sub == i, 1, 25 + (i * 12), sensors[i + offset]);
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
459 if (i == 3)
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
460 break;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
461 }
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
462 if ((i + offset) == num_sensors)
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
463 menu_line(sub == i, 1, 25 + (i * 12), "Terug");
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
464 }
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
465 u8g2_SendBuffer(&u8g2);
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
466 }
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
467
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
468
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
469
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 * @brief The unit setup screen.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 * @param no The unit index number.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473 * @param sub The submenu index number.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 void screen_unit_setup(int no, int sub)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 {
29
106464d4c727 Dutch translation on the screens.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
477 screen_top("Meter %d setup", no + 1);
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
478 menu_line(sub == 0, 1, 25, "Werking %s", units[no].mode ? "Aan":"Uit");
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
479 menu_line(sub == 1, 1, 37, "Nulpunt %d", units[no].pressure_zero);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
480 menu_line(sub == 2, 1, 49, "DS18B20 %s", units[no].temperature_rom_code);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
481 menu_line(sub == 3, 1, 61, "Terug");
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 u8g2_SendBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
487 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
488 * @brief The WiFi overview screen.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
489 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490 void screen_wifi()
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
491 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
492 char buf[65];
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
493 int8_t rssi = 0;
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
494 bool online = false;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
495
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
496 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
497 snprintf(buf, 65, "SSID %s", wifi_state->STA_ssid);
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
498 rssi = wifi_state->STA_rssi;
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
499 online = wifi_state->STA_online;
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
500 xSemaphoreGive(xSemaphoreWiFi);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
501 } else {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
502 ESP_LOGE(TAG, "screen_wifi() lock error");
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
503 }
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
504
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
505 screen_top("WiFi Status");
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
506 u8g2_DrawStr(&u8g2, 1, 28, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
507 snprintf(buf, 65, "RSSI %d", rssi);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
508 u8g2_DrawStr(&u8g2, 1, 43, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
509 snprintf(buf, 65, "Verbonden %s", online ? "Ja":"Nee");
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
510 u8g2_DrawStr(&u8g2, 1, 59, buf);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
511 u8g2_SendBuffer(&u8g2);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
516 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
517 * @brief The WiFi setup menu.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
518 * @param sub The submenu entry to hilite.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
519 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520 void screen_wifi_setup(int sub)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
521 {
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
522 screen_top("WiFi AP setup");
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
523 menu_line(sub == 0, 1, 25, "Lijst AP");
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
524 menu_line(sub == 1, 1, 37, "Nieuw AP");
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
525 menu_line(sub == 2, 1, 49, "Terug");
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
526 u8g2_SendBuffer(&u8g2);
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
527 }
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
528
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
529
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
530
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
531 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
532 * @brief Show the list if WiFi Access Points.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
533 * @param sub The sub entry line.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
534 * @param offset The offset in the list.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
535 */
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
536 void screen_list_aps(int sub, int offset)
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
537 {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
538 int i;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
539 struct strStations ap;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
540 uint8_t *dst = (uint8_t *)&ap;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
541 FILE *f;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
542 size_t bytes;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
543
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
544 num_ssids = 0;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
545 memset(dst, 0, sizeof(ap));
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
546 f = fopen("/spiffs/etc/stations.conf", "r+");
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
547 if (f) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
548 while (1) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
549 bytes = fread(dst, 1, sizeof(ap), f);
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
550 if (bytes < sizeof(ap)) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
551 fclose(f);
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
552 break;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
553 }
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
554 memcpy(APs[num_ssids].SSID, ap.SSID, 32);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
555 memcpy(APs[num_ssids].Password, ap.Password, 64);
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
556 num_ssids++;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
557 }
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
558 }
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
559
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
560 screen_top("WiFi AP lijst");
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
561 if (num_ssids == 0) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
562 menu_line(0, 1, 25, "Geen AP's");
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
563 } else {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
564 for (i = 0; i < num_ssids; i++) {
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
565 menu_line(sub == i, 1, 25 + (i * 12), APs[i + offset].SSID);
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
566 if (i == 3)
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
567 break;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
568 }
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
569 if ((i + offset) == num_ssids)
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
570 menu_line(sub == i, 1, 25 + (i * 12), "Terug");
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
571 }
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 u8g2_SendBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
577 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
578 * @brief Edit WiFi AP menu.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
579 * @param sub The menu entry to hilite.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
580 */
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
581 void screen_edit_ap(int sub)
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
582 {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
583 screen_top("WiFi wijzig AP");
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
584 menu_line(sub == 0, 1, 25, "SSID %s", editAP.SSID);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
585 menu_line(sub == 1, 1, 37, "PSK %s", editAP.Password);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
586 menu_line(sub == 2, 1, 49, "Opslaan");
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
587 if (edit_ssid >= 0) {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
588 menu_line(sub == 3, 1, 61, "Verwijder");
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
589 }
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
590 u8g2_SendBuffer(&u8g2);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
591 }
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
592
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
593
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
594
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
595 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
596 * @brief The network status screen.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
597 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 void screen_network()
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 {
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
600 char ip[17], nm[17], gw[17];
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
601
26
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
602 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
603 strcpy(ip, wifi_state->STA_ip);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
604 strcpy(nm, wifi_state->STA_nm);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
605 strcpy(gw, wifi_state->STA_gw);
26
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
606 xSemaphoreGive(xSemaphoreWiFi);
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
607 } else {
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
608 ESP_LOGE(TAG, "screen_network() lock error");
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
609 }
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
610
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
611 screen_top("Netwerk Status");
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
612 menu_line(0, 1, 25, "IP %s", ip);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
613 menu_line(0, 1, 37, "Mask %s", nm);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
614 menu_line(0, 1, 49, "GW %s", gw);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
615 menu_line(0, 1, 61, "Naam %s", config.hostname);
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
616 u8g2_SendBuffer(&u8g2);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
617 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
618
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
619
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
620
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
621 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
622 * @brief The network setup menu.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
623 * @param sub The menu entry to hilite.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
624 */
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
625 void screen_network_setup(int sub)
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
626 {
29
106464d4c727 Dutch translation on the screens.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
627 screen_top("Netwerk setup");
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
628 menu_line(sub == 0, 1, 25, "Naam %s", config.hostname);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
629 menu_line(sub == 1, 1, 37, "NTP %s", config.ntp_server);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
630 menu_line(sub == 2, 1, 49, "Terug");
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
631 u8g2_SendBuffer(&u8g2);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
632 }
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
633
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
634
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
635
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
636 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
637 * @brief MQTT status
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
638 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
639 void screen_mqtt()
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
640 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641 screen_top("MQTT Status");
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642 menu_line(0, 1, 25, "serv %s", config.mqtt_server);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643 menu_line(0, 1, 37, "port %d", config.mqtt_port);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
644 menu_line(0, 1, 49, "user %s", config.mqtt_user);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
645 u8g2_SendBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
646 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
647
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
648
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
649
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
650 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
651 * @brief MQTT setup menu.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
652 * @param sub The submenu entry to hilite.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
653 */
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
654 void screen_mqtt_setup(int sub)
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
655 {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
656 screen_top("MQTT Setup");
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
657 menu_line(sub == 0, 1, 25, "serv %s", config.mqtt_server);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
658 menu_line(sub == 1, 1, 37, "port %d", config.mqtt_port);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
659 menu_line(sub == 2, 1, 49, "user %s", config.mqtt_user);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
660 menu_line(sub == 3, 1, 61, "Terug");
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
661 u8g2_SendBuffer(&u8g2);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
662 }
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
663
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
664
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
665
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
666 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
667 * @brief The OTA update menu.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
668 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
669 void screen_update()
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
670 {
29
106464d4c727 Dutch translation on the screens.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
671 screen_top("Update software");
106464d4c727 Dutch translation on the screens.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
672 menu_line(0, 1, 43, "Druk voor update");
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
673 u8g2_SendBuffer(&u8g2);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
674 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
675
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
676
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
677
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
678 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
679 * @brief The update status screen.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
680 * @param m1 The first message line or NULL.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
681 * @param m2 The second message line or NULL.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
682 */
26
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
683 void screen_updating(char *m1, char *m2)
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
684 {
29
106464d4c727 Dutch translation on the screens.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
685 screen_top("Bijwerken ...");
26
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
686 u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
687 if (m1) {
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
688 u8g2_DrawUTF8(&u8g2,2,30, m1);
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
689 }
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
690 if (m2) {
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
691 u8g2_DrawUTF8(&u8g2,2,55, m2);
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
692 }
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
693 u8g2_SendBuffer(&u8g2);
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
694 }
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
695
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
696
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
697
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
698 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
699 * @brief Interrupt service routine for the rotary pushbutton.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
700 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
701 static void IRAM_ATTR gpio_isr_handler(void* arg)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
702 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
703 uint32_t gpio_num = (uint32_t) arg;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
704 xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
705 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
706
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
707
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
708
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
710 * @brief GPIO queue task. See if there is a rotary pushbutton event on the queue.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
711 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
712 static void gpio_task(void* arg)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
714 uint32_t io_num;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
715 static int64_t pushed = 0;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
716
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
717 for(;;) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
718 if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
719 if (io_num == ROT_ENC_SW_GPIO) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
720 if (gpio_get_level(io_num) == 0) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
721 pushed = esp_timer_get_time();
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
722 PushDuration = 0;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
723 } else if (gpio_get_level(io_num) == 1) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724 PushDuration = (esp_timer_get_time() - pushed) / 1000;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
725 ESP_LOGI(TAG, "GPIO rotary button intr, val: %d time: %d", gpio_get_level(io_num), PushDuration);
38
46e2c385e9de Removed all the deepsleep code since there will be no battery operation.
Michiel Broek <mbroek@mbse.eu>
parents: 37
diff changeset
726 if (! user_busy()) {
46e2c385e9de Removed all the deepsleep code since there will be no battery operation.
Michiel Broek <mbroek@mbse.eu>
parents: 37
diff changeset
727 xEventGroupSetBits(xEventGroupUser, TASK_USER_WAKEUP);
46e2c385e9de Removed all the deepsleep code since there will be no battery operation.
Michiel Broek <mbroek@mbse.eu>
parents: 37
diff changeset
728 }
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
729 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
730 } else {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
731 ESP_LOGE(TAG, "GPIO[%d] unknown intr, val: %d", io_num, gpio_get_level(io_num));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
732 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
733 UserTimer = INACTIVITY;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
734 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
736 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
737
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
738
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
739
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
740 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
741 * @brief Select new menu number on a postitive or negative rotary position.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
742 * @param pos The new position, positive, negative or zero.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
743 * @param next_menu The selected menu if rotated clockwise.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 * @param prev_menu The selected menu if rotated counter-clockwise.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746 static void rotate_to_menu(rotary_encoder_position_t pos, int next_menu, int prev_menu)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
747 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
748 if (pos > 0)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
749 New_Loop2 = next_menu;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
750 else if (pos < 0)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 New_Loop2 = prev_menu;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
752 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
753 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
754
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
755
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
756
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
757 /**
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758 * @brief Rotate subscreens numbers.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
759 * @param pos The new position, positive, negative or zero.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760 * @param max The highest number. If already at the highest, select the lowest.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
761 * @param cursub The subscreen number by reference. This is updated with the new number.
44
e52d11b8f252 Removed dead code. Added more doxygen documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
762 * @param curoffset The offset in the list. This is updated with the new number.
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
763 * @return Returns true if a new number is selected, false if nothing changed.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
764 */
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
765 bool rotate_to_sub(rotary_encoder_position_t pos, int max, int *cursub, int *curoffset)
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766 {
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
767 int sub = *cursub;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
768 int offset = *curoffset;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
769 bool rc = false;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
770
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 if (pos > 0) {
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
772 if ((sub + offset) < max) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
773 if (sub < 3) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
774 sub++;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
775 } else {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
776 offset++;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
777 }
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
778 } else {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
779 sub = offset = 0;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
780 }
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
781 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782 rc = true;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
783 } else if (pos < 0) {
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
784 if ((sub + offset) > 0) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
785 if (offset > 0) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
786 offset--;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
787 } else {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
788 sub--;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
789 }
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
790 } else {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
791 if (max > 3) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
792 offset = max - 3;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
793 sub = 3;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
794 } else {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
795 sub = max;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
796 offset = 0;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
797 }
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
798 }
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799 ESP_ERROR_CHECK(rotary_encoder_reset(&rinfo));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800 rc = true;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
801 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 *cursub = sub;
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
804 *curoffset = offset;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805 return rc;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
810 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
811 * @brief Handle menu changes.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
812 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
813 void menu_change(void)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815 if (New_Loop2 != Main_Loop2) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
816
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
817 Main_Loop2 = New_Loop2;
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
818 switch (Main_Loop2) {
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
819 case ML2_INIT:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
820 ESP_LOGI(TAG, "Loop user: Init");
43
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
821 New_Loop2 = -1;
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
822 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
823 for (int i = 0; i < 3; i++) {
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
824 if (units[i].mode) {
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
825 if (New_Loop2 == -1) { // Not selected yet
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
826 New_Loop2 = i;
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
827 } else if (New_Loop2 >= 0) { // One selected
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
828 New_Loop2 = -2;
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
829 break; // Multiple units are active
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
830 }
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
831 }
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
832 }
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
833 xSemaphoreGive(xSemaphoreUnits);
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
834 } else {
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
835 ESP_LOGE(TAG, "menu_change() ML2_INIT lock");
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
836 }
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
837 if (New_Loop2 < 0)
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
838 New_Loop2 = ML2_USER;
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
839 else
70c99c2084dc Version 0.2.1. When wakeup by user push, select the active unit screen if only one unit is active.
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
840 New_Loop2 += ML2_UNIT1;
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
841 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
842
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
843 case ML2_USER:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
844 screen_main();
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
845 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
846
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
847 case ML2_UNIT1:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
848 case ML2_UNIT2:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
849 case ML2_UNIT3:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
850 screen_unit(Main_Loop2 - ML2_UNIT1);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
851 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
852
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
853 case ML2_WIFI:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
854 screen_wifi();
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
855 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
856
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
857 case ML2_SETUP_WIFI:
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
858 ESP_LOGI(TAG, "Loop user: WiFi setup");
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
859 screen_wifi_setup(SubMenu);
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
860 break;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
861
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
862 case ML2_LIST_APS:
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
863 ESP_LOGI(TAG, "Loop user: WiFi list APs");
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
864 SubMenu = SubOffset = 0;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
865 screen_list_aps(SubMenu, SubOffset);
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
866 break;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
867
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
868 case ML2_EDIT_AP:
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
869 ESP_LOGI(TAG, "Loop user: WiFi edit AP");
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
870 screen_edit_ap(0);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
871 break;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
872
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
873 case ML2_NETWORK:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
874 screen_network();
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
875 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
876
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
877 case ML2_SETUP_NETWORK:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
878 ESP_LOGI(TAG, "Loop user: Network setup");
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
879 screen_network_setup(SubMenu);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
880 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
881
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
882 case ML2_MQTT:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
883 screen_mqtt();
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
884 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
885
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
886 case ML2_SETUP_MQTT:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
887 ESP_LOGI(TAG, "Loop user: MQTT setup");
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
888 screen_mqtt_setup(SubMenu);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
889 break;
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
890
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
891 case ML2_UPDATE:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
892 screen_update();
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
893 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
894
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
895 case ML2_SETUP_UNIT1:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
896 case ML2_SETUP_UNIT2:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
897 case ML2_SETUP_UNIT3:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
898 ESP_LOGI(TAG, "Loop user: Setup Unit %d", Main_Loop2 - ML2_SETUP_UNIT1);
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
899 SubMenu = SubOffset = 0;
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
900 screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, SubMenu);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
901 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
902
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
903 case ML2_ZERO_UNIT1:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
904 case ML2_ZERO_UNIT2:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
905 case ML2_ZERO_UNIT3:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
906 ESP_LOGI(TAG, "Loop user: Zero Unit %d", Main_Loop2 - ML2_ZERO_UNIT1);
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
907 SubMenu = SubOffset = 0;
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
908 screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, SubMenu);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
909 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
910
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
911 case ML2_SEL_SENSOR1:
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
912 case ML2_SEL_SENSOR2:
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
913 case ML2_SEL_SENSOR3:
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
914 ESP_LOGI(TAG, "Loop user: Select sensor %d", Main_Loop2 - ML2_SEL_SENSOR1);
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
915 SubMenu = SubOffset = 0;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
916 screen_list_sensors(Main_Loop2 - ML2_SEL_SENSOR1, SubMenu, SubOffset);
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
917 break;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
918
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
919 case ML2_INACTIVE:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
920 ESP_LOGI(TAG, "Loop user: Inactive");
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
921 u8g2_SetPowerSave(&u8g2, 1); // powersave display
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
922 New_Loop2 = ML2_DONE;
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
923 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
924
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
925 default:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
926 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
927 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
928 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
929 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
930
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
931
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
932
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
933 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
934 * @brief Handle rotary switch for menu navigation.
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
935 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
936 void menu_rotary(void)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
937 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
938 switch (Main_Loop2) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
939 case ML2_USER: rotate_to_menu(event.state.position, ML2_UNIT1, ML2_USER); break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
940 case ML2_UNIT1: rotate_to_menu(event.state.position, ML2_UNIT2, ML2_USER); break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
941 case ML2_UNIT2: rotate_to_menu(event.state.position, ML2_UNIT3, ML2_UNIT1); break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
942 case ML2_UNIT3: rotate_to_menu(event.state.position, ML2_WIFI, ML2_UNIT2); break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
943 case ML2_WIFI: rotate_to_menu(event.state.position, ML2_NETWORK, ML2_UNIT3); break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
944 case ML2_NETWORK: rotate_to_menu(event.state.position, ML2_MQTT, ML2_WIFI); break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
945 case ML2_MQTT: rotate_to_menu(event.state.position, ML2_UPDATE, ML2_NETWORK); break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
946 case ML2_UPDATE: rotate_to_menu(event.state.position, ML2_UPDATE, ML2_MQTT); break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
947 case ML2_SETUP_UNIT1:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
948 case ML2_SETUP_UNIT2:
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
949 case ML2_SETUP_UNIT3: if (rotate_to_sub(event.state.position, 3, &SubMenu, &SubOffset))
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
950 screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, SubMenu);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
951 break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
952 case ML2_ZERO_UNIT1:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
953 case ML2_ZERO_UNIT2:
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
954 case ML2_ZERO_UNIT3: if (rotate_to_sub(event.state.position, 1, &SubMenu, &SubOffset))
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
955 screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, SubMenu);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
956 break;
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
957 case ML2_SEL_SENSOR1:
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
958 case ML2_SEL_SENSOR2:
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
959 case ML2_SEL_SENSOR3: if (rotate_to_sub(event.state.position, num_sensors, &SubMenu, &SubOffset))
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
960 screen_list_sensors(Main_Loop2 - ML2_SEL_SENSOR1, SubMenu, SubOffset);
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
961 break;
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
962 case ML2_SETUP_WIFI: if (rotate_to_sub(event.state.position, 2, &SubMenu, &SubOffset))
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
963 screen_wifi_setup(SubMenu);
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
964 break;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
965 case ML2_LIST_APS: if (rotate_to_sub(event.state.position, num_ssids, &SubMenu, &SubOffset))
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
966 screen_list_aps(SubMenu, SubOffset);
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
967 break;
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
968 case ML2_EDIT_AP: if (edit_ssid < 0) {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
969 if (rotate_to_sub(event.state.position, 2, &SubMenu, &SubOffset))
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
970 screen_edit_ap(SubMenu);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
971 } else {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
972 if (rotate_to_sub(event.state.position, 3, &SubMenu, &SubOffset))
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
973 screen_edit_ap(SubMenu);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
974 }
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
975 break;
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
976 case ML2_SETUP_MQTT: if (rotate_to_sub(event.state.position, 3, &SubMenu, &SubOffset))
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
977 screen_mqtt_setup(SubMenu);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
978 break;
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
979 case ML2_SETUP_NETWORK: if (rotate_to_sub(event.state.position, 2, &SubMenu, &SubOffset))
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
980 screen_network_setup(SubMenu);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
981 break;
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
982 default:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
983 ESP_LOGI(TAG, "Event: position %d, direction %s", event.state.position,
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
984 event.state.direction ? (event.state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW":"CCW"):"NOT_SET");
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
985 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
986 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
987
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
988
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
989
22
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
990 /*
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
991 * Refresh screens that are in focus. Called by the main measurement loop.
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
992 */
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
993 void user_refresh(void)
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
994 {
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
995 if (UserTimer)
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
996 xEventGroupSetBits(xEventGroupUser, TASK_USER_REFRESH);
22
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
997 }
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
998
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
999
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
1000
41
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
1001 /**
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
1002 * @brief Pressed keys actions
d327e0aff62f Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
1003 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1004 void menu_loop(void)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1005 {
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1006 int idx = 0;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1007 char txt[32];
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1008
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1009 switch (Main_Loop2) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1010 case ML2_UNIT1:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1011 case ML2_UNIT2:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1012 case ML2_UNIT3:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1013 New_Loop2 = ML2_SETUP_UNIT1 + (Main_Loop2 - ML2_UNIT1);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1014 break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1015
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1016 case ML2_SETUP_UNIT1:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1017 case ML2_SETUP_UNIT2:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1018 case ML2_SETUP_UNIT3:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1019 idx = Main_Loop2 - ML2_SETUP_UNIT1;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1020 if (SubMenu == 0) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1021 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1022 if (units[idx].mode)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1023 units[idx].mode = 0;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1024 else
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1025 units[idx].mode = 1;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1026 write_units();
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1027 xSemaphoreGive(xSemaphoreUnits);
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1028 } else {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1029 ESP_LOGE(TAG, "menu_loop() ML2_SETUP_UNIT%d units lock", idx + 1);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1030 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1031 screen_unit_setup(idx, SubMenu);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1032 if (Main_Loop1 == ML1_DONE)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1033 Main_Loop1 = ML1_INIT;
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1034 } else if (SubMenu == 1) {
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1035 New_Loop2 = ML2_ZERO_UNIT1 + idx;
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1036 } else if (SubMenu == 2) {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1037 New_Loop2 = ML2_SEL_SENSOR1 + idx;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1038 } else if (SubMenu == 3) {
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1039 New_Loop2 = ML2_UNIT1 + idx;
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1040 }
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1041 break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1042
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1043 case ML2_ZERO_UNIT1:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1044 case ML2_ZERO_UNIT2:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1045 case ML2_ZERO_UNIT3:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1046 idx = Main_Loop2 - ML2_ZERO_UNIT1;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1047 if (SubMenu == 0) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1048 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE &&
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1049 xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE &&
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1050 adc_state->Pressure[idx].voltage > 165 &&
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1051 adc_state->Pressure[idx].voltage < 660) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1052 units[idx].pressure_zero = adc_state->Pressure[idx].voltage / (adc_state->Batt_voltage / 1000);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1053 write_units();
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1054 xSemaphoreGive(xSemaphoreADC);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1055 xSemaphoreGive(xSemaphoreUnits);
22
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
1056 ESP_LOGI(TAG, "Zero set unit %d, %d mV set %d", idx, adc_state->Pressure[idx].voltage, units[idx].pressure_zero);
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1057 screen_unit_zero(idx, SubMenu);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1058 if (Main_Loop1 == ML1_DONE)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1059 Main_Loop1 = ML1_INIT;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1060 }
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1061 } else if (SubMenu == 1) {
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1062 New_Loop2 = ML2_SETUP_UNIT1 + idx;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1063 SubMenu = 1;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1064 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1065 break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1066
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1067 case ML2_SEL_SENSOR1:
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1068 case ML2_SEL_SENSOR2:
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1069 case ML2_SEL_SENSOR3:
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1070 idx = Main_Loop2 - ML2_SEL_SENSOR1;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1071 if ((SubMenu + SubOffset) < num_sensors) {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1072 ESP_LOGI(TAG, "Select sensor %d %s for unit %d", SubMenu + SubOffset, sensors[SubMenu + SubOffset], idx + 1);
36
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1073 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) {
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1074 strcpy(units[idx].temperature_rom_code, sensors[SubMenu + SubOffset]);
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1075 write_units();
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1076 xSemaphoreGive(xSemaphoreUnits);
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1077 New_Loop2 = ML2_SETUP_UNIT1 + idx;
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1078 SubMenu = 2;
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1079 SubOffset = 0;
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1080 if (Main_Loop1 == ML1_DONE)
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1081 Main_Loop1 = ML1_INIT;
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1082 } else {
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1083 ESP_LOGE(TAG, "Failed units lock for new romcode");
e2a43e7c4035 Swapped ADC channels 6 and 7. Completed the DS18B20 assign to unit.
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
1084 }
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1085 } else {
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1086 New_Loop2 = ML2_SETUP_UNIT1 + idx;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1087 SubMenu = 2;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1088 SubOffset = 0;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1089 }
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1090 break;
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1091
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1092 case ML2_WIFI:
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1093 New_Loop2 = ML2_SETUP_WIFI;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1094 break;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1095
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1096 case ML2_SETUP_WIFI:
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1097 if (SubMenu == 0) {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1098 New_Loop2 = ML2_LIST_APS;
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1099 } else if (SubMenu == 1) {
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1100 edit_ssid = -1;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1101 editAP.SSID[0] = '\0';
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1102 editAP.Password[0] = '\0';
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1103 SubMenu = SubOffset = 0;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1104 New_Loop2 = ML2_EDIT_AP;
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1105 } else if (SubMenu == 2) {
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1106 New_Loop2 = ML2_WIFI;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1107 }
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1108 break;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1109
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1110 case ML2_LIST_APS:
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1111 if ((SubMenu + SubOffset) < num_ssids) {
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1112 edit_ssid = SubMenu + SubOffset;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1113 memcpy(editAP.SSID, APs[edit_ssid].SSID, 32);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1114 memcpy(editAP.Password, APs[edit_ssid].Password, 64);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1115 SubMenu = SubOffset = 0;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1116 New_Loop2 = ML2_EDIT_AP;
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1117 } else {
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1118 New_Loop2 = ML2_SETUP_WIFI;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1119 SubMenu = SubOffset = 0;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1120 }
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1121 break;
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1122
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1123 case ML2_EDIT_AP:
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1124 if (SubMenu == 0) {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1125 rotary_editer("SSID", editAP.SSID, "", 16, EDIT_TYPE_TEXT);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1126 screen_edit_ap(SubMenu);
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1127 } else if (SubMenu == 1) {
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1128 rotary_editer("PSK", editAP.Password, "", 16, EDIT_TYPE_TEXT);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1129 screen_edit_ap(SubMenu);
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1130 } else if (SubMenu == 2 || SubMenu == 3) {
33
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1131 update_running = 1; // Block measurements
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1132 int timeout = 600;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1133 if (edit_ssid < 0)
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1134 New_Loop2 = ML2_SETUP_WIFI;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1135 else
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1136 New_Loop2 = ML2_LIST_APS;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1137
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1138 for (;;) {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1139 vTaskDelay(100 / portTICK_PERIOD_MS);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1140 if (Main_Loop1 == ML1_DONE)
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1141 break;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1142 if (timeout)
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1143 timeout--;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1144 else {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1145 ESP_LOGE(TAG, "Timout request stop");
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1146 goto saveerr;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1147 }
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1148 }
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1149 if (edit_ssid >= 0) {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1150 ESP_LOGI(TAG, "Remove %s", APs[edit_ssid].SSID);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1151 remove_station((uint8_t *)APs[edit_ssid].SSID);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1152 }
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1153 if (SubMenu == 2) {
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1154 ESP_LOGI(TAG, "Add %s %s", editAP.SSID, editAP.Password);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1155 add_station((uint8_t *)editAP.SSID, (uint8_t *)editAP.Password);
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1156 }
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1157 }
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1158 saveerr:
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1159 update_running = 0;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1160 break;
331e7f700971 Added WiFi AP editor.
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
1161
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1162 case ML2_NETWORK:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1163 New_Loop2 = ML2_SETUP_NETWORK;
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1164 break;
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1165
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1166 case ML2_SETUP_NETWORK:
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1167 if (SubMenu == 0) {
29
106464d4c727 Dutch translation on the screens.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1168 rotary_editer("Hostnaam", config.hostname, "", 16, EDIT_TYPE_TEXT);
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1169 screen_network_setup(SubMenu);
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1170 } else if (SubMenu == 1) {
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1171 rotary_editer("NTP server", config.ntp_server, "", 16, EDIT_TYPE_TEXT);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1172 screen_network_setup(SubMenu);
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1173 } else if (SubMenu == 2) {
25
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1174 ESP_LOGI(TAG, "Hostname `%s`", config.hostname);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1175 ESP_LOGI(TAG, "NTP server `%s`", config.ntp_server);
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1176 write_config();
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1177 New_Loop2 = ML2_NETWORK;
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1178 }
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1179 break;
cc7c423f03fb Added network setup
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
1180
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1181 case ML2_MQTT:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1182 New_Loop2 = ML2_SETUP_MQTT;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1183 break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1184
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1185 case ML2_SETUP_MQTT:
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1186 if (SubMenu == 0) {
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1187 rotary_editer("MQTT server", config.mqtt_server, "", 16, EDIT_TYPE_TEXT);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1188 screen_mqtt_setup(SubMenu);
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1189 } else if (SubMenu == 1) {
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1190 sprintf(txt, "%d", config.mqtt_port);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1191 rotary_editer("MQTT server poort", txt, "", 6, EDIT_TYPE_INT);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1192 config.mqtt_port = atoi(txt);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1193 screen_mqtt_setup(SubMenu);
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1194 } else if (SubMenu == 2) {
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1195 rotary_editer("MQTT user", config.mqtt_user, "", 16, EDIT_TYPE_TEXT);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1196 rotary_editer("MQTT password", config.mqtt_pwd, "", 16, EDIT_TYPE_TEXT);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1197 screen_mqtt_setup(SubMenu);
34
495b7eafbf5a Temporary white splash screen. Select DS18B20 sensor per unit. Changed units result logging
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1198 } else if (SubMenu == 3) {
24
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1199 ESP_LOGI(TAG, "mqtt_server %s:%d", config.mqtt_server, config.mqtt_port);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1200 ESP_LOGI(TAG, "mqtt_user/pass `%s/%s`", config.mqtt_user, config.mqtt_pwd);
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1201 write_config();
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1202 New_Loop2 = ML2_MQTT;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1203 }
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1204 break;
64078aa15512 Finished the editor using the rotary switch. Added editing of the MQTT server parameters.
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
1205
26
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
1206 case ML2_UPDATE:
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
1207 bin_update();
27
8bb63daa7b46 Increased some lock timeouts. Application CPU speed from 160 to 240 MHz. Added timeout timers to the update process.
Michiel Broek <mbroek@mbse.eu>
parents: 26
diff changeset
1208 screen_update();
26
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
1209 break;
8a3696620c0a Increaded stacksize for the user process. Implemented the network update using the proven brewboard code. Reverted the lock release and display sendbuffer lines to the previous code. The networks status screen uses the wifi lock.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
1210
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1211 default:
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1212 break;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1213 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1214 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1215
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1216
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1217
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1218 void task_user(void *pvParameter)
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1219 {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1220 ESP_LOGI(TAG, "Starting User task");
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1221 Main_Loop2 = -1;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1222
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1223 /*
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1224 * Setup the OLED display.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1225 * See: https://github.com/nkolban/esp32-snippets/blob/master/hardware/displays/U8G2/
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1226 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1227 u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1228 u8g2_esp32_hal.sda = PIN_SDA;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1229 u8g2_esp32_hal.scl = PIN_SCL;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1230 u8g2_esp32_hal_init(u8g2_esp32_hal);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1231
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1232 u8g2_Setup_sh1106_i2c_128x64_noname_f(&u8g2, U8G2_R0, u8g2_esp32_i2c_byte_cb, u8g2_esp32_gpio_and_delay_cb); // init u8g2 structure
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1233 u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1234 u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1235
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1236 /*
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1237 * Setup the Rotary Encoder.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1238 * esp32-rotary-encoder requires that the GPIO ISR service is
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1239 * installed before calling rotary_encoder_register()
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1240 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1241 ESP_ERROR_CHECK(gpio_install_isr_service(0));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1242 ESP_ERROR_CHECK(rotary_encoder_init(&rinfo, ROT_ENC_A_GPIO, ROT_ENC_B_GPIO));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1243 ESP_ERROR_CHECK(rotary_encoder_enable_half_steps(&rinfo, false));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1244
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1245 gpio_config_t io_conf;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1246 io_conf.intr_type = GPIO_PIN_INTR_ANYEDGE;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1247 io_conf.pin_bit_mask = (1ULL << ROT_ENC_SW_GPIO);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1248 io_conf.mode = GPIO_MODE_INPUT;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1249 gpio_config(&io_conf);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1250
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1251 gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1252 xTaskCreate(gpio_task, "gpio_task", 2048, NULL, 10, NULL);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1253
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1254 gpio_isr_handler_add(ROT_ENC_SW_GPIO, gpio_isr_handler, (void*) ROT_ENC_SW_GPIO);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1255
37
358bbd5b608e menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 36
diff changeset
1256 /*
358bbd5b608e menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 36
diff changeset
1257 * Create a queue for events from the rotary encoder driver.
358bbd5b608e menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 36
diff changeset
1258 * Tasks can read from this queue to receive up to date position information.
358bbd5b608e menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 36
diff changeset
1259 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1260 event_queue = rotary_encoder_create_queue();
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1261 ESP_ERROR_CHECK(rotary_encoder_set_queue(&rinfo, event_queue));
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1262
37
358bbd5b608e menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 36
diff changeset
1263 /*
358bbd5b608e menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 36
diff changeset
1264 * Create a one second periodic timer.
358bbd5b608e menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 36
diff changeset
1265 */
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1266 esp_timer_create_args_t timerSecond = {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1267 .callback = &TimerCallback,
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1268 .name = "SecondsTimer"
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1269 };
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1270 ESP_ERROR_CHECK(esp_timer_create(&timerSecond, &timerHandle));
37
358bbd5b608e menuconfig settings now work for I2C display setup. Lot's of code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents: 36
diff changeset
1271 ESP_ERROR_CHECK(esp_timer_start_periodic(timerHandle, 1000000));
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1272
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1273 EventBits_t uxBits;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1274
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1275 /*
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1276 * Task loop forever.
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1277 */
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1278 while (1) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1279
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1280 uxBits = xEventGroupWaitBits(xEventGroupUser, TASK_USER_COLD | TASK_USER_WAKEUP, pdFALSE, pdFALSE, portMAX_DELAY );
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1281
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1282 if (uxBits & TASK_USER_COLD) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1283 ESP_LOGI(TAG, "User task cold start");
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1284 screen_splash();
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1285 xEventGroupClearBits(xEventGroupUser, TASK_USER_COLD);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1286 UserTimer = 10;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1287 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1288
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1289 if (uxBits & TASK_USER_WAKEUP) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1290 ESP_LOGI(TAG, "User task wakeup");
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1291 xEventGroupSetBits(xEventGroupUser, TASK_USER_BUSY);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1292 UserTimer = INACTIVITY;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1293 New_Loop2 = ML2_INIT;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1294 Main_Loop2 = -1;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1295 SubMenu = 0;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1296
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1297 while (UserTimer) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1298
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1299 menu_change();
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1300
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1301 if (xEventGroupGetBits(xEventGroupUser) & TASK_USER_REFRESH) {
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1302 xEventGroupClearBits(xEventGroupUser, TASK_USER_REFRESH);
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1303 switch (Main_Loop2) {
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1304 case ML2_USER: screen_main(); break;
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1305 case ML2_UNIT1: screen_unit(0); break;
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1306 case ML2_UNIT2: screen_unit(1); break;
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1307 case ML2_UNIT3: screen_unit(2); break;
32
7717ac1d2f7f Added WiFi list configured APs. Added offset to the menu rotary for large menus.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
1308 case ML2_WIFI: screen_wifi(); break;
30
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1309 }
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1310 }
8b630bf52092 Shorter lock times.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1311
22
cceb36fd3a2a Better update of the user screens. Added more internal documentation.
Michiel Broek <mbroek@mbse.eu>
parents: 21
diff changeset
1312 if (xQueueReceive(event_queue, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) {
21
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1313 UserTimer = INACTIVITY;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1314 menu_rotary();
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1315 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1316
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1317 if (PushDuration) {
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1318 PushDuration = 0;
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1319 menu_loop();
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1320 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1321 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1322
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1323 xEventGroupClearBits(xEventGroupUser, TASK_USER_WAKEUP);
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1324 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1325 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1326 }
043ae27633f8 Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1327

mercurial