From b7cbdf269d2b5fd88d1e3527b91ed402ad350cdf Mon Sep 17 00:00:00 2001 From: stweedo <108593831+stweedo@users.noreply.github.com> Date: Fri, 9 Jun 2023 02:19:35 -0500 Subject: [PATCH 1/7] [widbt] - fixes widget not showing on blue background --- apps/widbt/widget.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/widbt/widget.js b/apps/widbt/widget.js index c7ef8c0ad..31b8e12d8 100644 --- a/apps/widbt/widget.js +++ b/apps/widbt/widget.js @@ -1,9 +1,14 @@ WIDGETS["bluetooth"]={area:"tr",width:15,draw:function() { g.reset(); - if (NRF.getSecurityStatus().connected) - g.setColor((g.getBPP()>8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); - else + if (NRF.getSecurityStatus().connected) { + if (g.getBgColor() === 31) { // If background color is blue use cyan instead + g.setColor("#0ff"); + } else { + g.setColor((g.getBPP()>8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); + } + } else { g.setColor(g.theme.dark ? "#666" : "#999"); + } g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="),2+this.x,2+this.y); },changed:function() { WIDGETS["bluetooth"].draw(); From 465097b54b8c7e23db5dc5b1e1f2718b57bc1398 Mon Sep 17 00:00:00 2001 From: stweedo <108593831+stweedo@users.noreply.github.com> Date: Fri, 9 Jun 2023 02:27:49 -0500 Subject: [PATCH 2/7] Update ChangeLog --- apps/widbt/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/widbt/ChangeLog b/apps/widbt/ChangeLog index 4c2132122..292d1347e 100644 --- a/apps/widbt/ChangeLog +++ b/apps/widbt/ChangeLog @@ -5,3 +5,4 @@ 0.06: Tweaking colors for dark/light themes and low bpp screens 0.07: Memory usage improvements 0.08: Disable LCD on, on bluetooth status change +0.09: Fixes widget not showing on blue background From bed497a3bfa724027a885f98da0c002d7ac0f5bf Mon Sep 17 00:00:00 2001 From: stweedo <108593831+stweedo@users.noreply.github.com> Date: Fri, 9 Jun 2023 02:28:13 -0500 Subject: [PATCH 3/7] Update ChangeLog --- apps/widbt/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/widbt/ChangeLog b/apps/widbt/ChangeLog index 292d1347e..74d31ada6 100644 --- a/apps/widbt/ChangeLog +++ b/apps/widbt/ChangeLog @@ -5,4 +5,4 @@ 0.06: Tweaking colors for dark/light themes and low bpp screens 0.07: Memory usage improvements 0.08: Disable LCD on, on bluetooth status change -0.09: Fixes widget not showing on blue background +0.09: Fix widget not showing on blue background From 030279dc317a7e63b2b30f7c90e22f930863e62e Mon Sep 17 00:00:00 2001 From: stweedo <108593831+stweedo@users.noreply.github.com> Date: Fri, 9 Jun 2023 02:29:16 -0500 Subject: [PATCH 4/7] Update metadata.json --- apps/widbt/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/widbt/metadata.json b/apps/widbt/metadata.json index 1623db7a1..ec03fb353 100644 --- a/apps/widbt/metadata.json +++ b/apps/widbt/metadata.json @@ -1,7 +1,7 @@ { "id": "widbt", "name": "Bluetooth Widget", - "version": "0.08", + "version": "0.09", "description": "Show the current Bluetooth connection status in the top right of the clock", "icon": "widget.png", "type": "widget", 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 5/7] 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"} + ] +} From dbeb391e6965d1d9990b035054c47bcde5847df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20B=C3=BCsgen?= Date: Fri, 9 Jun 2023 10:43:50 +0200 Subject: [PATCH 6/7] feat: :sparkles: Added new bootloader "bootgatthrm" which exposes HRM data via BLE --- apps/bootgatthrm/boot.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/apps/bootgatthrm/boot.js b/apps/bootgatthrm/boot.js index 9f1ec1584..391f245b9 100644 --- a/apps/bootgatthrm/boot.js +++ b/apps/bootgatthrm/boot.js @@ -1,8 +1,9 @@ (() => { function setupHRMAdvertising() { /* - * This function preparse BLE heart rate Advertisement. + * This function prepares BLE heart rate Advertisement. */ + NRF.setServices({ 0x180D: { // heart_rate 0x2A37: { // heart_rate_measurement @@ -10,34 +11,44 @@ value: [0x06, 0], } } - }, { advertise: ['180D'] }); + }, { advertise: [0x180d] }); } - function updateBLEHeartRate(hrm) { /* * Send updated heart rate measurement via BLE */ - if (hrm === undefined) return; + if (hrm === undefined || hrm.confidence < 50) return; try { NRF.updateServices({ - '180d': { - '2a37': { + 0x180D: { + 0x2A37: { value: [ 0x06, // - hrm + hrm.bpm ], notify: true } } }); } catch (error) { - // After setupHRMAdvertising() BLE needs to restart. - // We force a disconnect if the Bangle was connected while setting HRM - NRF.disconnect(); + if (error.message.includes("BLE restart")) { + /* + * BLE has to restart after service setup. + */ + NRF.disconnect(); + } + else if (error.message.includes("UUID 0x2a37")) { + /* + * Setup service if it wasn't setup correctly for some reason + */ + setupHRMAdvertising(); + } else { + console.log("[bootgatthrm]: Unexpected error occured while updating HRM over BLE! Error: " + error.message); + } } } setupHRMAdvertising(); - Bangle.on("HRM", function (hrm) { updateBLEHeartRate(hrm.bpm); }); + Bangle.on("HRM", function (hrm) { updateBLEHeartRate(hrm); }); })(); From b424e0cb27fc33770a2ab5079e61879590eb888c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20B=C3=BCsgen?= Date: Fri, 9 Jun 2023 11:03:44 +0200 Subject: [PATCH 7/7] docs: :memo: Update Readme --- apps/bootgatthrm/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/bootgatthrm/README.md b/apps/bootgatthrm/README.md index 3e559c0a5..15bb2b670 100644 --- a/apps/bootgatthrm/README.md +++ b/apps/bootgatthrm/README.md @@ -1,16 +1,16 @@ -# BLE GATT Battery Service +# BLE GATT HRM Service -Adds the GATT Battery Service to advertise the percentage of battery currently remaining over Bluetooth. +Adds the GATT HRM Service to advertise the current HRM 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) +[Another Stranger](https://github.com/anotherstranger) + +## Aknowledgements + +Special thanks to [Jonathan Jefferies](https://github.com/jjok) for creating the +bootgattbat app, which was the inspiration for this App!