@@ -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
93109void 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}
0 commit comments