forked from xiaozhi/xiaozhi-esp32
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c17bd15baa | ||
|
|
b3ab3d0920 | ||
|
|
2b0362a812 | ||
|
|
d3367d6b92 | ||
|
|
116234a147 | ||
|
|
f29c1a11d9 | ||
|
|
f98ffdbb5c | ||
|
|
89f10365b1 | ||
|
|
e9f23ea231 | ||
|
|
7435c98609 | ||
|
|
bf125446b3 | ||
|
|
dfad6a5b2c | ||
|
|
d460af8426 | ||
|
|
7bb17f7539 | ||
|
|
f8c9126442 | ||
|
|
a118e8f786 | ||
|
|
85f3f1ba9f | ||
|
|
e2777cc16b | ||
|
|
5bb7c6deb8 | ||
|
|
895a3cfa72 | ||
|
|
c9dec29d73 | ||
|
|
968ed1fae3 | ||
|
|
f8cd0d30cd | ||
|
|
01215d77ed | ||
|
|
3df2f3970a |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -13,4 +13,6 @@ main/assets/lang_config.h
|
||||
main/mmap_generate_emoji.h
|
||||
.DS_Store
|
||||
.cache
|
||||
main/mmap_generate_emoji.h
|
||||
main/mmap_generate_emoji.h
|
||||
*.pyc
|
||||
*.bin
|
||||
@@ -4,7 +4,7 @@
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(PROJECT_VER "1.7.2")
|
||||
set(PROJECT_VER "1.7.6")
|
||||
|
||||
# Add this line to disable the specific warning
|
||||
add_compile_options(-Wno-missing-field-initializers)
|
||||
|
||||
@@ -113,6 +113,8 @@ elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_1_46)
|
||||
set(BOARD_TYPE "esp32-s3-touch-lcd-1.46")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_3_5)
|
||||
set(BOARD_TYPE "esp32-s3-touch-lcd-3.5")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32C6_LCD_1_69)
|
||||
set(BOARD_TYPE "waveshare-c6-lcd-1.69")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32P4_NANO)
|
||||
set(BOARD_TYPE "waveshare-p4-nano")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_4B)
|
||||
@@ -191,6 +193,8 @@ elseif(CONFIG_BOARD_TYPE_OTTO_ROBOT)
|
||||
set(BOARD_TYPE "otto-robot")
|
||||
elseif(CONFIG_BOARD_TYPE_ELECTRON_BOT)
|
||||
set(BOARD_TYPE "electron-bot")
|
||||
elseif(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI_CAM)
|
||||
set(BOARD_TYPE "bread-compact-wifi-s3cam")
|
||||
endif()
|
||||
file(GLOB BOARD_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc
|
||||
|
||||
@@ -34,6 +34,9 @@ choice BOARD_TYPE
|
||||
config BOARD_TYPE_BREAD_COMPACT_WIFI_LCD
|
||||
bool "面包板新版接线(WiFi)+ LCD"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
config BOARD_TYPE_BREAD_COMPACT_WIFI_CAM
|
||||
bool "面包板新版接线(WiFi)+ LCD + Camera"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
config BOARD_TYPE_BREAD_COMPACT_ML307
|
||||
bool "面包板新版接线(ML307 AT)"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
@@ -132,7 +135,7 @@ choice BOARD_TYPE
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
config BOARD_TYPE_ATOMMATRIX_ECHO_BASE
|
||||
bool "AtomMatrix + Echo Base"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
depends on IDF_TARGET_ESP32
|
||||
config BOARD_TYPE_ESP32S3_Touch_AMOLED_1_8
|
||||
bool "Waveshare ESP32-S3-Touch-AMOLED-1.8"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
@@ -148,6 +151,9 @@ choice BOARD_TYPE
|
||||
config BOARD_TYPE_ESP32S3_Touch_LCD_1_46
|
||||
bool "Waveshare ESP32-S3-Touch-LCD-1.46"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
config BOARD_TYPE_ESP32C6_LCD_1_69
|
||||
bool "Waveshare ESP32-C6-LCD-1.69"
|
||||
depends on IDF_TARGET_ESP32C6
|
||||
config BOARD_TYPE_ESP32S3_Touch_LCD_3_5
|
||||
bool "Waveshare ESP32-S3-Touch-LCD-3.5"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
@@ -292,7 +298,7 @@ choice DISPLAY_OLED_TYPE
|
||||
endchoice
|
||||
|
||||
choice DISPLAY_LCD_TYPE
|
||||
depends on BOARD_TYPE_BREAD_COMPACT_WIFI_LCD || BOARD_TYPE_BREAD_COMPACT_ESP32_LCD || BOARD_TYPE_ESP32_CGC || BOARD_TYPE_ESP32P4_NANO || BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_XC
|
||||
depends on BOARD_TYPE_BREAD_COMPACT_WIFI_LCD || BOARD_TYPE_BREAD_COMPACT_ESP32_LCD || BOARD_TYPE_ESP32_CGC || BOARD_TYPE_ESP32P4_NANO || BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_XC || BOARD_TYPE_BREAD_COMPACT_WIFI_CAM
|
||||
prompt "LCD Type"
|
||||
default LCD_ST7789_240X320
|
||||
help
|
||||
@@ -360,9 +366,9 @@ config USE_WECHAT_MESSAGE_STYLE
|
||||
config USE_ESP_WAKE_WORD
|
||||
bool "Enable Wake Word Detection (without AFE)"
|
||||
default n
|
||||
depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C5
|
||||
depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C5 || IDF_TARGET_ESP32C6 || (IDF_TARGET_ESP32 && SPIRAM)
|
||||
help
|
||||
支持 ESP32 C3 与 ESP32 C5
|
||||
支持 ESP32 C3、ESP32 C5 与 ESP32 C6,增加ESP32支持(需要开启PSRAM)
|
||||
|
||||
config USE_AFE_WAKE_WORD
|
||||
bool "Enable Wake Word Detection (AFE)"
|
||||
|
||||
@@ -45,6 +45,7 @@ static const char* const STATE_STRINGS[] = {
|
||||
"speaking",
|
||||
"upgrading",
|
||||
"activating",
|
||||
"audio_testing",
|
||||
"fatal_error",
|
||||
"invalid_state"
|
||||
};
|
||||
@@ -99,7 +100,7 @@ Application::~Application() {
|
||||
vEventGroupDelete(event_group_);
|
||||
}
|
||||
|
||||
void Application::CheckNewVersion() {
|
||||
void Application::CheckNewVersion(Ota& ota) {
|
||||
const int MAX_RETRY = 10;
|
||||
int retry_count = 0;
|
||||
int retry_delay = 10; // 初始重试延迟为10秒
|
||||
@@ -109,7 +110,7 @@ void Application::CheckNewVersion() {
|
||||
auto display = Board::GetInstance().GetDisplay();
|
||||
display->SetStatus(Lang::Strings::CHECKING_NEW_VERSION);
|
||||
|
||||
if (!ota_.CheckVersion()) {
|
||||
if (!ota.CheckVersion()) {
|
||||
retry_count++;
|
||||
if (retry_count >= MAX_RETRY) {
|
||||
ESP_LOGE(TAG, "Too many retries, exit version check");
|
||||
@@ -117,7 +118,7 @@ void Application::CheckNewVersion() {
|
||||
}
|
||||
|
||||
char buffer[128];
|
||||
snprintf(buffer, sizeof(buffer), Lang::Strings::CHECK_NEW_VERSION_FAILED, retry_delay, ota_.GetCheckVersionUrl().c_str());
|
||||
snprintf(buffer, sizeof(buffer), Lang::Strings::CHECK_NEW_VERSION_FAILED, retry_delay, ota.GetCheckVersionUrl().c_str());
|
||||
Alert(Lang::Strings::ERROR, buffer, "sad", Lang::Sounds::P3_EXCLAMATION);
|
||||
|
||||
ESP_LOGW(TAG, "Check new version failed, retry in %d seconds (%d/%d)", retry_delay, retry_count, MAX_RETRY);
|
||||
@@ -133,7 +134,7 @@ void Application::CheckNewVersion() {
|
||||
retry_count = 0;
|
||||
retry_delay = 10; // 重置重试延迟时间
|
||||
|
||||
if (ota_.HasNewVersion()) {
|
||||
if (ota.HasNewVersion()) {
|
||||
Alert(Lang::Strings::OTA_UPGRADE, Lang::Strings::UPGRADING, "happy", Lang::Sounds::P3_UPGRADE);
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
@@ -141,7 +142,7 @@ void Application::CheckNewVersion() {
|
||||
SetDeviceState(kDeviceStateUpgrading);
|
||||
|
||||
display->SetIcon(FONT_AWESOME_DOWNLOAD);
|
||||
std::string message = std::string(Lang::Strings::NEW_VERSION) + ota_.GetFirmwareVersion();
|
||||
std::string message = std::string(Lang::Strings::NEW_VERSION) + ota.GetFirmwareVersion();
|
||||
display->SetChatMessage("system", message.c_str());
|
||||
|
||||
auto& board = Board::GetInstance();
|
||||
@@ -160,7 +161,7 @@ void Application::CheckNewVersion() {
|
||||
background_task_ = nullptr;
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
ota_.StartUpgrade([display](int progress, size_t speed) {
|
||||
ota.StartUpgrade([display](int progress, size_t speed) {
|
||||
char buffer[64];
|
||||
snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024);
|
||||
display->SetChatMessage("system", buffer);
|
||||
@@ -175,8 +176,8 @@ void Application::CheckNewVersion() {
|
||||
}
|
||||
|
||||
// No new version, mark the current version as valid
|
||||
ota_.MarkCurrentVersionValid();
|
||||
if (!ota_.HasActivationCode() && !ota_.HasActivationChallenge()) {
|
||||
ota.MarkCurrentVersionValid();
|
||||
if (!ota.HasActivationCode() && !ota.HasActivationChallenge()) {
|
||||
xEventGroupSetBits(event_group_, CHECK_NEW_VERSION_DONE_EVENT);
|
||||
// Exit the loop if done checking new version
|
||||
break;
|
||||
@@ -184,14 +185,14 @@ void Application::CheckNewVersion() {
|
||||
|
||||
display->SetStatus(Lang::Strings::ACTIVATION);
|
||||
// Activation code is shown to the user and waiting for the user to input
|
||||
if (ota_.HasActivationCode()) {
|
||||
ShowActivationCode();
|
||||
if (ota.HasActivationCode()) {
|
||||
ShowActivationCode(ota.GetActivationCode(), ota.GetActivationMessage());
|
||||
}
|
||||
|
||||
// This will block the loop until the activation is done or timeout
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
ESP_LOGI(TAG, "Activating... %d/%d", i + 1, 10);
|
||||
esp_err_t err = ota_.Activate();
|
||||
esp_err_t err = ota.Activate();
|
||||
if (err == ESP_OK) {
|
||||
xEventGroupSetBits(event_group_, CHECK_NEW_VERSION_DONE_EVENT);
|
||||
break;
|
||||
@@ -207,10 +208,7 @@ void Application::CheckNewVersion() {
|
||||
}
|
||||
}
|
||||
|
||||
void Application::ShowActivationCode() {
|
||||
auto& message = ota_.GetActivationMessage();
|
||||
auto& code = ota_.GetActivationCode();
|
||||
|
||||
void Application::ShowActivationCode(const std::string& code, const std::string& message) {
|
||||
struct digit_sound {
|
||||
char digit;
|
||||
const std::string_view& sound;
|
||||
@@ -290,10 +288,31 @@ void Application::PlaySound(const std::string_view& sound) {
|
||||
}
|
||||
}
|
||||
|
||||
void Application::EnterAudioTestingMode() {
|
||||
ESP_LOGI(TAG, "Entering audio testing mode");
|
||||
ResetDecoder();
|
||||
SetDeviceState(kDeviceStateAudioTesting);
|
||||
}
|
||||
|
||||
void Application::ExitAudioTestingMode() {
|
||||
ESP_LOGI(TAG, "Exiting audio testing mode");
|
||||
SetDeviceState(kDeviceStateWifiConfiguring);
|
||||
// Copy audio_testing_queue_ to audio_decode_queue_
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
audio_decode_queue_ = std::move(audio_testing_queue_);
|
||||
audio_decode_cv_.notify_all();
|
||||
}
|
||||
|
||||
void Application::ToggleChatState() {
|
||||
if (device_state_ == kDeviceStateActivating) {
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
return;
|
||||
} else if (device_state_ == kDeviceStateWifiConfiguring) {
|
||||
EnterAudioTestingMode();
|
||||
return;
|
||||
} else if (device_state_ == kDeviceStateAudioTesting) {
|
||||
ExitAudioTestingMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!protocol_) {
|
||||
@@ -327,6 +346,9 @@ void Application::StartListening() {
|
||||
if (device_state_ == kDeviceStateActivating) {
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
return;
|
||||
} else if (device_state_ == kDeviceStateWifiConfiguring) {
|
||||
EnterAudioTestingMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!protocol_) {
|
||||
@@ -354,6 +376,11 @@ void Application::StartListening() {
|
||||
}
|
||||
|
||||
void Application::StopListening() {
|
||||
if (device_state_ == kDeviceStateAudioTesting) {
|
||||
ExitAudioTestingMode();
|
||||
return;
|
||||
}
|
||||
|
||||
const std::array<int, 3> valid_states = {
|
||||
kDeviceStateListening,
|
||||
kDeviceStateSpeaking,
|
||||
@@ -424,7 +451,8 @@ void Application::Start() {
|
||||
display->UpdateStatusBar(true);
|
||||
|
||||
// Check for new firmware version or get the MQTT broker address
|
||||
CheckNewVersion();
|
||||
Ota ota;
|
||||
CheckNewVersion(ota);
|
||||
|
||||
// Initialize the protocol
|
||||
display->SetStatus(Lang::Strings::LOADING_PROTOCOL);
|
||||
@@ -434,9 +462,9 @@ void Application::Start() {
|
||||
McpServer::GetInstance().AddCommonTools();
|
||||
#endif
|
||||
|
||||
if (ota_.HasMqttConfig()) {
|
||||
if (ota.HasMqttConfig()) {
|
||||
protocol_ = std::make_unique<MqttProtocol>();
|
||||
} else if (ota_.HasWebsocketConfig()) {
|
||||
} else if (ota.HasWebsocketConfig()) {
|
||||
protocol_ = std::make_unique<WebsocketProtocol>();
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No protocol specified in the OTA config, using MQTT");
|
||||
@@ -672,8 +700,9 @@ void Application::Start() {
|
||||
xEventGroupWaitBits(event_group_, CHECK_NEW_VERSION_DONE_EVENT, pdTRUE, pdFALSE, portMAX_DELAY);
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
|
||||
has_server_time_ = ota.HasServerTime();
|
||||
if (protocol_started) {
|
||||
std::string message = std::string(Lang::Strings::VERSION) + ota_.GetCurrentVersion();
|
||||
std::string message = std::string(Lang::Strings::VERSION) + ota.GetCurrentVersion();
|
||||
display->ShowNotification(message.c_str());
|
||||
display->SetChatMessage("system", "");
|
||||
// Play the success sound to indicate the device is ready
|
||||
@@ -701,7 +730,7 @@ void Application::OnClockTimer() {
|
||||
SystemInfo::PrintHeapStats();
|
||||
|
||||
// If we have synchronized server time, set the status to clock "HH:MM" if the device is idle
|
||||
if (ota_.HasServerTime()) {
|
||||
if (has_server_time_) {
|
||||
if (device_state_ == kDeviceStateIdle) {
|
||||
Schedule([this]() {
|
||||
// Set status to clock "HH:MM"
|
||||
@@ -824,6 +853,28 @@ void Application::OnAudioOutput() {
|
||||
}
|
||||
|
||||
void Application::OnAudioInput() {
|
||||
if (device_state_ == kDeviceStateAudioTesting) {
|
||||
if (audio_testing_queue_.size() >= AUDIO_TESTING_MAX_DURATION_MS / OPUS_FRAME_DURATION_MS) {
|
||||
ExitAudioTestingMode();
|
||||
return;
|
||||
}
|
||||
std::vector<int16_t> data;
|
||||
int samples = OPUS_FRAME_DURATION_MS * 16000 / 1000;
|
||||
if (ReadAudio(data, 16000, samples)) {
|
||||
background_task_->Schedule([this, data = std::move(data)]() mutable {
|
||||
opus_encoder_->Encode(std::move(data), [this](std::vector<uint8_t>&& opus) {
|
||||
AudioStreamPacket packet;
|
||||
packet.payload = std::move(opus);
|
||||
packet.frame_duration = OPUS_FRAME_DURATION_MS;
|
||||
packet.sample_rate = 16000;
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
audio_testing_queue_.push_back(std::move(packet));
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wake_word_->IsDetectionRunning()) {
|
||||
std::vector<int16_t> data;
|
||||
int samples = wake_word_->GetFeedSize();
|
||||
@@ -834,6 +885,7 @@ void Application::OnAudioInput() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (audio_processor_->IsRunning()) {
|
||||
std::vector<int16_t> data;
|
||||
int samples = audio_processor_->GetFeedSize();
|
||||
|
||||
@@ -44,11 +44,13 @@ enum DeviceState {
|
||||
kDeviceStateSpeaking,
|
||||
kDeviceStateUpgrading,
|
||||
kDeviceStateActivating,
|
||||
kDeviceStateAudioTesting,
|
||||
kDeviceStateFatalError
|
||||
};
|
||||
|
||||
#define OPUS_FRAME_DURATION_MS 60
|
||||
#define MAX_AUDIO_PACKETS_IN_QUEUE (2400 / OPUS_FRAME_DURATION_MS)
|
||||
#define AUDIO_TESTING_MAX_DURATION_MS 10000
|
||||
|
||||
class Application {
|
||||
public:
|
||||
@@ -88,7 +90,6 @@ private:
|
||||
std::unique_ptr<WakeWord> wake_word_;
|
||||
std::unique_ptr<AudioProcessor> audio_processor_;
|
||||
std::unique_ptr<AudioDebugger> audio_debugger_;
|
||||
Ota ota_;
|
||||
std::mutex mutex_;
|
||||
std::list<std::function<void()>> main_tasks_;
|
||||
std::unique_ptr<Protocol> protocol_;
|
||||
@@ -98,6 +99,7 @@ private:
|
||||
ListeningMode listening_mode_ = kListeningModeAutoStop;
|
||||
AecMode aec_mode_ = kAecOff;
|
||||
|
||||
bool has_server_time_ = false;
|
||||
bool aborted_ = false;
|
||||
bool voice_detected_ = false;
|
||||
bool busy_decoding_audio_ = false;
|
||||
@@ -111,6 +113,7 @@ private:
|
||||
std::list<AudioStreamPacket> audio_send_queue_;
|
||||
std::list<AudioStreamPacket> audio_decode_queue_;
|
||||
std::condition_variable audio_decode_cv_;
|
||||
std::list<AudioStreamPacket> audio_testing_queue_;
|
||||
|
||||
// 新增:用于维护音频包的timestamp队列
|
||||
std::list<uint32_t> timestamp_queue_;
|
||||
@@ -129,11 +132,13 @@ private:
|
||||
bool ReadAudio(std::vector<int16_t>& data, int sample_rate, int samples);
|
||||
void ResetDecoder();
|
||||
void SetDecodeSampleRate(int sample_rate, int frame_duration);
|
||||
void CheckNewVersion();
|
||||
void ShowActivationCode();
|
||||
void CheckNewVersion(Ota& ota);
|
||||
void ShowActivationCode(const std::string& code, const std::string& message);
|
||||
void OnClockTimer();
|
||||
void SetListeningMode(ListeningMode mode);
|
||||
void AudioLoop();
|
||||
void EnterAudioTestingMode();
|
||||
void ExitAudioTestingMode();
|
||||
};
|
||||
|
||||
#endif // _APPLICATION_H_
|
||||
|
||||
@@ -6,13 +6,16 @@
|
||||
|
||||
Es8311AudioCodec::Es8311AudioCodec(void* i2c_master_handle, i2c_port_t i2c_port, int input_sample_rate, int output_sample_rate,
|
||||
gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din,
|
||||
gpio_num_t pa_pin, uint8_t es8311_addr, bool use_mclk) {
|
||||
gpio_num_t pa_pin, uint8_t es8311_addr, bool use_mclk, bool pa_inverted) {
|
||||
duplex_ = true; // 是否双工
|
||||
input_reference_ = false; // 是否使用参考输入,实现回声消除
|
||||
input_channels_ = 1; // 输入通道数
|
||||
input_sample_rate_ = input_sample_rate;
|
||||
output_sample_rate_ = output_sample_rate;
|
||||
pa_pin_ = pa_pin;
|
||||
pa_inverted_ = pa_inverted;
|
||||
|
||||
assert(input_sample_rate_ == output_sample_rate_);
|
||||
CreateDuplexChannels(mclk, bclk, ws, dout, din);
|
||||
|
||||
// Do initialize of related interface: data_if, ctrl_if and gpio_if
|
||||
@@ -44,29 +47,15 @@ Es8311AudioCodec::Es8311AudioCodec(void* i2c_master_handle, i2c_port_t i2c_port,
|
||||
es8311_cfg.use_mclk = use_mclk;
|
||||
es8311_cfg.hw_gain.pa_voltage = 5.0;
|
||||
es8311_cfg.hw_gain.codec_dac_voltage = 3.3;
|
||||
es8311_cfg.pa_reverted = pa_inverted_;
|
||||
codec_if_ = es8311_codec_new(&es8311_cfg);
|
||||
assert(codec_if_ != NULL);
|
||||
|
||||
esp_codec_dev_cfg_t dev_cfg = {
|
||||
.dev_type = ESP_CODEC_DEV_TYPE_OUT,
|
||||
.codec_if = codec_if_,
|
||||
.data_if = data_if_,
|
||||
};
|
||||
output_dev_ = esp_codec_dev_new(&dev_cfg);
|
||||
assert(output_dev_ != NULL);
|
||||
dev_cfg.dev_type = ESP_CODEC_DEV_TYPE_IN;
|
||||
input_dev_ = esp_codec_dev_new(&dev_cfg);
|
||||
assert(input_dev_ != NULL);
|
||||
esp_codec_set_disable_when_closed(output_dev_, false);
|
||||
esp_codec_set_disable_when_closed(input_dev_, false);
|
||||
ESP_LOGI(TAG, "Es8311AudioCodec initialized");
|
||||
}
|
||||
|
||||
Es8311AudioCodec::~Es8311AudioCodec() {
|
||||
ESP_ERROR_CHECK(esp_codec_dev_close(output_dev_));
|
||||
esp_codec_dev_delete(output_dev_);
|
||||
ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
|
||||
esp_codec_dev_delete(input_dev_);
|
||||
esp_codec_dev_delete(dev_);
|
||||
|
||||
audio_codec_delete_codec_if(codec_if_);
|
||||
audio_codec_delete_ctrl_if(ctrl_if_);
|
||||
@@ -74,6 +63,36 @@ Es8311AudioCodec::~Es8311AudioCodec() {
|
||||
audio_codec_delete_data_if(data_if_);
|
||||
}
|
||||
|
||||
void Es8311AudioCodec::UpdateDeviceState() {
|
||||
if ((input_enabled_ || output_enabled_) && dev_ == nullptr) {
|
||||
esp_codec_dev_cfg_t dev_cfg = {
|
||||
.dev_type = ESP_CODEC_DEV_TYPE_IN_OUT,
|
||||
.codec_if = codec_if_,
|
||||
.data_if = data_if_,
|
||||
};
|
||||
dev_ = esp_codec_dev_new(&dev_cfg);
|
||||
assert(dev_ != NULL);
|
||||
|
||||
esp_codec_dev_sample_info_t fs = {
|
||||
.bits_per_sample = 16,
|
||||
.channel = 1,
|
||||
.channel_mask = 0,
|
||||
.sample_rate = (uint32_t)input_sample_rate_,
|
||||
.mclk_multiple = 0,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_codec_dev_open(dev_, &fs));
|
||||
ESP_ERROR_CHECK(esp_codec_dev_set_in_gain(dev_, AUDIO_CODEC_DEFAULT_MIC_GAIN));
|
||||
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(dev_, output_volume_));
|
||||
} else if (!input_enabled_ && !output_enabled_ && dev_ != nullptr) {
|
||||
esp_codec_dev_close(dev_);
|
||||
dev_ = nullptr;
|
||||
}
|
||||
if (pa_pin_ != GPIO_NUM_NC) {
|
||||
int level = output_enabled_ ? 1 : 0;
|
||||
gpio_set_level(pa_pin_, pa_inverted_ ? !level : level);
|
||||
}
|
||||
}
|
||||
|
||||
void Es8311AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din) {
|
||||
assert(input_sample_rate_ == output_sample_rate_);
|
||||
|
||||
@@ -131,7 +150,7 @@ void Es8311AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp
|
||||
}
|
||||
|
||||
void Es8311AudioCodec::SetOutputVolume(int volume) {
|
||||
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, volume));
|
||||
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(dev_, volume));
|
||||
AudioCodec::SetOutputVolume(volume);
|
||||
}
|
||||
|
||||
@@ -139,59 +158,28 @@ void Es8311AudioCodec::EnableInput(bool enable) {
|
||||
if (enable == input_enabled_) {
|
||||
return;
|
||||
}
|
||||
if (enable) {
|
||||
esp_codec_dev_sample_info_t fs = {
|
||||
.bits_per_sample = 16,
|
||||
.channel = 1,
|
||||
.channel_mask = 0,
|
||||
.sample_rate = (uint32_t)input_sample_rate_,
|
||||
.mclk_multiple = 0,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_codec_dev_open(input_dev_, &fs));
|
||||
ESP_ERROR_CHECK(esp_codec_dev_set_in_gain(input_dev_, AUDIO_CODEC_DEFAULT_MIC_GAIN));
|
||||
} else {
|
||||
ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
|
||||
}
|
||||
AudioCodec::EnableInput(enable);
|
||||
UpdateDeviceState();
|
||||
}
|
||||
|
||||
void Es8311AudioCodec::EnableOutput(bool enable) {
|
||||
if (enable == output_enabled_) {
|
||||
return;
|
||||
}
|
||||
if (enable) {
|
||||
// Play 16bit 1 channel
|
||||
esp_codec_dev_sample_info_t fs = {
|
||||
.bits_per_sample = 16,
|
||||
.channel = 1,
|
||||
.channel_mask = 0,
|
||||
.sample_rate = (uint32_t)output_sample_rate_,
|
||||
.mclk_multiple = 0,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_codec_dev_open(output_dev_, &fs));
|
||||
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, output_volume_));
|
||||
if (pa_pin_ != GPIO_NUM_NC) {
|
||||
gpio_set_level(pa_pin_, 1);
|
||||
}
|
||||
} else {
|
||||
ESP_ERROR_CHECK(esp_codec_dev_close(output_dev_));
|
||||
if (pa_pin_ != GPIO_NUM_NC) {
|
||||
gpio_set_level(pa_pin_, 0);
|
||||
}
|
||||
}
|
||||
AudioCodec::EnableOutput(enable);
|
||||
UpdateDeviceState();
|
||||
}
|
||||
|
||||
int Es8311AudioCodec::Read(int16_t* dest, int samples) {
|
||||
if (input_enabled_) {
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_codec_dev_read(input_dev_, (void*)dest, samples * sizeof(int16_t)));
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_codec_dev_read(dev_, (void*)dest, samples * sizeof(int16_t)));
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
int Es8311AudioCodec::Write(const int16_t* data, int samples) {
|
||||
if (output_enabled_) {
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_codec_dev_write(output_dev_, (void*)data, samples * sizeof(int16_t)));
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_codec_dev_write(dev_, (void*)data, samples * sizeof(int16_t)));
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
@@ -15,11 +15,12 @@ private:
|
||||
const audio_codec_if_t* codec_if_ = nullptr;
|
||||
const audio_codec_gpio_if_t* gpio_if_ = nullptr;
|
||||
|
||||
esp_codec_dev_handle_t output_dev_ = nullptr;
|
||||
esp_codec_dev_handle_t input_dev_ = nullptr;
|
||||
esp_codec_dev_handle_t dev_ = nullptr;
|
||||
gpio_num_t pa_pin_ = GPIO_NUM_NC;
|
||||
bool pa_inverted_ = false;
|
||||
|
||||
void CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din);
|
||||
void UpdateDeviceState();
|
||||
|
||||
virtual int Read(int16_t* dest, int samples) override;
|
||||
virtual int Write(const int16_t* data, int samples) override;
|
||||
@@ -27,7 +28,7 @@ private:
|
||||
public:
|
||||
Es8311AudioCodec(void* i2c_master_handle, i2c_port_t i2c_port, int input_sample_rate, int output_sample_rate,
|
||||
gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din,
|
||||
gpio_num_t pa_pin, uint8_t es8311_addr, bool use_mclk = true);
|
||||
gpio_num_t pa_pin, uint8_t es8311_addr, bool use_mclk = true, bool pa_inverted = false);
|
||||
virtual ~Es8311AudioCodec();
|
||||
|
||||
virtual void SetOutputVolume(int volume) override;
|
||||
|
||||
@@ -24,11 +24,15 @@ void AfeAudioProcessor::Initialize(AudioCodec* codec) {
|
||||
|
||||
srmodel_list_t *models = esp_srmodel_init("model");
|
||||
char* ns_model_name = esp_srmodel_filter(models, ESP_NSNET_PREFIX, NULL);
|
||||
|
||||
char* vad_model_name = esp_srmodel_filter(models, ESP_VADN_PREFIX, NULL);
|
||||
|
||||
afe_config_t* afe_config = afe_config_init(input_format.c_str(), NULL, AFE_TYPE_VC, AFE_MODE_HIGH_PERF);
|
||||
afe_config->aec_mode = AEC_MODE_VOIP_HIGH_PERF;
|
||||
afe_config->vad_mode = VAD_MODE_0;
|
||||
afe_config->vad_min_noise_ms = 100;
|
||||
if (vad_model_name != nullptr) {
|
||||
afe_config->vad_model_name = vad_model_name;
|
||||
}
|
||||
|
||||
if (ns_model_name != nullptr) {
|
||||
afe_config->ns_init = true;
|
||||
|
||||
@@ -35,6 +35,10 @@ void AfeWakeWord::Initialize(AudioCodec* codec) {
|
||||
int ref_num = codec_->input_reference() ? 1 : 0;
|
||||
|
||||
srmodel_list_t *models = esp_srmodel_init("model");
|
||||
if (models == nullptr || models->num == -1) {
|
||||
ESP_LOGE(TAG, "Failed to initialize wakenet model");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < models->num; i++) {
|
||||
ESP_LOGI(TAG, "Model %d: %s", i, models->model_name[i]);
|
||||
if (strstr(models->model_name[i], ESP_WN_PREFIX) != NULL) {
|
||||
|
||||
@@ -27,7 +27,10 @@ void EspWakeWord::Initialize(AudioCodec* codec) {
|
||||
codec_ = codec;
|
||||
|
||||
wakenet_model_ = esp_srmodel_init("model");
|
||||
|
||||
if (wakenet_model_ == nullptr || wakenet_model_->num == -1) {
|
||||
ESP_LOGE(TAG, "Failed to initialize wakenet model");
|
||||
return;
|
||||
}
|
||||
if(wakenet_model_->num > 1) {
|
||||
ESP_LOGW(TAG, "More than one model found, using the first one");
|
||||
} else if (wakenet_model_->num == 0) {
|
||||
|
||||
@@ -27,12 +27,12 @@ void BackgroundTask::Schedule(std::function<void()> callback) {
|
||||
}
|
||||
}
|
||||
active_tasks_++;
|
||||
main_tasks_.emplace_back([this, cb = std::move(callback)]() {
|
||||
background_tasks_.emplace_back([this, cb = std::move(callback)]() {
|
||||
cb();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
active_tasks_--;
|
||||
if (main_tasks_.empty() && active_tasks_ == 0) {
|
||||
if (background_tasks_.empty() && active_tasks_ == 0) {
|
||||
condition_variable_.notify_all();
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ void BackgroundTask::Schedule(std::function<void()> callback) {
|
||||
void BackgroundTask::WaitForCompletion() {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
condition_variable_.wait(lock, [this]() {
|
||||
return main_tasks_.empty() && active_tasks_ == 0;
|
||||
return background_tasks_.empty() && active_tasks_ == 0;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ void BackgroundTask::BackgroundTaskLoop() {
|
||||
ESP_LOGI(TAG, "background_task started");
|
||||
while (true) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
condition_variable_.wait(lock, [this]() { return !main_tasks_.empty(); });
|
||||
condition_variable_.wait(lock, [this]() { return !background_tasks_.empty(); });
|
||||
|
||||
std::list<std::function<void()>> tasks = std::move(main_tasks_);
|
||||
std::list<std::function<void()>> tasks = std::move(background_tasks_);
|
||||
lock.unlock();
|
||||
|
||||
for (auto& task : tasks) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::list<std::function<void()>> main_tasks_;
|
||||
std::list<std::function<void()>> background_tasks_;
|
||||
std::condition_variable condition_variable_;
|
||||
TaskHandle_t background_task_handle_ = nullptr;
|
||||
std::atomic<size_t> active_tasks_{0};
|
||||
|
||||
31
main/boards/bread-compact-wifi-s3cam/README.md
Normal file
31
main/boards/bread-compact-wifi-s3cam/README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
硬件基于基于ESP32S3CAM开发板,代码基于bread-compact-wifi-lcd修改
|
||||
使用的摄像头是OV2640
|
||||
注意因为摄像头占用IO较多,所以占用了ESP32S3的USB 19 20两个引脚
|
||||
连线方式参考config.h文件中对引脚的定义
|
||||
|
||||
|
||||
# 编译配置命令
|
||||
|
||||
**配置编译目标为 ESP32S3:**
|
||||
|
||||
```bash
|
||||
idf.py set-target esp32s3
|
||||
```
|
||||
|
||||
**打开 menuconfig:**
|
||||
|
||||
```bash
|
||||
idf.py menuconfig
|
||||
```
|
||||
|
||||
**选择板子:**
|
||||
|
||||
```
|
||||
Xiaozhi Assistant -> Board Type ->面包板新版接线(WiFi)+ LCD + Camera
|
||||
```
|
||||
|
||||
**编译烧入:**
|
||||
|
||||
```bash
|
||||
idf.py build flash
|
||||
```
|
||||
240
main/boards/bread-compact-wifi-s3cam/compact_wifi_board_s3cam.cc
Normal file
240
main/boards/bread-compact-wifi-s3cam/compact_wifi_board_s3cam.cc
Normal file
@@ -0,0 +1,240 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/no_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "system_reset.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "mcp_server.h"
|
||||
#include "lamp_controller.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "led/single_led.h"
|
||||
#include "esp32_camera.h"
|
||||
|
||||
#include <wifi_station.h>
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <driver/spi_common.h>
|
||||
|
||||
#if defined(LCD_TYPE_ILI9341_SERIAL)
|
||||
#include "esp_lcd_ili9341.h"
|
||||
#endif
|
||||
|
||||
#if defined(LCD_TYPE_GC9A01_SERIAL)
|
||||
#include "esp_lcd_gc9a01.h"
|
||||
static const gc9a01_lcd_init_cmd_t gc9107_lcd_init_cmds[] = {
|
||||
// {cmd, { data }, data_size, delay_ms}
|
||||
{0xfe, (uint8_t[]){0x00}, 0, 0},
|
||||
{0xef, (uint8_t[]){0x00}, 0, 0},
|
||||
{0xb0, (uint8_t[]){0xc0}, 1, 0},
|
||||
{0xb1, (uint8_t[]){0x80}, 1, 0},
|
||||
{0xb2, (uint8_t[]){0x27}, 1, 0},
|
||||
{0xb3, (uint8_t[]){0x13}, 1, 0},
|
||||
{0xb6, (uint8_t[]){0x19}, 1, 0},
|
||||
{0xb7, (uint8_t[]){0x05}, 1, 0},
|
||||
{0xac, (uint8_t[]){0xc8}, 1, 0},
|
||||
{0xab, (uint8_t[]){0x0f}, 1, 0},
|
||||
{0x3a, (uint8_t[]){0x05}, 1, 0},
|
||||
{0xb4, (uint8_t[]){0x04}, 1, 0},
|
||||
{0xa8, (uint8_t[]){0x08}, 1, 0},
|
||||
{0xb8, (uint8_t[]){0x08}, 1, 0},
|
||||
{0xea, (uint8_t[]){0x02}, 1, 0},
|
||||
{0xe8, (uint8_t[]){0x2A}, 1, 0},
|
||||
{0xe9, (uint8_t[]){0x47}, 1, 0},
|
||||
{0xe7, (uint8_t[]){0x5f}, 1, 0},
|
||||
{0xc6, (uint8_t[]){0x21}, 1, 0},
|
||||
{0xc7, (uint8_t[]){0x15}, 1, 0},
|
||||
{0xf0,
|
||||
(uint8_t[]){0x1D, 0x38, 0x09, 0x4D, 0x92, 0x2F, 0x35, 0x52, 0x1E, 0x0C,
|
||||
0x04, 0x12, 0x14, 0x1f},
|
||||
14, 0},
|
||||
{0xf1,
|
||||
(uint8_t[]){0x16, 0x40, 0x1C, 0x54, 0xA9, 0x2D, 0x2E, 0x56, 0x10, 0x0D,
|
||||
0x0C, 0x1A, 0x14, 0x1E},
|
||||
14, 0},
|
||||
{0xf4, (uint8_t[]){0x00, 0x00, 0xFF}, 3, 0},
|
||||
{0xba, (uint8_t[]){0xFF, 0xFF}, 2, 0},
|
||||
};
|
||||
#endif
|
||||
|
||||
#define TAG "CompactWifiBoardS3Cam"
|
||||
|
||||
LV_FONT_DECLARE(font_puhui_16_4);
|
||||
LV_FONT_DECLARE(font_awesome_16_4);
|
||||
|
||||
class CompactWifiBoardS3Cam : public WifiBoard {
|
||||
private:
|
||||
|
||||
Button boot_button_;
|
||||
LcdDisplay* display_;
|
||||
Esp32Camera* camera_;
|
||||
|
||||
void InitializeSpi() {
|
||||
spi_bus_config_t buscfg = {};
|
||||
buscfg.mosi_io_num = DISPLAY_MOSI_PIN;
|
||||
buscfg.miso_io_num = GPIO_NUM_NC;
|
||||
buscfg.sclk_io_num = DISPLAY_CLK_PIN;
|
||||
buscfg.quadwp_io_num = GPIO_NUM_NC;
|
||||
buscfg.quadhd_io_num = GPIO_NUM_NC;
|
||||
buscfg.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t);
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
}
|
||||
|
||||
void InitializeLcdDisplay() {
|
||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||
esp_lcd_panel_handle_t panel = nullptr;
|
||||
// 液晶屏控制IO初始化
|
||||
ESP_LOGD(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_spi_config_t io_config = {};
|
||||
io_config.cs_gpio_num = DISPLAY_CS_PIN;
|
||||
io_config.dc_gpio_num = DISPLAY_DC_PIN;
|
||||
io_config.spi_mode = DISPLAY_SPI_MODE;
|
||||
io_config.pclk_hz = 40 * 1000 * 1000;
|
||||
io_config.trans_queue_depth = 10;
|
||||
io_config.lcd_cmd_bits = 8;
|
||||
io_config.lcd_param_bits = 8;
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io));
|
||||
|
||||
// 初始化液晶屏驱动芯片
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
|
||||
panel_config.rgb_ele_order = DISPLAY_RGB_ORDER;
|
||||
panel_config.bits_per_pixel = 16;
|
||||
#if defined(LCD_TYPE_ILI9341_SERIAL)
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(panel_io, &panel_config, &panel));
|
||||
#elif defined(LCD_TYPE_GC9A01_SERIAL)
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_gc9a01(panel_io, &panel_config, &panel));
|
||||
gc9a01_vendor_config_t gc9107_vendor_config = {
|
||||
.init_cmds = gc9107_lcd_init_cmds,
|
||||
.init_cmds_size = sizeof(gc9107_lcd_init_cmds) / sizeof(gc9a01_lcd_init_cmd_t),
|
||||
};
|
||||
#else
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
|
||||
#endif
|
||||
|
||||
esp_lcd_panel_reset(panel);
|
||||
|
||||
|
||||
esp_lcd_panel_init(panel);
|
||||
esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR);
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
#ifdef LCD_TYPE_GC9A01_SERIAL
|
||||
panel_config.vendor_config = &gc9107_vendor_config;
|
||||
#endif
|
||||
display_ = new SpiLcdDisplay(panel_io, panel,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_16_4,
|
||||
.icon_font = &font_awesome_16_4,
|
||||
#if CONFIG_USE_WECHAT_MESSAGE_STYLE
|
||||
.emoji_font = font_emoji_32_init(),
|
||||
#else
|
||||
.emoji_font = DISPLAY_HEIGHT >= 240 ? font_emoji_64_init() : font_emoji_32_init(),
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
void InitializeCamera() {
|
||||
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_QVGA;
|
||||
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);
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
app.ToggleChatState();
|
||||
});
|
||||
}
|
||||
|
||||
// 物联网初始化,添加对 AI 可见设备
|
||||
void InitializeIot() {
|
||||
#if CONFIG_IOT_PROTOCOL_XIAOZHI
|
||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||
#elif CONFIG_IOT_PROTOCOL_MCP
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
CompactWifiBoardS3Cam() :
|
||||
boot_button_(BOOT_BUTTON_GPIO) {
|
||||
InitializeSpi();
|
||||
InitializeLcdDisplay();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
InitializeCamera();
|
||||
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
|
||||
GetBacklight()->RestoreBrightness();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual Led* GetLed() override {
|
||||
static SingleLed led(BUILTIN_LED_GPIO);
|
||||
return &led;
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
#ifdef AUDIO_I2S_METHOD_SIMPLEX
|
||||
static NoAudioCodecSimplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK, AUDIO_I2S_SPK_GPIO_DOUT, AUDIO_I2S_MIC_GPIO_SCK, AUDIO_I2S_MIC_GPIO_WS, AUDIO_I2S_MIC_GPIO_DIN);
|
||||
#else
|
||||
static NoAudioCodecDuplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN);
|
||||
#endif
|
||||
return &audio_codec;
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual Backlight* GetBacklight() override {
|
||||
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
|
||||
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
|
||||
return &backlight;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual Camera* GetCamera() override {
|
||||
return camera_;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(CompactWifiBoardS3Cam);
|
||||
308
main/boards/bread-compact-wifi-s3cam/config.h
Normal file
308
main/boards/bread-compact-wifi-s3cam/config.h
Normal file
@@ -0,0 +1,308 @@
|
||||
#ifndef _BOARD_CONFIG_H_
|
||||
#define _BOARD_CONFIG_H_
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#define AUDIO_INPUT_SAMPLE_RATE 16000
|
||||
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
|
||||
|
||||
// 如果使用 Duplex I2S 模式,请注释下面一行
|
||||
#define AUDIO_I2S_METHOD_SIMPLEX
|
||||
|
||||
#ifdef AUDIO_I2S_METHOD_SIMPLEX
|
||||
|
||||
#define AUDIO_I2S_MIC_GPIO_WS GPIO_NUM_1
|
||||
#define AUDIO_I2S_MIC_GPIO_SCK GPIO_NUM_2
|
||||
#define AUDIO_I2S_MIC_GPIO_DIN GPIO_NUM_42
|
||||
#define AUDIO_I2S_SPK_GPIO_DOUT GPIO_NUM_39
|
||||
#define AUDIO_I2S_SPK_GPIO_BCLK GPIO_NUM_40
|
||||
#define AUDIO_I2S_SPK_GPIO_LRCK GPIO_NUM_41
|
||||
|
||||
#else
|
||||
|
||||
#define AUDIO_I2S_GPIO_WS GPIO_NUM_4
|
||||
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_5
|
||||
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_6
|
||||
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_7
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define BUILTIN_LED_GPIO GPIO_NUM_48
|
||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||
#define TOUCH_BUTTON_GPIO GPIO_NUM_NC
|
||||
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC
|
||||
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC
|
||||
|
||||
//Camera Config
|
||||
#define CAMERA_PIN_D0 GPIO_NUM_11
|
||||
#define CAMERA_PIN_D1 GPIO_NUM_9
|
||||
#define CAMERA_PIN_D2 GPIO_NUM_8
|
||||
#define CAMERA_PIN_D3 GPIO_NUM_10
|
||||
#define CAMERA_PIN_D4 GPIO_NUM_12
|
||||
#define CAMERA_PIN_D5 GPIO_NUM_18
|
||||
#define CAMERA_PIN_D6 GPIO_NUM_17
|
||||
#define CAMERA_PIN_D7 GPIO_NUM_16
|
||||
#define CAMERA_PIN_XCLK GPIO_NUM_15
|
||||
#define CAMERA_PIN_PCLK GPIO_NUM_13
|
||||
#define CAMERA_PIN_VSYNC GPIO_NUM_6
|
||||
#define CAMERA_PIN_HREF GPIO_NUM_7
|
||||
#define CAMERA_PIN_SIOC GPIO_NUM_5
|
||||
#define CAMERA_PIN_SIOD GPIO_NUM_4
|
||||
#define CAMERA_PIN_PWDN GPIO_NUM_NC
|
||||
#define CAMERA_PIN_RESET GPIO_NUM_NC
|
||||
#define XCLK_FREQ_HZ 20000000
|
||||
|
||||
|
||||
#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_38
|
||||
#define DISPLAY_MOSI_PIN GPIO_NUM_20
|
||||
#define DISPLAY_CLK_PIN GPIO_NUM_19
|
||||
#define DISPLAY_DC_PIN GPIO_NUM_47
|
||||
#define DISPLAY_RST_PIN GPIO_NUM_21
|
||||
#define DISPLAY_CS_PIN GPIO_NUM_45
|
||||
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X320
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X320_NO_IPS
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR false
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_170X320
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 170
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 35
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_172X320
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 172
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 34
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X280
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 280
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 20
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X240
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X240_7PIN
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 3
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X135
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 135
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY true
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 40
|
||||
#define DISPLAY_OFFSET_Y 53
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7735_128X160
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 128
|
||||
#define DISPLAY_HEIGHT 160
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y true
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR false
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7735_128X128
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 128
|
||||
#define DISPLAY_HEIGHT 128
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y true
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR false
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 32
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7796_320X480
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 320
|
||||
#define DISPLAY_HEIGHT 480
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7796_320X480_NO_IPS
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 320
|
||||
#define DISPLAY_HEIGHT 480
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR false
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ILI9341_240X320
|
||||
#define LCD_TYPE_ILI9341_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ILI9341_240X320_NO_IPS
|
||||
#define LCD_TYPE_ILI9341_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR false
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_GC9A01_240X240
|
||||
#define LCD_TYPE_GC9A01_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_CUSTOM
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
|
||||
// A MCP Test: Control a lamp
|
||||
#define LAMP_GPIO GPIO_NUM_18
|
||||
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
@@ -212,24 +212,6 @@ std::string Esp32Camera::Explain(const std::string& question) {
|
||||
auto http = Board::GetInstance().CreateHttp();
|
||||
// 构造multipart/form-data请求体
|
||||
std::string boundary = "----ESP32_CAMERA_BOUNDARY";
|
||||
|
||||
// 构造question字段
|
||||
std::string question_field;
|
||||
question_field += "--" + boundary + "\r\n";
|
||||
question_field += "Content-Disposition: form-data; name=\"question\"\r\n";
|
||||
question_field += "\r\n";
|
||||
question_field += question + "\r\n";
|
||||
|
||||
// 构造文件字段头部
|
||||
std::string file_header;
|
||||
file_header += "--" + boundary + "\r\n";
|
||||
file_header += "Content-Disposition: form-data; name=\"file\"; filename=\"camera.jpg\"\r\n";
|
||||
file_header += "Content-Type: image/jpeg\r\n";
|
||||
file_header += "\r\n";
|
||||
|
||||
// 构造尾部
|
||||
std::string multipart_footer;
|
||||
multipart_footer += "\r\n--" + boundary + "--\r\n";
|
||||
|
||||
// 配置HTTP客户端,使用分块传输编码
|
||||
http->SetHeader("Device-Id", SystemInfo::GetMacAddress().c_str());
|
||||
@@ -255,12 +237,25 @@ std::string Esp32Camera::Explain(const std::string& question) {
|
||||
return "{\"success\": false, \"message\": \"Failed to connect to explain URL\"}";
|
||||
}
|
||||
|
||||
// 第一块:question字段
|
||||
http->Write(question_field.c_str(), question_field.size());
|
||||
|
||||
// 第二块:文件字段头部
|
||||
http->Write(file_header.c_str(), file_header.size());
|
||||
|
||||
{
|
||||
// 第一块:question字段
|
||||
std::string question_field;
|
||||
question_field += "--" + boundary + "\r\n";
|
||||
question_field += "Content-Disposition: form-data; name=\"question\"\r\n";
|
||||
question_field += "\r\n";
|
||||
question_field += question + "\r\n";
|
||||
http->Write(question_field.c_str(), question_field.size());
|
||||
}
|
||||
{
|
||||
// 第二块:文件字段头部
|
||||
std::string file_header;
|
||||
file_header += "--" + boundary + "\r\n";
|
||||
file_header += "Content-Disposition: form-data; name=\"file\"; filename=\"camera.jpg\"\r\n";
|
||||
file_header += "Content-Type: image/jpeg\r\n";
|
||||
file_header += "\r\n";
|
||||
http->Write(file_header.c_str(), file_header.size());
|
||||
}
|
||||
|
||||
// 第三块:JPEG数据
|
||||
size_t total_sent = 0;
|
||||
while (true) {
|
||||
@@ -281,9 +276,12 @@ std::string Esp32Camera::Explain(const std::string& question) {
|
||||
// 清理队列
|
||||
vQueueDelete(jpeg_queue);
|
||||
|
||||
// 第四块:multipart尾部
|
||||
http->Write(multipart_footer.c_str(), multipart_footer.size());
|
||||
|
||||
{
|
||||
// 第四块:multipart尾部
|
||||
std::string multipart_footer;
|
||||
multipart_footer += "\r\n--" + boundary + "--\r\n";
|
||||
http->Write(multipart_footer.c_str(), multipart_footer.size());
|
||||
}
|
||||
// 结束块
|
||||
http->Write("", 0);
|
||||
|
||||
|
||||
@@ -65,6 +65,9 @@ void Ml307Board::WaitForNetworkReady() {
|
||||
|
||||
// Close all previous connections
|
||||
modem_.ResetConnections();
|
||||
|
||||
// Enable sleep mode
|
||||
modem_.SetSleepMode(true, 30);
|
||||
}
|
||||
|
||||
Http* Ml307Board::CreateHttp() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "k10_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "esp_lcd_ili9341.h"
|
||||
#include "led_control.h"
|
||||
#include "font_awesome_symbols.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
@@ -37,6 +38,8 @@ private:
|
||||
button_driver_t* btn_a_driver_ = nullptr;
|
||||
button_driver_t* btn_b_driver_ = nullptr;
|
||||
|
||||
CircularStrip* led_strip_;
|
||||
|
||||
static Df_K10Board* instance_;
|
||||
|
||||
void InitializeI2c() {
|
||||
@@ -242,8 +245,8 @@ private:
|
||||
|
||||
// 物联网初始化,添加对 AI 可见设备
|
||||
void InitializeIot() {
|
||||
auto &thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
led_strip_ = new CircularStrip(BUILTIN_LED_GPIO, 3);
|
||||
new LedStripControl(led_strip_);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -262,9 +265,8 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual Led* GetLed() override {
|
||||
static CircularStrip led(BUILTIN_LED_GPIO, 3);
|
||||
return &led;
|
||||
virtual Led* GetLed() override {
|
||||
return led_strip_;
|
||||
}
|
||||
|
||||
virtual AudioCodec *GetAudioCodec() override {
|
||||
|
||||
124
main/boards/df-k10/led_control.cc
Normal file
124
main/boards/df-k10/led_control.cc
Normal file
@@ -0,0 +1,124 @@
|
||||
#include "led_control.h"
|
||||
#include "settings.h"
|
||||
#include "mcp_server.h"
|
||||
#include <esp_log.h>
|
||||
|
||||
#define TAG "LedStripControl"
|
||||
|
||||
|
||||
int LedStripControl::LevelToBrightness(int level) const {
|
||||
if (level < 0) level = 0;
|
||||
if (level > 8) level = 8;
|
||||
return (1 << level) - 1; // 2^n - 1
|
||||
}
|
||||
|
||||
StripColor LedStripControl::RGBToColor(int red, int green, int blue) {
|
||||
return {static_cast<uint8_t>(red), static_cast<uint8_t>(green), static_cast<uint8_t>(blue)};
|
||||
}
|
||||
|
||||
LedStripControl::LedStripControl(CircularStrip* led_strip)
|
||||
: led_strip_(led_strip) {
|
||||
// 从设置中读取亮度等级
|
||||
Settings settings("led_strip");
|
||||
brightness_level_ = settings.GetInt("brightness", 4); // 默认等级4
|
||||
led_strip_->SetBrightness(LevelToBrightness(brightness_level_), 4);
|
||||
|
||||
auto& mcp_server = McpServer::GetInstance();
|
||||
mcp_server.AddTool("self.led_strip.get_brightness",
|
||||
"Get the brightness of the led strip (0-8)",
|
||||
PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
return brightness_level_;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.led_strip.set_brightness",
|
||||
"Set the brightness of the led strip (0-8)",
|
||||
PropertyList({
|
||||
Property("level", kPropertyTypeInteger, 0, 8)
|
||||
}), [this](const PropertyList& properties) -> ReturnValue {
|
||||
int level = properties["level"].value<int>();
|
||||
ESP_LOGI(TAG, "Set LedStrip brightness level to %d", level);
|
||||
brightness_level_ = level;
|
||||
led_strip_->SetBrightness(LevelToBrightness(brightness_level_), 4);
|
||||
|
||||
// 保存设置
|
||||
Settings settings("led_strip", true);
|
||||
settings.SetInt("brightness", brightness_level_);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.led_strip.set_single_color",
|
||||
"Set the color of a single led.",
|
||||
PropertyList({
|
||||
Property("index", kPropertyTypeInteger, 0, 2),
|
||||
Property("red", kPropertyTypeInteger, 0, 255),
|
||||
Property("green", kPropertyTypeInteger, 0, 255),
|
||||
Property("blue", kPropertyTypeInteger, 0, 255)
|
||||
}), [this](const PropertyList& properties) -> ReturnValue {
|
||||
int index = properties["index"].value<int>();
|
||||
int red = properties["red"].value<int>();
|
||||
int green = properties["green"].value<int>();
|
||||
int blue = properties["blue"].value<int>();
|
||||
ESP_LOGI(TAG, "Set led strip single color %d to %d, %d, %d",
|
||||
index, red, green, blue);
|
||||
led_strip_->SetSingleColor(index, RGBToColor(red, green, blue));
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.led_strip.set_all_color",
|
||||
"Set the color of all leds.",
|
||||
PropertyList({
|
||||
Property("red", kPropertyTypeInteger, 0, 255),
|
||||
Property("green", kPropertyTypeInteger, 0, 255),
|
||||
Property("blue", kPropertyTypeInteger, 0, 255)
|
||||
}), [this](const PropertyList& properties) -> ReturnValue {
|
||||
int red = properties["red"].value<int>();
|
||||
int green = properties["green"].value<int>();
|
||||
int blue = properties["blue"].value<int>();
|
||||
ESP_LOGI(TAG, "Set led strip all color to %d, %d, %d",
|
||||
red, green, blue);
|
||||
led_strip_->SetAllColor(RGBToColor(red, green, blue));
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.led_strip.blink",
|
||||
"Blink the led strip. (闪烁)",
|
||||
PropertyList({
|
||||
Property("red", kPropertyTypeInteger, 0, 255),
|
||||
Property("green", kPropertyTypeInteger, 0, 255),
|
||||
Property("blue", kPropertyTypeInteger, 0, 255),
|
||||
Property("interval", kPropertyTypeInteger, 0, 1000)
|
||||
}), [this](const PropertyList& properties) -> ReturnValue {
|
||||
int red = properties["red"].value<int>();
|
||||
int green = properties["green"].value<int>();
|
||||
int blue = properties["blue"].value<int>();
|
||||
int interval = properties["interval"].value<int>();
|
||||
ESP_LOGI(TAG, "Blink led strip with color %d, %d, %d, interval %dms",
|
||||
red, green, blue, interval);
|
||||
led_strip_->Blink(RGBToColor(red, green, blue), interval);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.led_strip.scroll",
|
||||
"Scroll the led strip. (跑马灯)",
|
||||
PropertyList({
|
||||
Property("red", kPropertyTypeInteger, 0, 255),
|
||||
Property("green", kPropertyTypeInteger, 0, 255),
|
||||
Property("blue", kPropertyTypeInteger, 0, 255),
|
||||
Property("length", kPropertyTypeInteger, 1, 7),
|
||||
Property("interval", kPropertyTypeInteger, 0, 1000)
|
||||
}), [this](const PropertyList& properties) -> ReturnValue {
|
||||
int red = properties["red"].value<int>();
|
||||
int green = properties["green"].value<int>();
|
||||
int blue = properties["blue"].value<int>();
|
||||
int interval = properties["interval"].value<int>();
|
||||
int length = properties["length"].value<int>();
|
||||
ESP_LOGI(TAG, "Scroll led strip with color %d, %d, %d, length %d, interval %dms",
|
||||
red, green, blue, length, interval);
|
||||
StripColor low = RGBToColor(4, 4, 4);
|
||||
StripColor high = RGBToColor(red, green, blue);
|
||||
led_strip_->Scroll(low, high, length, interval);
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
18
main/boards/df-k10/led_control.h
Normal file
18
main/boards/df-k10/led_control.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef LED_CONTROL_H
|
||||
#define LED_CONTROL_H
|
||||
|
||||
#include "led/circular_strip.h"
|
||||
|
||||
class LedStripControl {
|
||||
private:
|
||||
CircularStrip* led_strip_;
|
||||
int brightness_level_; // 亮度等级 (0-8)
|
||||
|
||||
int LevelToBrightness(int level) const; // 将等级转换为实际亮度值
|
||||
StripColor RGBToColor(int red, int green, int blue);
|
||||
|
||||
public:
|
||||
explicit LedStripControl(CircularStrip* led_strip);
|
||||
};
|
||||
|
||||
#endif // LED_STRIP_CONTROL_H
|
||||
@@ -47,5 +47,5 @@
|
||||
|
||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||
|
||||
#define ELECTRON_BOT_VERSION "1.1.1"
|
||||
#define ELECTRON_BOT_VERSION "1.1.3"
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "mcp_server.h"
|
||||
#include "movements.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "settings.h"
|
||||
|
||||
#define TAG "ElectronBotController"
|
||||
|
||||
@@ -52,11 +53,14 @@ private:
|
||||
ACTION_BODY_TURN_CENTER = 15, // 回中心
|
||||
|
||||
// 头部动作 16-20
|
||||
ACTION_HEAD_UP = 16, // 抬头
|
||||
ACTION_HEAD_DOWN = 17, // 低头
|
||||
ACTION_HEAD_NOD_ONCE = 18, // 点头一次
|
||||
ACTION_HEAD_CENTER = 19, // 回中心
|
||||
ACTION_HEAD_NOD_REPEAT = 20 // 连续点头
|
||||
ACTION_HEAD_UP = 16, // 抬头
|
||||
ACTION_HEAD_DOWN = 17, // 低头
|
||||
ACTION_HEAD_NOD_ONCE = 18, // 点头一次
|
||||
ACTION_HEAD_CENTER = 19, // 回中心
|
||||
ACTION_HEAD_NOD_REPEAT = 20, // 连续点头
|
||||
|
||||
// 系统动作 21
|
||||
ACTION_HOME = 21 // 复位到初始位置
|
||||
};
|
||||
|
||||
static void ActionTask(void* arg) {
|
||||
@@ -87,6 +91,9 @@ private:
|
||||
int head_action = params.action_type - ACTION_HEAD_UP + 1;
|
||||
controller->electron_bot_.HeadAction(head_action, params.steps, params.amount,
|
||||
params.speed);
|
||||
} else if (params.action_type == ACTION_HOME) {
|
||||
// 复位动作
|
||||
controller->electron_bot_.Home(true);
|
||||
}
|
||||
controller->is_action_in_progress_ = false; // 动作执行完毕
|
||||
}
|
||||
@@ -110,14 +117,28 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void LoadTrimsFromNVS() {
|
||||
Settings settings("electron_trims", false);
|
||||
|
||||
int right_pitch = settings.GetInt("right_pitch", 0);
|
||||
int right_roll = settings.GetInt("right_roll", 0);
|
||||
int left_pitch = settings.GetInt("left_pitch", 0);
|
||||
int left_roll = settings.GetInt("left_roll", 0);
|
||||
int body = settings.GetInt("body", 0);
|
||||
int head = settings.GetInt("head", 0);
|
||||
electron_bot_.SetTrims(right_pitch, right_roll, left_pitch, left_roll, body, head);
|
||||
}
|
||||
|
||||
public:
|
||||
ElectronBotController() {
|
||||
electron_bot_.Init(Right_Pitch_Pin, Right_Roll_Pin, Left_Pitch_Pin, Left_Roll_Pin, Body_Pin,
|
||||
Head_Pin);
|
||||
|
||||
electron_bot_.Home(true);
|
||||
LoadTrimsFromNVS();
|
||||
action_queue_ = xQueueCreate(10, sizeof(ElectronBotActionParams));
|
||||
|
||||
QueueAction(ACTION_HOME, 1, 1000, 0, 0);
|
||||
|
||||
RegisterMcpTools();
|
||||
ESP_LOGI(TAG, "Electron Bot控制器已初始化并注册MCP工具");
|
||||
}
|
||||
@@ -231,7 +252,7 @@ public:
|
||||
// 清空队列但保持任务常驻
|
||||
xQueueReset(action_queue_);
|
||||
is_action_in_progress_ = false;
|
||||
electron_bot_.Home(true);
|
||||
QueueAction(ACTION_HOME, 1, 1000, 0, 0);
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -240,6 +261,85 @@ public:
|
||||
return is_action_in_progress_ ? "moving" : "idle";
|
||||
});
|
||||
|
||||
// 单个舵机校准工具
|
||||
mcp_server.AddTool(
|
||||
"self.electron.set_trim",
|
||||
"校准单个舵机位置。设置指定舵机的微调参数以调整ElectronBot的初始姿态,设置将永久保存。"
|
||||
"servo_type: 舵机类型(right_pitch:右臂旋转, right_roll:右臂推拉, left_pitch:左臂旋转, "
|
||||
"left_roll:左臂推拉, body:身体, head:头部); "
|
||||
"trim_value: 微调值(-30到30度)",
|
||||
PropertyList({Property("servo_type", kPropertyTypeString, "right_pitch"),
|
||||
Property("trim_value", kPropertyTypeInteger, 0, -30, 30)}),
|
||||
[this](const PropertyList& properties) -> ReturnValue {
|
||||
std::string servo_type = properties["servo_type"].value<std::string>();
|
||||
int trim_value = properties["trim_value"].value<int>();
|
||||
|
||||
ESP_LOGI(TAG, "设置舵机微调: %s = %d度", servo_type.c_str(), trim_value);
|
||||
|
||||
// 获取当前所有微调值
|
||||
Settings settings("electron_trims", true);
|
||||
int right_pitch = settings.GetInt("right_pitch", 0);
|
||||
int right_roll = settings.GetInt("right_roll", 0);
|
||||
int left_pitch = settings.GetInt("left_pitch", 0);
|
||||
int left_roll = settings.GetInt("left_roll", 0);
|
||||
int body = settings.GetInt("body", 0);
|
||||
int head = settings.GetInt("head", 0);
|
||||
|
||||
// 更新指定舵机的微调值
|
||||
if (servo_type == "right_pitch") {
|
||||
right_pitch = trim_value;
|
||||
settings.SetInt("right_pitch", right_pitch);
|
||||
} else if (servo_type == "right_roll") {
|
||||
right_roll = trim_value;
|
||||
settings.SetInt("right_roll", right_roll);
|
||||
} else if (servo_type == "left_pitch") {
|
||||
left_pitch = trim_value;
|
||||
settings.SetInt("left_pitch", left_pitch);
|
||||
} else if (servo_type == "left_roll") {
|
||||
left_roll = trim_value;
|
||||
settings.SetInt("left_roll", left_roll);
|
||||
} else if (servo_type == "body") {
|
||||
body = trim_value;
|
||||
settings.SetInt("body", body);
|
||||
} else if (servo_type == "head") {
|
||||
head = trim_value;
|
||||
settings.SetInt("head", head);
|
||||
} else {
|
||||
return "错误:无效的舵机类型,请使用: right_pitch, right_roll, left_pitch, "
|
||||
"left_roll, body, head";
|
||||
}
|
||||
|
||||
electron_bot_.SetTrims(right_pitch, right_roll, left_pitch, left_roll, body, head);
|
||||
|
||||
QueueAction(ACTION_HOME, 1, 500, 0, 0);
|
||||
|
||||
return "舵机 " + servo_type + " 微调设置为 " + std::to_string(trim_value) +
|
||||
" 度,已永久保存";
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.electron.get_trims", "获取当前的舵机微调设置", PropertyList(),
|
||||
[this](const PropertyList& properties) -> ReturnValue {
|
||||
Settings settings("electron_trims", false);
|
||||
|
||||
int right_pitch = settings.GetInt("right_pitch", 0);
|
||||
int right_roll = settings.GetInt("right_roll", 0);
|
||||
int left_pitch = settings.GetInt("left_pitch", 0);
|
||||
int left_roll = settings.GetInt("left_roll", 0);
|
||||
int body = settings.GetInt("body", 0);
|
||||
int head = settings.GetInt("head", 0);
|
||||
|
||||
std::string result =
|
||||
"{\"right_pitch\":" + std::to_string(right_pitch) +
|
||||
",\"right_roll\":" + std::to_string(right_roll) +
|
||||
",\"left_pitch\":" + std::to_string(left_pitch) +
|
||||
",\"left_roll\":" + std::to_string(left_roll) +
|
||||
",\"body\":" + std::to_string(body) +
|
||||
",\"head\":" + std::to_string(head) + "}";
|
||||
|
||||
ESP_LOGI(TAG, "获取微调设置: %s", result.c_str());
|
||||
return result;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.battery.get_level", "获取机器人电池电量和充电状态", PropertyList(),
|
||||
[](const PropertyList& properties) -> ReturnValue {
|
||||
auto& board = Board::GetInstance();
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "font_awesome_symbols.h"
|
||||
|
||||
#define TAG "ElectronEmojiDisplay"
|
||||
|
||||
@@ -68,7 +71,7 @@ void ElectronEmojiDisplay::SetupGifContainer() {
|
||||
lv_obj_del(content_);
|
||||
}
|
||||
|
||||
lv_obj_t* content_ = lv_obj_create(container_);
|
||||
content_ = lv_obj_create(container_);
|
||||
lv_obj_set_scrollbar_mode(content_, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_obj_set_size(content_, LV_HOR_RES, LV_HOR_RES);
|
||||
lv_obj_set_style_bg_opa(content_, LV_OPA_TRANSP, 0);
|
||||
@@ -141,4 +144,27 @@ void ElectronEmojiDisplay::SetChatMessage(const char* role, const char* content)
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置聊天消息 [%s]: %s", role, content);
|
||||
}
|
||||
|
||||
void ElectronEmojiDisplay::SetIcon(const char* icon) {
|
||||
if (!icon) {
|
||||
return;
|
||||
}
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
|
||||
if (chat_message_label_ != nullptr) {
|
||||
std::string icon_message = std::string(icon) + " ";
|
||||
|
||||
if (strcmp(icon, FONT_AWESOME_DOWNLOAD) == 0) {
|
||||
icon_message += "正在升级...";
|
||||
} else {
|
||||
icon_message += "系统状态";
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, icon_message.c_str());
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置图标: %s", icon);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,9 @@ public:
|
||||
// 重写聊天消息设置方法
|
||||
virtual void SetChatMessage(const char* role, const char* content) override;
|
||||
|
||||
// 重写图标设置方法
|
||||
virtual void SetIcon(const char* icon) override;
|
||||
|
||||
private:
|
||||
void SetupGifContainer();
|
||||
|
||||
|
||||
@@ -55,6 +55,25 @@ void Otto::DetachServos() {
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//-- OSCILLATORS TRIMS ------------------------------------------//
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void Otto::SetTrims(int right_pitch, int right_roll, int left_pitch, int left_roll, int body,
|
||||
int head) {
|
||||
servo_trim_[RIGHT_PITCH] = right_pitch;
|
||||
servo_trim_[RIGHT_ROLL] = right_roll;
|
||||
servo_trim_[LEFT_PITCH] = left_pitch;
|
||||
servo_trim_[LEFT_ROLL] = left_roll;
|
||||
servo_trim_[BODY] = body;
|
||||
servo_trim_[HEAD] = head;
|
||||
|
||||
for (int i = 0; i < SERVO_COUNT; i++) {
|
||||
if (servo_pins_[i] != -1) {
|
||||
servo_[i].SetTrim(servo_trim_[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//-- BASIC MOTION FUNCTIONS -------------------------------------//
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM=0",
|
||||
"CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=n",
|
||||
"CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y",
|
||||
"CONFIG_ESP_MAIN_TASK_STACK_SIZE=6144",
|
||||
"CONFIG_ESP_MAIN_TASK_STACK_SIZE=7168",
|
||||
"CONFIG_FREERTOS_HZ=1000",
|
||||
"CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=768",
|
||||
"CONFIG_LWIP_MAX_SOCKETS=10",
|
||||
@@ -28,7 +28,8 @@
|
||||
"CONFIG_MMAP_FILE_NAME_LENGTH=25",
|
||||
"CONFIG_ESP_CONSOLE_NONE=y",
|
||||
"CONFIG_USE_ESP_WAKE_WORD=y",
|
||||
"CONFIG_IOT_PROTOCOL_MCP=y"
|
||||
"CONFIG_IOT_PROTOCOL_MCP=y",
|
||||
"CONFIG_COMPILER_OPTIMIZATION_SIZE=y"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -85,17 +85,28 @@ private:
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) {
|
||||
EspHi* instance = static_cast<EspHi*>(arg);
|
||||
if (!instance->web_server_initialized_) {
|
||||
ESP_LOGI(TAG, "WiFi connected, init web control server");
|
||||
esp_err_t err = esp_hi_web_control_server_init();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to initialize web control server: %d", err);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Web control server initialized");
|
||||
instance->web_server_initialized_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
xTaskCreate(
|
||||
[](void* arg) {
|
||||
EspHi* instance = static_cast<EspHi*>(arg);
|
||||
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
|
||||
if (!instance->web_server_initialized_) {
|
||||
ESP_LOGI(TAG, "WiFi connected, init web control server");
|
||||
esp_err_t err = esp_hi_web_control_server_init();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to initialize web control server: %d", err);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Web control server initialized");
|
||||
instance->web_server_initialized_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
},
|
||||
"web_server_init",
|
||||
1024 * 10, arg, 5, nullptr);
|
||||
}
|
||||
}
|
||||
#endif //CONFIG_ESP_HI_WEB_CONTROL_ENABLED
|
||||
@@ -289,69 +300,58 @@ private:
|
||||
auto& mcp_server = McpServer::GetInstance();
|
||||
|
||||
// 基础动作控制
|
||||
mcp_server.AddTool("self.dog.forward", "机器人向前移动", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_FORWARD, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.backward", "机器人向后移动", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_BACKWARD, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.sway_back_forth", "机器人做前后摇摆动作", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_SWAY_BACK_FORTH, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.turn_left", "机器人向左转", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_TURN_LEFT, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.turn_right", "机器人向右转", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_TURN_RIGHT, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.lay_down", "机器人趴下", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_LAY_DOWN, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.sway", "机器人做左右摇摆动作", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
dog_action_args_t args = {
|
||||
.repeat_count = 4,
|
||||
};
|
||||
servo_dog_ctrl_send(DOG_STATE_SWAY, &args);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.basic_control", "机器人的基础动作。机器人可以做以下基础动作:\n"
|
||||
"forward: 向前移动\nbackward: 向后移动\nturn_left: 向左转\nturn_right: 向右转\nstop: 立即停止当前动作",
|
||||
PropertyList({
|
||||
Property("action", kPropertyTypeString),
|
||||
}), [this](const PropertyList& properties) -> ReturnValue {
|
||||
const std::string& action = properties["action"].value<std::string>();
|
||||
if (action == "forward") {
|
||||
servo_dog_ctrl_send(DOG_STATE_FORWARD, NULL);
|
||||
} else if (action == "backward") {
|
||||
servo_dog_ctrl_send(DOG_STATE_BACKWARD, NULL);
|
||||
} else if (action == "turn_left") {
|
||||
servo_dog_ctrl_send(DOG_STATE_TURN_LEFT, NULL);
|
||||
} else if (action == "turn_right") {
|
||||
servo_dog_ctrl_send(DOG_STATE_TURN_RIGHT, NULL);
|
||||
} else if (action == "stop") {
|
||||
servo_dog_ctrl_send(DOG_STATE_IDLE, NULL);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// 扩展动作控制
|
||||
mcp_server.AddTool("self.dog.retract_legs", "机器人收回腿部", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_RETRACT_LEGS, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.stop", "立即停止机器人当前动作", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_IDLE, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.shake_hand", "机器人做握手动作", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_SHAKE_HAND, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.shake_back_legs", "机器人伸懒腰", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_SHAKE_BACK_LEGS, NULL);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.dog.jump_forward", "机器人向前跳跃", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
servo_dog_ctrl_send(DOG_STATE_JUMP_FORWARD, NULL);
|
||||
return true;
|
||||
});
|
||||
mcp_server.AddTool("self.dog.advanced_control", "机器人的扩展动作。机器人可以做以下扩展动作:\n"
|
||||
"sway_back_forth: 前后摇摆\nlay_down: 趴下\nsway: 左右摇摆\nretract_legs: 收回腿部\n"
|
||||
"shake_hand: 握手\nshake_back_legs: 伸懒腰\njump_forward: 向前跳跃",
|
||||
PropertyList({
|
||||
Property("action", kPropertyTypeString),
|
||||
}), [this](const PropertyList& properties) -> ReturnValue {
|
||||
const std::string& action = properties["action"].value<std::string>();
|
||||
if (action == "sway_back_forth") {
|
||||
servo_dog_ctrl_send(DOG_STATE_SWAY_BACK_FORTH, NULL);
|
||||
} else if (action == "lay_down") {
|
||||
servo_dog_ctrl_send(DOG_STATE_LAY_DOWN, NULL);
|
||||
} else if (action == "sway") {
|
||||
dog_action_args_t args = {
|
||||
.repeat_count = 4,
|
||||
};
|
||||
servo_dog_ctrl_send(DOG_STATE_SWAY, &args);
|
||||
} else if (action == "retract_legs") {
|
||||
servo_dog_ctrl_send(DOG_STATE_RETRACT_LEGS, NULL);
|
||||
} else if (action == "shake_hand") {
|
||||
servo_dog_ctrl_send(DOG_STATE_SHAKE_HAND, NULL);
|
||||
} else if (action == "shake_back_legs") {
|
||||
servo_dog_ctrl_send(DOG_STATE_SHAKE_BACK_LEGS, NULL);
|
||||
} else if (action == "jump_forward") {
|
||||
servo_dog_ctrl_send(DOG_STATE_JUMP_FORWARD, NULL);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// 灯光控制
|
||||
mcp_server.AddTool("self.light.get_power", "获取灯是否打开", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
"sdkconfig_append": [
|
||||
"CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y",
|
||||
"CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"partitions/v1/8m.csv\"",
|
||||
"CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=n",
|
||||
"CONFIG_LWIP_IPV6=n",
|
||||
"CONFIG_USE_ESP_WAKE_WORD=y"
|
||||
"CONFIG_USE_ESP_WAKE_WORD=y",
|
||||
"CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
{
|
||||
"name": "lichuang-dev",
|
||||
"sdkconfig_append": [
|
||||
"CONFIG_USE_DEVICE_AEC=y",
|
||||
"CONFIG_SR_NSN_NSNET2=y"
|
||||
"CONFIG_USE_DEVICE_AEC=y"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,6 +47,6 @@
|
||||
|
||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||
|
||||
#define OTTO_ROBOT_VERSION "1.4.2"
|
||||
#define OTTO_ROBOT_VERSION "1.4.4"
|
||||
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "mcp_server.h"
|
||||
#include "otto_movements.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "settings.h"
|
||||
|
||||
#define TAG "OttoController"
|
||||
|
||||
@@ -48,7 +49,8 @@ private:
|
||||
ACTION_FLAPPING = 13,
|
||||
ACTION_HANDS_UP = 14,
|
||||
ACTION_HANDS_DOWN = 15,
|
||||
ACTION_HAND_WAVE = 16
|
||||
ACTION_HAND_WAVE = 16,
|
||||
ACTION_HOME = 17
|
||||
};
|
||||
|
||||
static void ActionTask(void* arg) {
|
||||
@@ -121,11 +123,16 @@ private:
|
||||
controller->otto_.HandWave(params.speed, params.direction);
|
||||
}
|
||||
break;
|
||||
case ACTION_HOME:
|
||||
controller->otto_.Home(params.direction == 1);
|
||||
break;
|
||||
}
|
||||
if (params.action_type != ACTION_HOME) {
|
||||
controller->otto_.Home(params.action_type < ACTION_HANDS_UP);
|
||||
}
|
||||
controller->otto_.Home(params.action_type < ACTION_HANDS_UP);
|
||||
controller->is_action_in_progress_ = false;
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +158,22 @@ private:
|
||||
StartActionTaskIfNeeded();
|
||||
}
|
||||
|
||||
void LoadTrimsFromNVS() {
|
||||
Settings settings("otto_trims", false);
|
||||
|
||||
int left_leg = settings.GetInt("left_leg", 0);
|
||||
int right_leg = settings.GetInt("right_leg", 0);
|
||||
int left_foot = settings.GetInt("left_foot", 0);
|
||||
int right_foot = settings.GetInt("right_foot", 0);
|
||||
int left_hand = settings.GetInt("left_hand", 0);
|
||||
int right_hand = settings.GetInt("right_hand", 0);
|
||||
|
||||
ESP_LOGI(TAG, "从NVS加载微调设置: 左腿=%d, 右腿=%d, 左脚=%d, 右脚=%d, 左手=%d, 右手=%d",
|
||||
left_leg, right_leg, left_foot, right_foot, left_hand, right_hand);
|
||||
|
||||
otto_.SetTrims(left_leg, right_leg, left_foot, right_foot, left_hand, right_hand);
|
||||
}
|
||||
|
||||
public:
|
||||
OttoController() {
|
||||
otto_.Init(LEFT_LEG_PIN, RIGHT_LEG_PIN, LEFT_FOOT_PIN, RIGHT_FOOT_PIN, LEFT_HAND_PIN,
|
||||
@@ -159,9 +182,12 @@ public:
|
||||
has_hands_ = (LEFT_HAND_PIN != -1 && RIGHT_HAND_PIN != -1);
|
||||
ESP_LOGI(TAG, "Otto机器人初始化%s手部舵机", has_hands_ ? "带" : "不带");
|
||||
|
||||
otto_.Home(true);
|
||||
LoadTrimsFromNVS();
|
||||
|
||||
action_queue_ = xQueueCreate(10, sizeof(OttoActionParams));
|
||||
|
||||
QueueAction(ACTION_HOME, 1, 1000, 1, 0); // direction=1表示复位手部
|
||||
|
||||
RegisterMcpTools();
|
||||
}
|
||||
|
||||
@@ -338,10 +364,94 @@ public:
|
||||
}
|
||||
is_action_in_progress_ = false;
|
||||
xQueueReset(action_queue_);
|
||||
otto_.Home(true);
|
||||
|
||||
QueueAction(ACTION_HOME, 1, 1000, 1, 0);
|
||||
return true;
|
||||
});
|
||||
|
||||
mcp_server.AddTool(
|
||||
"self.otto.set_trim",
|
||||
"校准单个舵机位置。设置指定舵机的微调参数以调整Otto的初始站立姿态,设置将永久保存。"
|
||||
"servo_type: 舵机类型(left_leg/right_leg/left_foot/right_foot/left_hand/right_hand); "
|
||||
"trim_value: 微调值(-50到50度)",
|
||||
PropertyList({Property("servo_type", kPropertyTypeString, "left_leg"),
|
||||
Property("trim_value", kPropertyTypeInteger, 0, -50, 50)}),
|
||||
[this](const PropertyList& properties) -> ReturnValue {
|
||||
std::string servo_type = properties["servo_type"].value<std::string>();
|
||||
int trim_value = properties["trim_value"].value<int>();
|
||||
|
||||
ESP_LOGI(TAG, "设置舵机微调: %s = %d度", servo_type.c_str(), trim_value);
|
||||
|
||||
// 获取当前所有微调值
|
||||
Settings settings("otto_trims", true);
|
||||
int left_leg = settings.GetInt("left_leg", 0);
|
||||
int right_leg = settings.GetInt("right_leg", 0);
|
||||
int left_foot = settings.GetInt("left_foot", 0);
|
||||
int right_foot = settings.GetInt("right_foot", 0);
|
||||
int left_hand = settings.GetInt("left_hand", 0);
|
||||
int right_hand = settings.GetInt("right_hand", 0);
|
||||
|
||||
// 更新指定舵机的微调值
|
||||
if (servo_type == "left_leg") {
|
||||
left_leg = trim_value;
|
||||
settings.SetInt("left_leg", left_leg);
|
||||
} else if (servo_type == "right_leg") {
|
||||
right_leg = trim_value;
|
||||
settings.SetInt("right_leg", right_leg);
|
||||
} else if (servo_type == "left_foot") {
|
||||
left_foot = trim_value;
|
||||
settings.SetInt("left_foot", left_foot);
|
||||
} else if (servo_type == "right_foot") {
|
||||
right_foot = trim_value;
|
||||
settings.SetInt("right_foot", right_foot);
|
||||
} else if (servo_type == "left_hand") {
|
||||
if (!has_hands_) {
|
||||
return "错误:机器人没有配置手部舵机";
|
||||
}
|
||||
left_hand = trim_value;
|
||||
settings.SetInt("left_hand", left_hand);
|
||||
} else if (servo_type == "right_hand") {
|
||||
if (!has_hands_) {
|
||||
return "错误:机器人没有配置手部舵机";
|
||||
}
|
||||
right_hand = trim_value;
|
||||
settings.SetInt("right_hand", right_hand);
|
||||
} else {
|
||||
return "错误:无效的舵机类型,请使用: left_leg, right_leg, left_foot, "
|
||||
"right_foot, left_hand, right_hand";
|
||||
}
|
||||
|
||||
otto_.SetTrims(left_leg, right_leg, left_foot, right_foot, left_hand, right_hand);
|
||||
|
||||
QueueAction(ACTION_JUMP, 1, 500, 0, 0);
|
||||
|
||||
return "舵机 " + servo_type + " 微调设置为 " + std::to_string(trim_value) +
|
||||
" 度,已永久保存";
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.otto.get_trims", "获取当前的舵机微调设置", PropertyList(),
|
||||
[this](const PropertyList& properties) -> ReturnValue {
|
||||
Settings settings("otto_trims", false);
|
||||
|
||||
int left_leg = settings.GetInt("left_leg", 0);
|
||||
int right_leg = settings.GetInt("right_leg", 0);
|
||||
int left_foot = settings.GetInt("left_foot", 0);
|
||||
int right_foot = settings.GetInt("right_foot", 0);
|
||||
int left_hand = settings.GetInt("left_hand", 0);
|
||||
int right_hand = settings.GetInt("right_hand", 0);
|
||||
|
||||
std::string result =
|
||||
"{\"left_leg\":" + std::to_string(left_leg) +
|
||||
",\"right_leg\":" + std::to_string(right_leg) +
|
||||
",\"left_foot\":" + std::to_string(left_foot) +
|
||||
",\"right_foot\":" + std::to_string(right_foot) +
|
||||
",\"left_hand\":" + std::to_string(left_hand) +
|
||||
",\"right_hand\":" + std::to_string(right_hand) + "}";
|
||||
|
||||
ESP_LOGI(TAG, "获取微调设置: %s", result.c_str());
|
||||
return result;
|
||||
});
|
||||
|
||||
mcp_server.AddTool("self.otto.get_status", "获取机器人状态,返回 moving 或 idle",
|
||||
PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
|
||||
return is_action_in_progress_ ? "moving" : "idle";
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "display/lcd_display.h"
|
||||
#include "font_awesome_symbols.h"
|
||||
|
||||
#define TAG "OttoEmojiDisplay"
|
||||
|
||||
// 表情映射表 - 将原版21种表情映射到现有6个GIF
|
||||
@@ -143,3 +146,26 @@ void OttoEmojiDisplay::SetChatMessage(const char* role, const char* content) {
|
||||
|
||||
ESP_LOGI(TAG, "设置聊天消息 [%s]: %s", role, content);
|
||||
}
|
||||
|
||||
void OttoEmojiDisplay::SetIcon(const char* icon) {
|
||||
if (!icon) {
|
||||
return;
|
||||
}
|
||||
|
||||
DisplayLockGuard lock(this);
|
||||
|
||||
if (chat_message_label_ != nullptr) {
|
||||
std::string icon_message = std::string(icon) + " ";
|
||||
|
||||
if (strcmp(icon, FONT_AWESOME_DOWNLOAD) == 0) {
|
||||
icon_message += "正在升级...";
|
||||
} else {
|
||||
icon_message += "系统状态";
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, icon_message.c_str());
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置图标: %s", icon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ public:
|
||||
// 重写聊天消息设置方法
|
||||
virtual void SetChatMessage(const char* role, const char* content) override;
|
||||
|
||||
// 添加SetIcon方法声明
|
||||
virtual void SetIcon(const char* icon) override;
|
||||
|
||||
private:
|
||||
void SetupGifContainer();
|
||||
|
||||
|
||||
49
main/boards/waveshare-c6-lcd-1.69/README.md
Normal file
49
main/boards/waveshare-c6-lcd-1.69/README.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# 产品链接
|
||||
|
||||
[微雪电子 ESP32-C6-Touch-LCD-1.69](https://www.waveshare.net/shop/ESP32-C6-Touch-LCD-1.69.htm)
|
||||
[微雪电子 ESP32-C6-LCD-1.69](https://www.waveshare.net/shop/ESP32-C6-LCD-1.69.htm)
|
||||
|
||||
# 编译配置命令
|
||||
|
||||
**克隆工程**
|
||||
|
||||
```bash
|
||||
git clone https://github.com/78/xiaozhi-esp32.git
|
||||
```
|
||||
|
||||
**进入工程**
|
||||
|
||||
```bash
|
||||
cd xiaozhi-esp32
|
||||
```
|
||||
|
||||
**配置编译目标为 ESP32C6**
|
||||
|
||||
```bash
|
||||
idf.py set-target esp32c6
|
||||
```
|
||||
|
||||
**打开 menuconfig**
|
||||
|
||||
```bash
|
||||
idf.py menuconfig
|
||||
```
|
||||
|
||||
**选择板子**
|
||||
|
||||
```bash
|
||||
Xiaozhi Assistant -> Board Type -> Waveshare ESP32-C6-LCD-1.69
|
||||
```
|
||||
|
||||
**编译**
|
||||
|
||||
```ba
|
||||
idf.py build
|
||||
```
|
||||
|
||||
**下载并打开串口终端**
|
||||
|
||||
```bash
|
||||
idf.py build flash monitor
|
||||
```
|
||||
|
||||
50
main/boards/waveshare-c6-lcd-1.69/config.h
Normal file
50
main/boards/waveshare-c6-lcd-1.69/config.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef _BOARD_CONFIG_H_
|
||||
#define _BOARD_CONFIG_H_
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_master.h>
|
||||
|
||||
#define AUDIO_INPUT_SAMPLE_RATE 24000
|
||||
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
|
||||
|
||||
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_19
|
||||
#define AUDIO_I2S_GPIO_WS GPIO_NUM_22
|
||||
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_20
|
||||
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_21
|
||||
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_23
|
||||
|
||||
#define AUDIO_CODEC_PA_PIN GPIO_NUM_NC
|
||||
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_8
|
||||
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_7
|
||||
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
|
||||
|
||||
#define BUILTIN_LED_GPIO GPIO_NUM_NC
|
||||
#define BOOT_BUTTON_GPIO GPIO_NUM_9
|
||||
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC
|
||||
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC
|
||||
|
||||
#define DISPLAY_SPI_MODE 3
|
||||
#define DISPLAY_CS_PIN GPIO_NUM_5
|
||||
#define DISPLAY_MOSI_PIN GPIO_NUM_2
|
||||
#define DISPLAY_MISO_PIN GPIO_NUM_NC
|
||||
#define DISPLAY_CLK_PIN GPIO_NUM_1
|
||||
#define DISPLAY_DC_PIN GPIO_NUM_3
|
||||
#define DISPLAY_RST_PIN GPIO_NUM_4
|
||||
|
||||
|
||||
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 280
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 20
|
||||
|
||||
#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_6
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
11
main/boards/waveshare-c6-lcd-1.69/config.json
Normal file
11
main/boards/waveshare-c6-lcd-1.69/config.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"target": "esp32c6",
|
||||
"builds": [
|
||||
{
|
||||
"name": "waveshare-c6-lcd-1.69",
|
||||
"sdkconfig_append": [
|
||||
"CONFIG_USE_ESP_WAKE_WORD=y"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
190
main/boards/waveshare-c6-lcd-1.69/esp32-c6-lcd-1.69.cc
Normal file
190
main/boards/waveshare-c6-lcd-1.69/esp32-c6-lcd-1.69.cc
Normal file
@@ -0,0 +1,190 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/es8311_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "system_reset.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "iot/thing_manager.h"
|
||||
|
||||
|
||||
#include <esp_log.h>
|
||||
#include "i2c_device.h"
|
||||
#include <driver/i2c_master.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <wifi_station.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
|
||||
#include <esp_timer.h>
|
||||
|
||||
|
||||
|
||||
#define TAG "waveshare_lcd_1_69"
|
||||
|
||||
|
||||
LV_FONT_DECLARE(font_puhui_20_4);
|
||||
LV_FONT_DECLARE(font_awesome_20_4);
|
||||
|
||||
|
||||
class CustomLcdDisplay : public SpiLcdDisplay {
|
||||
public:
|
||||
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,
|
||||
{
|
||||
.text_font = &font_puhui_20_4,
|
||||
.icon_font = &font_awesome_20_4,
|
||||
#if CONFIG_USE_WECHAT_MESSAGE_STYLE
|
||||
.emoji_font = font_emoji_32_init(),
|
||||
#else
|
||||
.emoji_font = font_emoji_64_init(),
|
||||
#endif
|
||||
}) {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CustomBoard : public WifiBoard {
|
||||
private:
|
||||
Button boot_button_;
|
||||
i2c_master_bus_handle_t i2c_bus_;
|
||||
LcdDisplay* display_;
|
||||
|
||||
void InitializeI2c() {
|
||||
// Initialize I2C peripheral
|
||||
i2c_master_bus_config_t i2c_bus_cfg = {
|
||||
.i2c_port = (i2c_port_t)I2C_NUM_0,
|
||||
.sda_io_num = AUDIO_CODEC_I2C_SDA_PIN,
|
||||
.scl_io_num = AUDIO_CODEC_I2C_SCL_PIN,
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.intr_priority = 0,
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
.enable_internal_pullup = 1,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
|
||||
}
|
||||
|
||||
void InitializeSpi() {
|
||||
ESP_LOGI(TAG, "Initialize QSPI bus");
|
||||
spi_bus_config_t buscfg = {};
|
||||
buscfg.mosi_io_num = DISPLAY_MOSI_PIN;
|
||||
buscfg.miso_io_num = DISPLAY_MISO_PIN;
|
||||
buscfg.sclk_io_num = DISPLAY_CLK_PIN;
|
||||
buscfg.quadwp_io_num = GPIO_NUM_NC;
|
||||
buscfg.quadhd_io_num = GPIO_NUM_NC;
|
||||
buscfg.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t);
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
}
|
||||
|
||||
void InitializeLcdDisplay() {
|
||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||
esp_lcd_panel_handle_t panel = nullptr;
|
||||
// 液晶屏控制IO初始化
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_spi_config_t io_config = {};
|
||||
io_config.cs_gpio_num = DISPLAY_CS_PIN;
|
||||
io_config.dc_gpio_num = DISPLAY_DC_PIN;
|
||||
io_config.spi_mode = DISPLAY_SPI_MODE;
|
||||
io_config.pclk_hz = 40 * 1000 * 1000;
|
||||
io_config.trans_queue_depth = 10;
|
||||
io_config.lcd_cmd_bits = 8;
|
||||
io_config.lcd_param_bits = 8;
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI2_HOST, &io_config, &panel_io));
|
||||
|
||||
|
||||
// 初始化液晶屏驱动芯片
|
||||
ESP_LOGI(TAG, "Install LCD driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
|
||||
panel_config.rgb_ele_order = DISPLAY_RGB_ORDER;
|
||||
panel_config.bits_per_pixel = 16;
|
||||
// panel_config.vendor_config = &st7796_vendor_config;
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
|
||||
|
||||
|
||||
esp_lcd_panel_reset(panel);
|
||||
|
||||
esp_lcd_panel_init(panel);
|
||||
esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR);
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
|
||||
|
||||
display_ = new CustomLcdDisplay(
|
||||
panel_io,
|
||||
panel,
|
||||
DISPLAY_WIDTH,
|
||||
DISPLAY_HEIGHT,
|
||||
DISPLAY_OFFSET_X,
|
||||
DISPLAY_OFFSET_Y,
|
||||
DISPLAY_MIRROR_X,
|
||||
DISPLAY_MIRROR_Y,
|
||||
DISPLAY_SWAP_XY
|
||||
);
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
app.ToggleChatState();
|
||||
});
|
||||
}
|
||||
|
||||
// 物联网初始化,添加对 AI 可见设备
|
||||
void InitializeIot() {
|
||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||
// thing_manager.AddThing(iot::CreateThing("Battery"));
|
||||
// thing_manager.AddThing(iot::CreateThing("BoardControl"));
|
||||
}
|
||||
|
||||
public:
|
||||
CustomBoard() :
|
||||
boot_button_(BOOT_BUTTON_GPIO) {
|
||||
InitializeI2c();
|
||||
InitializeSpi();
|
||||
InitializeLcdDisplay();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
GetBacklight()->RestoreBrightness();
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
static Es8311AudioCodec audio_codec(i2c_bus_, I2C_NUM_0, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN,
|
||||
AUDIO_CODEC_PA_PIN, AUDIO_CODEC_ES8311_ADDR);
|
||||
return &audio_codec;
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual Backlight* GetBacklight() override {
|
||||
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
|
||||
return &backlight;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(CustomBoard);
|
||||
@@ -6,7 +6,8 @@
|
||||
"sdkconfig_append": [
|
||||
"CONFIG_PM_ENABLE=y",
|
||||
"CONFIG_FREERTOS_USE_TICKLESS_IDLE=y",
|
||||
"CONFIG_USE_ESP_WAKE_WORD=y"
|
||||
"CONFIG_USE_ESP_WAKE_WORD=y",
|
||||
"CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -33,7 +33,11 @@ private:
|
||||
PowerSaveTimer* power_save_timer_ = nullptr;
|
||||
|
||||
void InitializePowerSaveTimer() {
|
||||
#if CONFIG_USE_ESP_WAKE_WORD
|
||||
power_save_timer_ = new PowerSaveTimer(160, 600);
|
||||
#else
|
||||
power_save_timer_ = new PowerSaveTimer(160, 60);
|
||||
#endif
|
||||
power_save_timer_->OnEnterSleepMode([this]() {
|
||||
ESP_LOGI(TAG, "Enabling sleep mode");
|
||||
auto display = GetDisplay();
|
||||
|
||||
@@ -5,7 +5,7 @@ dependencies:
|
||||
espressif/esp_lcd_gc9a01: ==2.0.1
|
||||
espressif/esp_lcd_st77916: ^1.0.1
|
||||
espressif/esp_lcd_st7796:
|
||||
version: '1.3.2'
|
||||
version: 1.3.2
|
||||
rules:
|
||||
- if: target not in [esp32c3]
|
||||
espressif/esp_lcd_spd2010: ==1.0.2
|
||||
@@ -14,7 +14,7 @@ dependencies:
|
||||
78/esp_lcd_nv3023: ~1.0.0
|
||||
78/esp-wifi-connect: ~2.4.2
|
||||
78/esp-opus-encoder: ~2.3.3
|
||||
78/esp-ml307: ~2.1.5
|
||||
78/esp-ml307: ~2.2.1
|
||||
78/xiaozhi-fonts: ~1.3.2
|
||||
espressif/led_strip: ^2.5.5
|
||||
espressif/esp_codec_dev: ~1.3.2
|
||||
@@ -30,9 +30,19 @@ dependencies:
|
||||
espressif/esp_io_expander_tca95xx_16bit: ^2.0.0
|
||||
espressif2022/image_player: ^1.1.0
|
||||
espressif/adc_mic: ^0.2.0
|
||||
espressif/esp_mmap_assets: ">=1.2"
|
||||
espressif/esp_mmap_assets: '>=1.2'
|
||||
txp666/otto-emoji-gif-component: ~1.0.2
|
||||
|
||||
# SenseCAP Watcher Board
|
||||
wvirgil123/esp_jpeg_simd:
|
||||
version: 1.0.0
|
||||
rules:
|
||||
- if: target in [esp32s3]
|
||||
wvirgil123/sscma_client:
|
||||
version: 1.0.2
|
||||
rules:
|
||||
- if: target in [esp32s3]
|
||||
|
||||
tny-robotics/sh1106-esp-idf:
|
||||
version: ^1.0.0
|
||||
rules:
|
||||
@@ -45,7 +55,7 @@ dependencies:
|
||||
waveshare/esp_lcd_st7703:
|
||||
version: '*'
|
||||
rules:
|
||||
- if: target in [esp32p4]
|
||||
- if: target in [esp32p4]
|
||||
espressif/esp_lcd_ili9881c:
|
||||
version: ^1.0.1
|
||||
rules:
|
||||
@@ -55,19 +65,9 @@ dependencies:
|
||||
rules:
|
||||
- if: target in [esp32p4]
|
||||
lijunru-hub/servo_dog_ctrl:
|
||||
version: '^0.1.6'
|
||||
version: ^0.1.6
|
||||
rules:
|
||||
- if: target in [esp32c3]
|
||||
|
||||
sscma_client:
|
||||
git: https://github.com/Seeed-Studio/SenseCAP-Watcher-Firmware.git
|
||||
path: components/sscma_client
|
||||
|
||||
esp_jpeg_simd:
|
||||
git: https://github.com/Seeed-Studio/SenseCAP-Watcher-Firmware.git
|
||||
path: components/esp_jpeg_simd
|
||||
rules:
|
||||
- if: target not in [esp32p4]
|
||||
|
||||
## Required IDF version
|
||||
idf:
|
||||
|
||||
@@ -205,7 +205,8 @@ void CircularStrip::OnStateChanged() {
|
||||
SetAllColor(color);
|
||||
break;
|
||||
}
|
||||
case kDeviceStateListening: {
|
||||
case kDeviceStateListening:
|
||||
case kDeviceStateAudioTesting: {
|
||||
StripColor color = { default_brightness_, low_brightness_, low_brightness_ };
|
||||
SetAllColor(color);
|
||||
break;
|
||||
|
||||
@@ -220,6 +220,7 @@ void GpioLed::OnStateChanged() {
|
||||
TurnOn();
|
||||
break;
|
||||
case kDeviceStateListening:
|
||||
case kDeviceStateAudioTesting:
|
||||
if (app.IsVoiceDetected()) {
|
||||
SetBrightness(HIGH_BRIGHTNESS);
|
||||
} else {
|
||||
|
||||
@@ -136,6 +136,7 @@ void SingleLed::OnStateChanged() {
|
||||
TurnOn();
|
||||
break;
|
||||
case kDeviceStateListening:
|
||||
case kDeviceStateAudioTesting:
|
||||
if (app.IsVoiceDetected()) {
|
||||
SetColor(HIGH_BRIGHTNESS, 0, 0);
|
||||
} else {
|
||||
|
||||
@@ -341,7 +341,7 @@ void McpServer::DoToolCall(int id, const std::string& tool_name, const cJSON* to
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
} catch (const std::exception& e) {
|
||||
ESP_LOGE(TAG, "tools/call: %s", e.what());
|
||||
ReplyError(id, e.what());
|
||||
return;
|
||||
@@ -358,7 +358,7 @@ void McpServer::DoToolCall(int id, const std::string& tool_name, const cJSON* to
|
||||
tool_call_thread_ = std::thread([this, id, tool_iter, arguments = std::move(arguments)]() {
|
||||
try {
|
||||
ReplyResult(id, (*tool_iter)->Call(arguments));
|
||||
} catch (const std::runtime_error& e) {
|
||||
} catch (const std::exception& e) {
|
||||
ESP_LOGE(TAG, "tools/call: %s", e.what());
|
||||
ReplyError(id, e.what());
|
||||
}
|
||||
|
||||
12
main/ota.cc
12
main/ota.cc
@@ -148,6 +148,10 @@ bool Ota::CheckVersion() {
|
||||
if (settings.GetString(item->string) != item->valuestring) {
|
||||
settings.SetString(item->string, item->valuestring);
|
||||
}
|
||||
} else if (cJSON_IsNumber(item)) {
|
||||
if (settings.GetInt(item->string) != item->valueint) {
|
||||
settings.SetInt(item->string, item->valueint);
|
||||
}
|
||||
}
|
||||
}
|
||||
has_mqtt_config_ = true;
|
||||
@@ -162,9 +166,13 @@ bool Ota::CheckVersion() {
|
||||
cJSON *item = NULL;
|
||||
cJSON_ArrayForEach(item, websocket) {
|
||||
if (cJSON_IsString(item)) {
|
||||
settings.SetString(item->string, item->valuestring);
|
||||
if (settings.GetString(item->string) != item->valuestring) {
|
||||
settings.SetString(item->string, item->valuestring);
|
||||
}
|
||||
} else if (cJSON_IsNumber(item)) {
|
||||
settings.SetInt(item->string, item->valueint);
|
||||
if (settings.GetInt(item->string) != item->valueint) {
|
||||
settings.SetInt(item->string, item->valueint);
|
||||
}
|
||||
}
|
||||
}
|
||||
has_websocket_config_ = true;
|
||||
|
||||
@@ -42,6 +42,7 @@ bool MqttProtocol::StartMqttClient(bool report_error) {
|
||||
auto client_id = settings.GetString("client_id");
|
||||
auto username = settings.GetString("username");
|
||||
auto password = settings.GetString("password");
|
||||
int keepalive_interval = settings.GetInt("keepalive", 120);
|
||||
publish_topic_ = settings.GetString("publish_topic");
|
||||
|
||||
if (endpoint.empty()) {
|
||||
@@ -53,7 +54,7 @@ bool MqttProtocol::StartMqttClient(bool report_error) {
|
||||
}
|
||||
|
||||
mqtt_ = Board::GetInstance().CreateMqtt();
|
||||
mqtt_->SetKeepAlive(90);
|
||||
mqtt_->SetKeepAlive(keepalive_interval);
|
||||
|
||||
mqtt_->OnDisconnected([this]() {
|
||||
ESP_LOGI(TAG, "Disconnected from endpoint");
|
||||
|
||||
@@ -82,6 +82,8 @@ def read_binary(dir_path):
|
||||
data = merged_bin_data[0x100000:]
|
||||
elif merged_bin_data[0x200000] == 0xE9:
|
||||
data = merged_bin_data[0x200000:]
|
||||
elif merged_bin_data[0xe0000] == 0xE9:
|
||||
data = merged_bin_data[0xe0000:]
|
||||
else:
|
||||
print(dir_path, "is not a valid image")
|
||||
return
|
||||
|
||||
7
sdkconfig.defaults.esp32
Normal file
7
sdkconfig.defaults.esp32
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions/v1/4m.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions/v1/4m.csv"
|
||||
CONFIG_SR_WN_WN9_NIHAOXIAOZHI_TTS=y
|
||||
CONFIG_ESP_TASK_WDT_TIMEOUT_S=20
|
||||
@@ -1,3 +1,13 @@
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
|
||||
CONFIG_SR_WN_WN9S_NIHAOXIAOZHI=y
|
||||
|
||||
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=3
|
||||
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=6
|
||||
CONFIG_ESP_WIFI_RX_BA_WIN=3
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
|
||||
CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=n
|
||||
CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM=0
|
||||
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=768
|
||||
CONFIG_LWIP_IPV6=n
|
||||
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=16
|
||||
4
sdkconfig.defaults.esp32c6
Normal file
4
sdkconfig.defaults.esp32c6
Normal file
@@ -0,0 +1,4 @@
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
|
||||
|
||||
CONFIG_SR_WN_WN9S_NIHAOXIAOZHI=y
|
||||
@@ -7,8 +7,8 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
|
||||
CONFIG_SPIRAM=y
|
||||
CONFIG_SPIRAM_MODE_OCT=y
|
||||
CONFIG_SPIRAM_SPEED_80M=y
|
||||
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=4096
|
||||
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=49152
|
||||
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=512
|
||||
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=65536
|
||||
CONFIG_SPIRAM_MEMTEST=n
|
||||
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
|
||||
|
||||
|
||||
Reference in New Issue
Block a user