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