Skip to content

Commit 7ca1851

Browse files
committed
end(): timout A2DP_DISCONNECT_LIMIT
1 parent 88638cf commit 7ca1851

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/BluetoothA2DPCommon.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ void BluetoothA2DPCommon::end(bool release_memory) {
8484

8585
// Disconnect and wait
8686
disconnect();
87+
int limit = A2DP_DISCONNECT_LIMIT;
8788
while(get_connection_state() != ESP_A2D_CONNECTION_STATE_DISCONNECTED){
8889
delay_ms(100);
90+
if (limit-- < 0) {
91+
ESP_LOGW(BT_AV_TAG,"Waiting for Disconnect has timed out");
92+
break;
93+
};
8994
}
9095

9196
// deinit AVRC
@@ -118,8 +123,14 @@ void BluetoothA2DPCommon::end(bool release_memory) {
118123
log_free_heap();
119124

120125
// waiting for status change
121-
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED)
122-
delay_ms(50);
126+
limit = A2DP_DISCONNECT_LIMIT;
127+
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
128+
delay_ms(100);
129+
if (limit-- < 0) {
130+
ESP_LOGW(BT_AV_TAG,"Waiting for Enabled has timed out");
131+
break;
132+
};
133+
}
123134

124135
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){
125136
ESP_LOGI(BT_AV_TAG,"esp_bt_controller_deinit");

src/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@
2424
#ifndef A2DP_I2S_MAX_WRITE_SIZE
2525
# define A2DP_I2S_MAX_WRITE_SIZE 1024 * 5
2626
#endif
27+
28+
// Maximum wait time for status change in 100 ms when calling end()
29+
#ifndef A2DP_DISCONNECT_LIMIT
30+
# define A2DP_DISCONNECT_LIMIT 20
31+
#endif

0 commit comments

Comments
 (0)