100 lines
2.7 KiB
C
100 lines
2.7 KiB
C
#include "lvgl.h"
|
|
#include "esp_lvgl_port.h"
|
|
#include "esp_log.h"
|
|
|
|
#include "lcd/ui.h"
|
|
#include "lcd/ui_internal.h"
|
|
#include "lcd/ui_log.h"
|
|
#include "lcd/ui_image_browser.h"
|
|
|
|
static const char *TAG = "ui";
|
|
static ui_view_t current_view = UI_VIEW_LOG;
|
|
|
|
static void ui_build_log_view_locked(void);
|
|
static void ui_build_image_browser_view_locked(void);
|
|
|
|
ui_view_t ui_current_view(void){
|
|
return current_view;
|
|
}
|
|
|
|
static void ui_toggle_view_async_cb(void *param){
|
|
(void)param;
|
|
if(current_view == UI_VIEW_IMAGE_BROWSER) ui_build_log_view_locked();
|
|
else ui_build_image_browser_view_locked();
|
|
}
|
|
|
|
static void ui_toggle_view_event_cb(lv_event_t *event){
|
|
if(lv_event_get_code(event) != LV_EVENT_CLICKED) return;
|
|
lv_async_call(ui_toggle_view_async_cb, NULL);
|
|
}
|
|
|
|
void ui_attach_toggle(lv_obj_t *object){
|
|
lv_obj_add_flag(object, LV_OBJ_FLAG_CLICKABLE);
|
|
lv_obj_add_event_cb(object, ui_toggle_view_event_cb, LV_EVENT_CLICKED, NULL);
|
|
}
|
|
|
|
static void ui_reset_active_screen_locked(void){
|
|
ui_image_browser_reset();
|
|
ui_log_detach();
|
|
lv_obj_clean(lv_screen_active());
|
|
}
|
|
|
|
static void ui_build_log_view_locked(void){
|
|
ui_reset_active_screen_locked();
|
|
ui_log_build_view(lv_screen_active());
|
|
current_view = UI_VIEW_LOG;
|
|
}
|
|
|
|
static void ui_build_image_browser_view_locked(void){
|
|
ui_reset_active_screen_locked();
|
|
ui_image_browser_build_view(lv_screen_active());
|
|
current_view = UI_VIEW_IMAGE_BROWSER;
|
|
}
|
|
|
|
void create_log_ui(void){
|
|
ui_log_append("Created by Timo Niemann");
|
|
|
|
ESP_LOGI(TAG, "Creating log UI");
|
|
ui_log_append("Creating log UI");
|
|
|
|
lvgl_port_lock(0);
|
|
ui_build_log_view_locked();
|
|
lvgl_port_unlock();
|
|
|
|
ESP_LOGI(TAG, "Log UI created");
|
|
ui_log_append("Log UI created");
|
|
}
|
|
|
|
void create_image_browser_ui(void){
|
|
ESP_LOGI(TAG, "Creating image browser UI");
|
|
ui_log_append("Creating image browser UI");
|
|
|
|
lvgl_port_lock(0);
|
|
ui_build_image_browser_view_locked();
|
|
lvgl_port_unlock();
|
|
|
|
const unsigned int image_count = (unsigned int)ui_image_browser_get_image_count();
|
|
ESP_LOGI(TAG, "Image browser UI created with %u images", image_count);
|
|
ui_log_appendf("Image browser UI created with %u images", image_count);
|
|
}
|
|
|
|
void ui_switch_view_to(ui_view_t view){
|
|
if(view == current_view) return;
|
|
|
|
switch(view){
|
|
case UI_VIEW_LOG:
|
|
lvgl_port_lock(0);
|
|
ui_build_log_view_locked();
|
|
lvgl_port_unlock();
|
|
break;
|
|
case UI_VIEW_IMAGE_BROWSER:
|
|
lvgl_port_lock(0);
|
|
ui_build_image_browser_view_locked();
|
|
lvgl_port_unlock();
|
|
break;
|
|
default:
|
|
ESP_LOGW(TAG, "Unknown UI view: %d", view);
|
|
ui_log_appendf("Unknown UI view: %d", view);
|
|
break;
|
|
}
|
|
} |