[terminalclock] Add altitude to terminalclock

pull/1805/head
Arne Schauf 2022-04-14 15:36:58 +02:00
parent d1873ad166
commit 5ac85350f9
4 changed files with 51 additions and 10 deletions

View File

@ -2,3 +2,4 @@
0.02: Rename "Activity" in "Motion" and display the true values for it
0.03: Add Banglejs 1 compatibility
0.04: Fix settings bug
0.05: Add altitude display

View File

@ -1,6 +1,7 @@
var locale = require("locale");
var fontColor = g.theme.dark ? "#0f0" : "#000";
var heartRate = 0;
var altitude = -9001;
// handling the differents versions of the Banglejs smartwatch
if (process.env.HWVERSION == 1){
@ -26,13 +27,13 @@ function setFontSize(pos){
}
function clearField(pos){
var yStartPos = Bangle.appRect.y +
paddingY * (pos - 1) +
font6x8At4Size * Math.min(1, pos-1) +
var yStartPos = Bangle.appRect.y +
paddingY * (pos - 1) +
font6x8At4Size * Math.min(1, pos-1) +
font6x8At2Size * Math.max(0, pos-2);
var yEndPos = Bangle.appRect.y +
paddingY * (pos - 1) +
font6x8At4Size * Math.min(1, pos) +
var yEndPos = Bangle.appRect.y +
paddingY * (pos - 1) +
font6x8At4Size * Math.min(1, pos) +
font6x8At2Size * Math.max(0, pos-1);
g.clearRect(Bangle.appRect.x, yStartPos, Bangle.appRect.x2, yEndPos);
}
@ -44,9 +45,9 @@ function clearWatchIfNeeded(now){
function drawLine(line, pos){
setFontSize(pos);
var yPos = Bangle.appRect.y +
paddingY * (pos - 1) +
font6x8At4Size * Math.min(1, pos-1) +
var yPos = Bangle.appRect.y +
paddingY * (pos - 1) +
font6x8At4Size * Math.min(1, pos-1) +
font6x8At2Size * Math.max(0, pos-2);
g.drawString(line, 5, yPos, true);
}
@ -84,6 +85,14 @@ function drawHRM(pos){
drawLine(">HR: unknown", pos);
}
function drawAltitude(pos){
clearField(pos);
if(altitude > 0)
drawLine(">Alt: " + altitude.toFixed(1) + "m", pos);
else
drawLine(">Alt: unknown", pos);
}
function drawActivity(pos){
clearField(pos);
var health = Bangle.getHealthStatus('last');
@ -104,6 +113,10 @@ function draw(){
drawDate(now, curPos);
curPos++;
}
if(settings.showAltitude){
drawAltitude(curPos);
curPos++;
}
if(settings.showHRM){
drawHRM(curPos);
curPos++;
@ -124,6 +137,18 @@ Bangle.on('HRM',function(hrmInfo) {
heartRate = hrmInfo.bpm;
});
var MEDIANLENGTH = 20;
var avr = [], median;
Bangle.on('pressure', function(e) {
while (avr.length>MEDIANLENGTH) avr.pop();
avr.unshift(e.altitude);
median = avr.slice().sort();
if (median.length>10) {
var mid = median.length>>1;
altitude = E.sum(median.slice(mid-4,mid+5)) / 9;
}
});
// Clear the screen once, at startup
g.clear();
@ -135,7 +160,13 @@ var settings = Object.assign({
showHRM: true,
showActivity: true,
showStepCount: true,
showAltitude: true,
}, require('Storage').readJSON("terminalclock.json", true) || {});
if(settings.showAltitude){
Bangle.setBarometerPower(true, "app");
}
// Show launcher when middle button pressed
Bangle.setUI("clock");
// Load widgets

View File

@ -3,7 +3,7 @@
"name": "Terminal Clock",
"shortName":"Terminal Clock",
"description": "A terminal cli like clock displaying multiple sensor data",
"version":"0.04",
"version":"0.05",
"icon": "app.png",
"type": "clock",
"tags": "clock",

View File

@ -4,6 +4,7 @@
var settings = Object.assign({
HRMinConfidence: 50,
showDate: true,
showAltitude: true,
showHRM: true,
showActivity: true,
showStepCount: true,
@ -33,6 +34,14 @@
writeSettings();
}
},
'Show Altitude': {
value: settings.showAltitude,
format: v => v?"Yes":"No",
onchange: v => {
settings.showAltitude = v;
writeSettings();
}
},
'Show HRM': {
value: settings.showHRM,
format: v => v?"Yes":"No",