Update app.js

* Remove local temperature
* Draw heart rate value in grey if the value is not up to date
master
Marco H 2021-12-09 15:35:17 +01:00 committed by GitHub
parent 5903aed3e4
commit 0a67d177bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 41 deletions

View File

@ -13,6 +13,7 @@ const topicColor = g.theme.dark ? "#fff" : "#000";
const textColor = g.theme.dark ? "#0f0" : "#080"; const textColor = g.theme.dark ? "#0f0" : "#080";
let hrtValue; let hrtValue;
let hrtValueIsOld = false;
let localTempValue; let localTempValue;
let weatherTempString; let weatherTempString;
let lastHeartRateRowIndex; let lastHeartRateRowIndex;
@ -76,19 +77,9 @@ function drawInfo(now) {
writeLineTopic("WTHR", i); writeLineTopic("WTHR", i);
writeLine(currentWeather.txt,i); writeLine(currentWeather.txt,i);
i++; i++;
}
// temperatures (local & weather)
if (localTempValue != undefined || weatherTempString != undefined) {
writeLineTopic("TEMP", i); writeLineTopic("TEMP", i);
let tempString = ""; writeLine(weatherTempValue,i);
if (localTempValue != undefined)
tempString += "l: " + localTempValue;
if (tempString != "")
tempString += ", ";
if (weatherTempString != undefined)
tempString += weatherTempString;
writeLine(tempString,i);
i++; i++;
} }
@ -104,11 +95,16 @@ function drawInfo(now) {
} }
function drawHeartRate(i) { function drawHeartRate(i) {
if (i == undefined)
i = lastHeartRateRowIndex;
writeLineTopic("HRTM", i); writeLineTopic("HRTM", i);
if (hrtValue != undefined) { if (hrtValue != undefined) {
if (!hrtValueIsOld)
writeLine(hrtValue,i); writeLine(hrtValue,i);
else
writeLine(hrtValue,i, topicColor);
} else { } else {
writeLine("-",i); writeLine("...",i);
} }
lastHeartRateRowIndex = i; lastHeartRateRowIndex = i;
} }
@ -123,47 +119,54 @@ function writeLineTopic(str, line) {
g.drawString("[" + str + "]",marginLeftTopic,y); g.drawString("[" + str + "]",marginLeftTopic,y);
} }
function writeLine(str,line){ function writeLine(str,line,pColor){
if (pColor == undefined)
pColor = textColor;
var y = marginTop+line*fontheight; var y = marginTop+line*fontheight;
g.setFont(font,fontsize); g.setFont(font,fontsize);
g.setColor(textColor).setFontAlign(-1,-1); g.setColor(pColor).setFontAlign(-1,-1);
g.drawString(str,marginLeftData,y); g.drawString(str,marginLeftData,y);
} }
// EVENTS:
// turn on HRM when the LCD is unlocked // turn on HRM when the LCD is unlocked
Bangle.on('lock', function(isLocked) { Bangle.on('lock', function(isLocked) {
if (!isLocked) { if (!isLocked) {
Bangle.setHRMPower(1,"clicompleteclk"); Bangle.setHRMPower(1,"clicompleteclk");
hrtValue = undefined; if (hrtValue == undefined)
hrtValue = "...";
else
hrtValueIsOld = true;
drawHeartRate();
} else { } else {
hrtValueIsOld = true;
Bangle.setHRMPower(0,"clicompleteclk"); Bangle.setHRMPower(0,"clicompleteclk");
} }
}); });
Bangle.on('lcdPower',function(on) {
if (on) {
drawAll(true);
} else {
hrtValueIsOld = true;
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
}
});
Bangle.on('HRM', function(hrm) { Bangle.on('HRM', function(hrm) {
//if(hrm.confidence > 90){ //if(hrm.confidence > 90){
hrtValue = hrm.bpm + " bpm"; hrtValueIsOld = false;
hrtValue = hrm.bpm;
if (Bangle.isLCDOn()) if (Bangle.isLCDOn())
drawHeartRate(lastHeartRateRowIndex); drawHeartRate();
//} else { //} else {
// hrtValue = undefined; // hrtValue = undefined;
//} //}
}); });
function getTemperature() {
if (Bangle.getPressure) {
Bangle.getPressure().then(onTemperature);
} else {
onTemperature({
temperature : E.getTemperature()
});
}
}
function onTemperature(p) {
localTempValue = locale.temp(p.temperature.toFixed(1));
}
function stepsWidget() { function stepsWidget() {
if (WIDGETS.activepedom !== undefined) { if (WIDGETS.activepedom !== undefined) {
return WIDGETS.activepedom; return WIDGETS.activepedom;
@ -173,7 +176,6 @@ function stepsWidget() {
return undefined; return undefined;
} }
function getWeather() { function getWeather() {
let jsonWeather = storage.readJSON('weather.json'); let jsonWeather = storage.readJSON('weather.json');
return jsonWeather; return jsonWeather;
@ -184,12 +186,3 @@ Bangle.setUI("clock");
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
drawAll(true); drawAll(true);
Bangle.on('lcdPower',function(on) {
if (on) {
drawAll(true);
} else {
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
}
});