add more fonts for version 1.0.0

This commit is contained in:
Terrence
2025-01-23 13:50:22 +08:00
parent a5d8db6bbb
commit 84f5674359
31 changed files with 176 additions and 58410 deletions

View File

@@ -18,9 +18,8 @@
#define TAG "waveshare_amoled_1_8"
LV_FONT_DECLARE(font_puhui_14_1);
LV_FONT_DECLARE(font_awesome_30_1);
LV_FONT_DECLARE(font_awesome_14_1);
LV_FONT_DECLARE(font_puhui_30_4);
LV_FONT_DECLARE(font_awesome_30_4);
static const sh8601_lcd_init_cmd_t vendor_specific_init[] = {
{0x11, (uint8_t[]){0x00}, 0, 120},
@@ -34,71 +33,34 @@ static const sh8601_lcd_init_cmd_t vendor_specific_init[] = {
{0x51, (uint8_t[]){0xFF}, 1, 0},
};
class SH8601Display : public LcdDisplay {
private:
lv_obj_t *user_messge_label_ = nullptr;
lv_obj_t *ai_messge_label_ = nullptr;
// 在waveshare_amoled_1_8类之前添加新的显示类
class CustomLcdDisplay : public LcdDisplay {
public:
SH8601Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
gpio_num_t backlight_pin, bool backlight_output_invert,
int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy)
: LcdDisplay(panel_io, panel, backlight_pin, backlight_output_invert, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {}
void SetChatMessage(const std::string &role, const std::string &content) override {
if (ai_messge_label_== nullptr || user_messge_label_== nullptr) {
return;
}
DisplayLockGuard lock(this);
ESP_LOGI(TAG, "role:%s", role.c_str());
if(role == "assistant") {
std::string new_content = "AI: " + content;
lv_label_set_text(ai_messge_label_, new_content.c_str());
} else if(role == "user") {
std::string new_content = "User: " + content;
lv_label_set_text(user_messge_label_, new_content.c_str());
} else{
lv_label_set_text(ai_messge_label_, "AI: ");
lv_label_set_text(user_messge_label_, "User: ");
}
}
void SetupUI() override {
DisplayLockGuard lock(this);
lv_obj_del(chat_message_label_);
lv_obj_set_flex_align(content_, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_EVENLY); // 子对象居中对齐,等距分布
lv_obj_set_style_text_font(emotion_label_, &font_awesome_30_1, 0);
lv_label_set_text(emotion_label_, FONT_AWESOME_AI_CHIP);
lv_obj_align(emotion_label_, LV_ALIGN_TOP_MID, 0, -10); // 左侧居中向右偏移10个单位
static lv_style_t style_msg;
lv_style_init(&style_msg);
lv_style_set_width(&style_msg, LV_HOR_RES - 25);
user_messge_label_ = lv_label_create(content_);
lv_obj_set_style_text_font(user_messge_label_, &font_puhui_14_1, 0);
lv_label_set_text(user_messge_label_, "User: ");
lv_obj_add_style(user_messge_label_, &style_msg, 0);
lv_obj_align(user_messge_label_, LV_ALIGN_TOP_LEFT, 2, 25);
ai_messge_label_ = lv_label_create(content_);
lv_obj_set_style_text_font(ai_messge_label_, &font_puhui_14_1, 0);
lv_label_set_text(ai_messge_label_, "AI: ");
lv_obj_add_style(ai_messge_label_, &style_msg, 0);
lv_obj_align(ai_messge_label_, LV_ALIGN_TOP_LEFT, 2, 77);
CustomLcdDisplay(esp_lcd_panel_io_handle_t io_handle,
esp_lcd_panel_handle_t panel_handle,
gpio_num_t backlight_pin,
bool backlight_output_invert,
int width,
int height,
int offset_x,
int offset_y,
bool mirror_x,
bool mirror_y,
bool swap_xy)
: LcdDisplay(io_handle, panel_handle, backlight_pin, backlight_output_invert,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy,
&font_puhui_30_4, &font_awesome_30_4) {
// 由于屏幕是带圆角的,所以状态栏需要增加左右内边距
lv_obj_set_style_pad_left(status_bar_, LV_HOR_RES * 0.1, 0);
lv_obj_set_style_pad_right(status_bar_, LV_HOR_RES * 0.1, 0);
}
};
class waveshare_amoled_1_8 : public WifiBoard {
private:
i2c_master_bus_handle_t codec_i2c_bus_;
Button boot_button_;
SH8601Display* display_;
LcdDisplay* display_;
void InitializeCodecI2c() {
// Initialize I2C peripheral
@@ -178,18 +140,12 @@ private:
esp_lcd_panel_reset(panel);
esp_lcd_panel_init(panel);
esp_lcd_panel_invert_color(panel, true);
esp_lcd_panel_invert_color(panel, false);
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
esp_lcd_panel_disp_on_off(panel, true);
display_ = new SH8601Display(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
display_ = new CustomLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
if (display_) {
display_->SetupUI();
} else {
ESP_LOGE(TAG, "Display is not initialized!");
}
}
// 物联网初始化,添加对 AI 可见设备