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:
@ -40,14 +40,18 @@ public:
|
||||
virtual Theme* GetTheme() { return current_theme_; }
|
||||
virtual void UpdateStatusBar(bool update_all = false);
|
||||
virtual void SetPowerSaveMode(bool on);
|
||||
virtual void SetupUI() { }
|
||||
virtual void SetupUI() {
|
||||
setup_ui_called_ = true;
|
||||
}
|
||||
|
||||
inline int width() const { return width_; }
|
||||
inline int height() const { return height_; }
|
||||
inline bool IsSetupUICalled() const { return setup_ui_called_; }
|
||||
|
||||
protected:
|
||||
int width_ = 0;
|
||||
int height_ = 0;
|
||||
bool setup_ui_called_ = false; // Track if SetupUI() has been called
|
||||
|
||||
Theme* current_theme_ = nullptr;
|
||||
|
||||
|
||||
@ -352,6 +352,13 @@ void LcdDisplay::Unlock() {
|
||||
|
||||
#if CONFIG_USE_WECHAT_MESSAGE_STYLE
|
||||
void LcdDisplay::SetupUI() {
|
||||
// Prevent duplicate calls - if already called, return early
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
|
||||
return;
|
||||
}
|
||||
|
||||
Display::SetupUI(); // Mark SetupUI as called
|
||||
DisplayLockGuard lock(this);
|
||||
|
||||
auto lvgl_theme = static_cast<LvglTheme*>(current_theme_);
|
||||
@ -495,8 +502,14 @@ void LcdDisplay::SetupUI() {
|
||||
#define MAX_MESSAGES 20
|
||||
#endif
|
||||
void LcdDisplay::SetChatMessage(const char* role, const char* content) {
|
||||
if (!setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetChatMessage('%s', '%s') called before SetupUI() - message will be lost!", role, content);
|
||||
}
|
||||
DisplayLockGuard lock(this);
|
||||
if (content_ == nullptr) {
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetChatMessage('%s', '%s') failed: content_ is nullptr (SetupUI() was called but container not created)", role, content);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -789,6 +802,13 @@ void LcdDisplay::ClearChatMessages() {
|
||||
}
|
||||
#else
|
||||
void LcdDisplay::SetupUI() {
|
||||
// Prevent duplicate calls - if already called, return early
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
|
||||
return;
|
||||
}
|
||||
|
||||
Display::SetupUI(); // Mark SetupUI as called
|
||||
DisplayLockGuard lock(this);
|
||||
LvglTheme* lvgl_theme = static_cast<LvglTheme*>(current_theme_);
|
||||
auto text_font = lvgl_theme->text_font()->font();
|
||||
@ -985,8 +1005,14 @@ void LcdDisplay::SetPreviewImage(std::unique_ptr<LvglImage> image) {
|
||||
}
|
||||
|
||||
void LcdDisplay::SetChatMessage(const char* role, const char* content) {
|
||||
if (!setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetChatMessage('%s', '%s') called before SetupUI() - message will be lost!", role, content);
|
||||
}
|
||||
DisplayLockGuard lock(this);
|
||||
if (chat_message_label_ == nullptr) {
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetChatMessage('%s', '%s') failed: chat_message_label_ is nullptr (SetupUI() was called but label not created)", role, content);
|
||||
}
|
||||
return;
|
||||
}
|
||||
lv_label_set_text(chat_message_label_, content);
|
||||
@ -1002,6 +1028,9 @@ void LcdDisplay::ClearChatMessages() {
|
||||
#endif
|
||||
|
||||
void LcdDisplay::SetEmotion(const char* emotion) {
|
||||
if (!setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetEmotion('%s') called before SetupUI() - emotion will not be displayed!", emotion);
|
||||
}
|
||||
// Stop any running GIF animation
|
||||
if (gif_controller_) {
|
||||
DisplayLockGuard lock(this);
|
||||
@ -1010,6 +1039,9 @@ void LcdDisplay::SetEmotion(const char* emotion) {
|
||||
}
|
||||
|
||||
if (emoji_image_ == nullptr) {
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetEmotion('%s') failed: emoji_image_ is nullptr (SetupUI() was called but emoji image not created)", emotion);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -70,8 +70,14 @@ LvglDisplay::~LvglDisplay() {
|
||||
}
|
||||
|
||||
void LvglDisplay::SetStatus(const char* status) {
|
||||
if (!setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetStatus('%s') called before SetupUI() - message will be lost!", status);
|
||||
}
|
||||
DisplayLockGuard lock(this);
|
||||
if (status_label_ == nullptr) {
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetStatus('%s') failed: status_label_ is nullptr (SetupUI() was called but label not created)", status);
|
||||
}
|
||||
return;
|
||||
}
|
||||
lv_label_set_text(status_label_, status);
|
||||
@ -86,8 +92,14 @@ void LvglDisplay::ShowNotification(const std::string ¬ification, int duration
|
||||
}
|
||||
|
||||
void LvglDisplay::ShowNotification(const char* notification, int duration_ms) {
|
||||
if (!setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "ShowNotification('%s') called before SetupUI() - message will be lost!", notification);
|
||||
}
|
||||
DisplayLockGuard lock(this);
|
||||
if (notification_label_ == nullptr) {
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "ShowNotification('%s') failed: notification_label_ is nullptr (SetupUI() was called but label not created)", notification);
|
||||
}
|
||||
return;
|
||||
}
|
||||
lv_label_set_text(notification_label_, notification);
|
||||
|
||||
@ -76,6 +76,18 @@ OledDisplay::OledDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handl
|
||||
return;
|
||||
}
|
||||
|
||||
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
|
||||
// to ensure lvgl objects are created after the display is fully initialized.
|
||||
}
|
||||
|
||||
void OledDisplay::SetupUI() {
|
||||
// Prevent duplicate calls - if already called, return early
|
||||
if (setup_ui_called_) {
|
||||
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
|
||||
return;
|
||||
}
|
||||
|
||||
Display::SetupUI(); // Mark SetupUI as called
|
||||
if (height_ == 64) {
|
||||
SetupUI_128x64();
|
||||
} else {
|
||||
|
||||
@ -32,6 +32,7 @@ public:
|
||||
OledDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, bool mirror_x, bool mirror_y);
|
||||
~OledDisplay();
|
||||
|
||||
virtual void SetupUI() override;
|
||||
virtual void SetChatMessage(const char* role, const char* content) override;
|
||||
virtual void SetEmotion(const char* emotion) override;
|
||||
virtual void SetTheme(Theme* theme) override;
|
||||
|
||||
Reference in New Issue
Block a user