Hopefully fix bug where no HRM data is received

master
Marco Heiming 2022-01-07 09:53:40 +01:00
parent ba20a7b51e
commit aa47b7fa99
1 changed files with 35 additions and 32 deletions

View File

@ -9,6 +9,7 @@ const powerIconGreen = heatshrink.decompress(atob("h0OwYQNkAEDpAEDiQEDkmSAgUJkmA
const powerIconRed = heatshrink.decompress(atob("h0OwYQNoAEDyAEDkgEDpIFDiVJBweSAgUJkmAAoYZDgQpEBwYAJA")); const powerIconRed = heatshrink.decompress(atob("h0OwYQNoAEDyAEDkgEDpIFDiVJBweSAgUJkmAAoYZDgQpEBwYAJA"));
let settings; let settings;
function loadSettings() { function loadSettings() {
settings = require("Storage").readJSON("circlesclock.json", 1) || { settings = require("Storage").readJSON("circlesclock.json", 1) || {
'minHR': 40, 'minHR': 40,
@ -97,7 +98,7 @@ function draw() {
function drawCircle(index, defaultType) { function drawCircle(index, defaultType) {
const type = settings['circle' + index] || defaultType; const type = settings['circle' + index] || defaultType;
const w = index == 1 ? w1: index == 2 ? w2 : w3; const w = index == 1 ? w1 : index == 2 ? w2 : w3;
switch (type) { switch (type) {
case "steps": case "steps":
@ -114,12 +115,13 @@ function drawCircle(index, defaultType) {
break; break;
} }
} }
function getCirclePosition(type, defaultPos) { function getCirclePosition(type, defaultPos) {
for (let i = 1; i <= 3; i++) { for (let i = 1; i <= 3; i++) {
const setting = settings['circle' + i]; const setting = settings['circle' + i];
if (setting == type) return i == 1 ? w1: i == 2 ? w2 : w3; if (setting == type) return i == 1 ? w1 : i == 2 ? w2 : w3;
} }
return defaultPos; return defaultPos || undefined;
} }
function isCircleEnabled(type) { function isCircleEnabled(type) {
@ -229,8 +231,7 @@ function drawBattery(w) {
if (Bangle.isCharging()) { if (Bangle.isCharging()) {
color = colorGreen; color = colorGreen;
icon = powerIconGreen; icon = powerIconGreen;
} } else {
else {
if (settings.batteryWarn != undefined && battery <= settings.batteryWarn) { if (settings.batteryWarn != undefined && battery <= settings.batteryWarn) {
color = colorRed; color = colorRed;
icon = powerIconRed; icon = powerIconRed;
@ -289,39 +290,41 @@ function getSteps() {
return 0; return 0;
} }
Bangle.on('lock', function(isLocked) { function enableHRMSensor() {
if (!isLocked) { Bangle.setHRMPower(1, "circleclock");
if (isCircleEnabled("hr")) {
Bangle.setHRMPower(1, "watch");
if (hrtValue == undefined) { if (hrtValue == undefined) {
hrtValue = '...'; hrtValue = '...';
drawHeartRate(); drawHeartRate();
} }
}
Bangle.on('lock', function(isLocked) {
if (!isLocked) {
if (isCircleEnabled("hr")) {
enableHRMSensor();
} }
draw(); draw();
} else { } else {
if (isCircleEnabled("hr")) { Bangle.setHRMPower(0, "circleclock");
Bangle.setHRMPower(0, "watch");
}
} }
}); });
if (isCircleEnabled("hr")) {
Bangle.on('HRM', function(hrm) { Bangle.on('HRM', function(hrm) {
//if(hrm.confidence > 90){ if (isCircleEnabled("hr")) {
hrtValue = hrm.bpm; hrtValue = hrm.bpm;
if (Bangle.isLCDOn()) if (Bangle.isLCDOn())
drawHeartRate(); drawHeartRate();
//} else { }
// hrtValue = undefined; });
//}
});
}
if (isCircleEnabled("battery")) {
Bangle.on('charging', function(charging) { Bangle.on('charging', function(charging) {
drawBattery(); if (isCircleEnabled("battery")) drawBattery();
}); });
if (isCircleEnabled("hr")) {
enableHRMSensor();
} }
Bangle.setUI("clock"); Bangle.setUI("clock");