Skip to content

Commit e5ed778

Browse files
committed
update scanner for SD v6 changes
- minor correct for USBSerial write()
1 parent bba2a74 commit e5ed778

File tree

6 files changed

+37
-21
lines changed

6 files changed

+37
-21
lines changed

changelog.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
## 0.9.0
44

5-
- Feather nRF52840 support
5+
- Added nRF52840-based board support (pca10056 and feather nRF52840 express)
66
- Upgrade bootloader to v6.1.0 ( single bank only )
7+
- Upgrade BSP code to match SD v6
8+
- Bluefruit.Scanner.start() must be called (often in callback) to resume scanning after received an report.
79
- Upgrade freeRTOS from v8 to v10.0.1
810
- Upgrade Segger SysView to 2.52d
911
- Added nrfx to core
@@ -34,7 +36,7 @@
3436
## 0.8.4
3537

3638
- Fix #160: hardware PWM issue that cause Servo freq is 640 hz instead of 50hz
37-
- Fix #134: hardcoded pulse limits with Servo
39+
- Fix #134: hardcoded pulse limits with Servo
3840
- Fix upload issue with windows when username has spaces
3941
- Support serialEvent()
4042

cores/nRF5/usb/USBSerial.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,21 @@ size_t USBSerial::write(uint8_t ch)
9898

9999
size_t USBSerial::write(const uint8_t *buffer, size_t size)
100100
{
101-
while ( size )
101+
size_t remain = size;
102+
while ( remain && tud_cdc_connected() )
102103
{
103-
size_t wrcount = tud_cdc_write(buffer, size);
104-
size -= wrcount;
104+
size_t wrcount = tud_cdc_write(buffer, remain);
105+
remain -= wrcount;
105106
buffer += wrcount;
106107

107108
// Write FIFO is full, flush and re-try
108-
if ( size )
109+
if ( remain )
109110
{
110111
tud_cdc_write_flush();
111112
}
112113
}
114+
115+
return size - remain;
113116
}
114117

115118
#endif // NRF52840_XXAA

libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
5151
Serial.print(report->rssi);
5252
Serial.print(" ");
5353

54-
Serial.printBuffer(report->data, report->dlen, '-');
54+
Serial.printBuffer(report->data.p_data, report->data.len, '-');
5555
Serial.println();
5656

5757
// Check if advertising contain BleUart service
@@ -61,13 +61,13 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
6161
}
6262

6363
Serial.println();
64+
65+
// For Softdevice v6: after received a report, scanner will be paused
66+
// We need to call Scanner start() to resume scanning
67+
Bluefruit.Scanner.start();
6468
}
6569

6670
void loop()
6771
{
68-
// Toggle both LEDs every 1 second
69-
digitalToggle(LED_RED);
70-
71-
delay(1000);
72+
// nothing to do
7273
}
73-

libraries/Bluefruit52Lib/examples/Peripheral/clearbonds/clearbonds.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include <bluefruit.h>
20-
#include <Nffs.h>
2120
#include <utility/bonding.h>
2221

2322
void setup()

libraries/Bluefruit52Lib/src/BLEScanner.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
#include "bluefruit.h"
3838

39-
static uint8_t _scan_data[BLE_GAP_SCAN_BUFFER_MAX];
40-
4139
BLEScanner::BLEScanner(void)
4240
{
4341
_report_data.p_data = _scan_data;
@@ -57,7 +55,7 @@ BLEScanner::BLEScanner(void)
5755
_rx_cb = NULL;
5856
_stop_cb = NULL;
5957

60-
_param = (ble_gap_scan_params_t) {
58+
_param = ((ble_gap_scan_params_t) {
6159
// TODO Extended Adv on secondary channels
6260
.extended = 0,
6361
.report_incomplete_evts = 0,
@@ -70,7 +68,7 @@ BLEScanner::BLEScanner(void)
7068
.window = BLE_SCAN_WINDOW_DFLT,
7169
.timeout = 0, // no timeout, in 10 ms units
7270
.channel_mask = { 0, 0, 0, 0, 0 }
73-
};
71+
});
7472
}
7573

7674
void BLEScanner::useActiveScan(bool enable)
@@ -117,11 +115,23 @@ ble_gap_scan_params_t* BLEScanner::getParams(void)
117115

118116
bool BLEScanner::start(uint16_t timeout)
119117
{
120-
_param.timeout = timeout;
121-
VERIFY_STATUS( sd_ble_gap_scan_start(&_param, &_report_data), false );
118+
_report_data.p_data = _scan_data;
119+
_report_data.len = BLE_GAP_SCAN_BUFFER_MAX;
120+
121+
if (_runnning)
122+
{
123+
// resume scanning after received an report
124+
VERIFY_STATUS( sd_ble_gap_scan_start(NULL, &_report_data), false );
125+
}else
126+
{
127+
// start a new scan
128+
_param.timeout = timeout;
122129

123-
Bluefruit._startConnLed(); // start blinking
124-
_runnning = true;
130+
VERIFY_STATUS( sd_ble_gap_scan_start(&_param, &_report_data), false );
131+
132+
Bluefruit._startConnLed(); // start blinking
133+
_runnning = true;
134+
}
125135

126136
return true;
127137
}
@@ -393,6 +403,7 @@ void BLEScanner::_eventHandler(ble_evt_t* evt)
393403
case BLE_GAP_EVT_TIMEOUT:
394404
if (evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
395405
{
406+
_runnning = false;
396407
if (_stop_cb) ada_callback(NULL, _stop_cb);
397408
}
398409
break;

libraries/Bluefruit52Lib/src/BLEScanner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class BLEScanner
9696
void _eventHandler(ble_evt_t* evt);
9797

9898
private:
99+
uint8_t _scan_data[BLE_GAP_SCAN_BUFFER_MAX];
99100
ble_data_t _report_data;
100101

101102
bool _runnning;

0 commit comments

Comments
 (0)