From 55760a426202d8b063b626418a4c5b2679461fcd Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 9 Nov 2018 11:29:37 +0700 Subject: [PATCH] add Scanner resume() --- README.md | 2 ++ changelog.md | 2 +- .../central_bleuart/central_bleuart.ino | 4 +-- .../Central/central_scan/central_scan.ino | 4 +-- .../central_scan_advanced.ino | 4 +-- .../central_ti_sensortag_optical.ino | 6 ++--- .../rssi_proximity_central.ino | 4 +++ libraries/Bluefruit52Lib/src/BLEScanner.cpp | 25 +++++++++---------- libraries/Bluefruit52Lib/src/BLEScanner.h | 1 + 9 files changed, 29 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1ca114ab..8cd37b48 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ This repository contains the Arduino BSP for Adafruit nRF52 series: - [Bluefruit Feather nRF52832](https://www.adafruit.com/product/3406) +- Bluefruit Feather nRF52840 Express (coming soon) +- [Noric nRF52840DK PCA10056](https://www.nordicsemi.com/eng/Products/nRF52840-DK) ## BSP Installation diff --git a/changelog.md b/changelog.md index 9b6b4b94..6b327c8f 100644 --- a/changelog.md +++ b/changelog.md @@ -5,7 +5,7 @@ - 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. + - Bluefruit.Scanner.resume() must be called in scan 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 diff --git a/libraries/Bluefruit52Lib/examples/Central/central_bleuart/central_bleuart.ino b/libraries/Bluefruit52Lib/examples/Central/central_bleuart/central_bleuart.ino index 87bbd45f..4ca6ad59 100644 --- a/libraries/Bluefruit52Lib/examples/Central/central_bleuart/central_bleuart.ino +++ b/libraries/Bluefruit52Lib/examples/Central/central_bleuart/central_bleuart.ino @@ -78,8 +78,8 @@ void scan_callback(ble_gap_evt_adv_report_t* report) }else { // For Softdevice v6: after received a report, scanner will be paused - // We need to call Scanner start() to resume scanning - Bluefruit.Scanner.start(); + // We need to call Scanner resume() to continue scanning + Bluefruit.Scanner.resume(); } } diff --git a/libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino b/libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino index 7905431d..191f978d 100644 --- a/libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino +++ b/libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino @@ -63,8 +63,8 @@ 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(); + // We need to call Scanner resume() to continue scanning + Bluefruit.Scanner.resume(); } void loop() diff --git a/libraries/Bluefruit52Lib/examples/Central/central_scan_advanced/central_scan_advanced.ino b/libraries/Bluefruit52Lib/examples/Central/central_scan_advanced/central_scan_advanced.ino index 999ef600..3aab152a 100644 --- a/libraries/Bluefruit52Lib/examples/Central/central_scan_advanced/central_scan_advanced.ino +++ b/libraries/Bluefruit52Lib/examples/Central/central_scan_advanced/central_scan_advanced.ino @@ -181,8 +181,8 @@ 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(); + // We need to call Scanner resume() to continue scanning + Bluefruit.Scanner.resume(); } void printUuid16List(uint8_t* buffer, uint8_t len) diff --git a/libraries/Bluefruit52Lib/examples/Central/central_ti_sensortag_optical/central_ti_sensortag_optical.ino b/libraries/Bluefruit52Lib/examples/Central/central_ti_sensortag_optical/central_ti_sensortag_optical.ino index dc590303..85891bbc 100644 --- a/libraries/Bluefruit52Lib/examples/Central/central_ti_sensortag_optical/central_ti_sensortag_optical.ino +++ b/libraries/Bluefruit52Lib/examples/Central/central_ti_sensortag_optical/central_ti_sensortag_optical.ino @@ -144,7 +144,7 @@ void scan_callback(ble_gap_evt_adv_report_t* report) else { Serial.println("No Match"); - Bluefruit.Scanner.start(); // continue scanning + Bluefruit.Scanner.resume(); // continue scanning } } else @@ -152,8 +152,8 @@ void scan_callback(ble_gap_evt_adv_report_t* report) Serial.println("Failed"); // For Softdevice v6: after received a report, scanner will be paused - // We need to call Scanner start() to resume scanning - Bluefruit.Scanner.start(); + // We need to call Scanner resume() to continue scanning + Bluefruit.Scanner.resume(); } } diff --git a/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino b/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino index 91878bc2..c2842681 100644 --- a/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino +++ b/libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino @@ -364,6 +364,10 @@ void scan_callback(ble_gap_evt_adv_report_t* report) Serial.println(); #endif + + // For Softdevice v6: after received a report, scanner will be paused + // We need to call Scanner resume() to continue scanning + Bluefruit.Scanner.resume(); } #if ENABLE_TFT diff --git a/libraries/Bluefruit52Lib/src/BLEScanner.cpp b/libraries/Bluefruit52Lib/src/BLEScanner.cpp index 73be6717..1ac73664 100644 --- a/libraries/Bluefruit52Lib/src/BLEScanner.cpp +++ b/libraries/Bluefruit52Lib/src/BLEScanner.cpp @@ -118,24 +118,23 @@ bool BLEScanner::start(uint16_t timeout) _report_data.p_data = _scan_data; _report_data.len = BLE_GAP_SCAN_BUFFER_MAX; - 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; + _param.timeout = timeout; - VERIFY_STATUS( sd_ble_gap_scan_start(&_param, &_report_data), false ); + VERIFY_STATUS( sd_ble_gap_scan_start(&_param, &_report_data), false ); - Bluefruit._startConnLed(); // start blinking - _runnning = true; - } + Bluefruit._startConnLed(); // start blinking + _runnning = true; return true; } +bool BLEScanner::resume(void) +{ + // resume scanning after received an report + VERIFY_STATUS( sd_ble_gap_scan_start(NULL, &_report_data), false ); + return true; +} + bool BLEScanner::stop(void) { VERIFY_STATUS( sd_ble_gap_scan_stop(), false ); @@ -377,7 +376,7 @@ void BLEScanner::_eventHandler(ble_evt_t* evt) }else { // continue scanning since report is filtered and callback is not invoked - VERIFY_STATUS( sd_ble_gap_scan_start(NULL, &_report_data), ); + this->resume(); } } break; diff --git a/libraries/Bluefruit52Lib/src/BLEScanner.h b/libraries/Bluefruit52Lib/src/BLEScanner.h index e25b3a54..8e06eb09 100644 --- a/libraries/Bluefruit52Lib/src/BLEScanner.h +++ b/libraries/Bluefruit52Lib/src/BLEScanner.h @@ -74,6 +74,7 @@ public: void clearFilters(void); bool start(uint16_t timeout = 0); + bool resume(void); bool stop(void); /*------------- Callbacks -------------*/