health 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

master
Gordon Williams 2025-05-19 10:28:57 +01:00
parent 9aca5f9952
commit c616a2b8a8
3 changed files with 24 additions and 21 deletions

View File

@ -34,3 +34,4 @@
0.30: Minor code improvements 0.30: Minor code improvements
0.31: Add support for new health format (storing more data) 0.31: Add support for new health format (storing more data)
Added graphs for Temperature and Battery 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

View File

@ -1,30 +1,32 @@
(function() { { // Handle turning HRM on/off at the right times
var settings = require("Storage").readJSON("health.json", 1) || {}; let settings = require("Storage").readJSON("health.json", 1) || {};
var hrm = 0|settings.hrm; let hrm = 0|settings.hrm;
if (hrm == 1 || hrm == 2) { if (hrm == 1 || hrm == 2) { // 1=every 3 minutes, 2=every 10 minutes
function onHealth() { let onHealth = function(h) {
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() { 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"); Bangle.setHRMPower(1, "health");
setTimeout(() => { setTimeout(() => {
Bangle.setHRMPower(0, "health"); Bangle.setHRMPower(0, "health");
}, 60000); }, 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, 200000);
setTimeout(startMeasurement, 400000); setTimeout(startMeasurement, 400000);
} }
} }
Bangle.on("health", onHealth); Bangle.on("health", onHealth);
Bangle.on("HRM", (h) => { 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 (h.confidence > 90 && Math.abs(Bangle.getHealthStatus().bpm - h.bpm) < 1) Bangle.setHRMPower(0, "health");
}); });
if (Bangle.getHealthStatus().bpmConfidence > 90) return; if (Bangle.getHealthStatus().bpmConfidence < 90) onHealth(); // if we didn't have a good HRM confidence already, start HRM now
onHealth(); } else Bangle.setHRMPower(!!hrm, "health"); // if HRM>2, keep it on permanently
} else Bangle.setHRMPower(!!hrm, "health"); }
})();
Bangle.on("health", health => { Bangle.on("health", health => {
(Bangle.getPressure?Bangle.getPressure():Promise.resolve({})).then(pressure => { (Bangle.getPressure?Bangle.getPressure():Promise.resolve({})).then(pressure => {
Object.assign(health, pressure); // add temperature/pressure/altitude Object.assign(health, pressure); // add temperature/pressure/altitude

View File

@ -2,7 +2,7 @@
"id": "health", "id": "health",
"name": "Health Tracking", "name": "Health Tracking",
"shortName": "Health", "shortName": "Health",
"version": "0.31", "version": "0.32",
"description": "Logs health data and provides an app to view it", "description": "Logs health data and provides an app to view it",
"icon": "app.png", "icon": "app.png",
"tags": "tool,system,health", "tags": "tool,system,health",