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..15bb2b670 --- /dev/null +++ b/apps/bootgatthrm/README.md @@ -0,0 +1,16 @@ +# BLE GATT HRM Service + +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. + +## Creator + +[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! diff --git a/apps/bootgatthrm/bluetooth.png b/apps/bootgatthrm/bluetooth.png new file mode 100644 index 000000000..1a884a62c Binary files /dev/null and b/apps/bootgatthrm/bluetooth.png differ diff --git a/apps/bootgatthrm/boot.js b/apps/bootgatthrm/boot.js new file mode 100644 index 000000000..391f245b9 --- /dev/null +++ b/apps/bootgatthrm/boot.js @@ -0,0 +1,54 @@ +(() => { + function setupHRMAdvertising() { + /* + * This function prepares BLE heart rate Advertisement. + */ + + NRF.setServices({ + 0x180D: { // heart_rate + 0x2A37: { // heart_rate_measurement + notify: true, + value: [0x06, 0], + } + } + }, { advertise: [0x180d] }); + + } + function updateBLEHeartRate(hrm) { + /* + * Send updated heart rate measurement via BLE + */ + if (hrm === undefined || hrm.confidence < 50) return; + try { + NRF.updateServices({ + 0x180D: { + 0x2A37: { + value: [ + 0x06, // + hrm.bpm + ], + notify: true + } + } + }); + } catch (error) { + 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); }); +})(); 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"} + ] +}