fix display issues

This commit is contained in:
Terrence
2025-02-04 14:24:03 +08:00
parent 252755f615
commit a0adbfd774
5 changed files with 29 additions and 28 deletions

View File

@@ -4,7 +4,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
set(PROJECT_VER "1.1.0")
set(PROJECT_VER "1.1.1")
# Add this line to disable the specific warning
add_compile_options(-Wno-missing-field-initializers)

View File

@@ -26,8 +26,8 @@
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 240
#define DISPLAY_MIRROR_X true
#define DISPLAY_MIRROR_Y true
#define DISPLAY_MIRROR_X false
#define DISPLAY_MIRROR_Y false
#define DISPLAY_SWAP_XY false
#define DISPLAY_OFFSET_X 0

View File

@@ -63,20 +63,20 @@ Display::~Display() {
}
void Display::SetStatus(const std::string &status) {
DisplayLockGuard lock(this);
if (status_label_ == nullptr) {
return;
}
DisplayLockGuard lock(this);
lv_label_set_text(status_label_, status.c_str());
lv_obj_clear_flag(status_label_, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
}
void Display::ShowNotification(const std::string &notification, int duration_ms) {
DisplayLockGuard lock(this);
if (notification_label_ == nullptr) {
return;
}
DisplayLockGuard lock(this);
lv_label_set_text(notification_label_, notification.c_str());
lv_obj_clear_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(status_label_, LV_OBJ_FLAG_HIDDEN);
@@ -86,15 +86,15 @@ void Display::ShowNotification(const std::string &notification, int duration_ms)
}
void Display::Update() {
if (mute_label_ == nullptr) {
return;
}
auto& board = Board::GetInstance();
auto codec = board.GetAudioCodec();
{
DisplayLockGuard lock(this);
if (mute_label_ == nullptr) {
return;
}
// 如果静音状态改变,则更新图标
if (codec->output_volume() == 0 && !muted_) {
muted_ = true;
@@ -123,8 +123,8 @@ void Display::Update() {
};
icon = levels[battery_level / 20];
}
if (battery_icon_ != icon) {
DisplayLockGuard lock(this);
DisplayLockGuard lock(this);
if (battery_label_ != nullptr && battery_icon_ != icon) {
battery_icon_ = icon;
lv_label_set_text(battery_label_, battery_icon_);
}
@@ -140,7 +140,7 @@ void Display::Update() {
};
if (std::find(allowed_states.begin(), allowed_states.end(), device_state) != allowed_states.end()) {
icon = board.GetNetworkStateIcon();
if (network_icon_ != icon) {
if (network_label_ != nullptr && network_icon_ != icon) {
DisplayLockGuard lock(this);
network_icon_ = icon;
lv_label_set_text(network_label_, network_icon_);
@@ -150,10 +150,6 @@ void Display::Update() {
void Display::SetEmotion(const std::string &emotion) {
if (emotion_label_ == nullptr) {
return;
}
struct Emotion {
const char* icon;
const char* text;
@@ -188,6 +184,10 @@ void Display::SetEmotion(const std::string &emotion) {
[&emotion](const Emotion& e) { return e.text == emotion; });
DisplayLockGuard lock(this);
if (emotion_label_ == nullptr) {
return;
}
// 如果找到匹配的表情就显示对应图标否则显示默认的neutral表情
if (it != emotions.end()) {
lv_label_set_text(emotion_label_, it->icon);
@@ -197,10 +197,10 @@ void Display::SetEmotion(const std::string &emotion) {
}
void Display::SetIcon(const char* icon) {
DisplayLockGuard lock(this);
if (emotion_label_ == nullptr) {
return;
}
DisplayLockGuard lock(this);
lv_label_set_text(emotion_label_, icon);
}

View File

@@ -75,7 +75,9 @@ LcdDisplay::LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_
return;
}
lv_display_set_offset(display_, offset_x, offset_y);
if (offset_x != 0 || offset_y != 0) {
lv_display_set_offset(display_, offset_x, offset_y);
}
SetBacklight(100);
@@ -166,7 +168,7 @@ void LcdDisplay::Unlock() {
void LcdDisplay::SetupUI() {
DisplayLockGuard lock(this);
auto screen = lv_disp_get_scr_act(lv_disp_get_default());
auto screen = lv_screen_active();
lv_obj_set_style_text_font(screen, fonts_.text_font, 0);
lv_obj_set_style_text_color(screen, lv_color_black(), 0);
@@ -237,19 +239,14 @@ void LcdDisplay::SetupUI() {
}
void LcdDisplay::SetChatMessage(const std::string &role, const std::string &content) {
DisplayLockGuard lock(this);
if (chat_message_label_ == nullptr) {
return;
}
DisplayLockGuard lock(this);
lv_label_set_text(chat_message_label_, content.c_str());
}
void LcdDisplay::SetEmotion(const std::string &emotion) {
if (emotion_label_ == nullptr) {
return;
}
struct Emotion {
const char* icon;
const char* text;
@@ -284,6 +281,10 @@ void LcdDisplay::SetEmotion(const std::string &emotion) {
[&emotion](const Emotion& e) { return e.text == emotion; });
DisplayLockGuard lock(this);
if (emotion_label_ == nullptr) {
return;
}
// 如果找到匹配的表情就显示对应图标否则显示默认的neutral表情
lv_obj_set_style_text_font(emotion_label_, fonts_.emoji_font, 0);
if (it != emotions.end()) {
@@ -294,10 +295,10 @@ void LcdDisplay::SetEmotion(const std::string &emotion) {
}
void LcdDisplay::SetIcon(const char* icon) {
DisplayLockGuard lock(this);
if (emotion_label_ == nullptr) {
return;
}
DisplayLockGuard lock(this);
lv_obj_set_style_text_font(emotion_label_, &font_awesome_30_4, 0);
lv_label_set_text(emotion_label_, icon);
}

View File

@@ -135,7 +135,7 @@ void Ssd1306Display::Unlock() {
void Ssd1306Display::SetupUI_128x64() {
DisplayLockGuard lock(this);
auto screen = lv_disp_get_scr_act(display_);
auto screen = lv_screen_active();
lv_obj_set_style_text_font(screen, text_font_, 0);
lv_obj_set_style_text_color(screen, lv_color_black(), 0);
@@ -197,7 +197,7 @@ void Ssd1306Display::SetupUI_128x64() {
void Ssd1306Display::SetupUI_128x32() {
DisplayLockGuard lock(this);
auto screen = lv_disp_get_scr_act(display_);
auto screen = lv_screen_active();
lv_obj_set_style_text_font(screen, text_font_, 0);
/* Container */