Skip to content

Commit

Permalink
nRF5x: Add 'onWriteDesc' in NRF.setServices - allowing you to know wh…
Browse files Browse the repository at this point in the history
…en something subscribed for notifications
  • Loading branch information
gfwilliams committed Jul 5, 2022
1 parent 8458dfd commit c79fa00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -11,6 +11,7 @@
nRF52: Fix recent regression which stopped reconnection after a bluetooth disconnect (fix #2226)
Bangle.js: Include the 'sched' library in installed apps (needed for alarm) (fix #2229)
Bangle.js2: Fix text size on buttons when they are tapped in E.showPrompt
nRF5x: Add 'onWriteDesc' in NRF.setServices - allowing you to know when something subscribed for notifications

2v14 : Bangle.js2: Fix issue with E.showMenu creating a global `s` variable
Bangle.js2: Recheck string wrapping after font change inside E.showMenu
Expand Down
4 changes: 4 additions & 0 deletions libs/bluetooth/jswrap_bluetooth.c
Expand Up @@ -1249,6 +1249,10 @@ NRF.setServices({
},
onWrite : function(evt) { // optional
console.log("Got ", evt.data); // an ArrayBuffer
},
onWriteDesc : function(evt) { // optional - called when the 'cccd' descriptor is written
// for example this is called when notifications are requested by the client:
console.log("Notifications enabled = ", evt.data[0]&1);
}
}
// more characteristics allowed
Expand Down
7 changes: 7 additions & 0 deletions targets/nrf5x/bluetooth.c
Expand Up @@ -3029,6 +3029,13 @@ void jsble_set_services(JsVar *data) {
bleGetWriteEventName(eventName, characteristic_handles.value_handle);
jsvObjectSetChildAndUnLock(execInfo.root, eventName, writeCb);
}
// Add
writeCb = jsvObjectGetChild(charVar, "onWriteDesc", 0);
if (writeCb) {
char eventName[12];
bleGetWriteEventName(eventName, characteristic_handles.cccd_handle);
jsvObjectSetChildAndUnLock(execInfo.root, eventName, writeCb);
}

jsvUnLock(charVar);

Expand Down

0 comments on commit c79fa00

Please sign in to comment.