[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.02: Rename "Activity" in "Motion" and display the true values for it
0.03: Add Banglejs 1 compatibility 0.03: Add Banglejs 1 compatibility
0.04: Fix settings bug 0.04: Fix settings bug
0.05: Add altitude display

View File

@ -1,6 +1,7 @@
var locale = require("locale"); var locale = require("locale");
var fontColor = g.theme.dark ? "#0f0" : "#000"; var fontColor = g.theme.dark ? "#0f0" : "#000";
var heartRate = 0; var heartRate = 0;
var altitude = -9001;
// handling the differents versions of the Banglejs smartwatch // handling the differents versions of the Banglejs smartwatch
if (process.env.HWVERSION == 1){ if (process.env.HWVERSION == 1){
@ -84,6 +85,14 @@ function drawHRM(pos){
drawLine(">HR: unknown", 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){ function drawActivity(pos){
clearField(pos); clearField(pos);
var health = Bangle.getHealthStatus('last'); var health = Bangle.getHealthStatus('last');
@ -104,6 +113,10 @@ function draw(){
drawDate(now, curPos); drawDate(now, curPos);
curPos++; curPos++;
} }
if(settings.showAltitude){
drawAltitude(curPos);
curPos++;
}
if(settings.showHRM){ if(settings.showHRM){
drawHRM(curPos); drawHRM(curPos);
curPos++; curPos++;
@ -124,6 +137,18 @@ Bangle.on('HRM',function(hrmInfo) {
heartRate = hrmInfo.bpm; 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 // Clear the screen once, at startup
g.clear(); g.clear();
@ -135,7 +160,13 @@ var settings = Object.assign({
showHRM: true, showHRM: true,
showActivity: true, showActivity: true,
showStepCount: true, showStepCount: true,
showAltitude: true,
}, require('Storage').readJSON("terminalclock.json", true) || {}); }, require('Storage').readJSON("terminalclock.json", true) || {});
if(settings.showAltitude){
Bangle.setBarometerPower(true, "app");
}
// Show launcher when middle button pressed // Show launcher when middle button pressed
Bangle.setUI("clock"); Bangle.setUI("clock");
// Load widgets // Load widgets

View File

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

View File

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