From 76d2b5793474571169c4d1caf64292c2cb35e569 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 23 Feb 2024 08:59:05 +0000 Subject: [PATCH] nRF52: Added window/interval arguments to NRF.setScan (default was 100ms) (ref #2465) --- ChangeLog | 1 + libs/bluetooth/jswrap_bluetooth.c | 5 +++++ targets/nrf5x/bluetooth.c | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 54b9a10f3b..d03f844571 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ nRF52: Write flash in 2k blocks (not 4k) as SD 6.1.1 can crash (probably good for earlier SD too) g.wrapString fix issues wrapping long words in UTF8 strings over multiple lines Bangle.js2: Fix parsing of UTF8 strings containing char codes 0xF5..0xFF (which are not valid UTF8) + nRF52: Added window/interval arguments to NRF.setScan (default was 100ms) 2v21 : nRF52: free up 800b more flash by removing vector table padding Throw Exception when a Promise tries to resolve with another Promise (#2450) diff --git a/libs/bluetooth/jswrap_bluetooth.c b/libs/bluetooth/jswrap_bluetooth.c index 2dc3a9cb55..4d2e64fdb6 100644 --- a/libs/bluetooth/jswrap_bluetooth.c +++ b/libs/bluetooth/jswrap_bluetooth.c @@ -3281,6 +3281,11 @@ filters: [ ... ] })` be `"1mbps/2mbps/both/coded"`) * `extended` - (NRF52833/NRF52840 only) support receiving extended-length advertising packets (default=true if phy isn't `"1mbps"`) +* `extended` - (NRF52833/NRF52840 only) support receiving extended-length advertising + packets (default=true if phy isn't `"1mbps"`) +* `window` - (2v22+) how long we scan for in milliseconds (default 100ms) +* `interval` - (2v22+) how often we scan in milliseconds (default 100ms) - `window=interval=100`(default) is all the time. When +scanning on both `1mbps` and `coded`, `interval` needs to be twice `window`. **NOTE:** `timeout` and `active` are not part of the Web Bluetooth standard. diff --git a/targets/nrf5x/bluetooth.c b/targets/nrf5x/bluetooth.c index 7bbda07316..e34179dd90 100644 --- a/targets/nrf5x/bluetooth.c +++ b/targets/nrf5x/bluetooth.c @@ -3004,6 +3004,14 @@ uint32_t jsble_set_scanning(bool enabled, JsVar *options) { } else jsWarn("Unknown phy %q\n", advPhy); jsvUnLock(advPhy); #endif + uint32_t scan_window = MSEC_TO_UNITS(jsvObjectGetIntegerChild(options, "window"), UNIT_0_625_MS); + if (scan_window>=4 && scan_window<=16384) + m_scan_param.window = scan_window; + uint32_t scan_interval = MSEC_TO_UNITS(jsvObjectGetIntegerChild(options, "interval"), UNIT_0_625_MS); + if (scan_interval>=4 && scan_interval<=16384) + m_scan_param.interval = scan_interval; + if (m_scan_param.interval < m_scan_param.window) + m_scan_param.interval = m_scan_param.window; } err_code = sd_ble_gap_scan_start(&m_scan_param