diff --git a/apps/health/ChangeLog b/apps/health/ChangeLog index a4c3c49b9..128b5940e 100644 --- a/apps/health/ChangeLog +++ b/apps/health/ChangeLog @@ -33,4 +33,5 @@ 0.29: Minor code improvements 0.30: Minor code improvements 0.31: Add support for new health format (storing more data) - Added graphs for Temperature and Battery \ No newline at end of file + Added graphs for Temperature and Battery +0.32: If getting HRM every 3/10 minutes, don't turn it on if the Bangle is charging or hasn't moved and is face down/up \ No newline at end of file diff --git a/apps/health/boot.js b/apps/health/boot.js index d53c823dc..fca55fa10 100644 --- a/apps/health/boot.js +++ b/apps/health/boot.js @@ -1,30 +1,32 @@ -(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) { - function startMeasurement() { - Bangle.setHRMPower(1, "health"); - setTimeout(() => { - Bangle.setHRMPower(0, "health"); - }, 60000); - } +{ // Handle turning HRM on/off at the right times + let settings = require("Storage").readJSON("health.json", 1) || {}; + let hrm = 0|settings.hrm; + if (hrm == 1 || hrm == 2) { // 1=every 3 minutes, 2=every 10 minutes + let onHealth = function(h) { + function startMeasurement() { + // if is charging, or hardly moved and face up/down, don't start HRM + if (Bangle.isCharging() || + (Bangle.getHealthStatus("last").movement<400 && Math.abs(Bangle.getAccel().z)>0.99)) return; + // otherwise turn HRM on + 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 + } + startMeasurement(); + if (hrm == 1) { // 3 minutes setTimeout(startMeasurement, 200000); setTimeout(startMeasurement, 400000); } } Bangle.on("health", onHealth); Bangle.on("HRM", (h) => { + // as soon as we have a decent HRM reading, turn it off if (h.confidence > 90 && Math.abs(Bangle.getHealthStatus().bpm - h.bpm) < 1) Bangle.setHRMPower(0, "health"); }); - if (Bangle.getHealthStatus().bpmConfidence > 90) return; - onHealth(); - } else Bangle.setHRMPower(!!hrm, "health"); -})(); - + if (Bangle.getHealthStatus().bpmConfidence < 90) onHealth(); // if we didn't have a good HRM confidence already, start HRM now + } else Bangle.setHRMPower(!!hrm, "health"); // if HRM>2, keep it on permanently +} Bangle.on("health", health => { (Bangle.getPressure?Bangle.getPressure():Promise.resolve({})).then(pressure => { Object.assign(health, pressure); // add temperature/pressure/altitude diff --git a/apps/health/metadata.json b/apps/health/metadata.json index 029723639..fff178265 100644 --- a/apps/health/metadata.json +++ b/apps/health/metadata.json @@ -2,7 +2,7 @@ "id": "health", "name": "Health Tracking", "shortName": "Health", - "version": "0.31", + "version": "0.32", "description": "Logs health data and provides an app to view it", "icon": "app.png", "tags": "tool,system,health",