Combine the scanner failure check so we only stop the scanner once (#4111)

This commit is contained in:
J. Nick Koston 2022-11-28 18:11:54 -10:00 committed by GitHub
parent 873de13b3d
commit ad0d6f6337
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -144,28 +144,31 @@ void ESP32BLETracker::loop() {
xSemaphoreGive(this->scan_result_lock_); xSemaphoreGive(this->scan_result_lock_);
} }
if (this->scan_set_param_failed_) {
ESP_LOGE(TAG, "Scan set param failed: %d", this->scan_set_param_failed_);
esp_ble_gap_stop_scanning();
this->scan_set_param_failed_ = ESP_BT_STATUS_SUCCESS;
}
if (this->scan_start_failed_) {
ESP_LOGE(TAG, "Scan start failed: %d", this->scan_start_failed_);
esp_ble_gap_stop_scanning();
this->scan_start_failed_ = ESP_BT_STATUS_SUCCESS;
}
if (!connecting && xSemaphoreTake(this->scan_end_lock_, 0L)) { if (!connecting && xSemaphoreTake(this->scan_end_lock_, 0L)) {
if (this->scan_continuous_) { if (this->scan_continuous_) {
if (!promote_to_connecting) { if (!promote_to_connecting && !this->scan_start_failed_ && !this->scan_set_param_failed_) {
this->start_scan_(false); this->start_scan_(false);
} else {
// We didn't start the scan, so we need to release the lock
xSemaphoreGive(this->scan_end_lock_);
} }
} else if (!this->scanner_idle_) { } else if (!this->scanner_idle_) {
this->end_of_scan_(); this->end_of_scan_();
return; return;
} }
} }
if (this->scan_start_failed_ || this->scan_set_param_failed_) {
esp_ble_gap_stop_scanning();
if (this->scan_start_failed_) {
ESP_LOGE(TAG, "Scan start failed: %d", this->scan_start_failed_);
this->scan_start_failed_ = ESP_BT_STATUS_SUCCESS;
}
if (this->scan_set_param_failed_) {
ESP_LOGE(TAG, "Scan set param failed: %d", this->scan_set_param_failed_);
this->scan_set_param_failed_ = ESP_BT_STATUS_SUCCESS;
}
}
} }
// If there is a discovered client and no connecting // If there is a discovered client and no connecting