forked from xiaozhi/xiaozhi-esp32
rename St7789 to LCD
This commit is contained in:
@@ -32,7 +32,7 @@ public:
|
||||
|
||||
virtual void StartNetwork() = 0;
|
||||
virtual ~Board() = default;
|
||||
virtual Led* GetLed() = 0;
|
||||
virtual Led* GetLed();
|
||||
virtual AudioCodec* GetAudioCodec() = 0;
|
||||
virtual Display* GetDisplay();
|
||||
virtual Http* CreateHttp() = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/box_audio_codec.h"
|
||||
#include "display/st7789_display.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "esp_lcd_ili9341.h"
|
||||
#include "font_awesome_symbols.h"
|
||||
#include "application.h"
|
||||
@@ -42,7 +42,7 @@ static const ili9341_lcd_init_cmd_t vendor_specific_init[] = {
|
||||
};
|
||||
|
||||
// Example Display and UI overwrite in different board
|
||||
class Ili9341Display : public St7789Display {
|
||||
class Ili9341Display : public LcdDisplay {
|
||||
private:
|
||||
lv_obj_t *user_messge_label_ = nullptr;
|
||||
lv_obj_t *ai_messge_label_ = nullptr;
|
||||
@@ -50,44 +50,27 @@ 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());
|
||||
}
|
||||
: 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;
|
||||
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:";
|
||||
} 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);
|
||||
|
||||
@@ -97,23 +80,23 @@ public:
|
||||
|
||||
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个单位
|
||||
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);
|
||||
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_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);
|
||||
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_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);
|
||||
lv_obj_align(ai_messge_label_, LV_ALIGN_TOP_LEFT, 2, 77);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -228,13 +211,6 @@ public:
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual bool GetBatteryLevel(int &level, bool& charging) override
|
||||
{
|
||||
charging = false;
|
||||
level = 60;
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
DECLARE_BOARD(EspBox3Board);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/box_audio_codec.h"
|
||||
#include "display/st7789_display.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
@@ -36,7 +36,7 @@ private:
|
||||
i2c_master_bus_handle_t i2c_bus_;
|
||||
i2c_master_dev_handle_t pca9557_handle_;
|
||||
Button boot_button_;
|
||||
St7789Display* display_;
|
||||
LcdDisplay* display_;
|
||||
Pca9557* pca9557_;
|
||||
|
||||
void InitializeI2c() {
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
esp_lcd_panel_invert_color(panel, true);
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
display_ = new St7789Display(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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/cores3_audio_codec.h"
|
||||
#include "display/st7789_display.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "led.h"
|
||||
#include "config.h"
|
||||
#include "i2c_device.h"
|
||||
#include "iot/thing_manager.h"
|
||||
@@ -31,6 +30,18 @@ public:
|
||||
WriteReg(0x94, 33 - 5);
|
||||
WriteReg(0x95, 33 - 5);
|
||||
}
|
||||
|
||||
int GetBatteryCurrentDirection() {
|
||||
return (ReadReg(0x01) & 0b01100000) >> 5;
|
||||
}
|
||||
|
||||
bool IsCharging() {
|
||||
return GetBatteryCurrentDirection() == 1;
|
||||
}
|
||||
|
||||
int GetBatteryLevel() {
|
||||
return ReadReg(0xA4);
|
||||
}
|
||||
};
|
||||
|
||||
class Aw9523 : public I2cDevice {
|
||||
@@ -103,7 +114,7 @@ private:
|
||||
Axp2101* axp2101_;
|
||||
Aw9523* aw9523_;
|
||||
Ft6336* ft6336_;
|
||||
St7789Display* display_;
|
||||
LcdDisplay* display_;
|
||||
Button boot_button_;
|
||||
|
||||
void InitializeI2c() {
|
||||
@@ -227,7 +238,7 @@ private:
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
|
||||
display_ = new St7789Display(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);
|
||||
}
|
||||
|
||||
@@ -256,11 +267,6 @@ public:
|
||||
InitializeIot();
|
||||
}
|
||||
|
||||
virtual Led* GetBuiltinLed() override {
|
||||
static Led led(GPIO_NUM_NC);
|
||||
return &led;
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
static CoreS3AudioCodec* audio_codec = nullptr;
|
||||
if (audio_codec == nullptr) {
|
||||
@@ -276,6 +282,19 @@ public:
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual bool GetBatteryLevel(int &level, bool& charging) override {
|
||||
static int last_level = 0;
|
||||
static bool last_charging = false;
|
||||
level = axp2101_->GetBatteryLevel();
|
||||
charging = axp2101_->IsCharging();
|
||||
if (level != last_level || charging != last_charging) {
|
||||
last_level = level;
|
||||
last_charging = charging;
|
||||
ESP_LOGI(TAG, "Battery level: %d, charging: %d", level, charging);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Ft6336* GetTouchpad() {
|
||||
return ft6336_;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "wifi_board.h"
|
||||
#include "display/st7789_display.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "audio_codecs/es8311_audio_codec.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "led.h"
|
||||
#include "led/single_led.h"
|
||||
#include "config.h"
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <wifi_station.h>
|
||||
@@ -17,7 +17,7 @@ class magiclick_2p4 : public WifiBoard {
|
||||
private:
|
||||
i2c_master_bus_handle_t codec_i2c_bus_;
|
||||
Button boot_button_;
|
||||
St7789Display* display_;
|
||||
LcdDisplay* display_;
|
||||
|
||||
void InitializeCodecI2c() {
|
||||
// Initialize I2C peripheral
|
||||
@@ -39,7 +39,7 @@ private:
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetChatState() == kChatStateUnknown && !WifiStation::GetInstance().IsConnected()) {
|
||||
if (app.GetDeviceState() == kDeviceStateUnknown && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
});
|
||||
@@ -57,6 +57,7 @@ private:
|
||||
gpio_set_direction(BUILTIN_LED_POWER, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(BUILTIN_LED_POWER, BUILTIN_LED_POWER_OUTPUT_INVERT ? 0 : 1);
|
||||
}
|
||||
|
||||
void InitializeSpi() {
|
||||
spi_bus_config_t buscfg = {};
|
||||
buscfg.mosi_io_num = DISPLAY_SDA_PIN;
|
||||
@@ -68,7 +69,7 @@ private:
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
}
|
||||
|
||||
void InitializeSt7789Display(){
|
||||
void InitializeNv3023Display(){
|
||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||
esp_lcd_panel_handle_t panel = nullptr;
|
||||
// 液晶屏控制IO初始化
|
||||
@@ -83,7 +84,7 @@ private:
|
||||
io_config.lcd_param_bits = 8;
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io));
|
||||
|
||||
// 初始化液晶屏驱动芯片ST7789
|
||||
// 初始化液晶屏驱动芯片NV3023
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
|
||||
@@ -99,7 +100,7 @@ private:
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel, true));
|
||||
display_ = new St7789Display(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);
|
||||
}
|
||||
|
||||
@@ -110,13 +111,11 @@ public:
|
||||
InitializeButtons();
|
||||
InitializeLedPower();
|
||||
InitializeSpi();
|
||||
InitializeSt7789Display();
|
||||
InitializeNv3023Display();
|
||||
}
|
||||
|
||||
virtual Led* GetBuiltinLed() override {
|
||||
// static Led led(BUILTIN_LED_GPIO,BUILTIN_LED_NUM);
|
||||
static Led led(BUILTIN_LED_GPIO);
|
||||
|
||||
virtual Led* GetLed() override {
|
||||
static SingleLed led(BUILTIN_LED_GPIO);
|
||||
return &led;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user