89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
#include "esp_system.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/queue.h"
|
|
#include "freertos/task.h"
|
|
#include "impl_lvgl.h"
|
|
|
|
#define IF_EVENT_QUEUE_LEN 2
|
|
#define IF_EVENT_QUEUE_SIZE() (sizeof(int))
|
|
#define IF_EVENT_QUEUE_TIMEOUT 100
|
|
|
|
#define IF_EVENT_EXIT_BUTTON 0
|
|
|
|
static TaskHandle_t s_if_wifi_task_handle;
|
|
static QueueHandle_t s_if_wifi_event_queue;
|
|
|
|
static void if_wifi_event_handler(lv_event_t *ev) {
|
|
int button_event = (int)ev->user_data;
|
|
xQueueSend(s_if_wifi_event_queue, &button_event, pdMS_TO_TICKS(100));
|
|
}
|
|
|
|
void if_wifi_task(void *pvParameters) {
|
|
lv_obj_t *parent = pvParameters;
|
|
|
|
impl_lvgl_lock();
|
|
|
|
lv_obj_t *wifi_main = lv_obj_create(parent);
|
|
lv_obj_set_size(wifi_main, 360, 280);
|
|
lv_obj_set_align(wifi_main, LV_ALIGN_CENTER);
|
|
|
|
lv_obj_t *exit_obj = lv_btn_create(wifi_main);
|
|
|
|
lv_obj_set_size(exit_obj, 36, 36);
|
|
|
|
lv_obj_align(exit_obj, LV_ALIGN_TOP_RIGHT, 0, 0);
|
|
|
|
lv_obj_add_event_cb(exit_obj, if_wifi_event_handler, LV_EVENT_CLICKED, (void *)IF_EVENT_EXIT_BUTTON);
|
|
|
|
lv_obj_t *exit_label = lv_label_create(exit_obj);
|
|
|
|
lv_obj_set_style_text_font(exit_label, &material_webfont_32, 0);
|
|
|
|
lv_label_set_text(exit_label, "\U000F05AD");
|
|
|
|
lv_obj_set_align(exit_label, LV_ALIGN_CENTER);
|
|
|
|
impl_lvgl_unlock();
|
|
|
|
int button_event = 0;
|
|
uint8_t terminate_flag = 0;
|
|
|
|
for (;;) {
|
|
if (xQueueReceive(s_if_wifi_event_queue, &button_event, portMAX_DELAY) == pdPASS) {
|
|
switch (button_event) {
|
|
case IF_EVENT_EXIT_BUTTON:
|
|
terminate_flag = 1;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (terminate_flag) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// When we are done, delete UI elements and task
|
|
lv_obj_del_async(wifi_main);
|
|
|
|
vQueueDelete(s_if_wifi_event_queue);
|
|
s_if_wifi_event_queue = NULL;
|
|
vTaskDelete(NULL);
|
|
}
|
|
|
|
/**
|
|
* @brief Initialize WiFi status/configuration component
|
|
*
|
|
* @param parent_obj
|
|
* @return esp_err_t
|
|
*/
|
|
esp_err_t if_wifi_init(lv_obj_t *parent_obj) {
|
|
s_if_wifi_event_queue = xQueueCreate(IF_EVENT_QUEUE_LEN, IF_EVENT_QUEUE_SIZE());
|
|
|
|
if (xTaskCreate(if_wifi_task, "STBY_TASK", 4096, parent_obj, 6, &s_if_wifi_task_handle) != pdPASS) {
|
|
return ESP_FAIL;
|
|
}
|
|
return ESP_OK;
|
|
}
|