Add option for ISO 8601 date
parent
f0ee2be3db
commit
e8642e7f41
|
|
@ -1,7 +1,8 @@
|
||||||
# Terminal clock
|
# Terminal clock
|
||||||
|
|
||||||
A clock displayed as a terminal cli.
|
A clock displayed as a terminal cli.
|
||||||
It can display :
|
It can display:
|
||||||
|
|
||||||
- time
|
- time
|
||||||
- date
|
- date
|
||||||
- altitude
|
- altitude
|
||||||
|
|
@ -9,7 +10,6 @@ It can display :
|
||||||
- motion
|
- motion
|
||||||
- steps
|
- steps
|
||||||
|
|
||||||
|
"Power saving" setting control the HR and pressure (altitude) sensors.
|
||||||
"Power saving" setting control the HR and pressure (altitude) sensors.
|
If "Off" they will always be on.
|
||||||
If "Off" they will always be on.
|
If "On" the sensors will be turned on every "Power on interval" minutes for 45 seconds
|
||||||
If "On" the sensors will be turned on every "Power on interval" minutes for 45 secondes
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
let font6x8At2Size = 18;
|
let font6x8At2Size = 18;
|
||||||
let font6x8FirstTextSize = 4;
|
let font6x8FirstTextSize = 4;
|
||||||
let font6x8DefaultTextSize = 2;
|
let font6x8DefaultTextSize = 2;
|
||||||
if (process.env.HWVERSION == 1){
|
if (process.env.HWVERSION == 1) {
|
||||||
paddingY = 3;
|
paddingY = 3;
|
||||||
font6x8At4Size = 48;
|
font6x8At4Size = 48;
|
||||||
font6x8At2Size = 27;
|
font6x8At2Size = 27;
|
||||||
|
|
@ -36,24 +36,24 @@
|
||||||
if (this.powerSave===undefined) this.powerSave = true;
|
if (this.powerSave===undefined) this.powerSave = true;
|
||||||
|
|
||||||
["L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9"].forEach(k => {
|
["L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9"].forEach(k => {
|
||||||
if (this[k]===undefined){
|
if (this[k]===undefined) {
|
||||||
if(k == "L2") this[k] = "Date";
|
if (k == "L2") this[k] = "Date";
|
||||||
else if(k == "L3") {
|
else if (k == "L3") {
|
||||||
this[k] = "HR";
|
this[k] = "HR";
|
||||||
this.showHRM = true;
|
this.showHRM = true;
|
||||||
}else if(k == "L4") this[k] = "Motion";
|
} else if (k == "L4") this[k] = "Motion";
|
||||||
else if(k == "L5") this[k] = "Steps";
|
else if (k == "L5") this[k] = "Steps";
|
||||||
else if(k == "L6") this[k] = ">";
|
else if (k == "L6") this[k] = ">";
|
||||||
else this[k] = "Empty";
|
else this[k] = "Empty";
|
||||||
}
|
}
|
||||||
else if (this[k]==="HR") this.showHRM = true;
|
else if (this[k]==="HR") this.showHRM = true;
|
||||||
else if (this[k]==="Alt") this.showAltitude = true && process.env.HWVERSION == 2;
|
else if (this[k]==="Alt") this.showAltitude = true && process.env.HWVERSION == 2;
|
||||||
});
|
});
|
||||||
|
|
||||||
// set the services (HRM, pressure sensor, etc....)
|
// set the services (HRM, pressure sensor, etc....)
|
||||||
if(!this.powerSave){
|
if (!this.powerSave) {
|
||||||
turnOnServices();
|
turnOnServices();
|
||||||
} else{
|
} else {
|
||||||
this.turnOnInterval = setInterval(turnOnServices, this.PowerOnInterval*60000); // every PowerOnInterval min
|
this.turnOnInterval = setInterval(turnOnServices, this.PowerOnInterval*60000); // every PowerOnInterval min
|
||||||
}
|
}
|
||||||
// start the clock unlocked
|
// start the clock unlocked
|
||||||
|
|
@ -68,7 +68,7 @@
|
||||||
curPos++;
|
curPos++;
|
||||||
|
|
||||||
["L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9"].forEach(line => {
|
["L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9"].forEach(line => {
|
||||||
if (this[line]==='Date') drawDate(date, curPos);
|
if (this[line]==='Date') drawDate(date, this.isoDate, curPos);
|
||||||
else if (this[line]==='HR') drawHRM(curPos);
|
else if (this[line]==='HR') drawHRM(curPos);
|
||||||
else if (this[line]==='Motion') drawMotion(curPos);
|
else if (this[line]==='Motion') drawMotion(curPos);
|
||||||
else if (this[line]==='Alt') drawAltitude(curPos);
|
else if (this[line]==='Alt') drawAltitude(curPos);
|
||||||
|
|
@ -79,11 +79,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: function() {
|
remove: function() {
|
||||||
if (this.turnOnInterval){
|
if (this.turnOnInterval) {
|
||||||
clearInterval(this.turnOnInterval);
|
clearInterval(this.turnOnInterval);
|
||||||
delete this.turnOnInterval;
|
delete this.turnOnInterval;
|
||||||
}
|
}
|
||||||
if (this.turnOffServiceTimeout){
|
if (this.turnOffServiceTimeout) {
|
||||||
clearTimeout(this.turnOffServiceTimeout)
|
clearTimeout(this.turnOffServiceTimeout)
|
||||||
delete this.turnOffServiceTimeout
|
delete this.turnOffServiceTimeout
|
||||||
}
|
}
|
||||||
|
|
@ -96,15 +96,16 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------
|
/* ----------------------------
|
||||||
Draw related of specific lines
|
Draw related of specific lines
|
||||||
-------------------------------- */
|
-------------------------------- */
|
||||||
|
|
||||||
let drawLine = function(line, pos){
|
let drawLine = function(line, pos) {
|
||||||
if(pos == 1)
|
if (pos == 1) {
|
||||||
g.setFont("6x8", font6x8FirstTextSize);
|
g.setFont("6x8", font6x8FirstTextSize);
|
||||||
else
|
} else {
|
||||||
g.setFont("6x8", font6x8DefaultTextSize);
|
g.setFont("6x8", font6x8DefaultTextSize);
|
||||||
|
}
|
||||||
|
|
||||||
let yPos = Bangle.appRect.y +
|
let yPos = Bangle.appRect.y +
|
||||||
paddingY * (pos - 1) +
|
paddingY * (pos - 1) +
|
||||||
|
|
@ -113,47 +114,57 @@
|
||||||
g.drawString(line, 5, yPos, true);
|
g.drawString(line, 5, yPos, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawTime = function(now, pos){
|
let drawTime = function(now, pos) {
|
||||||
let h = now.getHours();
|
let h = now.getHours();
|
||||||
let m = now.getMinutes();
|
let m = now.getMinutes();
|
||||||
let time = ">" + (""+h).substr(-2) + ":" + ("0"+m).substr(-2);
|
let time = ">" + (""+h).substr(-2) + ":" + ("0"+m).substr(-2);
|
||||||
drawLine(time, pos);
|
drawLine(time, pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawDate = function(now, pos){
|
let drawDate = function(now, isoDate, pos) {
|
||||||
let dow = locale.dow(now, 1);
|
let date;
|
||||||
let date = locale.date(now, 1).substr(0,6) + locale.date(now, 1).substr(-2);
|
if (clock.isoDate) {
|
||||||
let locale_date = ">" + dow + " " + date;
|
let year = now.getFullYear();
|
||||||
drawLine(locale_date, pos);
|
let month = now.getMonth() + 1; // Months are 0-11
|
||||||
|
let day = now.getDate();
|
||||||
|
date = ">" + year + "-" + month + "-" + day;
|
||||||
|
} else {
|
||||||
|
let dow = locale.dow(now, 1);
|
||||||
|
date = locale.date(now, 1).substr(0,6) + locale.date(now, 1).substr(-2);
|
||||||
|
date = ">" + dow + " " + date;
|
||||||
|
}
|
||||||
|
drawLine(date, pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawInput = function(pos){
|
let drawInput = function(pos) {
|
||||||
drawLine(">", pos);
|
drawLine(">", pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawStepCount = function(pos){
|
let drawStepCount = function(pos) {
|
||||||
let health = Bangle.getHealthStatus("day");
|
let health = Bangle.getHealthStatus("day");
|
||||||
let steps_formated = ">Steps: " + health.steps;
|
let steps_formated = ">Steps: " + health.steps;
|
||||||
drawLine(steps_formated, pos);
|
drawLine(steps_formated, pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawHRM = function(pos){
|
let drawHRM = function(pos) {
|
||||||
if(heartRate != 0)
|
if (heartRate != 0) {
|
||||||
drawLine(">HR: " + parseInt(heartRate), pos);
|
drawLine(">HR: " + parseInt(heartRate), pos);
|
||||||
else
|
} else {
|
||||||
drawLine(
|
drawLine(
|
||||||
">HR: " + parseInt(Math.round(Bangle.getHealthStatus().bpm||Bangle.getHealthStatus("last").bpm)),
|
">HR: " + parseInt(Math.round(Bangle.getHealthStatus().bpm||Bangle.getHealthStatus("last").bpm)),
|
||||||
pos);
|
pos);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawAltitude = function(pos){
|
let drawAltitude = function(pos) {
|
||||||
if(altitude > 0)
|
if (altitude > 0) {
|
||||||
drawLine(">Alt: " + altitude.toFixed(1) + "m", pos);
|
drawLine(">Alt: " + altitude.toFixed(1) + "m", pos);
|
||||||
else
|
} else {
|
||||||
drawLine(">Alt: unknown", pos);
|
drawLine(">Alt: unknown", pos);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawMotion = function(pos){
|
let drawMotion = function(pos) {
|
||||||
let health = Bangle.getHealthStatus('last');
|
let health = Bangle.getHealthStatus('last');
|
||||||
let steps_formated = ">Motion: " + parseInt(health.movement);
|
let steps_formated = ">Motion: " + parseInt(health.movement);
|
||||||
drawLine(steps_formated, pos);
|
drawLine(steps_formated, pos);
|
||||||
|
|
@ -163,26 +174,26 @@
|
||||||
Services functions (HRM, pressure, etc...)
|
Services functions (HRM, pressure, etc...)
|
||||||
-------------------------------------------------- */
|
-------------------------------------------------- */
|
||||||
|
|
||||||
let turnOnServices = function(){
|
let turnOnServices = function() {
|
||||||
if(clock.showHRM){
|
if (clock.showHRM) {
|
||||||
Bangle.setHRMPower(true, "terminalclock");
|
Bangle.setHRMPower(true, "terminalclock");
|
||||||
}
|
}
|
||||||
if(clock.showAltitude){
|
if (clock.showAltitude) {
|
||||||
Bangle.setBarometerPower(true, "terminalclock");
|
Bangle.setBarometerPower(true, "terminalclock");
|
||||||
}
|
}
|
||||||
if(clock.powerSave){
|
if (clock.powerSave) {
|
||||||
if(clock.turnOffServiceTimeout) clearTimeout(clock.turnOffServiceTimeout);
|
if (clock.turnOffServiceTimeout) clearTimeout(clock.turnOffServiceTimeout);
|
||||||
clock.turnOffServiceTimeout = setTimeout(function () {
|
clock.turnOffServiceTimeout = setTimeout(function () {
|
||||||
turnOffServices();
|
turnOffServices();
|
||||||
}, 45000);
|
}, 45000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let turnOffServices = function(){
|
let turnOffServices = function() {
|
||||||
if(clock.showHRM){
|
if (clock.showHRM) {
|
||||||
Bangle.setHRMPower(false, "terminalclock");
|
Bangle.setHRMPower(false, "terminalclock");
|
||||||
}
|
}
|
||||||
if(clock.showAltitude){
|
if (clock.showAltitude) {
|
||||||
Bangle.setBarometerPower(false, "terminalclock");
|
Bangle.setBarometerPower(false, "terminalclock");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -195,7 +206,7 @@
|
||||||
Bangle.on("lock", clock.onLock);
|
Bangle.on("lock", clock.onLock);
|
||||||
|
|
||||||
clock.onHRM = hrmInfo => {
|
clock.onHRM = hrmInfo => {
|
||||||
if(hrmInfo.confidence >= clock.HRMinConfidence)
|
if (hrmInfo.confidence >= clock.HRMinConfidence)
|
||||||
heartRate = hrmInfo.bpm;
|
heartRate = hrmInfo.bpm;
|
||||||
};
|
};
|
||||||
Bangle.on('HRM', clock.onHRM);
|
Bangle.on('HRM', clock.onHRM);
|
||||||
|
|
@ -211,7 +222,7 @@
|
||||||
altitude = E.sum(median.slice(mid-4,mid+5)) / 9;
|
altitude = E.sum(median.slice(mid-4,mid+5)) / 9;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
altitude = pressureInfo.altitude;
|
altitude = pressureInfo.altitude;
|
||||||
};
|
};
|
||||||
Bangle.on('pressure', clock.onPressure);
|
Bangle.on('pressure', clock.onPressure);
|
||||||
|
|
||||||
|
|
@ -220,19 +231,19 @@
|
||||||
Clock related functions but not in the ClockFace module
|
Clock related functions but not in the ClockFace module
|
||||||
---------------------------------------------------- */
|
---------------------------------------------------- */
|
||||||
|
|
||||||
let unlock = function(){
|
let unlock = function() {
|
||||||
if(clock.powerSave){
|
if (clock.powerSave) {
|
||||||
turnOnServices();
|
turnOnServices();
|
||||||
}
|
}
|
||||||
clock.precision = clock.unlock_precision;
|
clock.precision = clock.unlock_precision;
|
||||||
clock.tick();
|
clock.tick();
|
||||||
};
|
};
|
||||||
|
|
||||||
let lock = function(){
|
let lock = function() {
|
||||||
clock.precision = clock.lock_precision;
|
clock.precision = clock.lock_precision;
|
||||||
clock.tick();
|
clock.tick();
|
||||||
};
|
};
|
||||||
|
|
||||||
// starting the clock
|
// starting the clock
|
||||||
clock.start();
|
clock.start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.10",
|
"version":"0.11",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"type": "clock",
|
"type": "clock",
|
||||||
"tags": "clock",
|
"tags": "clock",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// Load settings
|
// Load settings
|
||||||
var settings = Object.assign({
|
var settings = Object.assign({
|
||||||
// TerminalClock specific
|
// TerminalClock specific
|
||||||
|
isoDate: false,
|
||||||
HRMinConfidence: 50,
|
HRMinConfidence: 50,
|
||||||
PowerOnInterval: 15,
|
PowerOnInterval: 15,
|
||||||
L2: 'Date',
|
L2: 'Date',
|
||||||
|
|
@ -72,6 +73,13 @@
|
||||||
writeSettings();
|
writeSettings();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ISO date": {
|
||||||
|
value: !!settings.isoDate,
|
||||||
|
onchange: v => {
|
||||||
|
settings.isoDate = v;
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const save = (key, v) => {
|
const save = (key, v) => {
|
||||||
settings[key] = v;
|
settings[key] = v;
|
||||||
|
|
@ -98,4 +106,4 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
E.showMenu(getMainMenu());
|
E.showMenu(getMainMenu());
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue