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/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..f5e0e1e5b 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"); } @@ -454,7 +460,7 @@ exports.enable = () => { } else { log("Start bonding"); return gatt.startBonding() - .then(() => console.log(gatt.getSecurityStatus())); + .then(() => log("Security status" + gatt.getSecurityStatus())); } }); } @@ -520,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 @@ -638,7 +645,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) + } } }); } 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", 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); } };