Selaa lähdekoodia

btdm:fix emit `ESP_BT_GAP_DISC_STATE_CHANGED_EVT` event when call API `esp_bt_gap_start_discovery`

closes BT-594

See merge request espressif/esp-idf!8808
liqigan 5 vuotta sitten
vanhempi
sitoutus
55f6a927b5

+ 3 - 2
components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c

@@ -950,11 +950,12 @@ void btc_gap_bt_busy_level_updated(uint8_t bl_flags)
         param.disc_st_chg.state = ESP_BT_GAP_DISCOVERY_STARTED;
         btc_gap_bt_cb_to_app(ESP_BT_GAP_DISC_STATE_CHANGED_EVT, &param);
         btc_gap_bt_inquiry_in_progress = true;
-    } else if (bl_flags == BTM_BL_INQUIRY_CANCELLED ||
-               bl_flags == BTM_BL_INQUIRY_COMPLETE) {
+    } else if (bl_flags == BTM_BL_INQUIRY_CANCELLED) {
         param.disc_st_chg.state = ESP_BT_GAP_DISCOVERY_STOPPED;
         btc_gap_bt_cb_to_app(ESP_BT_GAP_DISC_STATE_CHANGED_EVT, &param);
         btc_gap_bt_inquiry_in_progress = false;
+    } else if (bl_flags == BTM_BL_INQUIRY_COMPLETE) {
+        btc_gap_bt_inquiry_in_progress = false;
     }
 }
 

+ 1 - 9
examples/bluetooth/esp_hid_device/main/esp_hid_gap.c

@@ -379,18 +379,10 @@ static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst)
 
 static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
 {
-    static bool scan_running = false;
-    static bool scan_wait_stop = false;
     switch (event) {
     case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: {
         ESP_LOGV(TAG, "BT GAP DISC_STATE %s", (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STARTED) ? "START" : "STOP");
-        if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STARTED) {
-            scan_running = true;
-            scan_wait_stop = true;
-        } else if (scan_wait_stop) {
-            scan_wait_stop = false;
-        } else if (scan_running) {
-            scan_running = false;
+        if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED) {
             SEND_BT_CB();
         }
         break;

+ 1 - 9
examples/bluetooth/esp_hid_host/main/esp_hid_gap.c

@@ -379,18 +379,10 @@ static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst)
 
 static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
 {
-    static bool scan_running = false;
-    static bool scan_wait_stop = false;
     switch (event) {
     case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: {
         ESP_LOGV(TAG, "BT GAP DISC_STATE %s", (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STARTED) ? "START" : "STOP");
-        if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STARTED) {
-            scan_running = true;
-            scan_wait_stop = true;
-        } else if (scan_wait_stop) {
-            scan_wait_stop = false;
-        } else if (scan_running) {
-            scan_running = false;
+        if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED) {
             SEND_BT_CB();
         }
         break;