diff options
author | Neil Kolban <kolban1@kolban.com> | 2018-05-27 10:56:49 -0500 |
---|---|---|
committer | Neil Kolban <kolban1@kolban.com> | 2018-05-27 10:56:49 -0500 |
commit | e885eea75617598e3b1dff9e972d2e59f297ae28 (patch) | |
tree | 7244f26854294af16fef14605e321016f213d98a /src/BLEScan.cpp | |
parent | Fixes for BLE_notify sample (diff) | |
download | thermostat-e885eea75617598e3b1dff9e972d2e59f297ae28.tar.gz thermostat-e885eea75617598e3b1dff9e972d2e59f297ae28.tar.bz2 thermostat-e885eea75617598e3b1dff9e972d2e59f297ae28.zip |
0.4.13
Diffstat (limited to 'src/BLEScan.cpp')
-rw-r--r-- | src/BLEScan.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/BLEScan.cpp b/src/BLEScan.cpp index e450664..73086c6 100644 --- a/src/BLEScan.cpp +++ b/src/BLEScan.cpp @@ -74,6 +74,9 @@ void BLEScan::handleGAPEvent( // asked to stop. case ESP_GAP_SEARCH_INQ_CMPL_EVT: { m_stopped = true; + if (m_scanCompleteCB != nullptr) { + m_scanCompleteCB(m_scanResults); + } m_semaphoreScanEnd.give(); break; } // ESP_GAP_SEARCH_INQ_CMPL_EVT @@ -186,10 +189,14 @@ void BLEScan::setWindow(uint16_t windowMSecs) { /** * @brief Start scanning. * @param [in] duration The duration in seconds for which to scan. - * @return N/A. + * @param [in] scanCompleteCB A function to be called when scanning has completed. This can + * be supplied as nullptr (the default) in which case the call to start will block until scanning has + * been completed. + * @return The BLEScanResults. Only applicable if we are waiting for results. */ -BLEScanResults BLEScan::start(uint32_t duration) { +BLEScanResults BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults)) { ESP_LOGD(LOG_TAG, ">> start(duration=%d)", duration); + m_scanCompleteCB = scanCompleteCB; // Save the callback to be invoked when the scan completes. m_semaphoreScanEnd.take(std::string("start")); @@ -213,7 +220,9 @@ BLEScanResults BLEScan::start(uint32_t duration) { m_stopped = false; - m_semaphoreScanEnd.wait("start"); // Wait for the semaphore to release. + if (m_scanCompleteCB == nullptr) { + m_semaphoreScanEnd.wait("start"); // Wait for the semaphore to release. + } ESP_LOGD(LOG_TAG, "<< start()"); return m_scanResults; |