Skip to content

Commit

Permalink
A2DPSource disconnect() prevent reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Dec 19, 2024
1 parent 5b50fe0 commit 4024fd0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/BluetoothA2DPCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void BluetoothA2DPCommon::set_auto_reconnect(bool active){
/// Reconnects to the last device
bool BluetoothA2DPCommon::reconnect() {
if (has_last_connection()) {
is_target_status_active = true;
is_autoreconnect_allowed = true;
reconnect_status = IsReconnecting;
reconnect_timout = get_millis() + default_reconnect_timout;
Expand Down Expand Up @@ -66,6 +67,7 @@ void BluetoothA2DPCommon::disconnect()
{
ESP_LOGI(BT_AV_TAG, "disconect a2d: %s", to_str(last_connection));

is_target_status_active = false;
// Prevent automatic reconnect
is_autoreconnect_allowed = false;

Expand Down
1 change: 1 addition & 0 deletions src/BluetoothA2DPCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class BluetoothA2DPCommon {
A2DPVolumeControl *volume_control_ptr = nullptr;
esp_bd_addr_t last_connection = {0,0,0,0,0,0};
bool is_start_disabled = false;
bool is_target_status_active = true;
void (*connection_state_callback)(esp_a2d_connection_state_t state, void* obj) = nullptr;
void (*audio_state_callback)(esp_a2d_audio_state_t state, void* obj) = nullptr;
void (*audio_state_callback_post)(esp_a2d_audio_state_t state, void* obj) = nullptr;
Expand Down
9 changes: 6 additions & 3 deletions src/BluetoothA2DPSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,12 @@ void BluetoothA2DPSource::bt_app_av_state_unconnected_hdlr(uint16_t event,
case ESP_A2D_MEDIA_CTRL_ACK_EVT:
break;
case BT_APP_HEART_BEAT_EVT: {
esp_a2d_connect(peer_bd_addr);
s_a2d_state = APP_AV_STATE_CONNECTING;
s_connecting_heatbeat_count = 0;
// prevent reconnect after disconnect()
if (is_target_status_active) {
esp_a2d_connect(peer_bd_addr);
s_a2d_state = APP_AV_STATE_CONNECTING;
s_connecting_heatbeat_count = 0;
}
break;
}
// case ESP_A2D_REPORT_SNK_DELAY_VALUE_EVT: {
Expand Down

0 comments on commit 4024fd0

Please sign in to comment.