From cdb441d40fef1ca7788977c86fad1fbdff782eec Mon Sep 17 00:00:00 2001 From: Kendell R Date: Thu, 13 Apr 2023 09:02:29 -0400 Subject: [PATCH] Fix some logic in the health app --- apps/health/boot.js | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/apps/health/boot.js b/apps/health/boot.js index ae9a7cdc9..c5751bf7d 100644 --- a/apps/health/boot.js +++ b/apps/health/boot.js @@ -1,28 +1,28 @@ -(function(){ - var settings = require("Storage").readJSON("health.json",1)||{}; +(function() { + var settings = require("Storage").readJSON("health.json", 1) || {}; var hrm = 0|settings.hrm; if (hrm == 1 || hrm == 2) { - function onHealth() { - Bangle.setHRMPower(1, "health"); - setTimeout(()=>Bangle.setHRMPower(0, "health"),hrm*60000); // give it 1 minute detection time for 3 min setting and 2 minutes for 10 min setting - if (hrm == 1){ - for (var i = 1; i <= 2; i++){ - setTimeout(()=>{ - Bangle.setHRMPower(1, "health"); - setTimeout(()=>{ - Bangle.setHRMPower(0, "health"); - }, 60000); - }, (i * 200000)); - } - } - } - Bangle.on("health", onHealth); - Bangle.on('HRM', h => { - if (h.confidence>80) Bangle.setHRMPower(0, "health"); - }); - if (Bangle.getHealthStatus().bpmConfidence) return; - onHealth(); - } else Bangle.setHRMPower(hrm!=0, "health"); + function onHealth() { + Bangle.setHRMPower(1, "health"); + setTimeout(() => Bangle.setHRMPower(0, "health"), hrm * 60000); // give it 1 minute detection time for 3 min setting and 2 minutes for 10 min setting + if (hrm == 1) { + function startMeasurement() { + Bangle.setHRMPower(1, "health"); + setTimeout(() => { + Bangle.setHRMPower(0, "health"); + }, 60000); + } + setTimeout(startMeasurement, 200000); + setTimeout(startMeasurement, 400000); + } + } + Bangle.on("health", onHealth); + Bangle.on("HRM", (h) => { + if (h.confidence > 80 && Bangle.getHealthStatus().bpm == h.bpm) Bangle.setHRMPower(0, "health"); + }); + if (Bangle.getHealthStatus().bpmConfidence > 80) return; + onHealth(); + } else Bangle.setHRMPower(!!hrm, "health"); })(); Bangle.on("health", health => {