Skip to content

Commit

Permalink
nRF52: Added window/interval arguments to NRF.setScan (default was 10…
Browse files Browse the repository at this point in the history
…0ms) (ref #2465)
  • Loading branch information
gfwilliams committed Feb 23, 2024
1 parent c6408a3 commit 76d2b57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions libs/bluetooth/jswrap_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions targets/nrf5x/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76d2b57

Please sign in to comment.