@@ -66,8 +66,21 @@ static void bt_app_hdl_stack_evt(uint16_t event, void *p_param)
66
66
esp_a2d_sink_register_data_callback (bt_app_a2d_data_cb );
67
67
esp_a2d_sink_init ();
68
68
69
- /* set discoverable and connectable mode, wait to be connected */
70
- esp_bt_gap_set_scan_mode (ESP_BT_CONNECTABLE , ESP_BT_GENERAL_DISCOVERABLE );
69
+ if (memcmp (last_remote_bda , "\x00\x00\x00\x00\x00\x00" , 6 ) != 0 ) {
70
+ EventBits_t uxBits = xEventGroupGetBits (user_event_group );
71
+ if (!(uxBits & OS_PWR_SLEEP_BIT ) && !(uxBits & OS_PWR_RESET_BIT )) {
72
+ ESP_LOGW (BT_APP_TAG , "connecting to [%02x:%02x:%02x:%02x:%02x:%02x]" ,
73
+ last_remote_bda [0 ], last_remote_bda [1 ], last_remote_bda [2 ],
74
+ last_remote_bda [3 ], last_remote_bda [4 ], last_remote_bda [5 ]);
75
+
76
+ esp_a2d_sink_connect (last_remote_bda );
77
+ }
78
+ } else {
79
+ xEventGroupSetBits (user_event_group , BT_A2DP_IDLE_BIT );
80
+
81
+ /* set discoverable and connectable mode, wait to be connected */
82
+ esp_bt_gap_set_scan_mode (ESP_BT_CONNECTABLE , ESP_BT_GENERAL_DISCOVERABLE );
83
+ }
71
84
72
85
break ;
73
86
}
@@ -82,8 +95,6 @@ void bt_app_init(void)
82
95
size_t length = sizeof (esp_bd_addr_t );
83
96
app_getenv ("LAST_REMOTE_BDA" , & last_remote_bda , & length );
84
97
85
- xEventGroupSetBits (user_event_group , BT_A2DP_IDLE_BIT );
86
-
87
98
/* create application task */
88
99
bt_app_task_start_up ();
89
100
@@ -103,17 +114,4 @@ void bt_app_init(void)
103
114
esp_bt_gap_set_pin (pin_type , 4 , pin_code );
104
115
105
116
ESP_LOGI (BT_APP_TAG , "started." );
106
-
107
- if (memcmp (last_remote_bda , "\x00\x00\x00\x00\x00\x00" , 6 ) != 0 ) {
108
- vTaskDelay (2000 / portTICK_RATE_MS );
109
-
110
- EventBits_t uxBits = xEventGroupGetBits (user_event_group );
111
- if (uxBits & BT_A2DP_IDLE_BIT && !(uxBits & OS_PWR_SLEEP_BIT ) && !(uxBits & OS_PWR_RESET_BIT )) {
112
- ESP_LOGW (BT_APP_TAG , "connecting to [%02x:%02x:%02x:%02x:%02x:%02x]" ,
113
- last_remote_bda [0 ], last_remote_bda [1 ], last_remote_bda [2 ],
114
- last_remote_bda [3 ], last_remote_bda [4 ], last_remote_bda [5 ]);
115
-
116
- esp_a2d_sink_connect (last_remote_bda );
117
- }
118
- }
119
117
}
0 commit comments