Skip to content

Commit 36cc974

Browse files
cparatafpistm
authored andcommitted
chore(GAP): improve scan
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 2ff4216 commit 36cc974

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/local/BLELocalDevice.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ int BLELocalDevice::scanForAddress(String address, bool withDuplicates)
421421
return GAP.scanForAddress(address, withDuplicates);
422422
}
423423

424-
void BLELocalDevice::stopScan()
424+
int BLELocalDevice::stopScan()
425425
{
426-
GAP.stopScan();
426+
return GAP.stopScan();
427427
}
428428

429429
BLEDevice BLELocalDevice::central()

src/local/BLELocalDevice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class BLELocalDevice {
7777
virtual int scanForName(String name, bool withDuplicates = false);
7878
virtual int scanForUuid(String uuid, bool withDuplicates = false);
7979
virtual int scanForAddress(String address, bool withDuplicates = false);
80-
virtual void stopScan();
80+
virtual int stopScan();
8181

8282
virtual BLEDevice central();
8383
virtual BLEDevice available();

src/utility/GAP.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ void GAPClass::stopAdvertise()
8484

8585
int GAPClass::scan(bool withDuplicates)
8686
{
87-
HCI.leSetScanEnable(false, true);
87+
if(_scanning) {
88+
// Check if the HCI command fails
89+
if (HCI.leSetScanEnable(false, true) != 0) {
90+
return 0;
91+
}
92+
}
8893

8994
// active scan, 20 ms scan interval (N * 0.625), 20 ms scan window (N * 0.625), public own address type, no filter
9095
/*
@@ -133,9 +138,14 @@ int GAPClass::scanForAddress(String address, bool withDuplicates)
133138
return scan(withDuplicates);
134139
}
135140

136-
void GAPClass::stopScan()
141+
int GAPClass::stopScan()
137142
{
138-
HCI.leSetScanEnable(false, false);
143+
if(_scanning) {
144+
// Check if the HCI command fails
145+
if (HCI.leSetScanEnable(false, false) != 0) {
146+
return 0;
147+
}
148+
}
139149

140150
_scanning = false;
141151

@@ -146,6 +156,8 @@ void GAPClass::stopScan()
146156
}
147157

148158
_discoveredDevices.clear();
159+
160+
return 1;
149161
}
150162

151163
BLEDevice GAPClass::available()

src/utility/GAP.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GAPClass {
3737
virtual int scanForName(String name, bool withDuplicates);
3838
virtual int scanForUuid(String uuid, bool withDuplicates);
3939
virtual int scanForAddress(String address, bool withDuplicates);
40-
virtual void stopScan();
40+
virtual int stopScan();
4141
virtual BLEDevice available();
4242

4343
virtual void setAdvertisingInterval(uint16_t advertisingInterval);

0 commit comments

Comments
 (0)