使用imgfont在LCD显示器显示彩色表情图标 (#77)

* 使用imgfont在LCD显示器显示彩色表情图标

* fix one emotion

---------

Co-authored-by: zk <982145@qq.com>
This commit is contained in:
ZhouKe
2025-01-19 04:29:23 +08:00
committed by GitHub
parent 48229607d2
commit 3c719d5c91
4 changed files with 56 additions and 0 deletions

View File

@ -5,6 +5,8 @@
#include <esp_err.h>
#include <driver/ledc.h>
#include <vector>
#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<Emotion> 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);
}
}

View File

@ -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

View File

@ -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"

View File

@ -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