Skip to content

Commit

Permalink
remove the special code for box3 lcd
Browse files Browse the repository at this point in the history
  • Loading branch information
78 committed Jan 12, 2025
1 parent bfdee9b commit 679130c
Showing 1 changed file with 3 additions and 68 deletions.
71 changes: 3 additions & 68 deletions main/boards/esp-box-3/esp_box3_board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

#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},
Expand All @@ -42,70 +37,11 @@ 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 LcdDisplay {
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)
: 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);
}
};

class EspBox3Board : public WifiBoard {
private:
i2c_master_bus_handle_t i2c_bus_;
Button boot_button_;
Ili9341Display* display_;
LcdDisplay* display_;

void InitializeI2c() {
// Initialize I2C peripheral
Expand Down Expand Up @@ -178,13 +114,12 @@ class EspBox3Board : public WifiBoard {

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 Ili9341Display(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
display_ = new LcdDisplay(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 可见设备
Expand Down

0 comments on commit 679130c

Please sign in to comment.