Skip to content

Commit 82373a5

Browse files
committed
Update the scan interface based on latest updates
1 parent 5e04938 commit 82373a5

File tree

8 files changed

+104
-33
lines changed

8 files changed

+104
-33
lines changed

libraries/BLE/examples/central/led_control/led_control.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void setup() {
3737
Serial.println("BLE Central - LED control");
3838

3939
// start scanning for peripherals
40-
BLE.startScanning();
40+
BLE.scan();
4141
}
4242

4343
void loop() {
@@ -57,12 +57,12 @@ void loop() {
5757
// see if peripheral is advertising the LED service
5858
if (peripheral.advertisedServiceUuid() == "19b10000-e8f2-537e-4f6c-d104768a1214") {
5959
// stop scanning
60-
BLE.stopScanning();
60+
BLE.stopScan();
6161

6262
controlLed(peripheral);
6363

6464
// peripheral disconnected, start scanning again
65-
BLE.startScanning();
65+
BLE.scan();
6666
}
6767
}
6868
}

libraries/BLE/examples/central/peripheral_explorer/peripheral_explorer.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void setup() {
2828
Serial.println("BLE Central - Peripheral Explorer");
2929

3030
// start scanning for peripherals
31-
BLE.startScanning();
31+
BLE.scan();
3232
}
3333

