diff --git a/apps.json b/apps.json index bdc9cc7bf..494b98766 100644 --- a/apps.json +++ b/apps.json @@ -49,7 +49,7 @@ { "id": "health", "name": "Health Tracking", - "version": "0.03", + "version": "0.04", "description": "Logs health data and provides an app to view it (BETA - requires firmware 2v11)", "icon": "app.png", "tags": "tool,system", diff --git a/apps/health/ChangeLog b/apps/health/ChangeLog index 9ce15a982..a21d76fd1 100644 --- a/apps/health/ChangeLog +++ b/apps/health/ChangeLog @@ -1,3 +1,5 @@ 0.01: New App! 0.02: Modified data format to include daily summaries 0.03: Settings to turn HRM on +0.04: Add HRM graph view + Don't restart HRM when changing apps if we've already got a good BPM value diff --git a/apps/health/app.js b/apps/health/app.js index 6cc46298b..4d692e638 100644 --- a/apps/health/app.js +++ b/apps/health/app.js @@ -12,6 +12,7 @@ function menuMain() { "< Back":()=>load(), "Step Counting":()=>menuStepCount(), "Movement":()=>menuMovement(), + "Heart Rate":()=>menuHRM(), "Settings":()=>menuSettings() }); } @@ -20,7 +21,7 @@ function menuSettings() { var s=getSettings(); E.showMenu({ "":{title:"Health Tracking"}, - "< Back":()=>load(), + "< Back":()=>menuMain(), "Heart Rt":{ value : 0|s.hrm, min : 0, max : 2, @@ -48,6 +49,16 @@ function menuMovement() { }); } +function menuHRM() { + E.showMenu({ + "":{title:"Heart Rate"}, + "< Back":()=>menuMain(), + "per hour":()=>hrmPerHour(), + "per day":()=>hrmPerDay(), + }); +} + + function stepsPerHour() { E.showMessage("Loading..."); var data = new Uint16Array(24); @@ -67,7 +78,7 @@ function stepsPerHour() { function stepsPerDay() { E.showMessage("Loading..."); - var data = new Uint16Array(24); + var data = new Uint16Array(31); require("health").readDailySummaries(new Date(), h=>data[h.day]+=h.steps); g.clear(1); Bangle.drawWidgets(); @@ -82,6 +93,50 @@ function stepsPerDay() { Bangle.setUI("updown", ()=>menuStepCount()); } +function hrmPerHour() { + E.showMessage("Loading..."); + var data = new Uint16Array(24); + var cnt = new Uint8Array(23); + require("health").readDay(new Date(), h=>{ + data[h.hr]+=h.bpm; + if (h.bpm) cnt[h.hr]++; + }); + data.forEach((d,i)=>data[i] = d/cnt[i]); + g.clear(1); + Bangle.drawWidgets(); + g.reset(); + require("graph").drawBar(g, data, { + y:24, + miny: 0, + axes : true, + gridx : 6, + gridy : 20 + }); + Bangle.setUI("updown", ()=>menuHRM()); +} + +function hrmPerDay() { + E.showMessage("Loading..."); + var data = new Uint16Array(31); + var cnt = new Uint8Array(31); + require("health").readDailySummaries(new Date(), h=>{ + data[h.day]+=h.bpm; + if (h.bpm) cnt[h.day]++; + }); + data.forEach((d,i)=>data[i] = d/cnt[i]); + g.clear(1); + Bangle.drawWidgets(); + g.reset(); + require("graph").drawBar(g, data, { + y:24, + miny: 0, + axes : true, + gridx : 5, + gridy : 20 + }); + Bangle.setUI("updown", ()=>menuHRM()); +} + function movementPerHour() { E.showMessage("Loading..."); var data = new Uint16Array(24); @@ -96,12 +151,12 @@ function movementPerHour() { gridx : 6, ylabel : null }); - Bangle.setUI("updown", ()=>menuStepCount()); + Bangle.setUI("updown", ()=>menuMovement()); } function movementPerDay() { E.showMessage("Loading..."); - var data = new Uint16Array(24); + var data = new Uint16Array(31); require("health").readDailySummaries(new Date(), h=>data[h.day]+=h.movement); g.clear(1); Bangle.drawWidgets(); @@ -113,7 +168,7 @@ function movementPerDay() { gridx : 5, ylabel : null }); - Bangle.setUI("updown", ()=>menuStepCount()); + Bangle.setUI("updown", ()=>menuMovement()); } Bangle.loadWidgets(); diff --git a/apps/health/boot.js b/apps/health/boot.js index 200a89f67..17fbaaaa8 100644 --- a/apps/health/boot.js +++ b/apps/health/boot.js @@ -1,7 +1,6 @@ (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"); @@ -11,8 +10,9 @@ Bangle.on('HRM', h => { if (h.confidence>80) Bangle.setHRMPower(0, "health"); }); + if (Bangle.getHealthStatus().bpmConfidence) return; onHealth(); - } + } else Bangle.setHRMPower(hrm!=0, "health"); })(); Bangle.on("health", health => {