Skip to content

Commit

Permalink
end(): timout A2DP_DISCONNECT_LIMIT
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Jun 22, 2024
1 parent 88638cf commit 7ca1851
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/BluetoothA2DPCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ void BluetoothA2DPCommon::end(bool release_memory) {

// Disconnect and wait
disconnect();
int limit = A2DP_DISCONNECT_LIMIT;
while(get_connection_state() != ESP_A2D_CONNECTION_STATE_DISCONNECTED){
delay_ms(100);
if (limit-- < 0) {
ESP_LOGW(BT_AV_TAG,"Waiting for Disconnect has timed out");
break;
};
}

// deinit AVRC
Expand Down Expand Up @@ -118,8 +123,14 @@ void BluetoothA2DPCommon::end(bool release_memory) {
log_free_heap();

// waiting for status change
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED)
delay_ms(50);
limit = A2DP_DISCONNECT_LIMIT;
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
delay_ms(100);
if (limit-- < 0) {
ESP_LOGW(BT_AV_TAG,"Waiting for Enabled has timed out");
break;
};
}

if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){
ESP_LOGI(BT_AV_TAG,"esp_bt_controller_deinit");
Expand Down
5 changes: 5 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@
#ifndef A2DP_I2S_MAX_WRITE_SIZE
# define A2DP_I2S_MAX_WRITE_SIZE 1024 * 5
#endif

// Maximum wait time for status change in 100 ms when calling end()
#ifndef A2DP_DISCONNECT_LIMIT
# define A2DP_DISCONNECT_LIMIT 20
#endif

0 comments on commit 7ca1851

Please sign in to comment.