forked from h2zero/esp-nimble-cpp
Only start scan/advertise when host re-synced if duration was indefinite.
Previously when the host reset while scanning (if active prior) it would be restarted automatically. This caused errors for some applications and has been removed since the event invokes the scan ended callback for the app to take action. Instead scanning will now only be restarted if the duration was indefinite and a callback was set for the advertisment events, this use case is less likely to have a scan ended callback. Advertising (if active prior) would be started without regard to it's previous state. This has been corrected to only start advertising again if it was advertising for an idefinite time.
This commit is contained in:
+15
-1
@@ -41,6 +41,7 @@ NimBLEScan::NimBLEScan() {
|
||||
m_ignoreResults = false;
|
||||
m_wantDuplicates = false;
|
||||
m_pTaskData = nullptr;
|
||||
m_duration = BLE_HS_FOREVER; // make sure this is non-zero in the event of a host reset
|
||||
}
|
||||
|
||||
|
||||
@@ -378,12 +379,25 @@ void NimBLEScan::erase(const NimBLEAddress &address) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief If the host reset the scan will have stopped so we should set the flag as stopped.
|
||||
* @brief Called when host reset, we set a flag to stop scanning until synced.
|
||||
*/
|
||||
void NimBLEScan::onHostReset() {
|
||||
m_ignoreResults = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief If the host reset and re-synced this is called.
|
||||
* If the application was scanning indefinitely with a callback, restart it.
|
||||
*/
|
||||
void NimBLEScan::onHostSync() {
|
||||
m_ignoreResults = false;
|
||||
|
||||
if(m_duration == 0 && m_pAdvertisedDeviceCallbacks != nullptr) {
|
||||
start(m_duration, m_scanCompleteCB);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the results of the scan.
|
||||
* @return NimBLEScanResults object.
|
||||
|
||||
Reference in New Issue
Block a user