From d42a80da00883a86cb74be2f62f69c803b499d96 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 24 Apr 2023 11:27:08 +0100 Subject: [PATCH] add workaround for connection timeout issue --- apps/bthrmlite/boot.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/bthrmlite/boot.js b/apps/bthrmlite/boot.js index 89ca49c38..d10266789 100644 --- a/apps/bthrmlite/boot.js +++ b/apps/bthrmlite/boot.js @@ -1,6 +1,6 @@ -(function() { - var log = function() {};//print - var gatt; +{ + let log = function() {};//print + let gatt; Bangle.enableBTHRMLog = function() { log = print; @@ -57,8 +57,11 @@ log("Ready"); console.log("Done!"); }).catch(function(err) { - console.log("Error",err); + console.log("BTHRM Error",err); gatt = undefined; + // retry connection if we got a connect timeout + if (err == "Connection Timeout") + setTimeout(Bangle.setHRMPower, 1000, isOn, app); }); } } else { // not on @@ -72,4 +75,15 @@ } } }; -})(); \ No newline at end of file +// disconnect when swapping apps +E.on("kill", function() { + if (gatt) { + log("HRM connected - disconnecting"); + try {gatt.disconnect();}catch(e) { + log("HRM disconnect error", e); + } + gatt = undefined; + } +}); + +} \ No newline at end of file