update scanner for SD v6 changes

- minor correct for USBSerial write()
This commit is contained in:
hathach committed 2018-11-07 23:44:46 +07:00
1 parent bba2a74b23
commit e5ed77856b
6 files changed
+37 -21

No files matched your search

+4 -2
View File
@@ -2,8 +2,10 @@
## 0.9.0
- Feather nRF52840 support
- Added nRF52840-based board support (pca10056 and feather nRF52840 express)
- Upgrade bootloader to v6.1.0 ( single bank only )
- Upgrade BSP code to match SD v6
- Bluefruit.Scanner.start() must be called (often in callback) to resume scanning after received an report.
- Upgrade freeRTOS from v8 to v10.0.1
- Upgrade Segger SysView to 2.52d
- Added nrfx to core
@@ -34,7 +36,7 @@
## 0.8.4
- Fix #160: hardware PWM issue that cause Servo freq is 640 hz instead of 50hz
- Fix #134: hardcoded pulse limits with Servo
- Fix #134: hardcoded pulse limits with Servo
- Fix upload issue with windows when username has spaces
- Support serialEvent()
+7 -4
View File
@@ -98,18 +98,21 @@ size_t USBSerial::write(uint8_t ch)
size_t USBSerial::write(const uint8_t *buffer, size_t size)
{
while ( size )
size_t remain = size;
while ( remain && tud_cdc_connected() )
{
size_t wrcount = tud_cdc_write(buffer, size);
size -= wrcount;
size_t wrcount = tud_cdc_write(buffer, remain);
remain -= wrcount;
buffer += wrcount;
// Write FIFO is full, flush and re-try
if ( size )
if ( remain )
{
tud_cdc_write_flush();
}
}
return size - remain;
}
#endif // NRF52840_XXAA
@@ -51,7 +51,7 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
Serial.print(report->rssi);
Serial.print(" ");
Serial.printBuffer(report->data, report->dlen, '-');
Serial.printBuffer(report->data.p_data, report->data.len, '-');
Serial.println();
// Check if advertising contain BleUart service
@@ -61,13 +61,13 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
}
Serial.println();
// For Softdevice v6: after received a report, scanner will be paused
// We need to call Scanner start() to resume scanning
Bluefruit.Scanner.start();
}
void loop()
{
// Toggle both LEDs every 1 second
digitalToggle(LED_RED);
delay(1000);
// nothing to do
}
@@ -17,7 +17,6 @@
*/
#include <bluefruit.h>
#include <Nffs.h>
#include <utility/bonding.h>
void setup()
+19 -8
View File
@@ -36,8 +36,6 @@
#include "bluefruit.h"
static uint8_t _scan_data[BLE_GAP_SCAN_BUFFER_MAX];
BLEScanner::BLEScanner(void)
{
_report_data.p_data = _scan_data;
@@ -57,7 +55,7 @@ BLEScanner::BLEScanner(void)
_rx_cb = NULL;
_stop_cb = NULL;
_param = (ble_gap_scan_params_t) {
_param = ((ble_gap_scan_params_t) {
// TODO Extended Adv on secondary channels
.extended = 0,
.report_incomplete_evts = 0,
@@ -70,7 +68,7 @@ BLEScanner::BLEScanner(void)
.window = BLE_SCAN_WINDOW_DFLT,
.timeout = 0, // no timeout, in 10 ms units
.channel_mask = { 0, 0, 0, 0, 0 }
};
});
}
void BLEScanner::useActiveScan(bool enable)
@@ -117,11 +115,23 @@ ble_gap_scan_params_t* BLEScanner::getParams(void)
bool BLEScanner::start(uint16_t timeout)
{
_param.timeout = timeout;
VERIFY_STATUS( sd_ble_gap_scan_start(&_param, &_report_data), false );
_report_data.p_data = _scan_data;
_report_data.len = BLE_GAP_SCAN_BUFFER_MAX;
Bluefruit._startConnLed(); // start blinking
_runnning = true;
if (_runnning)
{
// resume scanning after received an report
VERIFY_STATUS( sd_ble_gap_scan_start(NULL, &_report_data), false );
}else
{
// start a new scan
_param.timeout = timeout;
VERIFY_STATUS( sd_ble_gap_scan_start(&_param, &_report_data), false );
Bluefruit._startConnLed(); // start blinking
_runnning = true;
}
return true;
}
@@ -393,6 +403,7 @@ void BLEScanner::_eventHandler(ble_evt_t* evt)
case BLE_GAP_EVT_TIMEOUT:
if (evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
{
_runnning = false;
if (_stop_cb) ada_callback(NULL, _stop_cb);
}
break;
@@ -96,6 +96,7 @@ public:
void _eventHandler(ble_evt_t* evt);
private:
uint8_t _scan_data[BLE_GAP_SCAN_BUFFER_MAX];
ble_data_t _report_data;
bool _runnning;