mirror of https://github.com/espruino/BangleApps
commit
f31054a34b
|
@ -4845,7 +4845,7 @@
|
|||
{ "id": "clicompleteclk",
|
||||
"name": "CLI complete clock",
|
||||
"shortName":"CLI cmplt clock",
|
||||
"version":"0.02",
|
||||
"version":"0.03",
|
||||
"description": "Command line styled clock with lots of information",
|
||||
"icon": "app.png",
|
||||
"allow_emulator": true,
|
||||
|
@ -4855,7 +4855,9 @@
|
|||
"readme": "README.md",
|
||||
"storage": [
|
||||
{"name":"clicompleteclk.app.js","url":"app.js"},
|
||||
{"name":"clicompleteclk.img","url":"app-icon.js","evaluate":true}
|
||||
]
|
||||
{"name":"clicompleteclk.img","url":"app-icon.js","evaluate":true},
|
||||
{"name":"clicompleteclk.settings.js","url":"settings.js"}
|
||||
],
|
||||
"data": [{"name":"clicompleteclk.json"}]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
Command line styled clock with lots of information:
|
||||
|
||||
It can show the following (depending on availability) information:
|
||||
* Time
|
||||
* Day of week
|
||||
* Date
|
||||
* Weather conditions and temperature (requires app [Weather](https://banglejs.com/apps/#weather))
|
||||
* Steps (requires app [Health Tracking](https://banglejs.com/apps/#health%20tracking) or a step widget)
|
||||
* Heart rate (when screen is on and unlocked)
|
||||
* Time data:
|
||||
* Time
|
||||
* Day of week
|
||||
* Date
|
||||
* Additional information (can be toggled via settings):
|
||||
* Weather conditions and temperature (requires app [Weather](https://banglejs.com/apps/#weather))
|
||||
* Steps (requires app [Health Tracking](https://banglejs.com/apps/#health%20tracking) or a step widget)
|
||||
* Heart rate (when screen is on and unlocked)
|
||||
|
||||
## TODO
|
||||
* Make time font bigger
|
||||
|
|
|
@ -1,31 +1,60 @@
|
|||
const storage = require('Storage');
|
||||
const locale = require("locale");
|
||||
|
||||
const font = "12x20";
|
||||
const fontsize = 1;
|
||||
const font12 = g.getFonts().includes("12x20");
|
||||
const font = font12 ? "12x20" : "6x8";
|
||||
const fontsize = font12 ? 1: 2;
|
||||
const fontheight = 19;
|
||||
|
||||
const marginTop = 10;
|
||||
const marginTop = 5;
|
||||
const marginLeftTopic = 3; // margin of topics
|
||||
const marginLeftData = 68; // margin of data values
|
||||
const marginLeftData = font12 ? 64 : 75; // margin of data values
|
||||
|
||||
const topicColor = g.theme.dark ? "#fff" : "#000";
|
||||
const textColor = g.theme.dark ? "#0f0" : "#080";
|
||||
const textColorRed = g.theme.dark ? "#FF0000" : "#FF0000";
|
||||
|
||||
let hrtValue;
|
||||
let hrtValueIsOld = false;
|
||||
|
||||
let localTempValue;
|
||||
let weatherTempString;
|
||||
let lastHeartRateRowIndex;
|
||||
let lastStepsRowIndex;
|
||||
let i = 2;
|
||||
|
||||
let settings;
|
||||
|
||||
function loadSettings() {
|
||||
settings = storage.readJSON('clicompleteclk.json', 1) || {};
|
||||
}
|
||||
|
||||
function setting(key) {
|
||||
if (!settings) { loadSettings(); }
|
||||
const DEFAULTS = {
|
||||
'battery': true,
|
||||
'batteryLvl': 30,
|
||||
'weather': true,
|
||||
'steps': true,
|
||||
'heartrate': true
|
||||
};
|
||||
return (key in settings) ? settings[key] : DEFAULTS[key];
|
||||
}
|
||||
|
||||
|
||||
let showBattery = setting('battery');
|
||||
let batteryWarnLevel = setting('batteryLvl');
|
||||
let showWeather = setting('weather');
|
||||
let showSteps = setting('steps');
|
||||
let showHeartRate = setting('heartrate');
|
||||
|
||||
|
||||
// timeout used to update every minute
|
||||
var drawTimeout;
|
||||
// schedule a draw for the next minute
|
||||
function queueDraw() {
|
||||
if (drawTimeout) clearTimeout(drawTimeout);
|
||||
drawTimeout = setTimeout(function() {
|
||||
drawTimeout = undefined;
|
||||
drawAll(false);
|
||||
drawAll(true);
|
||||
}, 60000 - (Date.now() % 60000));
|
||||
}
|
||||
|
||||
|
@ -42,15 +71,13 @@ function updateTime(now){
|
|||
if (!Bangle.isLCDOn()) return;
|
||||
writeLineTopic("TIME", 1);
|
||||
writeLine(locale.time(now,1),1);
|
||||
if(now.getMinutes() == 0)
|
||||
drawInfo(now);
|
||||
}
|
||||
|
||||
function drawInfo(now) {
|
||||
if (now == undefined)
|
||||
if (now == undefined)
|
||||
now = new Date();
|
||||
|
||||
let i = 2;
|
||||
i = 2;
|
||||
|
||||
writeLineTopic("DOWK", i);
|
||||
writeLine(locale.dow(now),i);
|
||||
|
@ -60,14 +87,28 @@ function drawInfo(now) {
|
|||
writeLine(locale.date(now,1),i);
|
||||
i++;
|
||||
|
||||
/*
|
||||
writeLineTopic("BAT", i);
|
||||
const b = E.getBattery();
|
||||
writeLine(b + "%", i); // TODO make bars
|
||||
i++;
|
||||
*/
|
||||
if (showBattery) {
|
||||
writeLineTopic("BATT", i);
|
||||
const b = E.getBattery();
|
||||
writeLine(b + "%", i, b < batteryWarnLevel ? textColorRed : textColor);
|
||||
i++;
|
||||
}
|
||||
|
||||
// weather
|
||||
if (showWeather) {
|
||||
drawWeather();
|
||||
}
|
||||
|
||||
if (showSteps) {
|
||||
drawSteps(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (showHeartRate) {
|
||||
drawHeartRate(i);
|
||||
}
|
||||
}
|
||||
|
||||
function drawWeather() {
|
||||
const weatherJson = getWeather();
|
||||
if(weatherJson && weatherJson.weather){
|
||||
const currentWeather = weatherJson.weather;
|
||||
|
@ -82,19 +123,22 @@ function drawInfo(now) {
|
|||
writeLine(weatherTempValue,i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// steps
|
||||
function drawSteps(i) {
|
||||
if (!showSteps) return;
|
||||
if (i == undefined)
|
||||
i = lastStepsRowIndex;
|
||||
const steps = getSteps();
|
||||
if (steps != undefined) {
|
||||
writeLineTopic("STEP", i);
|
||||
writeLine(steps, i);
|
||||
i++;
|
||||
}
|
||||
|
||||
drawHeartRate(i);
|
||||
lastStepsRowIndex = i;
|
||||
}
|
||||
|
||||
function drawHeartRate(i) {
|
||||
if (!showHeartRate) return;
|
||||
if (i == undefined)
|
||||
i = lastHeartRateRowIndex;
|
||||
writeLineTopic("HRTM", i);
|
||||
|
@ -155,15 +199,21 @@ function getWeather() {
|
|||
// turn on HRM when the LCD is unlocked
|
||||
Bangle.on('lock', function(isLocked) {
|
||||
if (!isLocked) {
|
||||
Bangle.setHRMPower(1,"clicompleteclk");
|
||||
if (hrtValue == undefined)
|
||||
hrtValue = "...";
|
||||
else
|
||||
hrtValueIsOld = true;
|
||||
if (showHeartRate) {
|
||||
Bangle.setHRMPower(1,"clicompleteclk");
|
||||
if (hrtValue == undefined)
|
||||
hrtValue = "...";
|
||||
else
|
||||
hrtValueIsOld = true;
|
||||
}
|
||||
} else {
|
||||
hrtValueIsOld = true;
|
||||
Bangle.setHRMPower(0,"clicompleteclk");
|
||||
if (showHeartRate) {
|
||||
hrtValueIsOld = true;
|
||||
Bangle.setHRMPower(0,"clicompleteclk");
|
||||
}
|
||||
}
|
||||
// Update steps and heart rate
|
||||
drawSteps();
|
||||
drawHeartRate();
|
||||
});
|
||||
|
||||
|
@ -171,25 +221,30 @@ Bangle.on('lcdPower',function(on) {
|
|||
if (on) {
|
||||
drawAll(true);
|
||||
} else {
|
||||
hrtValueIsOld = true;
|
||||
if (showHeartRate) {
|
||||
hrtValueIsOld = true;
|
||||
}
|
||||
if (drawTimeout) clearTimeout(drawTimeout);
|
||||
drawTimeout = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
Bangle.on('HRM', function(hrm) {
|
||||
//if(hrm.confidence > 90){
|
||||
hrtValueIsOld = false;
|
||||
hrtValue = hrm.bpm;
|
||||
if (Bangle.isLCDOn())
|
||||
drawHeartRate();
|
||||
//} else {
|
||||
// hrtValue = undefined;
|
||||
//}
|
||||
});
|
||||
if (showHeartRate) {
|
||||
Bangle.on('HRM', function(hrm) {
|
||||
//if(hrm.confidence > 90){
|
||||
hrtValueIsOld = false;
|
||||
hrtValue = hrm.bpm;
|
||||
if (Bangle.isLCDOn())
|
||||
drawHeartRate();
|
||||
//} else {
|
||||
// hrtValue = undefined;
|
||||
//}
|
||||
});
|
||||
}
|
||||
|
||||
g.clear();
|
||||
Bangle.setUI("clock");
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
loadSettings();
|
||||
drawAll(true);
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
(function(back) {
|
||||
const storage = require('Storage');
|
||||
let settings = storage.readJSON('clicompleteclk.json', 1) || {};
|
||||
function save(key, value) {
|
||||
settings[key] = value;
|
||||
storage.write('clicompleteclk.json', settings);
|
||||
}
|
||||
E.showMenu({
|
||||
'': { 'title': 'CLI complete clk' },
|
||||
'Show battery': {
|
||||
value: "battery" in settings ? settings.battery : false,
|
||||
format: () => (settings.battery ? 'Yes' : 'No'),
|
||||
onchange: () => {
|
||||
settings.battery = !settings.battery;
|
||||
save('battery', settings.battery);
|
||||
},
|
||||
},
|
||||
'Battery warn': {
|
||||
value: "batteryLvl" in settings ? settings.batteryLvl : 30,
|
||||
min: 0,
|
||||
max : 100,
|
||||
step: 10,
|
||||
format: x => {
|
||||
return x + "%";
|
||||
},
|
||||
onchange: x => save('batteryLvl', x),
|
||||
},
|
||||
'Show weather': {
|
||||
value: "weather" in settings ? settings.weather : false,
|
||||
format: () => (settings.weather ? 'Yes' : 'No'),
|
||||
onchange: () => {
|
||||
settings.weather = !settings.weather;
|
||||
save('weather', settings.weather);
|
||||
},
|
||||
},
|
||||
'Show steps': {
|
||||
value: "steps" in settings ? settings.steps : false,
|
||||
format: () => (settings.steps ? 'Yes' : 'No'),
|
||||
onchange: () => {
|
||||
settings.steps = !settings.steps;
|
||||
save('steps', settings.steps);
|
||||
},
|
||||
},
|
||||
'Show heartrate': {
|
||||
value: "heartrate" in settings ? settings.heartrate : false,
|
||||
format: () => (settings.heartrate ? 'Yes' : 'No'),
|
||||
onchange: () => {
|
||||
settings.heartrate = !settings.heartrate;
|
||||
save('heartrate', settings.heartrate);
|
||||
},
|
||||
},
|
||||
'< Back': back,
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue