Optimized interface event routines.
This commit is contained in:
parent
38b517ca1b
commit
228883c700
|
@ -10,7 +10,7 @@
|
||||||
#define EPD_DISPLAY_FRAME_SIZE (EPD_DISPLAY_PIXEL_COUNT * 2 / 8)
|
#define EPD_DISPLAY_FRAME_SIZE (EPD_DISPLAY_PIXEL_COUNT * 2 / 8)
|
||||||
|
|
||||||
#define EPD_DISPLAY_GS 0
|
#define EPD_DISPLAY_GS 0
|
||||||
#define EPD_DISPLAY_MAX_PARTIAL 32 /* !! Must be even !! */
|
#define EPD_DISPLAY_MAX_PARTIAL 64 /* !! Must be even !! */
|
||||||
|
|
||||||
static impl_epd_handle_t s_epd_impl;
|
static impl_epd_handle_t s_epd_impl;
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,15 @@
|
||||||
#define IF_EVENT_WIFI_BUTTON 0
|
#define IF_EVENT_WIFI_BUTTON 0
|
||||||
#define IF_EVENT_BAT_BUTTON 1
|
#define IF_EVENT_BAT_BUTTON 1
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
if_standby_component_t component;
|
||||||
|
char payload[IF_STANDBY_PAYLOAD_LENGTH];
|
||||||
|
} if_standby_request_t;
|
||||||
|
|
||||||
static TaskHandle_t s_if_standby_handle;
|
static TaskHandle_t s_if_standby_handle;
|
||||||
|
static QueueHandle_t s_standby_screen_queue;
|
||||||
|
|
||||||
lv_obj_t *g_standby_screen;
|
lv_obj_t *g_standby_screen;
|
||||||
QueueHandle_t g_standby_screen_queue;
|
|
||||||
|
|
||||||
void if_standby_event_handler(lv_event_t *ev) {
|
void if_standby_event_handler(lv_event_t *ev) {
|
||||||
int button_event = (int)ev->user_data;
|
int button_event = (int)ev->user_data;
|
||||||
|
@ -147,35 +152,35 @@ void if_standby_task(void *pvParameters) {
|
||||||
|
|
||||||
ESP_LOGI(LOG_TAG, "Standby screen created.");
|
ESP_LOGI(LOG_TAG, "Standby screen created.");
|
||||||
|
|
||||||
if_standby_queue_t queue_item;
|
if_standby_request_t update_request;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Read from queue for UI element updates.
|
// Read from queue for UI element updates.
|
||||||
xQueueReceive(g_standby_screen_queue, &queue_item, portMAX_DELAY);
|
xQueueReceive(s_standby_screen_queue, &update_request, portMAX_DELAY);
|
||||||
impl_lvgl_lock();
|
impl_lvgl_lock();
|
||||||
switch (queue_item.item) {
|
switch (update_request.component) {
|
||||||
case IF_STANDBY_ITEM_TEMP:
|
case IF_STANDBY_COMPONENT_TEMP:
|
||||||
lv_label_set_text(temp_label, queue_item.payload);
|
lv_label_set_text(temp_label, update_request.payload);
|
||||||
lv_obj_align(temp_label, LV_ALIGN_CENTER, 0, 16);
|
lv_obj_align(temp_label, LV_ALIGN_CENTER, 0, 16);
|
||||||
break;
|
break;
|
||||||
case IF_STANDBY_ITEM_HUMID:
|
case IF_STANDBY_COMPONENT_HUMID:
|
||||||
lv_label_set_text(humid_label, queue_item.payload);
|
lv_label_set_text(humid_label, update_request.payload);
|
||||||
lv_obj_align(humid_label, LV_ALIGN_CENTER, 0, 16);
|
lv_obj_align(humid_label, LV_ALIGN_CENTER, 0, 16);
|
||||||
break;
|
break;
|
||||||
case IF_STANDBY_ITEM_TIME:
|
case IF_STANDBY_COMPONENT_TIME:
|
||||||
lv_label_set_text(time_label, queue_item.payload);
|
lv_label_set_text(time_label, update_request.payload);
|
||||||
lv_obj_set_align(time_label, LV_ALIGN_CENTER);
|
lv_obj_set_align(time_label, LV_ALIGN_CENTER);
|
||||||
break;
|
break;
|
||||||
case IF_STANDBY_ITEM_DATE:
|
case IF_STANDBY_COMPONENT_DATE:
|
||||||
lv_label_set_text(date_label, queue_item.payload);
|
lv_label_set_text(date_label, update_request.payload);
|
||||||
lv_obj_set_align(date_label, LV_ALIGN_CENTER);
|
lv_obj_set_align(date_label, LV_ALIGN_CENTER);
|
||||||
break;
|
break;
|
||||||
case IF_STANDBY_ITEM_WEEKDAY:
|
case IF_STANDBY_COMPONENT_WEEKDAY:
|
||||||
lv_label_set_text(weekday_label, queue_item.payload);
|
lv_label_set_text(weekday_label, update_request.payload);
|
||||||
lv_obj_set_align(weekday_label, LV_ALIGN_CENTER);
|
lv_obj_set_align(weekday_label, LV_ALIGN_CENTER);
|
||||||
break;
|
break;
|
||||||
case IF_STANDBY_ITEM_WIFI:
|
case IF_STANDBY_COMPONENT_WIFI:
|
||||||
lv_label_set_text(network_status_label, queue_item.payload);
|
lv_label_set_text(network_status_label, update_request.payload);
|
||||||
lv_obj_set_align(network_status_label, LV_ALIGN_CENTER);
|
lv_obj_set_align(network_status_label, LV_ALIGN_CENTER);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -191,8 +196,8 @@ esp_err_t if_standby_init(void) {
|
||||||
lv_disp_load_scr(g_standby_screen);
|
lv_disp_load_scr(g_standby_screen);
|
||||||
impl_lvgl_unlock();
|
impl_lvgl_unlock();
|
||||||
|
|
||||||
g_standby_screen_queue = xQueueCreate(8, sizeof(if_standby_queue_t));
|
s_standby_screen_queue = xQueueCreate(8, sizeof(if_standby_request_t));
|
||||||
if (g_standby_screen_queue == NULL) {
|
if (s_standby_screen_queue == NULL) {
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,5 +205,22 @@ esp_err_t if_standby_init(void) {
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t if_standby_component_update(if_standby_component_t component, const char *fmt, ...) {
|
||||||
|
if_standby_request_t req;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
req.component = component;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(req.payload, IF_STANDBY_PAYLOAD_LENGTH, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if(xQueueSendToBack(s_standby_screen_queue, &req, 0) != pdPASS) {
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
|
@ -11,23 +11,18 @@
|
||||||
#define IF_STANDBY_PAYLOAD_LENGTH 16
|
#define IF_STANDBY_PAYLOAD_LENGTH 16
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
IF_STANDBY_ITEM_WIFI,
|
IF_STANDBY_COMPONENT_WIFI,
|
||||||
IF_STANDBY_ITEM_WEEKDAY,
|
IF_STANDBY_COMPONENT_WEEKDAY,
|
||||||
IF_STANDBY_ITEM_DATE,
|
IF_STANDBY_COMPONENT_DATE,
|
||||||
IF_STANDBY_ITEM_BAT,
|
IF_STANDBY_COMPONENT_BAT,
|
||||||
IF_STANDBY_ITEM_TIME,
|
IF_STANDBY_COMPONENT_TIME,
|
||||||
IF_STANDBY_ITEM_TEMP,
|
IF_STANDBY_COMPONENT_TEMP,
|
||||||
IF_STANDBY_ITEM_HUMID,
|
IF_STANDBY_COMPONENT_HUMID,
|
||||||
} if_standby_item_t ;
|
} if_standby_component_t;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
if_standby_item_t item;
|
|
||||||
char payload[IF_STANDBY_PAYLOAD_LENGTH];
|
|
||||||
} if_standby_queue_t;
|
|
||||||
|
|
||||||
extern lv_obj_t *g_standby_screen;
|
extern lv_obj_t *g_standby_screen;
|
||||||
extern QueueHandle_t g_standby_screen_queue;
|
|
||||||
|
|
||||||
esp_err_t if_standby_init(void);
|
esp_err_t if_standby_init(void);
|
||||||
|
esp_err_t if_standby_component_update(if_standby_component_t component, const char *fmt, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
static TaskHandle_t s_clock_task_handle;
|
static TaskHandle_t s_clock_task_handle;
|
||||||
|
|
||||||
static char *s_wday_array[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI"};
|
static const char *s_wday_array[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI"};
|
||||||
|
|
||||||
void clock_task(void *pvParameters) {
|
void clock_task(void *pvParameters) {
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -19,8 +19,6 @@ void clock_task(void *pvParameters) {
|
||||||
uint8_t prev_mday = 0xFF;
|
uint8_t prev_mday = 0xFF;
|
||||||
uint8_t prev_wday = 0xFF;
|
uint8_t prev_wday = 0xFF;
|
||||||
|
|
||||||
if_standby_queue_t queue_item;
|
|
||||||
|
|
||||||
setenv("TZ", "CST-8", 1);
|
setenv("TZ", "CST-8", 1);
|
||||||
tzset();
|
tzset();
|
||||||
|
|
||||||
|
@ -29,25 +27,18 @@ void clock_task(void *pvParameters) {
|
||||||
localtime_r(&now, &timeinfo);
|
localtime_r(&now, &timeinfo);
|
||||||
|
|
||||||
if ((timeinfo.tm_min != prev_min) || (prev_min == 0xFF)) {
|
if ((timeinfo.tm_min != prev_min) || (prev_min == 0xFF)) {
|
||||||
queue_item.item = IF_STANDBY_ITEM_TIME;
|
if_standby_component_update(IF_STANDBY_COMPONENT_TIME, "%02u:%02u", timeinfo.tm_hour, timeinfo.tm_min);
|
||||||
snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "%02u:%02u", timeinfo.tm_hour, timeinfo.tm_min);
|
|
||||||
xQueueSendToBack(g_standby_screen_queue, &queue_item, 0);
|
|
||||||
|
|
||||||
prev_min = timeinfo.tm_min;
|
prev_min = timeinfo.tm_min;
|
||||||
}
|
}
|
||||||
if ((timeinfo.tm_mday != prev_mday) || (prev_mday == 0xFF)) {
|
if ((timeinfo.tm_mday != prev_mday) || (prev_mday == 0xFF)) {
|
||||||
queue_item.item = IF_STANDBY_ITEM_DATE;
|
if_standby_component_update(IF_STANDBY_COMPONENT_DATE, "%04u/%02d/%02d", timeinfo.tm_year + 1900,
|
||||||
snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "%04u/%02d/%02d",
|
timeinfo.tm_mon + 1, timeinfo.tm_mday);
|
||||||
(uint16_t)(timeinfo.tm_year + 1900), (uint8_t)(timeinfo.tm_mon + 1), (uint8_t)timeinfo.tm_mday);
|
|
||||||
xQueueSendToBack(g_standby_screen_queue, &queue_item, 0);
|
|
||||||
|
|
||||||
prev_mday = timeinfo.tm_mday;
|
prev_mday = timeinfo.tm_mday;
|
||||||
}
|
}
|
||||||
if ((timeinfo.tm_wday != prev_wday) || (prev_wday == 0xFF)) {
|
if ((timeinfo.tm_wday != prev_wday) || (prev_wday == 0xFF)) {
|
||||||
queue_item.item = IF_STANDBY_ITEM_WEEKDAY;
|
if_standby_component_update(IF_STANDBY_COMPONENT_WEEKDAY, s_wday_array[timeinfo.tm_wday]);
|
||||||
memcpy(queue_item.payload, s_wday_array[timeinfo.tm_wday], 4);
|
|
||||||
xQueueSendToBack(g_standby_screen_queue, &queue_item, 0);
|
|
||||||
|
|
||||||
prev_wday = timeinfo.tm_wday;
|
prev_wday = timeinfo.tm_wday;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,6 @@ static htu21d_t s_htu = {
|
||||||
static TaskHandle_t s_dht_task_handle;
|
static TaskHandle_t s_dht_task_handle;
|
||||||
|
|
||||||
void dht_task(void *pvParameters) {
|
void dht_task(void *pvParameters) {
|
||||||
if_standby_queue_t queue_item;
|
|
||||||
|
|
||||||
htu21d_result_t result;
|
htu21d_result_t result;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -28,13 +26,8 @@ void dht_task(void *pvParameters) {
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_item.item = IF_STANDBY_ITEM_TEMP,
|
if_standby_component_update(IF_STANDBY_COMPONENT_TEMP, "%.2f", result.temperature);
|
||||||
snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "%.2f", result.temperature);
|
if_standby_component_update(IF_STANDBY_COMPONENT_HUMID, "%.2f", result.humidity);
|
||||||
xQueueSendToBack(g_standby_screen_queue, &queue_item, 0);
|
|
||||||
|
|
||||||
queue_item.item = IF_STANDBY_ITEM_HUMID;
|
|
||||||
snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "%.2f", result.humidity);
|
|
||||||
xQueueSendToBack(g_standby_screen_queue, &queue_item, 0);
|
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(30000));
|
vTaskDelay(pdMS_TO_TICKS(30000));
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,12 +66,8 @@ void service_wifi_task(void *pvParameters) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if_standby_queue_t queue_item;
|
|
||||||
|
|
||||||
if (!wifi_config_valid) {
|
if (!wifi_config_valid) {
|
||||||
queue_item.item = IF_STANDBY_ITEM_WIFI;
|
if_standby_component_update(IF_STANDBY_COMPONENT_WIFI, "\U000F092D");
|
||||||
snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "\U000F092D");
|
|
||||||
xQueueSend(g_standby_screen_queue, &queue_item, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wifi_config_t wifi_config = {
|
wifi_config_t wifi_config = {
|
||||||
|
@ -97,9 +93,7 @@ void service_wifi_task(void *pvParameters) {
|
||||||
if (xQueueReceive(s_service_wifi_event_queue, &queue_event, portMAX_DELAY) == pdPASS) {
|
if (xQueueReceive(s_service_wifi_event_queue, &queue_event, portMAX_DELAY) == pdPASS) {
|
||||||
switch (queue_event) {
|
switch (queue_event) {
|
||||||
case SERVICE_WIFI_EVENT_CONNECTED:
|
case SERVICE_WIFI_EVENT_CONNECTED:
|
||||||
queue_item.item = IF_STANDBY_ITEM_WIFI;
|
if_standby_component_update(IF_STANDBY_COMPONENT_WIFI, "\U000F0928");
|
||||||
snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "\U000F0928");
|
|
||||||
xQueueSend(g_standby_screen_queue, &queue_item, 0);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue