@@ -189,16 +189,14 @@ void BLEScan::setWindow(uint16_t windowMSecs) {
189
189
/* *
190
190
* @brief Start scanning.
191
191
* @param [in] duration The duration in seconds for which to scan.
192
- * @param [in] scanCompleteCB A function to be called when scanning has completed. This can
193
- * be supplied as nullptr (the default) in which case the call to start will block until scanning has
194
- * been completed.
195
- * @return The BLEScanResults. Only applicable if we are waiting for results.
192
+ * @param [in] scanCompleteCB A function to be called when scanning has completed.
193
+ * @return True if scan started or false if there was an error.
196
194
*/
197
- BLEScanResults BLEScan::start (uint32_t duration, void (*scanCompleteCB)(BLEScanResults)) {
195
+ bool BLEScan::start (uint32_t duration, void (*scanCompleteCB)(BLEScanResults)) {
198
196
ESP_LOGD (LOG_TAG, " >> start(duration=%d)" , duration);
199
- m_scanCompleteCB = scanCompleteCB; // Save the callback to be invoked when the scan completes.
200
197
201
198
m_semaphoreScanEnd.take (std::string (" start" ));
199
+ m_scanCompleteCB = scanCompleteCB; // Save the callback to be invoked when the scan completes.
202
200
203
201
m_scanResults.m_vectorAdvertisedDevices .clear ();
204
202
@@ -207,24 +205,33 @@ BLEScanResults BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanR
207
205
if (errRc != ESP_OK) {
208
206
ESP_LOGE (LOG_TAG, " esp_ble_gap_set_scan_params: err: %d, text: %s" , errRc, GeneralUtils::errorToString (errRc));
209
207
m_semaphoreScanEnd.give ();
210
- return m_scanResults ;
208
+ return false ;
211
209
}
212
210
213
211
errRc = ::esp_ble_gap_start_scanning (duration);
214
212
215
213
if (errRc != ESP_OK) {
216
214
ESP_LOGE (LOG_TAG, " esp_ble_gap_start_scanning: err: %d, text: %s" , errRc, GeneralUtils::errorToString (errRc));
217
215
m_semaphoreScanEnd.give ();
218
- return m_scanResults ;
216
+ return false ;
219
217
}
220
218
221
219
m_stopped = false ;
222
220
223
- if (m_scanCompleteCB == nullptr ) {
221
+ ESP_LOGD (LOG_TAG, " << start()" );
222
+ return true ;
223
+ } // start
224
+
225
+
226
+ /* *
227
+ * @brief Start scanning and block until scanning has been completed.
228
+ * @param [in] duration The duration in seconds for which to scan.
229
+ * @return The BLEScanResults.
230
+ */
231
+ BLEScanResults BLEScan::start (uint32_t duration) {
232
+ if (start (duration, nullptr )) {
224
233
m_semaphoreScanEnd.wait (" start" ); // Wait for the semaphore to release.
225
234
}
226
-
227
- ESP_LOGD (LOG_TAG, " << start()" );
228
235
return m_scanResults;
229
236
} // start
230
237
0 commit comments