Skip to content

Add optional clearing of scan results when stopping scan. #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NimBLEClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {

case BLE_HS_EBUSY:
// Scan was still running, stop it and try again
if (!NimBLEDevice::getScan()->stop()) {
if (!NimBLEDevice::getScan()->stop(false)) {
rc = BLE_HS_EUNKNOWN;
}
break;
Expand Down
6 changes: 4 additions & 2 deletions src/NimBLEScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,11 @@ NimBLEScanResults NimBLEScan::start(uint32_t duration, bool is_continue) {

/**
* @brief Stop an in progress scan.
* @param [in] clear_results Only used when scanning continuously, clears leftover results if true.\n
NimBLEClient::connect will call with false to avoid concurrent access in edge cases. Default = true.
* @return True if successful.
*/
bool NimBLEScan::stop() {
bool NimBLEScan::stop(bool clear_results) {
NIMBLE_LOGD(LOG_TAG, ">> stop()");

int rc = ble_gap_disc_cancel();
Expand All @@ -381,7 +383,7 @@ bool NimBLEScan::stop() {
return false;
}

if(m_maxResults == 0) {
if(m_maxResults == 0 && clear_results) {
clearResults();
}

Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class NimBLEScan {
void setLimitedOnly(bool enabled);
void setFilterPolicy(uint8_t filter);
void clearDuplicateCache();
bool stop();
bool stop(bool clear_results = true);
void clearResults();
NimBLEScanResults getResults();
void setMaxResults(uint8_t maxResults);
Expand Down