fix: Enhance UI setup across multiple boards (#1753)
* chore: Update component versions and enhance UI setup across multiple boards - Bumped uart-eth-modem version from ~0.3.2 to ~0.3.3 in idf_component.yml. - Added SetupUI method to various display classes to ensure proper UI initialization before usage. - Improved error handling in display classes to prevent issues when UI is not set up. - Ensured UI customization is performed in SetupUI rather than constructors for better reliability. * remove pm config code
This commit is contained in:
@ -106,6 +106,10 @@ private:
|
||||
InitializeGc9107Display();
|
||||
InitializeButtons();
|
||||
GetBacklight()->SetBrightness(100);
|
||||
|
||||
// Ensure UI is set up before displaying error
|
||||
display_->SetupUI();
|
||||
|
||||
display_->SetStatus(Lang::Strings::ERROR);
|
||||
display_->SetEmotion("triangle_exclamation");
|
||||
display_->SetChatMessage("system", "Echo Base\nnot connected");
|
||||
|
||||
@ -173,6 +173,10 @@ private:
|
||||
InitializeGc9107Display();
|
||||
InitializeButtons();
|
||||
GetBacklight()->SetBrightness(100);
|
||||
|
||||
// Ensure UI is set up before displaying error
|
||||
display_->SetupUI();
|
||||
|
||||
display_->SetStatus(Lang::Strings::ERROR);
|
||||
display_->SetEmotion("triangle_exclamation");
|
||||
display_->SetChatMessage("system", "Echo Base\nnot connected");
|
||||
|
||||
@ -15,17 +15,28 @@
|
||||
ElectronEmojiDisplay::ElectronEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y,
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(panel_io, panel, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
InitializeElectronEmojis();
|
||||
SetupChatLabel();
|
||||
}
|
||||
|
||||
void ElectronEmojiDisplay::SetupUI() {
|
||||
// Prevent duplicate calls - parent SetupUI() will also check, but check here for early return
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
|
||||
return;
|
||||
}
|
||||
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
// Set default emotion after UI is initialized
|
||||
SetEmotion("staticstate");
|
||||
}
|
||||
|
||||
void ElectronEmojiDisplay::InitializeElectronEmojis() {
|
||||
ESP_LOGI(TAG, "Electron表情初始化将由Assets系统处理");
|
||||
// 表情初始化已移至assets系统,通过DEFAULT_EMOJI_COLLECTION=otto-gif配置
|
||||
// assets.cc会从assets分区加载GIF表情并设置到theme
|
||||
|
||||
// 设置默认表情为staticstate
|
||||
SetEmotion("staticstate");
|
||||
// Note: Default emotion is now set in SetupUI() after LVGL objects are created
|
||||
}
|
||||
|
||||
void ElectronEmojiDisplay::SetupChatLabel() {
|
||||
|
||||
@ -15,6 +15,7 @@ class ElectronEmojiDisplay : public SpiLcdDisplay {
|
||||
|
||||
virtual ~ElectronEmojiDisplay() = default;
|
||||
virtual void SetStatus(const char* status) override;
|
||||
virtual void SetupUI() override;
|
||||
|
||||
private:
|
||||
void InitializeElectronEmojis();
|
||||
|
||||
@ -39,6 +39,13 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy)
|
||||
{
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
|
||||
@ -49,7 +56,6 @@ public:
|
||||
lv_obj_align(emoji_box_, LV_ALIGN_CENTER, 0, -50); // 向上偏移50
|
||||
// 消息栏适配
|
||||
lv_obj_align(bottom_bar_, LV_ALIGN_BOTTOM_MID, 0, -40); // 向上偏移40
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -31,6 +31,13 @@ public:
|
||||
bool mirror_y,
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
// 由于屏幕是圆的,所以状态栏需要增加左右内边距
|
||||
|
||||
@ -14,13 +14,33 @@
|
||||
#define TAG "OttoEmojiDisplay"
|
||||
OttoEmojiDisplay::OttoEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy)
|
||||
: SpiLcdDisplay(panel_io, panel, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
InitializeOttoEmojis();
|
||||
SetupPreviewImage();
|
||||
SetTheme(LvglThemeManager::GetInstance().GetTheme("dark"));
|
||||
}
|
||||
|
||||
void OttoEmojiDisplay::SetupUI() {
|
||||
// Prevent duplicate calls - parent SetupUI() will also check, but check here for early return
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
|
||||
return;
|
||||
}
|
||||
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
// Setup preview image after UI is initialized
|
||||
DisplayLockGuard lock(this);
|
||||
lv_obj_set_size(preview_image_, width_ , height_ );
|
||||
|
||||
// Set default emotion after UI is initialized
|
||||
SetEmotion("staticstate");
|
||||
}
|
||||
|
||||
void OttoEmojiDisplay::SetupPreviewImage() {
|
||||
DisplayLockGuard lock(this);
|
||||
if (preview_image_ == nullptr) {
|
||||
ESP_LOGW(TAG, "SetupPreviewImage called but preview_image_ is nullptr (UI not initialized yet)");
|
||||
return;
|
||||
}
|
||||
lv_obj_set_size(preview_image_, width_ , height_ );
|
||||
}
|
||||
|
||||
@ -28,9 +48,7 @@ void OttoEmojiDisplay::InitializeOttoEmojis() {
|
||||
ESP_LOGI(TAG, "Otto表情初始化将由Assets系统处理");
|
||||
// 表情初始化已移至assets系统,通过DEFAULT_EMOJI_COLLECTION=otto-gif配置
|
||||
// assets.cc会从assets分区加载GIF表情并设置到theme
|
||||
|
||||
// 设置默认表情为staticstate
|
||||
SetEmotion("staticstate");
|
||||
// Note: Default emotion is now set in SetupUI() after LVGL objects are created
|
||||
}
|
||||
|
||||
LV_FONT_DECLARE(OTTO_ICON_FONT);
|
||||
|
||||
@ -16,6 +16,7 @@ class OttoEmojiDisplay : public SpiLcdDisplay {
|
||||
virtual ~OttoEmojiDisplay() = default;
|
||||
virtual void SetStatus(const char* status) override;
|
||||
virtual void SetPreviewImage(std::unique_ptr<LvglImage> image) override;
|
||||
virtual void SetupUI() override;
|
||||
|
||||
private:
|
||||
void InitializeOttoEmojis();
|
||||
|
||||
@ -45,7 +45,14 @@ class CustomLcdDisplay : public SpiLcdDisplay {
|
||||
bool mirror_y,
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
auto lvgl_theme = static_cast<LvglTheme*>(current_theme_);
|
||||
auto text_font = lvgl_theme->text_font()->font();
|
||||
|
||||
@ -115,6 +115,13 @@ public:
|
||||
bool mirror_y,
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
// 由于屏幕是圆的,所以状态栏需要增加左右内边距
|
||||
|
||||
@ -32,6 +32,14 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle,
|
||||
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_obj_set_style_pad_left(status_bar_, LV_HOR_RES * 0.1, 0);
|
||||
lv_obj_set_style_pad_right(status_bar_, LV_HOR_RES * 0.1, 0);
|
||||
|
||||
@ -61,9 +61,17 @@ class CustomLcdDisplay : public SpiLcdDisplay {
|
||||
CustomLcdDisplay(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_handle_t panel_handle, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy) :
|
||||
SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy),
|
||||
io_handle_(io_handle) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
SetMIRROR_XY(0xC0); // Rotate 180 degrees - this is safe as it only operates on hardware
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_display_add_event_cb(display_, my_draw_event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
|
||||
SetMIRROR_XY(0xC0); // Rotate 180 degrees
|
||||
lv_obj_invalidate(lv_screen_active());
|
||||
}
|
||||
};
|
||||
|
||||
@ -54,6 +54,14 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle,
|
||||
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_display_add_event_cb(display_, MyDrawEventCb, LV_EVENT_INVALIDATE_AREA, NULL);
|
||||
}
|
||||
|
||||
@ -83,6 +83,14 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle,
|
||||
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_obj_set_style_pad_left(status_bar_, LV_HOR_RES * 0.1, 0);
|
||||
lv_obj_set_style_pad_right(status_bar_, LV_HOR_RES * 0.1, 0);
|
||||
|
||||
@ -102,6 +102,14 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle,
|
||||
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_obj_set_style_pad_left(status_bar_, LV_HOR_RES* 0.1, 0);
|
||||
lv_obj_set_style_pad_right(status_bar_, LV_HOR_RES* 0.1, 0);
|
||||
|
||||
@ -120,9 +120,8 @@ CustomLcdDisplay::CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_p
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "ui start");
|
||||
|
||||
SetupUI();
|
||||
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
|
||||
// to ensure lvgl objects are created after the display is fully initialized.
|
||||
}
|
||||
|
||||
CustomLcdDisplay::~CustomLcdDisplay() {
|
||||
|
||||
@ -117,9 +117,8 @@ height_(height)
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "ui start");
|
||||
|
||||
SetupUI();
|
||||
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
|
||||
// to ensure lvgl objects are created after the display is fully initialized.
|
||||
}
|
||||
|
||||
CustomLcdDisplay::~CustomLcdDisplay() {
|
||||
|
||||
@ -61,9 +61,17 @@ class CustomLcdDisplay : public SpiLcdDisplay {
|
||||
CustomLcdDisplay(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_handle_t panel_handle, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy) :
|
||||
SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy),
|
||||
io_handle_(io_handle) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
SetMIRROR_XY(0xC0); // Rotate 180 degrees - this is safe as it only operates on hardware
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_display_add_event_cb(display_, my_draw_event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
|
||||
SetMIRROR_XY(0xC0); // Rotate 180 degrees
|
||||
lv_obj_invalidate(lv_screen_active());
|
||||
}
|
||||
};
|
||||
|
||||
@ -107,6 +107,14 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle,
|
||||
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_obj_set_style_pad_left(status_bar_, LV_HOR_RES* 0.1, 0);
|
||||
lv_obj_set_style_pad_right(status_bar_, LV_HOR_RES* 0.1, 0);
|
||||
|
||||
@ -83,6 +83,14 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle,
|
||||
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_obj_set_style_pad_left(status_bar_, LV_HOR_RES * 0.1, 0);
|
||||
lv_obj_set_style_pad_right(status_bar_, LV_HOR_RES * 0.1, 0);
|
||||
|
||||
@ -103,6 +103,14 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle,
|
||||
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_obj_set_style_pad_left(status_bar_, LV_HOR_RES* 0.1, 0);
|
||||
lv_obj_set_style_pad_right(status_bar_, LV_HOR_RES* 0.1, 0);
|
||||
|
||||
@ -43,6 +43,14 @@ public:
|
||||
bool swap_xy)
|
||||
: SpiLcdDisplay(io_handle, panel_handle,
|
||||
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
||||
// Note: UI customization should be done in SetupUI(), not in constructor
|
||||
// to ensure lvgl objects are created before accessing them
|
||||
}
|
||||
|
||||
virtual void SetupUI() override {
|
||||
// Call parent SetupUI() first to create all lvgl objects
|
||||
SpiLcdDisplay::SetupUI();
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
lv_display_add_event_cb(display_, rounder_event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
|
||||
}
|
||||
|
||||
@ -141,5 +141,7 @@ CustomLcdDisplay::CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_p
|
||||
if (offset_x != 0 || offset_y != 0) {
|
||||
lv_display_set_offset(display_, offset_x, offset_y);
|
||||
}
|
||||
SetupUI();
|
||||
|
||||
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
|
||||
// to ensure lvgl objects are created after the display is fully initialized.
|
||||
}
|
||||
@ -281,6 +281,6 @@ CustomLcdDisplay::CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_p
|
||||
lv_display_set_offset(display_, offset_x, offset_y);
|
||||
}
|
||||
|
||||
|
||||
SetupUI();
|
||||
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
|
||||
// to ensure lvgl objects are created after the display is fully initialized.
|
||||
}
|
||||
Reference in New Issue
Block a user