Update app.js

Load steps from Health Tracking app (if installed)
master
Marco H 2021-12-10 08:58:44 +01:00 committed by GitHub
parent a45f7506ff
commit f8628dd26d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 18 deletions

View File

@ -68,7 +68,7 @@ function drawInfo(now) {
*/ */
// weather // weather
var weatherJson = getWeather(); const weatherJson = getWeather();
if(weatherJson && weatherJson.weather){ if(weatherJson && weatherJson.weather){
const currentWeather = weatherJson.weather; const currentWeather = weatherJson.weather;
@ -84,9 +84,9 @@ function drawInfo(now) {
} }
// steps // steps
if (stepsWidget() != undefined) { const steps = getSteps();
if (steps != undefined) {
writeLineTopic("STEP", i); writeLineTopic("STEP", i);
const steps = stepsWidget().getSteps();
writeLine(steps, i); writeLine(steps, i);
i++; i++;
} }
@ -128,6 +128,30 @@ function writeLine(str,line,pColor){
g.drawString(str,marginLeftData,y); g.drawString(str,marginLeftData,y);
} }
function getSteps() {
var steps = 0;
let health;
try {
health = require("health");
} catch (e) {
// Module health not found
}
if (health != undefined) {
health.readDay(new Date(), h=>steps+=h.steps);
} else if (WIDGETS.wpedom !== undefined) {
return WIDGETS.wpedom.getSteps();
} else if (WIDGETS.activepedom !== undefined) {
return WIDGETS.activepedom.getSteps();
}
return steps;
}
function getWeather() {
let jsonWeather = storage.readJSON('weather.json');
return jsonWeather;
}
// EVENTS: // EVENTS:
// turn on HRM when the LCD is unlocked // turn on HRM when the LCD is unlocked
@ -166,21 +190,6 @@ Bangle.on('HRM', function(hrm) {
//} //}
}); });
function stepsWidget() {
if (WIDGETS.activepedom !== undefined) {
return WIDGETS.activepedom;
} else if (WIDGETS.wpedom !== undefined) {
return WIDGETS.wpedom;
}
return undefined;
}
function getWeather() {
let jsonWeather = storage.readJSON('weather.json');
return jsonWeather;
}
g.clear(); g.clear();
Bangle.setUI("clock"); Bangle.setUI("clock");
Bangle.loadWidgets(); Bangle.loadWidgets();