fix display for esp32 box3

This commit is contained in:
whble
2025-01-01 22:43:20 +08:00
parent 11a3bb3f35
commit f98be27000
5 changed files with 95 additions and 429 deletions

View File

@@ -1,6 +1,8 @@
#include "wifi_board.h"
#include "audio_codecs/box_audio_codec.h"
#include "display/ili9341_display.h"
#include "display/st7789_display.h"
#include "esp_lcd_ili9341.h"
#include "font_awesome_symbols.h"
#include "application.h"
#include "button.h"
#include "led.h"
@@ -14,6 +16,12 @@
#define TAG "EspBox3Board"
// Can move to display/st7789_display.h
LV_FONT_DECLARE(font_puhui_14_1);
LV_FONT_DECLARE(font_awesome_30_1);
LV_FONT_DECLARE(font_awesome_14_1);
// Init ili9341 by custom cmd
static const ili9341_lcd_init_cmd_t vendor_specific_init[] = {
{0xC8, (uint8_t []){0xFF, 0x93, 0x42}, 3, 0},
{0xC0, (uint8_t []){0x0E, 0x0E}, 2, 0},
@@ -34,6 +42,82 @@ static const ili9341_lcd_init_cmd_t vendor_specific_init[] = {
{0, (uint8_t []){0}, 0xff, 0},
};
// Example Display and UI overwrite in different board
class Ili9341Display : public St7789Display {
private:
lv_obj_t *user_messge_label_ = nullptr;
lv_obj_t *ai_messge_label_ = nullptr;
public:
Ili9341Display(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)
: St7789Display(panel_io, panel, backlight_pin, backlight_output_invert, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {}
void SetStatus(const std::string &status) override
{
if (status_label_ == nullptr) {
return;
}
if(status=="待命")
{
SetChatMessage(" "," ");
}
DisplayLockGuard lock(this);
lv_label_set_text(status_label_, status.c_str());
}
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{
std::string new_content = "AI:";
lv_label_set_text(ai_messge_label_, new_content.c_str());
new_content="User:";
lv_label_set_text(user_messge_label_, new_content.c_str());
}
}
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);
}
};
class EspBox3Board : public WifiBoard {
private:
i2c_master_bus_handle_t i2c_bus_;
@@ -113,6 +197,7 @@ private:
esp_lcd_panel_disp_on_off(panel, true);
display_ = new Ili9341Display(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);
display_->SetupUI();
}
// 物联网初始化,添加对 AI 可见设备
@@ -149,6 +234,13 @@ public:
virtual Display* GetDisplay() override {
return display_;
}
virtual bool GetBatteryLevel(int &level, bool& charging) override
{
charging = false;
level =60;
return true;
};
};
DECLARE_BOARD(EspBox3Board);