Compare commits

...

4 Commits
xx ... main

Author SHA1 Message Date
小林同志
6be351b5a0 Adjust jiuchuan-s3 UI (#1747)
* 修复SetupUI接口引入导致的屏幕适配失败问题

* 修正board中屏幕高度错误,调整偏移量

---------

Co-authored-by: smalllin0 <aslinqf@163.com>
Co-authored-by: Xiaoxia <terrence@tenclass.com>
2026-02-09 19:16:49 +08:00
Xiaoxia
d9447ad060 fix: Enhance UI setup across multiple boards (#1753)
* chore: Update component versions and enhance UI setup across multiple boards

- Bumped uart-eth-modem version from ~0.3.2 to ~0.3.3 in idf_component.yml.
- Added SetupUI method to various display classes to ensure proper UI initialization before usage.
- Improved error handling in display classes to prevent issues when UI is not set up.
- Ensured UI customization is performed in SetupUI rather than constructors for better reliability.

* remove pm config code
2026-02-09 19:13:14 +08:00
Xiaoxia
9215a04a7e Delay init success sound playback and remove gif playback delay (#1748)
* refactor: Remove hardcoded loop delay for GIF playback in LcdDisplay class

* chore: Update esp-ml307 and uart-eth-modem component versions in idf_component.yml

- Bump esp-ml307 version from ~3.6.3 to ~3.6.4
- Update uart-eth-modem version from ~0.3.1 to ~0.3.2

* feat: Add PrintPmLocks method to SystemInfo class

- Introduced PrintPmLocks method to display power management locks using esp_pm_dump_locks.
- Updated system_info.h to declare the new method.

* refactor: Streamline audio codec initialization and enablement

- Removed redundant channel enable checks from AudioCodec::Start.
- Added channel enablement in CreateDuplexChannels for various audio codecs.
- Implemented EnableInput and EnableOutput methods in NoAudioCodec for better control over input/output states.

* refactor: Delay audio success sound playback until after activation completion

- Moved the success sound playback to a scheduled task to ensure it occurs after the activation process is complete.
- This change improves the responsiveness of the application during activation events.

* refactor: Update camera integration from EspVideo to Esp32Camera

- Replaced EspVideo with Esp32Camera for improved camera configuration and initialization.
- Streamlined camera setup by utilizing a new configuration structure for better clarity and maintainability.
- Updated README.md to remove outdated camera sensor configuration instructions.

* refactor: Update audio demuxing process in AudioService

- Replaced the existing demuxer instance with a local unique pointer in the PlaySound method for better memory management.
- Moved the OnDemuxerFinished callback setup into the PlaySound method to ensure it is correctly associated with the new demuxer instance.
- Removed the member variable demuxer_ from AudioService to streamline the class structure.
2026-02-08 22:09:45 +08:00
Wang is proud
7b7d22c495 feat: modify CircularStrip constructor parameter types and add SetMultiColors method (#1750) 2026-02-08 11:17:12 +08:00
56 changed files with 353 additions and 122 deletions

View File

@@ -309,13 +309,15 @@ void Application::HandleActivationDoneEvent() {
display->ShowNotification(message.c_str());
display->SetChatMessage("system", "");
// Play the success sound to indicate the device is ready
audio_service_.PlaySound(Lang::Sounds::OGG_SUCCESS);
// Release OTA object after activation is complete
ota_.reset();
auto& board = Board::GetInstance();
board.SetPowerSaveLevel(PowerSaveLevel::LOW_POWER);
Schedule([this]() {
// Play the success sound to indicate the device is ready
audio_service_.PlaySound(Lang::Sounds::OGG_SUCCESS);
});
}
void Application::ActivationTask() {

View File

@@ -34,16 +34,6 @@ void AudioCodec::Start() {
output_volume_ = 10;
}
if (tx_handle_ != nullptr) {
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
}
if (rx_handle_ != nullptr) {
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
}
EnableInput(true);
EnableOutput(true);
ESP_LOGI(TAG, "Audio codec started");
}

View File

@@ -39,15 +39,6 @@
AudioService::AudioService() {
event_group_ = xEventGroupCreate();
demuxer_.OnDemuxerFinished([this](const uint8_t* data, int sample_rate, size_t size){
auto packet = std::make_unique<AudioStreamPacket>();
packet->sample_rate = sample_rate;
packet->frame_duration = 60;
packet->payload.resize(size);
std::memcpy(packet->payload.data(), data, size);
PushPacketToDecodeQueue(std::move(packet), true);
});
}
AudioService::~AudioService() {
@@ -314,6 +305,7 @@ void AudioService::AudioOutputTask() {
esp_timer_start_periodic(audio_power_timer_, AUDIO_POWER_CHECK_INTERVAL_MS * 1000);
codec_->EnableOutput(true);
}
codec_->OutputData(task->pcm);
/* Update the last output time */
@@ -647,8 +639,18 @@ void AudioService::PlaySound(const std::string_view& ogg) {
const auto* buf = reinterpret_cast<const uint8_t*>(ogg.data());
size_t size = ogg.size();
demuxer_.Reset();
demuxer_.Process(buf, size);
auto demuxer = std::make_unique<OggDemuxer>();
demuxer->OnDemuxerFinished([this](const uint8_t* data, int sample_rate, size_t size){
auto packet = std::make_unique<AudioStreamPacket>();
packet->sample_rate = sample_rate;
packet->frame_duration = 60;
packet->payload.resize(size);
std::memcpy(packet->payload.data(), data, size);
PushPacketToDecodeQueue(std::move(packet), true);
});
demuxer->Reset();
demuxer->Process(buf, size);
}
bool AudioService::IsIdle() {

View File

@@ -146,8 +146,6 @@ private:
std::mutex input_resampler_mutex_;
esp_ae_rate_cvt_handle_t input_resampler_ = nullptr;
esp_ae_rate_cvt_handle_t output_resampler_ = nullptr;
OggDemuxer demuxer_;
// Encoder/Decoder state
int encoder_sample_rate_ = 16000;

View File

@@ -176,6 +176,8 @@ void BoxAudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_tdm_mode(rx_handle_, &tdm_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -150,6 +150,8 @@ void Es8311AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -126,6 +126,8 @@ void Es8374AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -131,6 +131,8 @@ void Es8388AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -132,6 +132,8 @@ void Es8389AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -254,6 +254,32 @@ int NoAudioCodec::Read(int16_t* dest, int samples) {
return samples;
}
void NoAudioCodec::EnableInput(bool enable) {
std::lock_guard<std::mutex> lock(data_if_mutex_);
if (enable == input_enabled_) {
return;
}
if (enable) {
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
} else {
ESP_ERROR_CHECK(i2s_channel_disable(rx_handle_));
}
AudioCodec::EnableInput(enable);
}
void NoAudioCodec::EnableOutput(bool enable) {
std::lock_guard<std::mutex> lock(data_if_mutex_);
if (enable == output_enabled_) {
return;
}
if (enable) {
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
} else {
ESP_ERROR_CHECK(i2s_channel_disable(tx_handle_));
}
AudioCodec::EnableOutput(enable);
}
// Delegating constructor: calls the main constructor with default slot mask
NoAudioCodecSimplexPdm::NoAudioCodecSimplexPdm(int input_sample_rate, int output_sample_rate, gpio_num_t spk_bclk, gpio_num_t spk_ws, gpio_num_t spk_dout, gpio_num_t mic_sck, gpio_num_t mic_din)
: NoAudioCodecSimplexPdm(input_sample_rate, output_sample_rate, spk_bclk, spk_ws, spk_dout, I2S_STD_SLOT_LEFT, mic_sck, mic_din) {

View File

@@ -13,6 +13,8 @@ protected:
virtual int Write(const int16_t* data, int samples) override;
virtual int Read(int16_t* dest, int samples) override;
virtual void EnableInput(bool enable) override;
virtual void EnableOutput(bool enable) override;
public:
virtual ~NoAudioCodec();

View File

@@ -106,6 +106,10 @@ private:
InitializeGc9107Display();
InitializeButtons();
GetBacklight()->SetBrightness(100);
// Ensure UI is set up before displaying error
display_->SetupUI();
display_->SetStatus(Lang::Strings::ERROR);
display_->SetEmotion("triangle_exclamation");
display_->SetChatMessage("system", "Echo Base\nnot connected");

View File

@@ -173,6 +173,10 @@ private:
InitializeGc9107Display();
InitializeButtons();
GetBacklight()->SetBrightness(100);
// Ensure UI is set up before displaying error
display_->SetupUI();
display_->SetStatus(Lang::Strings::ERROR);
display_->SetEmotion("triangle_exclamation");
display_->SetChatMessage("system", "Echo Base\nnot connected");

View File

@@ -24,26 +24,6 @@ idf.py menuconfig
Xiaozhi Assistant -> Board Type ->面包板新版接线WiFi+ LCD + Camera
```
**配置摄像头传感器:**
> **注意:** 确认摄像头传感器型号,确定型号在 esp_cam_sensor 支持的范围内。当前板子用的是 OV2640是符合支持范围。
在 menuconfig 中按以下步骤启用对应型号的支持:
1. **导航到传感器配置:**
```
(Top) → Component config → Espressif Camera Sensors Configurations → Camera Sensor Configuration → Select and Set Camera Sensor
```
2. **选择传感器型号:**
- 选中所需的传感器型号OV2640
3. **配置传感器参数:**
- 按 → 进入传感器详细设置
- 启用 **Auto detect**
- 推荐将 **default output format** 调整为 **YUV422** 及合适的分辨率大小
- (目前支持 YUV422、RGB565YUV422 更节省内存空间)
**编译烧入:**
```bash

View File

@@ -8,7 +8,7 @@
#include "mcp_server.h"
#include "lamp_controller.h"
#include "led/single_led.h"
#include "esp_video.h"
#include "esp32_camera.h"
#include <esp_log.h>
#include <driver/i2c_master.h>
@@ -65,7 +65,7 @@ private:
Button boot_button_;
LcdDisplay* display_;
EspVideo* camera_;
Esp32Camera* camera_;
void InitializeSpi() {
spi_bus_config_t buscfg = {};
@@ -125,47 +125,32 @@ private:
}
void InitializeCamera() {
static esp_cam_ctlr_dvp_pin_config_t dvp_pin_config = {
.data_width = CAM_CTLR_DATA_WIDTH_8,
.data_io = {
[0] = CAMERA_PIN_D0,
[1] = CAMERA_PIN_D1,
[2] = CAMERA_PIN_D2,
[3] = CAMERA_PIN_D3,
[4] = CAMERA_PIN_D4,
[5] = CAMERA_PIN_D5,
[6] = CAMERA_PIN_D6,
[7] = CAMERA_PIN_D7,
},
.vsync_io = CAMERA_PIN_VSYNC,
.de_io = CAMERA_PIN_HREF,
.pclk_io = CAMERA_PIN_PCLK,
.xclk_io = CAMERA_PIN_XCLK,
};
esp_video_init_sccb_config_t sccb_config = {
.init_sccb = true,
.i2c_config = {
.port = 0,
.scl_pin = CAMERA_PIN_SIOC,
.sda_pin = CAMERA_PIN_SIOD,
},
.freq = 100000,
};
esp_video_init_dvp_config_t dvp_config = {
.sccb_config = sccb_config,
.reset_pin = CAMERA_PIN_RESET,
.pwdn_pin = CAMERA_PIN_PWDN,
.dvp_pin = dvp_pin_config,
.xclk_freq = XCLK_FREQ_HZ,
};
esp_video_init_config_t video_config = {
.dvp = &dvp_config,
};
camera_ = new EspVideo(video_config);
camera_config_t config = {};
config.pin_d0 = CAMERA_PIN_D0;
config.pin_d1 = CAMERA_PIN_D1;
config.pin_d2 = CAMERA_PIN_D2;
config.pin_d3 = CAMERA_PIN_D3;
config.pin_d4 = CAMERA_PIN_D4;
config.pin_d5 = CAMERA_PIN_D5;
config.pin_d6 = CAMERA_PIN_D6;
config.pin_d7 = CAMERA_PIN_D7;
config.pin_xclk = CAMERA_PIN_XCLK;
config.pin_pclk = CAMERA_PIN_PCLK;
config.pin_vsync = CAMERA_PIN_VSYNC;
config.pin_href = CAMERA_PIN_HREF;
config.pin_sccb_sda = CAMERA_PIN_SIOD;
config.pin_sccb_scl = CAMERA_PIN_SIOC;
config.sccb_i2c_port = 0;
config.pin_pwdn = CAMERA_PIN_PWDN;
config.pin_reset = CAMERA_PIN_RESET;
config.xclk_freq_hz = XCLK_FREQ_HZ;
config.pixel_format = PIXFORMAT_RGB565;
config.frame_size = FRAMESIZE_VGA;
config.jpeg_quality = 12;
config.fb_count = 1;
config.fb_location = CAMERA_FB_IN_PSRAM;
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
camera_ = new Esp32Camera(config);
camera_->SetHMirror(false);
}

View File

@@ -152,6 +152,8 @@ void K10AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_tdm_mode(rx_handle_, &tdm_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -15,17 +15,28 @@
ElectronEmojiDisplay::ElectronEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y,
bool swap_xy)
: SpiLcdDisplay(panel_io, panel, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
InitializeElectronEmojis();
SetupChatLabel();
}
void ElectronEmojiDisplay::SetupUI() {
// Prevent duplicate calls - parent SetupUI() will also check, but check here for early return
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
return;
}
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
// Set default emotion after UI is initialized
SetEmotion("staticstate");
}
void ElectronEmojiDisplay::InitializeElectronEmojis() {
ESP_LOGI(TAG, "Electron表情初始化将由Assets系统处理");
// 表情初始化已移至assets系统,通过DEFAULT_EMOJI_COLLECTION=otto-gif配置
// assets.cc会从assets分区加载GIF表情并设置到theme
// 设置默认表情为staticstate
SetEmotion("staticstate");
// Note: Default emotion is now set in SetupUI() after LVGL objects are created
}
void ElectronEmojiDisplay::SetupChatLabel() {

View File

@@ -15,6 +15,7 @@ class ElectronEmojiDisplay : public SpiLcdDisplay {
virtual ~ElectronEmojiDisplay() = default;
virtual void SetStatus(const char* status) override;
virtual void SetupUI() override;
private:
void InitializeElectronEmojis();

View File

@@ -165,6 +165,8 @@ void BoxAudioCodecLite::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, g
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_tdm_mode(rx_handle_, &tdm_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -81,6 +81,7 @@ AdcPdmAudioCodec::AdcPdmAudioCodec(int input_sample_rate, int output_sample_rate
const i2s_pdm_tx_config_t *p_i2s_cfg = &pdm_cfg_default;
ESP_ERROR_CHECK(i2s_channel_init_pdm_tx_mode(tx_handle_, p_i2s_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
audio_codec_i2s_cfg_t i2s_cfg = {
.port = I2S_NUM_0,

View File

@@ -81,6 +81,7 @@ AdcPdmAudioCodec::AdcPdmAudioCodec(int input_sample_rate, int output_sample_rate
const i2s_pdm_tx_config_t *p_i2s_cfg = &pdm_cfg_default;
ESP_ERROR_CHECK(i2s_channel_init_pdm_tx_mode(tx_handle_, p_i2s_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
audio_codec_i2s_cfg_t i2s_cfg = {
.port = I2S_NUM_0,

View File

@@ -37,7 +37,7 @@
#define DISPLAY_SPI_CS_PIN GPIO_NUM_9
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 320
#define DISPLAY_HEIGHT 296
#define DISPLAY_MIRROR_X true
#define DISPLAY_MIRROR_Y false
#define DISPLAY_SWAP_XY false

View File

@@ -39,6 +39,13 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy)
{
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
@@ -46,10 +53,9 @@ public:
lv_obj_set_style_pad_left(top_bar_, LV_HOR_RES * 0.12, 0); // 左侧填充12%
lv_obj_set_style_pad_right(top_bar_, LV_HOR_RES * 0.12, 0); // 右侧填充12%
// 表情容器上移适配
lv_obj_align(emoji_box_, LV_ALIGN_CENTER, 0, -50); // 向上偏移50
lv_obj_align(emoji_box_, LV_ALIGN_CENTER, 0, -30); // 向上偏移30
// 消息栏适配
lv_obj_align(bottom_bar_, LV_ALIGN_BOTTOM_MID, 0, -40); // 向上偏移40
lv_obj_align(bottom_bar_, LV_ALIGN_BOTTOM_MID, 0, -20); // 向上偏移20
}
};

View File

@@ -230,7 +230,7 @@ private:
config.pin_reset = CAMERA_PIN_RESET;
config.xclk_freq_hz = XCLK_FREQ_HZ;
config.pixel_format = PIXFORMAT_RGB565;
config.frame_size = FRAMESIZE_VGA;
config.frame_size = FRAMESIZE_QVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
config.fb_location = CAMERA_FB_IN_PSRAM;

View File

@@ -177,6 +177,8 @@ void CoreS3AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_tdm_mode(rx_handle_, &tdm_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -176,6 +176,8 @@ void Tab5AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_tdm_mode(rx_handle_, &tdm_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -31,6 +31,13 @@ public:
bool mirror_y,
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
// 由于屏幕是圆的,所以状态栏需要增加左右内边距

View File

@@ -14,13 +14,33 @@
#define TAG "OttoEmojiDisplay"
OttoEmojiDisplay::OttoEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy)
: SpiLcdDisplay(panel_io, panel, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
InitializeOttoEmojis();
SetupPreviewImage();
SetTheme(LvglThemeManager::GetInstance().GetTheme("dark"));
}
void OttoEmojiDisplay::SetupUI() {
// Prevent duplicate calls - parent SetupUI() will also check, but check here for early return
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
return;
}
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
// Setup preview image after UI is initialized
DisplayLockGuard lock(this);
lv_obj_set_size(preview_image_, width_ , height_ );
// Set default emotion after UI is initialized
SetEmotion("staticstate");
}
void OttoEmojiDisplay::SetupPreviewImage() {
DisplayLockGuard lock(this);
if (preview_image_ == nullptr) {
ESP_LOGW(TAG, "SetupPreviewImage called but preview_image_ is nullptr (UI not initialized yet)");
return;
}
lv_obj_set_size(preview_image_, width_ , height_ );
}
@@ -28,9 +48,7 @@ void OttoEmojiDisplay::InitializeOttoEmojis() {
ESP_LOGI(TAG, "Otto表情初始化将由Assets系统处理");
// 表情初始化已移至assets系统,通过DEFAULT_EMOJI_COLLECTION=otto-gif配置
// assets.cc会从assets分区加载GIF表情并设置到theme
// 设置默认表情为staticstate
SetEmotion("staticstate");
// Note: Default emotion is now set in SetupUI() after LVGL objects are created
}
LV_FONT_DECLARE(OTTO_ICON_FONT);

View File

@@ -16,6 +16,7 @@ class OttoEmojiDisplay : public SpiLcdDisplay {
virtual ~OttoEmojiDisplay() = default;
virtual void SetStatus(const char* status) override;
virtual void SetPreviewImage(std::unique_ptr<LvglImage> image) override;
virtual void SetupUI() override;
private:
void InitializeOttoEmojis();

View File

@@ -143,6 +143,8 @@ void SensecapAudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk,
std_cfg.slot_cfg.slot_mask = I2S_STD_SLOT_RIGHT;
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
ESP_LOGI(TAG, "Duplex channels created");
}

View File

@@ -45,7 +45,14 @@ class CustomLcdDisplay : public SpiLcdDisplay {
bool mirror_y,
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
auto lvgl_theme = static_cast<LvglTheme*>(current_theme_);
auto text_font = lvgl_theme->text_font()->font();

View File

@@ -115,6 +115,13 @@ public:
bool mirror_y,
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
// 由于屏幕是圆的,所以状态栏需要增加左右内边距

View File

@@ -32,6 +32,14 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
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);

View File

@@ -61,9 +61,17 @@ class CustomLcdDisplay : public SpiLcdDisplay {
CustomLcdDisplay(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_handle_t panel_handle, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy) :
SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy),
io_handle_(io_handle) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
SetMIRROR_XY(0xC0); // Rotate 180 degrees - this is safe as it only operates on hardware
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
lv_display_add_event_cb(display_, my_draw_event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
SetMIRROR_XY(0xC0); // Rotate 180 degrees
lv_obj_invalidate(lv_screen_active());
}
};

View File

@@ -54,6 +54,14 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
lv_display_add_event_cb(display_, MyDrawEventCb, LV_EVENT_INVALIDATE_AREA, NULL);
}

View File

@@ -83,6 +83,14 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
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);

View File

@@ -102,6 +102,14 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
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);

View File

@@ -120,9 +120,8 @@ CustomLcdDisplay::CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_p
return;
}
ESP_LOGI(TAG, "ui start");
SetupUI();
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
// to ensure lvgl objects are created after the display is fully initialized.
}
CustomLcdDisplay::~CustomLcdDisplay() {

View File

@@ -117,9 +117,8 @@ height_(height)
return;
}
ESP_LOGI(TAG, "ui start");
SetupUI();
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
// to ensure lvgl objects are created after the display is fully initialized.
}
CustomLcdDisplay::~CustomLcdDisplay() {

View File

@@ -61,9 +61,17 @@ class CustomLcdDisplay : public SpiLcdDisplay {
CustomLcdDisplay(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_handle_t panel_handle, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy) :
SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy),
io_handle_(io_handle) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
SetMIRROR_XY(0xC0); // Rotate 180 degrees - this is safe as it only operates on hardware
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
lv_display_add_event_cb(display_, my_draw_event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
SetMIRROR_XY(0xC0); // Rotate 180 degrees
lv_obj_invalidate(lv_screen_active());
}
};

View File

@@ -107,6 +107,14 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
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);

View File

@@ -83,6 +83,14 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
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);

View File

@@ -103,6 +103,14 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
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);

View File

@@ -43,6 +43,14 @@ public:
bool swap_xy)
: SpiLcdDisplay(io_handle, panel_handle,
width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
// Note: UI customization should be done in SetupUI(), not in constructor
// to ensure lvgl objects are created before accessing them
}
virtual void SetupUI() override {
// Call parent SetupUI() first to create all lvgl objects
SpiLcdDisplay::SetupUI();
DisplayLockGuard lock(this);
lv_display_add_event_cb(display_, rounder_event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
}

View File

@@ -141,5 +141,7 @@ CustomLcdDisplay::CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_p
if (offset_x != 0 || offset_y != 0) {
lv_display_set_offset(display_, offset_x, offset_y);
}
SetupUI();
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
// to ensure lvgl objects are created after the display is fully initialized.
}

View File

@@ -281,6 +281,6 @@ CustomLcdDisplay::CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_p
lv_display_set_offset(display_, offset_x, offset_y);
}
SetupUI();
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
// to ensure lvgl objects are created after the display is fully initialized.
}

View File

@@ -40,14 +40,18 @@ public:
virtual Theme* GetTheme() { return current_theme_; }
virtual void UpdateStatusBar(bool update_all = false);
virtual void SetPowerSaveMode(bool on);
virtual void SetupUI() { }
virtual void SetupUI() {
setup_ui_called_ = true;
}
inline int width() const { return width_; }
inline int height() const { return height_; }
inline bool IsSetupUICalled() const { return setup_ui_called_; }
protected:
int width_ = 0;
int height_ = 0;
bool setup_ui_called_ = false; // Track if SetupUI() has been called
Theme* current_theme_ = nullptr;

View File

@@ -352,6 +352,13 @@ void LcdDisplay::Unlock() {
#if CONFIG_USE_WECHAT_MESSAGE_STYLE
void LcdDisplay::SetupUI() {
// Prevent duplicate calls - if already called, return early
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
return;
}
Display::SetupUI(); // Mark SetupUI as called
DisplayLockGuard lock(this);
auto lvgl_theme = static_cast<LvglTheme*>(current_theme_);
@@ -495,8 +502,14 @@ void LcdDisplay::SetupUI() {
#define MAX_MESSAGES 20
#endif
void LcdDisplay::SetChatMessage(const char* role, const char* content) {
if (!setup_ui_called_) {
ESP_LOGW(TAG, "SetChatMessage('%s', '%s') called before SetupUI() - message will be lost!", role, content);
}
DisplayLockGuard lock(this);
if (content_ == nullptr) {
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetChatMessage('%s', '%s') failed: content_ is nullptr (SetupUI() was called but container not created)", role, content);
}
return;
}
@@ -789,6 +802,13 @@ void LcdDisplay::ClearChatMessages() {
}
#else
void LcdDisplay::SetupUI() {
// Prevent duplicate calls - if already called, return early
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
return;
}
Display::SetupUI(); // Mark SetupUI as called
DisplayLockGuard lock(this);
LvglTheme* lvgl_theme = static_cast<LvglTheme*>(current_theme_);
auto text_font = lvgl_theme->text_font()->font();
@@ -985,8 +1005,14 @@ void LcdDisplay::SetPreviewImage(std::unique_ptr<LvglImage> image) {
}
void LcdDisplay::SetChatMessage(const char* role, const char* content) {
if (!setup_ui_called_) {
ESP_LOGW(TAG, "SetChatMessage('%s', '%s') called before SetupUI() - message will be lost!", role, content);
}
DisplayLockGuard lock(this);
if (chat_message_label_ == nullptr) {
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetChatMessage('%s', '%s') failed: chat_message_label_ is nullptr (SetupUI() was called but label not created)", role, content);
}
return;
}
lv_label_set_text(chat_message_label_, content);
@@ -1002,6 +1028,9 @@ void LcdDisplay::ClearChatMessages() {
#endif
void LcdDisplay::SetEmotion(const char* emotion) {
if (!setup_ui_called_) {
ESP_LOGW(TAG, "SetEmotion('%s') called before SetupUI() - emotion will not be displayed!", emotion);
}
// Stop any running GIF animation
if (gif_controller_) {
DisplayLockGuard lock(this);
@@ -1010,6 +1039,9 @@ void LcdDisplay::SetEmotion(const char* emotion) {
}
if (emoji_image_ == nullptr) {
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetEmotion('%s') failed: emoji_image_ is nullptr (SetupUI() was called but emoji image not created)", emotion);
}
return;
}
@@ -1032,8 +1064,6 @@ void LcdDisplay::SetEmotion(const char* emotion) {
gif_controller_ = std::make_unique<LvglGif>(image->image_dsc());
if (gif_controller_->IsLoaded()) {
// Set loop delay to 1000ms
gif_controller_->SetLoopDelay(3000);
// Set up frame update callback
gif_controller_->SetFrameCallback([this]() {
lv_image_set_src(emoji_image_, gif_controller_->image_dsc());

View File

@@ -70,8 +70,14 @@ LvglDisplay::~LvglDisplay() {
}
void LvglDisplay::SetStatus(const char* status) {
if (!setup_ui_called_) {
ESP_LOGW(TAG, "SetStatus('%s') called before SetupUI() - message will be lost!", status);
}
DisplayLockGuard lock(this);
if (status_label_ == nullptr) {
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetStatus('%s') failed: status_label_ is nullptr (SetupUI() was called but label not created)", status);
}
return;
}
lv_label_set_text(status_label_, status);
@@ -86,8 +92,14 @@ void LvglDisplay::ShowNotification(const std::string &notification, int duration
}
void LvglDisplay::ShowNotification(const char* notification, int duration_ms) {
if (!setup_ui_called_) {
ESP_LOGW(TAG, "ShowNotification('%s') called before SetupUI() - message will be lost!", notification);
}
DisplayLockGuard lock(this);
if (notification_label_ == nullptr) {
if (setup_ui_called_) {
ESP_LOGW(TAG, "ShowNotification('%s') failed: notification_label_ is nullptr (SetupUI() was called but label not created)", notification);
}
return;
}
lv_label_set_text(notification_label_, notification);

View File

@@ -76,6 +76,18 @@ OledDisplay::OledDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handl
return;
}
// Note: SetupUI() should be called by Application::Initialize(), not in constructor
// to ensure lvgl objects are created after the display is fully initialized.
}
void OledDisplay::SetupUI() {
// Prevent duplicate calls - if already called, return early
if (setup_ui_called_) {
ESP_LOGW(TAG, "SetupUI() called multiple times, skipping duplicate call");
return;
}
Display::SetupUI(); // Mark SetupUI as called
if (height_ == 64) {
SetupUI_128x64();
} else {

View File

@@ -32,6 +32,7 @@ public:
OledDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, bool mirror_x, bool mirror_y);
~OledDisplay();
virtual void SetupUI() override;
virtual void SetChatMessage(const char* role, const char* content) override;
virtual void SetEmotion(const char* emotion) override;
virtual void SetTheme(Theme* theme) override;

View File

@@ -22,9 +22,9 @@ dependencies:
78/esp-wifi-connect: ~3.0.2
espressif/esp_audio_effects: ~1.2.1
espressif/esp_audio_codec: ~2.4.1
78/esp-ml307: ~3.6.3
78/esp-ml307: ~3.6.4
78/uart-eth-modem:
version: ~0.3.1
version: ~0.3.3
rules:
- if: target not in [esp32]
78/xiaozhi-fonts: ~1.6.0

View File

@@ -1,12 +1,13 @@
#include "circular_strip.h"
#include "application.h"
#include <esp_log.h>
#include <algorithm>
#define TAG "CircularStrip"
#define BLINK_INFINITE -1
CircularStrip::CircularStrip(gpio_num_t gpio, uint8_t max_leds) : max_leds_(max_leds) {
CircularStrip::CircularStrip(gpio_num_t gpio, uint16_t max_leds) : max_leds_(max_leds) {
// If the gpio is not connected, you should use NoLed class
assert(gpio != GPIO_NUM_NC);
@@ -66,6 +67,17 @@ void CircularStrip::SetSingleColor(uint8_t index, StripColor color) {
led_strip_refresh(led_strip_);
}
void CircularStrip::SetMultiColors(const std::vector<StripColor>& colors) {
std::lock_guard<std::mutex> lock(mutex_);
esp_timer_stop(strip_timer_);
int count = std::min(max_leds_, static_cast<int>(colors.size()));
for (int i = 0; i < count; i++) {
colors_[i] = colors[i];
led_strip_set_pixel(led_strip_, i, colors[i].red, colors[i].green, colors[i].blue);
}
led_strip_refresh(led_strip_);
}
void CircularStrip::Blink(StripColor color, int interval_ms) {
for (int i = 0; i < max_leds_; i++) {
colors_[i] = color;

View File

@@ -18,13 +18,14 @@ struct StripColor {
class CircularStrip : public Led {
public:
CircularStrip(gpio_num_t gpio, uint8_t max_leds);
CircularStrip(gpio_num_t gpio, uint16_t max_leds);
virtual ~CircularStrip();
void OnStateChanged() override;
void SetBrightness(uint8_t default_brightness, uint8_t low_brightness);
void SetAllColor(StripColor color);
void SetSingleColor(uint8_t index, StripColor color);
void SetMultiColors(const std::vector<StripColor>& colors);
void Blink(StripColor color, int interval_ms);
void Breathe(StripColor low, StripColor high, int interval_ms);
void Scroll(StripColor low, StripColor high, int length, int interval_ms);

View File

@@ -8,6 +8,7 @@
#include <esp_partition.h>
#include <esp_app_desc.h>
#include <esp_ota_ops.h>
#include <esp_pm.h>
#if CONFIG_IDF_TARGET_ESP32P4
#include "esp_wifi_remote.h"
#endif
@@ -149,3 +150,7 @@ void SystemInfo::PrintHeapStats() {
int min_free_sram = heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL);
ESP_LOGI(TAG, "free sram: %u minimal sram: %u", free_sram, min_free_sram);
}
void SystemInfo::PrintPmLocks() {
esp_pm_dump_locks(stdout);
}

View File

@@ -17,6 +17,7 @@ public:
static esp_err_t PrintTaskCpuUsage(TickType_t xTicksToWait);
static void PrintTaskList();
static void PrintHeapStats();
static void PrintPmLocks();
};
#endif // _SYSTEM_INFO_H_