From cdb441d40fef1ca7788977c86fad1fbdff782eec Mon Sep 17 00:00:00 2001 From: Kendell R Date: Thu, 13 Apr 2023 09:02:29 -0400 Subject: [PATCH 1/5] 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 => { From a21b6827ff6fd73ac6669016ebae3e858b38e2d3 Mon Sep 17 00:00:00 2001 From: Kendell R Date: Thu, 13 Apr 2023 09:05:06 -0400 Subject: [PATCH 2/5] bump version --- apps/health/ChangeLog | 3 ++- apps/health/metadata.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/health/ChangeLog b/apps/health/ChangeLog index 921b2b682..12740959a 100644 --- a/apps/health/ChangeLog +++ b/apps/health/ChangeLog @@ -20,4 +20,5 @@ 0.19: Can show notification when daily step goal is reached 0.20: Fix the settings page, it would not update settings correctly. 0.21: Update boot.min.js. -0.22: Fix timeout for heartrate sensor on 3 minute setting (#2435) \ No newline at end of file +0.22: Fix timeout for heartrate sensor on 3 minute setting (#2435) +0.23: Fix HRM logic diff --git a/apps/health/metadata.json b/apps/health/metadata.json index d80585200..30e4b4276 100644 --- a/apps/health/metadata.json +++ b/apps/health/metadata.json @@ -2,7 +2,7 @@ "id": "health", "name": "Health Tracking", "shortName": "Health", - "version": "0.22", + "version": "0.23", "description": "Logs health data and provides an app to view it", "icon": "app.png", "tags": "tool,system,health", From f7d8ab1a5bff7df77bbf17de9b64ba1ea6cf0e77 Mon Sep 17 00:00:00 2001 From: Kendell R Date: Thu, 13 Apr 2023 09:09:44 -0400 Subject: [PATCH 3/5] turns out the two bpms can be a bit off --- apps/health/boot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/health/boot.js b/apps/health/boot.js index c5751bf7d..e369cb5bd 100644 --- a/apps/health/boot.js +++ b/apps/health/boot.js @@ -18,7 +18,7 @@ } Bangle.on("health", onHealth); Bangle.on("HRM", (h) => { - if (h.confidence > 80 && Bangle.getHealthStatus().bpm == h.bpm) Bangle.setHRMPower(0, "health"); + if (h.confidence > 80 && Math.abs(Bangle.getHealthStatus().bpm - h.bpm) < 1) Bangle.setHRMPower(0, "health"); }); if (Bangle.getHealthStatus().bpmConfidence > 80) return; onHealth(); From a67f819cf3adaf63e801aa10c497042cff619a3a Mon Sep 17 00:00:00 2001 From: Kendell R Date: Mon, 17 Apr 2023 06:00:09 -0400 Subject: [PATCH 4/5] Raise threshold to 90% confidence --- apps/health/boot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/health/boot.js b/apps/health/boot.js index e369cb5bd..62e8b87ab 100644 --- a/apps/health/boot.js +++ b/apps/health/boot.js @@ -18,9 +18,9 @@ } Bangle.on("health", onHealth); Bangle.on("HRM", (h) => { - if (h.confidence > 80 && Math.abs(Bangle.getHealthStatus().bpm - h.bpm) < 1) Bangle.setHRMPower(0, "health"); + if (h.confidence > 90 && Math.abs(Bangle.getHealthStatus().bpm - h.bpm) < 1) Bangle.setHRMPower(0, "health"); }); - if (Bangle.getHealthStatus().bpmConfidence > 80) return; + if (Bangle.getHealthStatus().bpmConfidence > 90) return; onHealth(); } else Bangle.setHRMPower(!!hrm, "health"); })(); From 0e461352d115a0cbcaa77be65606cbf1a4f6954b Mon Sep 17 00:00:00 2001 From: Kendell R Date: Mon, 17 Apr 2023 06:24:47 -0400 Subject: [PATCH 5/5] Update boot.min.js --- apps/health/boot.min.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/health/boot.min.js b/apps/health/boot.min.js index e3e45c400..651231195 100644 --- a/apps/health/boot.min.js +++ b/apps/health/boot.min.js @@ -1,5 +1,5 @@ function l(){var a=require("Storage").readJSON("health.json",1)||{},d=Bangle.getHealthStatus("day").steps;a.stepGoalNotification&&0=a.stepGoal&&(d=(new Date(Date.now())).toISOString().split("T")[0],!a.stepGoalNotificationDate||a.stepGoalNotificationDateBangle.setHRMPower(0,"health"),6E4*a);if(1==a)for(var b=1;2>=b;b++)setTimeout(()=>{Bangle.setHRMPower(1,"health");setTimeout(()=>{Bangle.setHRMPower(0,"health")},6E4)},2E5*b)}Bangle.on("health",d);Bangle.on("HRM",b=>{80{function d(c){return String.fromCharCode(c.steps>>8,c.steps&255,c.bpm,Math.min(c.movement/8,255))}var b=new Date(Date.now()-59E4);a&&0k;k++)e=g.substr(h,4),"\u00ff\u00ff\u00ff\u00ff"!=e&&(a.steps+=(e.charCodeAt(0)<<8)+e.charCodeAt(1),a.movement+=e.charCodeAt(2),a.movCnt++,e=e.charCodeAt(2),a.bpm+=e,e&&a.bpmCnt++),h-=4;a.bpmCnt&&(a.bpm/=a.bpmCnt);a.movCnt&&(a.movement/=a.movCnt); -require("Storage").write(b,d(a),f,17988)}}) \ No newline at end of file +a))}(function(){var a=0|(require("Storage").readJSON("health.json",1)||{}).hrm;if(1==a||2==a){var d=function(){Bangle.setHRMPower(1,"health");setTimeout(function(){return Bangle.setHRMPower(0,"health")},6E4*a);if(1==a){var b=function(){Bangle.setHRMPower(1,"health");setTimeout(function(){Bangle.setHRMPower(0,"health")},6E4)};setTimeout(b,2E5);setTimeout(b,4E5)}};Bangle.on("health",d);Bangle.on("HRM",function(b){90Math.abs(Bangle.getHealthStatus().bpm-b.bpm)&&Bangle.setHRMPower(0, +"health")});90>8,c.steps&255,c.bpm,Math.min(c.movement/8,255))}var b=new Date(Date.now()-59E4);a&&0k;k++)e=g.substr(h,4),"\u00ff\u00ff\u00ff\u00ff"!=e&&(a.steps+=(e.charCodeAt(0)<<8)+e.charCodeAt(1),a.movement+=e.charCodeAt(2), +a.movCnt++,e=e.charCodeAt(2),a.bpm+=e,e&&a.bpmCnt++),h-=4;a.bpmCnt&&(a.bpm/=a.bpmCnt);a.movCnt&&(a.movement/=a.movCnt);require("Storage").write(b,d(a),f,17988)}})