1
0
Fork 0

health: Settings to turn HRM on

master
Gordon Williams 2021-10-29 20:50:51 +01:00
parent aeaf508897
commit 6d27159cdd
5 changed files with 52 additions and 3 deletions

View File

@ -49,7 +49,7 @@
{
"id": "health",
"name": "Health Tracking",
"version": "0.02",
"version": "0.03",
"description": "Logs health data and provides an app to view it (BETA - requires firmware 2v11)",
"icon": "app.png",
"tags": "tool,system",

View File

@ -1,2 +1,3 @@
0.01: New App!
0.02: Modified data format to include daily summaries
0.03: Settings to turn HRM on

View File

@ -14,10 +14,18 @@ To view data, run the `Health` app from your watch.
Stores:
* Heart rate (TODO)
* Heart rate
* Step count
* Movement
## Settings
* **Heart Rt** - Whether to monitor heart rate or not
* **Off** - Don't turn HRM on, but record heart rate if the HRM was turned on by another app/widget
* **10 Min** - Turn HRM on every 10 minutes (for each heath entry) and turn it off after 2 minutes, or when a good reading is found
* **Always** - Keep HRM on all the time (more accurate recording, but reduces battery life to ~36 hours)
## Technical Info
Once installed, the `health.boot.js` hooks onto the `Bangle.health` event and

View File

@ -1,9 +1,32 @@
function getSettings() {
return require("Storage").readJSON("health.json",1)||{};
}
function setSettings(s) {
require("Storage").writeJSON("health.json",s);
}
function menuMain() {
E.showMenu({
"":{title:"Health Tracking"},
"< Back":()=>load(),
"Step Counting":()=>menuStepCount(),
"Movement":()=>menuMovement()
"Movement":()=>menuMovement(),
"Settings":()=>menuSettings()
});
}
function menuSettings() {
var s=getSettings();
E.showMenu({
"":{title:"Health Tracking"},
"< Back":()=>load(),
"Heart Rt":{
value : 0|s.hrm,
min : 0, max : 2,
format : v=>["Off","10 mins","Always"][v],
onchange : v => { s.hrm=v;setSettings(s); }
}
});
}

View File

@ -1,3 +1,20 @@
(function(){
var settings = require("Storage").readJSON("health.json",1)||{};
var hrm = 0|settings.hrm;
Bangle.setHRMPower(hrm!=0, "health");
if (hrm==1) {
function onHealth() {
Bangle.setHRMPower(1, "health");
setTimeout(()=>Bangle.setHRMPower(0, "health"),2*60000); // give it 2 minutes
}
Bangle.on("health", onHealth);
Bangle.on('HRM', h => {
if (h.confidence>80) Bangle.setHRMPower(0, "health");
});
onHealth();
}
})();
Bangle.on("health", health => {
// ensure we write health info for *last* block
var d = new Date(Date.now() - 590000);