[TerminalClock] Change the settings to be able to personalize the line display more

master
Stiralbios 2022-06-18 18:39:51 +02:00
parent 93b6fdb974
commit a6fa71290b
4 changed files with 103 additions and 115 deletions

View File

@ -4,3 +4,4 @@
0.04: Fix settings bug 0.04: Fix settings bug
0.05: Add altitude display (only Bangle.js 2) 0.05: Add altitude display (only Bangle.js 2)
0.06: Add power related settings to control the HR and pressure(altitude) sensor from the watchface 0.06: Add power related settings to control the HR and pressure(altitude) sensor from the watchface
0.07: Use ClockFace module and rework the settings to be able to personnalize the order of the lines

View File

@ -23,15 +23,15 @@ const ClockFace = require("ClockFace");
const clock = new ClockFace({ const clock = new ClockFace({
init: function () { init: function () {
// check settings and set default if needed // check settings and set default if needed
this.showHRM = false;
this.showAltitude = false;
if (this.HRMinConfidence === undefined) this.HRMinConfidence = 50; if (this.HRMinConfidence === undefined) this.HRMinConfidence = 50;
if (this.PowerOnInterval === undefined) this.PowerOnInterval = 15; if (this.PowerOnInterval === undefined) this.PowerOnInterval = 15;
if (this.showAltitude === undefined){ if (this.powerSaving===undefined) this[k] = true;
this.showAltitude = true && process.env.HWVERSION == 2; ["L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9"].forEach(k => {
}else { if (this[k]===undefined) this[k] = "Empty";
this.showAltitude = this.showAltitude && process.env.HWVERSION == 2; else if (this[k]==="HR") this.showHRM = true;
} else if (this[k]==="Alt") this.showAltitude = true && process.env.HWVERSION == 2;
["showHRM", "showActivity", "showStepCount", "powerSaving"].forEach(k => {
if (this[k]===undefined) this[k] = true;
}); });
Bangle.on("lock", on => { Bangle.on("lock", on => {
@ -52,27 +52,16 @@ const clock = new ClockFace({
g.setColor(fontColor); g.setColor(fontColor);
drawTime(date, curPos); drawTime(date, curPos);
curPos++; curPos++;
if(this.showDate){
drawDate(date, curPos); ["L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9"].forEach(line => {
if (this[line]==='Date') drawDate(date, curPos);
else if (this[line]==='HR') drawHRM(curPos);
else if (this[line]==='Motion') drawMotion(curPos);
else if (this[line]==='Alt') drawAltitude(curPos);
else if (this[line]==='Steps') drawStepCount(curPos);
else if (this[line]==='>') drawInput(curPos);
curPos++; curPos++;
} });
if(this.showAltitude){
drawAltitude(curPos);
curPos++;
}
if(this.showHRM){
drawHRM(curPos);
curPos++;
}
if(this.showActivity){
drawActivity(curPos);
curPos++;
}
if(this.showStepCount){
drawStepCount(curPos);
curPos++;
}
drawInput(curPos);
}, },
settingsFile: "terminalclock.json" settingsFile: "terminalclock.json"
@ -134,13 +123,12 @@ function drawAltitude(pos){
drawLine(">Alt: unknown", pos); drawLine(">Alt: unknown", pos);
} }
function drawActivity(pos){ function drawMotion(pos){
var health = Bangle.getHealthStatus('last'); var health = Bangle.getHealthStatus('last');
var steps_formated = ">Motion: " + parseInt(health.movement); var steps_formated = ">Motion: " + parseInt(health.movement);
drawLine(steps_formated, pos); drawLine(steps_formated, pos);
} }
/* ----------------------------------------------- /* -----------------------------------------------
Services functions (HRM, pressure, etc...) Services functions (HRM, pressure, etc...)
-------------------------------------------------- */ -------------------------------------------------- */

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.06", "version":"0.07",
"icon": "app.png", "icon": "app.png",
"type": "clock", "type": "clock",
"tags": "clock", "tags": "clock",

View File

@ -3,24 +3,56 @@
// Load settings // Load settings
var settings = Object.assign({ var settings = Object.assign({
// ClockFace lib // ClockFace lib
showDate: true,
loadWidgets: true, loadWidgets: true,
// TerminalClock specific // TerminalClock specific
HRMinConfidence: 50, HRMinConfidence: 50,
showAltitude: process.env.HWVERSION == 2 ? true : false,
showHRM: true,
showActivity: true,
showStepCount: true,
powerSaving: true, powerSaving: true,
PowerOnInterval: 15, PowerOnInterval: 15,
L2: 'Date',
L3: 'HR',
L4: 'Motion',
L5: 'Steps',
L6: '>',
L7: 'Empty',
L8: 'Empty',
L9: 'Empty',
}, require('Storage').readJSON(FILE, true) || {}); }, require('Storage').readJSON(FILE, true) || {});
function writeSettings() { function writeSettings() {
require('Storage').writeJSON(FILE, settings); require('Storage').writeJSON(FILE, settings);
} }
// Show the menu if(process.env.HWVERSION == 2) {
var menu = { var lineType = ['Date', 'HR', 'Motion', 'Alt', 'Steps', '>', 'Empty'];
} else{
var lineType = ['Date', 'HR', 'Motion', 'Steps', '>', 'Empty'];
}
function getLineChooser(lineID){
return {
value: lineType.indexOf(settings[lineID]),
min: 0, max: lineType.length-1,
format: v => lineType[v],
onchange: v => {
settings[lineID] = lineType[v];
writeSettings();
},
};
}
var lineMenu = {
'< Back': function() { E.showMenu(getMainMenu());},
'Line 2': getLineChooser('L2'),
'Line 3': getLineChooser('L3'),
'Line 4': getLineChooser('L4'),
'Line 5': getLineChooser('L5'),
'Line 6': getLineChooser('L6'),
'Line 7': getLineChooser('L7'),
'Line 8': getLineChooser('L8'),
'Line 9': getLineChooser('L9'),
};
function getMainMenu(){
var mainMenu = {
"" : { "title" : "Terminal Clock" }, "" : { "title" : "Terminal Clock" },
"< Back" : () => back(), "< Back" : () => back(),
'HR confidence': { 'HR confidence': {
@ -39,55 +71,20 @@
writeSettings(); writeSettings();
} }
}, },
'Show date': {
value: settings.showDate,
format: v => v?"Yes":"No",
onchange: v => {
settings.showDate = v;
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",
onchange: v => {
settings.showHRM = v;
writeSettings();
}
},
'Show Activity': {
value: settings.showActivity,
format: v => v?"Yes":"No",
onchange: v => {
settings.showActivity = v;
writeSettings();
}
},
'Show Steps': {
value: settings.showStepCount,
format: v => v?"Yes":"No",
onchange: v => {
settings.showStepCount = v;
writeSettings();
}
},
'Power saving': { 'Power saving': {
value: settings.powerSaving, value: settings.powerSaving,
format: v => v?"On":"Off", format: v => v?"On":"Off",
onchange: v => { onchange: v => {
settings.powerSaving = v; settings.powerSaving = v;
writeSettings(); writeSettings();
setTimeout(function() {
E.showMenu(getMainMenu());
},0);
} }
}, }
'Power on interval': { };
if(settings.powerSaving){
mainMenu['Power on interval'] = {
value: settings.PowerOnInterval, value: settings.PowerOnInterval,
min: 3, max: 60, min: 3, max: 60,
onchange: v => { onchange: v => {
@ -96,11 +93,13 @@
}, },
format: x => { format: x => {
return x + " min"; return x + " min";
},
};
} }
mainMenu['Lines'] = function() { E.showMenu(lineMenu);};
return mainMenu;
} }
}
if (process.env.HWVERSION == 1) { E.showMenu(getMainMenu());
delete menu['Show Altitude'] })();
}
E.showMenu(menu);
})