forked from xiaozhi/xiaozhi-esp32
feat&fix: 小智云聊增加蓝牙功能 (#1732)
This commit is contained in:
@@ -186,9 +186,6 @@ void Es8388AudioCodec::EnableOutput(bool enable) {
|
||||
|
||||
// Set analog output volume to 0dB, default is -45dB
|
||||
uint8_t reg_val = 30; // 0dB
|
||||
if(input_reference_){
|
||||
reg_val = 27;
|
||||
}
|
||||
uint8_t regs[] = { 46, 47, 48, 49 }; // HP_LVOL, HP_RVOL, SPK_LVOL, SPK_RVOL
|
||||
for (uint8_t reg : regs) {
|
||||
ctrl_if_->write_reg(ctrl_if_, reg, 1, ®_val, 1);
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
> | 单手机配网 | X | ✓ |
|
||||
> | 扫码访问控制台 | X | ✓ |
|
||||
> | 繁日英文界面 | X | ✓ |
|
||||
> | 多语言支持 | X | ✓ |
|
||||
> | 外接蓝牙音箱 | X | ✓ |
|
||||
> | 多语言支持 | 需自行编译 | ✓ |
|
||||
> | 外接蓝牙音箱 | ✓ | ✓ |
|
||||
|
||||
# 编译配置命令
|
||||
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
|
||||
#define BOOT_BUTTON_PIN GPIO_NUM_2
|
||||
#define BOOT_5V_PIN GPIO_NUM_3 //5V升压输出
|
||||
#define BOOT_4G_PIN GPIO_NUM_5 //4G模块使能
|
||||
#define MON_BTLINK_PIN GPIO_NUM_4 //检测BT连接状态
|
||||
#define BOOT_4G5V_PIN GPIO_NUM_5 //4G模块供电
|
||||
#define BOOT_4GEN_PIN GPIO_NUM_6 //4G模块使能
|
||||
#define MON_BATT_PIN GPIO_NUM_43 //检测PMU电池指示
|
||||
#define MON_BATT_CNT 70 //检测PMU电池秒数
|
||||
#define MON_USB_PIN GPIO_NUM_47 //检测USB插入
|
||||
@@ -49,7 +51,7 @@
|
||||
#define DISPLAY_SWAP_XY true
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y true
|
||||
#define DISPLAY_INVERT_COLOR false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER_COLOR LCD_RGB_ELEMENT_ORDER_RGB
|
||||
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
|
||||
@@ -42,6 +42,8 @@ static void calBattLife() {
|
||||
}
|
||||
|
||||
PowerManager::PowerManager(){
|
||||
m_bt_task_handle = nullptr;
|
||||
bt_link_callback_ = nullptr;
|
||||
}
|
||||
|
||||
void PowerManager::Initialize(){
|
||||
@@ -57,7 +59,7 @@ void PowerManager::Initialize(){
|
||||
|
||||
// 初始化4G控制引脚
|
||||
gpio_config_t io_conf_4g = {
|
||||
.pin_bit_mask = 1<<BOOT_4G_PIN,
|
||||
.pin_bit_mask = (1<<BOOT_4G5V_PIN) | (1<<BOOT_4GEN_PIN),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_ENABLE,
|
||||
@@ -175,19 +177,28 @@ void PowerManager::Shutdown5V() {
|
||||
}
|
||||
|
||||
void PowerManager::Start4G() {
|
||||
gpio_set_level(BOOT_4G_PIN, 1);
|
||||
gpio_set_level(BOOT_4G5V_PIN, 1);
|
||||
}
|
||||
|
||||
void PowerManager::Shutdown4G() {
|
||||
gpio_set_level(BOOT_4G_PIN, 0);
|
||||
gpio_set_level(BOOT_4G5V_PIN, 0);
|
||||
gpio_set_level(ML307_RX_PIN,1);
|
||||
gpio_set_level(ML307_TX_PIN,1);
|
||||
}
|
||||
|
||||
void PowerManager::Enable4G() {
|
||||
gpio_set_level(BOOT_4GEN_PIN, 1);
|
||||
}
|
||||
|
||||
void PowerManager::Disable4G() {
|
||||
gpio_set_level(BOOT_4GEN_PIN, 0);
|
||||
}
|
||||
|
||||
void PowerManager::Sleep() {
|
||||
ESP_LOGI(TAG, "Entering deep sleep");
|
||||
Settings settings("board", true);
|
||||
settings.SetInt("sleep_flag", 1);
|
||||
Disable4G();
|
||||
Shutdown4G();
|
||||
Shutdown5V();
|
||||
|
||||
@@ -200,4 +211,68 @@ void PowerManager::Sleep() {
|
||||
ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(BOOT_BUTTON_PIN));
|
||||
ESP_ERROR_CHECK(rtc_gpio_pullup_en(BOOT_BUTTON_PIN));
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
void PowerManager::InitializeBtModul() {
|
||||
if (MON_BTLINK_PIN == GPIO_NUM_NC) {
|
||||
ESP_LOGW(TAG, "MON_BTLINK_PIN not configured, skipping GPIO polling setup");
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_config_t io_conf = {};
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.pin_bit_mask = (1ULL << MON_BTLINK_PIN);
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
if (gpio_config(&io_conf) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to configure GPIO %d", MON_BTLINK_PIN);
|
||||
return;
|
||||
}
|
||||
BaseType_t ret = xTaskCreate(BtTask, "bt_task", 2048, this, 10, &m_bt_task_handle);
|
||||
if (ret != pdPASS) {
|
||||
ESP_LOGE(TAG, "Failed to create BT task");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerManager::DeinitBtModul() {
|
||||
if (MON_BTLINK_PIN == GPIO_NUM_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_bt_task_handle != nullptr) {
|
||||
vTaskDelete(m_bt_task_handle);
|
||||
m_bt_task_handle = nullptr;
|
||||
}
|
||||
|
||||
gpio_reset_pin(MON_BTLINK_PIN);
|
||||
}
|
||||
|
||||
void PowerManager::BtTask(void *arg) {
|
||||
PowerManager *instance = static_cast<PowerManager *>(arg);
|
||||
int last_level = -1;
|
||||
for (;;) {
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
int level = gpio_get_level(MON_BTLINK_PIN);
|
||||
if (level != last_level) {
|
||||
last_level = level;
|
||||
if (level == 1) {
|
||||
ESP_LOGI(TAG, "BTLINK %d high - BT connected", MON_BTLINK_PIN);
|
||||
if (instance->bt_link_callback_) {
|
||||
instance->bt_link_callback_(true);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGI(TAG, "BTLINK %d low - BT disconnected", MON_BTLINK_PIN);
|
||||
if (instance->bt_link_callback_) {
|
||||
instance->bt_link_callback_(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void PowerManager::OnBtLinkStatusChanged(std::function<void(bool)> callback) {
|
||||
bt_link_callback_ = callback;
|
||||
}
|
||||
@@ -21,17 +21,25 @@ public:
|
||||
void Shutdown5V();
|
||||
void Start4G();
|
||||
void Shutdown4G();
|
||||
void Enable4G();
|
||||
void Disable4G();
|
||||
void Sleep();
|
||||
void CheckBatteryStatus();
|
||||
void OnChargingStatusChanged(std::function<void(bool)> callback);
|
||||
void OnChargingStatusDisChanged(std::function<void(bool)> callback);
|
||||
void OnBtLinkStatusChanged(std::function<void(bool)> callback);
|
||||
void InitializeBtModul();
|
||||
void DeinitBtModul();
|
||||
private:
|
||||
esp_timer_handle_t timer_handle_;
|
||||
std::function<void(bool)> charging_callback_;
|
||||
std::function<void(bool)> discharging_callback_;
|
||||
std::function<void(bool)> bt_link_callback_;
|
||||
int is_charging_ = -1;
|
||||
int is_discharging_ = -1;
|
||||
int call_count_ = 0;
|
||||
TaskHandle_t m_bt_task_handle;
|
||||
static void BtTask(void *arg);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -153,6 +153,8 @@ class YunliaoS3 : public DualNetworkBoard {
|
||||
}), [this](const PropertyList& properties) {
|
||||
bool enable = properties["enable"].value<bool>();
|
||||
SetAecMode(enable);
|
||||
Settings settings("aec", true);
|
||||
settings.SetInt("mode", enable);
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -169,8 +171,6 @@ class YunliaoS3 : public DualNetworkBoard {
|
||||
app.StopListening();
|
||||
app.SetDeviceState(kDeviceStateIdle);
|
||||
app.SetAecMode(newMode);
|
||||
Settings settings("aec", true);
|
||||
settings.SetInt("mode", newMode);
|
||||
}
|
||||
void SwitchTFT() {
|
||||
Settings settings("display", true);
|
||||
@@ -203,11 +203,6 @@ class YunliaoS3 : public DualNetworkBoard {
|
||||
}
|
||||
}
|
||||
});
|
||||
if (GetNetworkType() == NetworkType::WIFI) {
|
||||
power_manager_->Shutdown4G();
|
||||
} else {
|
||||
power_manager_->Start4G();
|
||||
}
|
||||
GetBacklight()->RestoreBrightness();
|
||||
while (gpio_get_level(BOOT_BUTTON_PIN) == 0) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
@@ -216,6 +211,16 @@ class YunliaoS3 : public DualNetworkBoard {
|
||||
Settings settings("aec", false);
|
||||
auto& app = Application::GetInstance();
|
||||
app.SetAecMode(settings.GetInt("mode",kAecOnDeviceSide) == kAecOnDeviceSide ? kAecOnDeviceSide : kAecOff);
|
||||
power_manager_->Start4G();
|
||||
if (GetNetworkType() == NetworkType::WIFI) {
|
||||
power_manager_->Disable4G();
|
||||
}else{
|
||||
power_manager_->Enable4G();
|
||||
}
|
||||
power_manager_->OnBtLinkStatusChanged([this](bool is_connected) {
|
||||
SetAecMode(!is_connected);
|
||||
});
|
||||
power_manager_->InitializeBtModul();
|
||||
InitializeTools();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user