add workaround for connection timeout issue

pull/2707/head
Gordon Williams 2023-04-24 11:27:08 +01:00
parent b7d49cbbf8
commit d42a80da00
1 changed files with 19 additions and 5 deletions

View File

@ -1,6 +1,6 @@
(function() { {
var log = function() {};//print let log = function() {};//print
var gatt; let gatt;
Bangle.enableBTHRMLog = function() { Bangle.enableBTHRMLog = function() {
log = print; log = print;
@ -57,8 +57,11 @@
log("Ready"); log("Ready");
console.log("Done!"); console.log("Done!");
}).catch(function(err) { }).catch(function(err) {
console.log("Error",err); console.log("BTHRM Error",err);
gatt = undefined; gatt = undefined;
// retry connection if we got a connect timeout
if (err == "Connection Timeout")
setTimeout(Bangle.setHRMPower, 1000, isOn, app);
}); });
} }
} else { // not on } else { // not on
@ -72,4 +75,15 @@
} }
} }
}; };
})(); // 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;
}
});
}