From 727f1ac504aa3f7b2d661c1bdbf6a67874a1f4ac Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Wed, 16 Nov 2022 17:30:52 +0100 Subject: [PATCH 1/4] bthrm - Add debug option for active scanning --- apps/bthrm/default.json | 3 ++- apps/bthrm/lib.js | 10 ++++++++-- apps/bthrm/settings.js | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/bthrm/default.json b/apps/bthrm/default.json index 2c729ec68..79605b412 100644 --- a/apps/bthrm/default.json +++ b/apps/bthrm/default.json @@ -17,5 +17,6 @@ "gracePeriodConnect": 0, "gracePeriodService": 0, "gracePeriodRequest": 0, - "bonding": false + "bonding": false, + "active": true } diff --git a/apps/bthrm/lib.js b/apps/bthrm/lib.js index 32a0f5a40..08f626392 100644 --- a/apps/bthrm/lib.js +++ b/apps/bthrm/lib.js @@ -387,8 +387,14 @@ exports.enable = () => { return; } log("Requesting device with filters", filters); - promise = NRF.requestDevice({ filters: filters, active: true }); - + try { + promise = NRF.requestDevice({ filters: filters, active: settings.active }); + } catch (e){ + log("Error during initial request:", e); + onDisconnect(e); + return; + } + if (settings.gracePeriodRequest){ log("Add " + settings.gracePeriodRequest + "ms grace period after request"); } diff --git a/apps/bthrm/settings.js b/apps/bthrm/settings.js index fb5aa04da..459ed29fc 100644 --- a/apps/bthrm/settings.js +++ b/apps/bthrm/settings.js @@ -102,6 +102,12 @@ writeSettings("bonding",v); } }, + 'Use active scanning': { + value: !!settings.active, + onchange: v => { + writeSettings("active",v); + } + }, 'Grace periods': function() { E.showMenu(submenu_grace); } }; From a484e0379c1302dba882441dd1738badef24eec5 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Wed, 16 Nov 2022 17:31:19 +0100 Subject: [PATCH 2/4] bthrm - More logging for errors --- apps/bthrm/lib.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/bthrm/lib.js b/apps/bthrm/lib.js index 08f626392..2dd3dc662 100644 --- a/apps/bthrm/lib.js +++ b/apps/bthrm/lib.js @@ -460,7 +460,7 @@ exports.enable = () => { } else { log("Start bonding"); return gatt.startBonding() - .then(() => console.log(gatt.getSecurityStatus())); + .then(() => log("Security status" + gatt.getSecurityStatus())); } }); } @@ -644,7 +644,11 @@ exports.enable = () => { E.on("kill", ()=>{ if (gatt && gatt.connected){ log("Got killed, trying to disconnect"); - gatt.disconnect().then(()=>log("Disconnected on kill")).catch((e)=>log("Error during disconnnect on kill", e)); + try { + gatt.disconnect().then(()=>log("Disconnected on kill")).catch((e)=>log("Error during disconnnect promise on kill", e)); + } catch (e) { + log("Error during disconnnect on kill", e) + } } }); } From f7aa8340f0ac247bade3615dd12016df56bcd221 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Wed, 16 Nov 2022 17:32:20 +0100 Subject: [PATCH 3/4] bthrm - Reset powerdownRequested when start BTHRM --- apps/bthrm/lib.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/bthrm/lib.js b/apps/bthrm/lib.js index 2dd3dc662..f5e0e1e5b 100644 --- a/apps/bthrm/lib.js +++ b/apps/bthrm/lib.js @@ -526,6 +526,7 @@ exports.enable = () => { isOn = Bangle._PWR.BTHRM.length; // so now we know if we're really on if (isOn) { + powerdownRequested = false; switchFallback(); if (!Bangle.isBTHRMConnected()) initBt(); } else { // not on From 7ce10a18b6b16e094fddf57a138feaa12543a880 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Wed, 16 Nov 2022 17:34:05 +0100 Subject: [PATCH 4/4] bthrm - Bump version --- apps/bthrm/ChangeLog | 3 +++ apps/bthrm/metadata.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/bthrm/ChangeLog b/apps/bthrm/ChangeLog index e5b41482f..99cf0c670 100644 --- a/apps/bthrm/ChangeLog +++ b/apps/bthrm/ChangeLog @@ -37,3 +37,6 @@ 0.15: Fix recording internal sensor Handle fallback to internal sensor consistently if BT bpm is 0 Power internal sensor down if not needed for fallback +0.16: Set powerdownRequested correctly on BTHRM power on + Additional logging on errors + Add debug option for disabling active scanning diff --git a/apps/bthrm/metadata.json b/apps/bthrm/metadata.json index 2803de5cf..18c34ea33 100644 --- a/apps/bthrm/metadata.json +++ b/apps/bthrm/metadata.json @@ -2,7 +2,7 @@ "id": "bthrm", "name": "Bluetooth Heart Rate Monitor", "shortName": "BT HRM", - "version": "0.15", + "version": "0.16", "description": "Overrides Bangle.js's build in heart rate monitor with an external Bluetooth one.", "icon": "app.png", "type": "app",