Skip to content

Commit 3de1c07

Browse files
committed
Reconnect error: Start buedroid only once
1 parent 8a86331 commit 3de1c07

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/BluetoothA2DPCommon.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ void BluetoothA2DPCommon::end(bool release_memory) {
217217
if (esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT) != ESP_OK) {
218218
ESP_LOGE(BT_AV_TAG, "esp_bt_controller_mem_release failed");
219219
}
220+
221+
esp_bluedroid_deinit();
222+
is_bluedroid_initialized = false;
223+
220224
log_free_heap();
221225
is_start_disabled = true;
222226
}
@@ -428,6 +432,7 @@ bool BluetoothA2DPCommon::bt_start() {
428432
}
429433

430434
esp_err_t BluetoothA2DPCommon::bluedroid_init() {
435+
if (is_bluedroid_initialized) return ESP_OK;
431436
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 1)
432437
return esp_bluedroid_init_with_cfg(&bluedroid_config);
433438
#else

src/BluetoothA2DPCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ class BluetoothA2DPCommon {
369369
// volume
370370
uint8_t volume_value = 0;
371371
bool is_volume_used = false;
372+
bool is_bluedroid_initialized = false;
372373
BaseType_t task_core = 1;
373374

374375
int event_queue_size = 20;

src/BluetoothA2DPSink.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ int BluetoothA2DPSink::init_bluetooth() {
217217
ESP_LOGE(BT_AV_TAG, "Failed to initialize bluedroid");
218218
return false;
219219
}
220+
is_bluedroid_initialized = true;
220221
ESP_LOGI(BT_AV_TAG, "bluedroid initialized");
221222
}
222223

src/BluetoothA2DPSource.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,17 @@ void BluetoothA2DPSource::start(std::vector<const char *> names) {
108108
return;
109109
}
110110

111-
if (bluedroid_init() != ESP_OK) {
112-
ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed\n", __func__);
113-
return;
114-
}
111+
if (!is_bluedroid_initialized){
112+
if (bluedroid_init() != ESP_OK) {
113+
ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed\n", __func__);
114+
return;
115+
}
115116

116-
if (esp_bluedroid_enable() != ESP_OK) {
117-
ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed\n", __func__);
118-
return;
117+
if (esp_bluedroid_enable() != ESP_OK) {
118+
ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed\n", __func__);
119+
return;
120+
}
121+
is_bluedroid_initialized = true;
119122
}
120123

121124
if (ssp_enabled) {

0 commit comments

Comments
 (0)