From f1ae6c92157f71ebd24495495339aa6e180f11cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20B=C3=BCsgen?= Date: Thu, 8 Jun 2023 20:50:56 +0200 Subject: [PATCH] feat: :sparkles: add gatthrm bootloader code --- apps/bootgatthrm/ChangeLog | 1 + apps/bootgatthrm/README.md | 16 ++++++++++++ apps/bootgatthrm/bluetooth.png | Bin 0 -> 1119 bytes apps/bootgatthrm/boot.js | 43 +++++++++++++++++++++++++++++++++ apps/bootgatthrm/metadata.json | 15 ++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 apps/bootgatthrm/ChangeLog create mode 100644 apps/bootgatthrm/README.md create mode 100644 apps/bootgatthrm/bluetooth.png create mode 100644 apps/bootgatthrm/boot.js create mode 100644 apps/bootgatthrm/metadata.json diff --git a/apps/bootgatthrm/ChangeLog b/apps/bootgatthrm/ChangeLog new file mode 100644 index 000000000..2a37193a3 --- /dev/null +++ b/apps/bootgatthrm/ChangeLog @@ -0,0 +1 @@ +0.01: Initial release. diff --git a/apps/bootgatthrm/README.md b/apps/bootgatthrm/README.md new file mode 100644 index 000000000..3e559c0a5 --- /dev/null +++ b/apps/bootgatthrm/README.md @@ -0,0 +1,16 @@ +# BLE GATT Battery Service + +Adds the GATT Battery Service to advertise the percentage of battery currently remaining over Bluetooth. + +## Usage + +This boot code runs in the background and has no user interface. + +## Requests + +If you have any suggestions or ideas please post in [this forum thread](http://forum.espruino.com/conversations/351959/), +or [@jjok](https://github.com/jjok) in your Github issue. + +## Creator + +[Jonathan Jefferies](https://github.com/jjok) diff --git a/apps/bootgatthrm/bluetooth.png b/apps/bootgatthrm/bluetooth.png new file mode 100644 index 0000000000000000000000000000000000000000..1a884a62c1029ae43243f8f58ef9dc3a3327e437 GIT binary patch literal 1119 zcmV-l1fctgP)cE5(396`@Dz$wLqIPzYppJ*B(brZX|I zHChYW;Hm1lL~9feUi^283bm!!Ka0DG`v(zZvk8h?W%2@c?XT zES*ZPJU3a{7h{cB0RRrPTh=dGr*a^!0&xQX?DMczGEQwQ4)Y`c0EQJR_Oa?r)W%5x z0HhI_x1HK2pc0j7k^sKW*iQXQ=2YX6D9n-q_%qO+(!1;R%(3!ggBm9SkZ!j|fYm^E zR%O?(qZ5_=gLo$b@WZ#`wXJ`4=)@t~Y>Yv)Y!7y;OB zeO8rs?l*_RK!7NCKLhRU0}||esEhzCyx)O;I=Y5XtC(@B$NTljy45^tT?SHJ10ruX zOS$(<@@!=?P@`0+S)vnkL!=bB)DOg{Q*}L+GO)XAK;&$g@DSo22n#XlR9!)?07D(! zDxz;SOSunBbNCAVm!5U2c~9jVx@WU3=u3)pJ!ur3cu;sm-)NQ!pM}i;0{{TnZpA^Z ztASvff%b#?JdoF$<=hv8)Q159pyx{LBoBD4SyIzhb(HlW;>}!J+1=AqCDO_A6&XN}=e)0!pcibn z_HtD9d_@BAknp}zDCb9=>MK#y^fmCZ_8GoYkv>KTT7e$nHy?0mXP*UpX*>1PgVgRc z3#Fdn#d~2}5mATky^{qxZ#%U!Ve5AonQN!;&C-!_@cJGbKmk6^xYakqWbkDSU>e?6 zF9=onXw<2mHO=A62q0{DUp*iYB(+@Ja7a-n2aQU$C-1do)^M)j_l7Z`m-DHf;N2WNgeIsEr6@kFmJ z8_YbwGn3bL?QPY+LOBr_TDRcEMmfJ|;s=HR0IQ!ry9xAti1(G5Y&@#1^&${_&Hfi+ z9c`2jUpMuHhg{we{KebpwXs3NLqaRiAr)b6sg!$n>kZxDN)lj0k<-mm?qZatNdeqJ z)Lky+8&Ml40dUjvB)_tlzY&Ld+&A&{bh~wEWib~^c!+ZagoS&X-t=l^d_A@r#J2*U lKABp3ezkHW*6{xc{R@3@kib`1LqGrk002ovPDHLkV1l684mkh- literal 0 HcmV?d00001 diff --git a/apps/bootgatthrm/boot.js b/apps/bootgatthrm/boot.js new file mode 100644 index 000000000..9f1ec1584 --- /dev/null +++ b/apps/bootgatthrm/boot.js @@ -0,0 +1,43 @@ +(() => { + function setupHRMAdvertising() { + /* + * This function preparse BLE heart rate Advertisement. + */ + NRF.setServices({ + 0x180D: { // heart_rate + 0x2A37: { // heart_rate_measurement + notify: true, + value: [0x06, 0], + } + } + }, { advertise: ['180D'] }); + + } + + function updateBLEHeartRate(hrm) { + /* + * Send updated heart rate measurement via BLE + */ + if (hrm === undefined) return; + try { + NRF.updateServices({ + '180d': { + '2a37': { + value: [ + 0x06, // + hrm + ], + notify: true + } + } + }); + } catch (error) { + // After setupHRMAdvertising() BLE needs to restart. + // We force a disconnect if the Bangle was connected while setting HRM + NRF.disconnect(); + } + } + + setupHRMAdvertising(); + Bangle.on("HRM", function (hrm) { updateBLEHeartRate(hrm.bpm); }); +})(); diff --git a/apps/bootgatthrm/metadata.json b/apps/bootgatthrm/metadata.json new file mode 100644 index 000000000..e7bfb0762 --- /dev/null +++ b/apps/bootgatthrm/metadata.json @@ -0,0 +1,15 @@ +{ + "id": "bootgatthrm", + "name": "BLE GATT HRM Service", + "shortName": "BLE HRM Service", + "version": "0.01", + "description": "Adds the GATT HRM Service to advertise the measured HRM over Bluetooth.\n", + "icon": "bluetooth.png", + "type": "bootloader", + "tags": "hrm,health,ble,bluetooth,gatt", + "supports": ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"gatthrm.boot.js","url":"boot.js"} + ] +}