forked from xiaozhi/xiaozhi-esp32
使用imgfont在LCD显示器显示彩色表情图标 (#77)
* 使用imgfont在LCD显示器显示彩色表情图标 * fix one emotion --------- Co-authored-by: zk <982145@qq.com>
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
#include <driver/ledc.h>
|
#include <driver/ledc.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "emoji_font.h"
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
#define TAG "LcdDisplay"
|
#define TAG "LcdDisplay"
|
||||||
#define LCD_LEDC_CH LEDC_CHANNEL_0
|
#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;
|
offset_y_ = offset_y;
|
||||||
|
|
||||||
|
|
||||||
|
emoji_font_init();
|
||||||
InitializeBacklight(backlight_pin);
|
InitializeBacklight(backlight_pin);
|
||||||
|
|
||||||
// draw white
|
// 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());
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public:
|
|||||||
~LcdDisplay();
|
~LcdDisplay();
|
||||||
|
|
||||||
void SetChatMessage(const std::string &role, const std::string &content) override;
|
void SetChatMessage(const std::string &role, const std::string &content) override;
|
||||||
|
void SetEmotion(const std::string &emotion) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LCD_DISPLAY_H
|
#endif // LCD_DISPLAY_H
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ dependencies:
|
|||||||
espressif/button: "^3.3.1"
|
espressif/button: "^3.3.1"
|
||||||
lvgl/lvgl: "~8.4.0"
|
lvgl/lvgl: "~8.4.0"
|
||||||
esp_lvgl_port: "~2.4.1"
|
esp_lvgl_port: "~2.4.1"
|
||||||
|
zhoukes/emoji_font: "~1.0.0"
|
||||||
## Required IDF version
|
## Required IDF version
|
||||||
idf:
|
idf:
|
||||||
version: ">=5.3"
|
version: ">=5.3"
|
||||||
|
|||||||
@@ -25,3 +25,4 @@ CONFIG_ESP_WIFI_IRAM_OPT=n
|
|||||||
CONFIG_ESP_WIFI_RX_IRAM_OPT=n
|
CONFIG_ESP_WIFI_RX_IRAM_OPT=n
|
||||||
|
|
||||||
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
|
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
|
||||||
|
CONFIG_LV_USE_IMGFONT=y
|
||||||
Reference in New Issue
Block a user