From 3c719d5c910fdac339e5af25a183b30dd8a7ef88 Mon Sep 17 00:00:00 2001 From: ZhouKe <9482145@qq.com> Date: Sun, 19 Jan 2025 04:29:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8imgfont=E5=9C=A8LCD=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=99=A8=E6=98=BE=E7=A4=BA=E5=BD=A9=E8=89=B2=E8=A1=A8?= =?UTF-8?q?=E6=83=85=E5=9B=BE=E6=A0=87=20(#77)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 使用imgfont在LCD显示器显示彩色表情图标 * fix one emotion --------- Co-authored-by: zk <982145@qq.com> --- main/display/lcd_display.cc | 53 +++++++++++++++++++++++++++++++++++++ main/display/lcd_display.h | 1 + main/idf_component.yml | 1 + sdkconfig.defaults | 1 + 4 files changed, 56 insertions(+) diff --git a/main/display/lcd_display.cc b/main/display/lcd_display.cc index ad724b1b..199d4995 100644 --- a/main/display/lcd_display.cc +++ b/main/display/lcd_display.cc @@ -5,6 +5,8 @@ #include #include #include +#include "emoji_font.h" +#include "board.h" #define TAG "LcdDisplay" #define LCD_LEDC_CH LEDC_CHANNEL_0 @@ -97,6 +99,7 @@ LcdDisplay::LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_ offset_y_ = offset_y; + emoji_font_init(); InitializeBacklight(backlight_pin); // draw white @@ -323,3 +326,53 @@ void LcdDisplay::SetChatMessage(const std::string &role, const std::string &cont } 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; + }; + + static const std::vector emotions = { + {"😶", "neutral"}, + {"😊", "happy"}, + {"😆", "laughing"}, + {"😂", "funny"}, + {"😔", "sad"}, + {"😠", "angry"}, + {"😭", "crying"}, + {"😍", "loving"}, + {"😳", "embarrassed"}, + {"😲", "surprised"}, + {"😨", "shocked"}, + {"🤔", "thinking"}, + {"😉", "winking"}, + {"😎", "cool"}, + {"😌", "relaxed"}, + {"😋", "delicious"}, + {"😘", "kissy"}, + {"😏", "confident"}, + {"😴", "sleepy"}, + {"🤪", "silly"}, + {"😕", "confused"} + }; + + DisplayLockGuard lock(this); + + // 查找匹配的表情 + auto it = std::find_if(emotions.begin(), emotions.end(), + [&emotion](const Emotion& e) { return e.text == emotion; }); + + // 如果找到匹配的表情就显示对应图标,否则显示默认的neutral表情 + lv_obj_set_style_text_font(emotion_label_, emoji_font, 0); + if (it != emotions.end()) { + lv_label_set_text(emotion_label_, it->icon); + } else { + lv_label_set_text(emotion_label_, FONT_AWESOME_EMOJI_NEUTRAL); + } +} + diff --git a/main/display/lcd_display.h b/main/display/lcd_display.h index 67f6ad9c..f21bfab5 100644 --- a/main/display/lcd_display.h +++ b/main/display/lcd_display.h @@ -45,6 +45,7 @@ public: ~LcdDisplay(); void SetChatMessage(const std::string &role, const std::string &content) override; + void SetEmotion(const std::string &emotion) override; }; #endif // LCD_DISPLAY_H diff --git a/main/idf_component.yml b/main/idf_component.yml index d1f3c337..dc32bbc7 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -15,6 +15,7 @@ dependencies: espressif/button: "^3.3.1" lvgl/lvgl: "~8.4.0" esp_lvgl_port: "~2.4.1" + zhoukes/emoji_font: "~1.0.0" ## Required IDF version idf: version: ">=5.3" diff --git a/sdkconfig.defaults b/sdkconfig.defaults index e26c03dc..682db277 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -25,3 +25,4 @@ CONFIG_ESP_WIFI_IRAM_OPT=n CONFIG_ESP_WIFI_RX_IRAM_OPT=n CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n +CONFIG_LV_USE_IMGFONT=y \ No newline at end of file