Skip to content

Commit 07c895e

Browse files
committed
bt_app: add reconnecting delay
1 parent 582a316 commit 07c895e

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

main/src/user/bt_app.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,6 @@ static void bt_app_hdl_stack_evt(uint16_t event, void *p_param)
7979
esp_a2d_sink_register_data_callback(bt_app_a2d_data_cb);
8080
esp_a2d_sink_init();
8181

82-
if (strlen((const char *)last_remote_bda) != 0) {
83-
ESP_LOGI(BT_APP_TAG, "attempting to reconnect [%02x:%02x:%02x:%02x:%02x:%02x]",
84-
last_remote_bda[0], last_remote_bda[1], last_remote_bda[2],
85-
last_remote_bda[3], last_remote_bda[4], last_remote_bda[5]);
86-
#ifdef CONFIG_ENABLE_AUDIO_PROMPT
87-
xEventGroupWaitBits(
88-
user_event_group,
89-
AUDIO_PLAYER_IDLE_BIT,
90-
pdFALSE,
91-
pdFALSE,
92-
portMAX_DELAY
93-
);
94-
#endif
95-
esp_a2d_sink_connect(last_remote_bda);
96-
}
97-
9882
/* set discoverable and connectable mode, wait to be connected */
9983
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
10084

@@ -133,4 +117,28 @@ void bt_app_init(void)
133117
esp_bt_gap_set_pin(pin_type, 4, pin_code);
134118

135119
ESP_LOGI(BT_APP_TAG, "started.");
120+
121+
if (strlen((const char *)last_remote_bda) != 0) {
122+
// Reconnecting Delay
123+
vTaskDelay(1000 / portTICK_RATE_MS);
124+
#ifdef CONFIG_ENABLE_AUDIO_PROMPT
125+
xEventGroupWaitBits(
126+
user_event_group,
127+
AUDIO_PLAYER_IDLE_BIT,
128+
pdFALSE,
129+
pdFALSE,
130+
portMAX_DELAY
131+
);
132+
#endif
133+
EventBits_t uxBits = xEventGroupGetBits(user_event_group);
134+
if (uxBits & BT_A2DP_IDLE_BIT) {
135+
ESP_LOGI(BT_APP_TAG, "reconnect to [%02x:%02x:%02x:%02x:%02x:%02x]",
136+
last_remote_bda[0], last_remote_bda[1], last_remote_bda[2],
137+
last_remote_bda[3], last_remote_bda[4], last_remote_bda[5]);
138+
139+
esp_a2d_sink_connect(last_remote_bda);
140+
} else {
141+
ESP_LOGW(BT_APP_TAG, "reconnecting aborted");
142+
}
143+
}
136144
}

0 commit comments

Comments
 (0)