Skip to content

Commit d99882c

Browse files
committed
bt_app: code refactoring
1 parent 59b33f0 commit d99882c

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

main/src/user/bt_app.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ 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+
8298
/* set discoverable and connectable mode, wait to be connected */
8399
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
84100

@@ -92,9 +108,11 @@ static void bt_app_hdl_stack_evt(uint16_t event, void *p_param)
92108

93109
void bt_app_init(void)
94110
{
111+
size_t length = sizeof(esp_bd_addr_t);
112+
app_getenv("LAST_REMOTE_BDA", &last_remote_bda, &length);
113+
95114
xEventGroupSetBits(user_event_group, BT_SPP_IDLE_BIT);
96115
xEventGroupSetBits(user_event_group, BT_A2DP_IDLE_BIT);
97-
xEventGroupSetBits(user_event_group, BLE_GATTS_IDLE_BIT);
98116

99117
/* create application task */
100118
bt_app_task_start_up();
@@ -114,15 +132,5 @@ void bt_app_init(void)
114132
pin_code[3] = '4';
115133
esp_bt_gap_set_pin(pin_type, 4, pin_code);
116134

117-
size_t length = sizeof(esp_bd_addr_t);
118-
app_getenv("LAST_REMOTE_BDA", &last_remote_bda, &length);
119-
120-
if (strlen((const char *)last_remote_bda) != 0) {
121-
ESP_LOGI(BT_APP_TAG, "attempting to reconnect [%02x:%02x:%02x:%02x:%02x:%02x]",
122-
last_remote_bda[0], last_remote_bda[1], last_remote_bda[2],
123-
last_remote_bda[3], last_remote_bda[4], last_remote_bda[5]);
124-
esp_a2d_sink_connect(last_remote_bda);
125-
}
126-
127135
ESP_LOGI(BT_APP_TAG, "started.");
128136
}

main/src/user/bt_app_core.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "freertos/queue.h"
1616
#include "freertos/task.h"
1717

18-
#include "core/os.h"
1918
#include "user/bt_app_core.h"
2019

2120
#define BT_APP_CORE_TAG "bt_app_core"
@@ -99,13 +98,5 @@ void bt_app_task_start_up(void)
9998
{
10099
s_bt_app_task_queue = xQueueCreate(10, sizeof(bt_app_msg_t));
101100

102-
xEventGroupWaitBits(
103-
user_event_group,
104-
AUDIO_PLAYER_IDLE_BIT,
105-
pdFALSE,
106-
pdFALSE,
107-
portMAX_DELAY
108-
);
109-
110101
xTaskCreatePinnedToCore(bt_app_task, "BtAppT", 2048, NULL, configMAX_PRIORITIES - 3, NULL, 0);
111102
}

0 commit comments

Comments
 (0)