3434
void loop() {
@@ -48,7 +48,7 @@ void loop() {
4848
// see if peripheral is a SensorTag
4949
if (peripheral.localName() == "SensorTag") {
5050
// stop scanning
51-
BLE.stopScanning();
51+
BLE.stopScan();
5252

5353
explorerPeripheral(peripheral);
5454

libraries/BLE/examples/central/scan/scan.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void setup() {
2828
Serial.println("BLE Central scan");
2929

3030
// start scanning for peripheral
31-
BLE.startScanning();
31+
BLE.scan();
3232
}
3333

3434
void loop() {

libraries/BLE/examples/central/scan_callback/scan_callback.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void setup() {
3131
BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler);
3232

3333
// start scanning for peripherals with duplicates
34-
BLE.startScanningWithDuplicates();
34+
BLE.scan(true);
3535
}
3636

3737
void loop() {

libraries/BLE/examples/central/sensortag_button/sensortag_button.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void setup() {
2828
Serial.println("BLE Central - SensorTag button");
2929

3030
// start scanning for peripheral
31-
BLE.startScanning();
31+
BLE.scan();
3232
}
3333

3434
void loop() {
@@ -48,12 +48,12 @@ void loop() {
4848
// see if peripheral is a SensorTag
4949
if (peripheral.localName() == "SensorTag") {
5050
// stop scanning
51-
BLE.stopScanning();
51+
BLE.stopScan();
5252

5353
monitorSensorTagButtons(peripheral);
5454

5555
// peripheral disconnected, start scanning again
56-
BLE.startScanning();
56+
BLE.scan();
5757
}
5858
}
5959
}

libraries/BLE/src/BLEDevice.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,33 +212,55 @@ bool BLEDevice::operator!=(const BLEDevice& device) const
212212
}
213213

214214

215-
void BLEDevice::startScanning()
215+
bool BLEDevice::startScan(bool withDuplicates)
216216
{
217217
preCheckProfile();
218+
if (withDuplicates)
219+
{
220+
return BLEDeviceManager::instance()->startScanningWithDuplicates();
221+
}
222+
else
223+
{
224+
return BLEDeviceManager::instance()->startScanning();
225+
}
226+
}
227+
228+
229+
void BLEDevice::scan()
230+
{
231+
scan(false);
232+
}
233+
234+
void BLEDevice::scan(bool withDuplicates)
235+
{
218236
BLEDeviceManager::instance()->clearAdvertiseCritical();
219-
BLEDeviceManager::instance()->startScanning();
237+
startScan(withDuplicates);
220238
}
221239

222-
void BLEDevice::startScanning(String name)
240+
void BLEDevice::scanFoName(String name)
241+
{
242+
scanFoName(name, false);
243+
}
244+
245+
void BLEDevice::scanFoName(String name, bool withDuplicates)
223246
{
224-
preCheckProfile();
225247
BLEDeviceManager::instance()->setAdvertiseCritical(name);
226-
BLEDeviceManager::instance()->startScanning();
248+
startScan(withDuplicates);
227249
}
228250

229-
void BLEDevice::startScanning(BLEService& service)
251+
void BLEDevice::scanForUuid(String uuid)
230252
{
231-
preCheckProfile();
232-
BLEDeviceManager::instance()->setAdvertiseCritical(service);
233-
BLEDeviceManager::instance()->startScanning();
253+
scanForUuid(uuid, false);
234254
}
235255

236-
void BLEDevice::startScanningWithDuplicates()
256+
void BLEDevice::scanForUuid(String uuid, bool withDuplicates)
237257
{
238-
// TODO
258+
BLEService service_temp(uuid.c_str());
259+
BLEDeviceManager::instance()->setAdvertiseCritical(service_temp);
260+
startScan(withDuplicates);
239261
}
240262

241-
void BLEDevice::stopScanning()
263+
void BLEDevice::stopScan()
242264
{
243265
BLEDeviceManager::instance()->stopScanning();
244266
}

libraries/BLE/src/BLEDevice.h

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ class BLEDevice
342342
bool operator!=(const BLEDevice& device) const;
343343

344344
// central mode
345+
346+
//void scanForAddress(String address); // Not include in baseline. Add here as feature for feature release.
347+
345348
/**
346349
* @brief Start scanning for peripherals without filter
347350
*
@@ -351,7 +354,20 @@ class BLEDevice
351354
*
352355
* @note none
353356
*/
354-
void startScanning();
357+
void scan();
358+
359+
/**
360+
* @brief Start scanning for peripherals with filter
361+
*
362+
* @param[in] withDuplicates true - with duplicate filter
363+
* false- without duplicate filter
364+
*
365+
* @return none
366+
*
367+
* @note option to filter out duplicate addresses for Arduino.
368+
* The current only support fileter duplicate mode.
369+
*/
370+
void scan(bool withDuplicates);
355371

356372
/**
357373
* @brief Start scanning for peripherals and filter by device name in ADV
@@ -360,9 +376,25 @@ class BLEDevice
360376
*
361377
* @return none
362378
*
363-
* @note none
379+
* @note option to filter out duplicate addresses for Arduino.
380+
* The current only support fileter duplicate mode.
364381
*/
365-
void startScanning(String name);
382+
void scanFoName(String name);
383+
384+
/**
385+
* @brief Start scanning for peripherals and filter by device name in ADV
386+
*
387+
* @param[in] name The device's local name.
388+
*
389+
* @param[in] withDuplicates true - with duplicate filter
390+
* false- without duplicate filter
391+
*
392+
* @return none
393+
*
394+
* @note option to filter out duplicate addresses for Arduino.
395+
* The current only support fileter duplicate mode.
396+
*/
397+
void scanFoName(String name, bool withDuplicates);
366398

367399
/**
368400
* @brief Start scanning for peripherals and filter by service in ADV
@@ -373,20 +405,22 @@ class BLEDevice
373405
*
374406
* @note none
375407
*/
376-
void startScanning(BLEService& service);
408+
void scanForUuid(String uuid);
377409

378410
/**
379-
* @brief start scanning for peripherals, and report all duplicates
411+
* @brief Start scanning for peripherals and filter by service in ADV
380412
*
381-
* @param none
413+
* @param[in] service The service
414+
*
415+
* @param[in] withDuplicates true - with duplicate filter
416+
* false- without duplicate filter
382417
*
383418
* @return none
384419
*
385-
* @note none
386-
// Does this necessory? This will take more memory to store the ADV
387-
// I suggest delete it.
420+
* @note option to filter out duplicate addresses for Arduino.
421+
* The current only support fileter duplicate mode.
388422
*/
389-
void startScanningWithDuplicates();
423+
void scanForUuid(String uuid, bool withDuplicates);
390424

391425
/**
392426
* @brief Stop scanning for peripherals
@@ -397,7 +431,7 @@ class BLEDevice
397431
*
398432
* @note none
399433
*/
400-
void stopScanning();
434+
void stopScan();
401435

402436
/**
403437
* @brief Retrieve a discovered peripheral
@@ -631,6 +665,19 @@ class BLEDevice
631665
private:
632666
void preCheckProfile();
633667

668+
/**
669+
* @brief Start scanning for peripherals with/without duplicate filter
670+
*
671+
* @param[in] withDuplicates true - with duplicate filter
672+
* false- without duplicate filter
673+
*
674+
* @return none
675+
*
676+
* @note option to filter out duplicate addresses for Arduino.
677+
* The current only support fileter duplicate mode.
678+
*/
679+
bool startScan(bool withDuplicates);
680+
634681
private:
635682
bt_addr_le_t _bt_addr;
636683

libraries/BLE/src/BLEService.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ BLEService::BLEService(const char* uuid):_bledevice(),
3636
{
3737
bt_uuid_128_t uuid_tmp;
3838
memset(_uuid_cstr, 0, sizeof (_uuid_cstr));
39+
3940
BLEUtils::uuidString2BT(uuid, (bt_uuid_t *)&uuid_tmp);
4041
BLEUtils::uuidBT2String((const bt_uuid_t *)&uuid_tmp, _uuid_cstr);
4142

@@ -55,6 +56,7 @@ BLEService::BLEService(BLEServiceImp* serviceImp, const BLEDevice* bledev):
5556
_service_local_imp(NULL)
5657
{
5758
memset(_uuid_cstr, 0, sizeof (_uuid_cstr));
59+
5860
BLEUtils::uuidBT2String(serviceImp->bt_uuid(), _uuid_cstr);
5961
}
6062

0 commit comments

Comments
 (0)