reformatted json clock
parent
eebfc56b95
commit
81755f82e8
|
|
@ -17,7 +17,7 @@ var settings = {
|
|||
};
|
||||
|
||||
let clrs = {
|
||||
tab : "#505050", // grey
|
||||
tab: "#505050", // grey
|
||||
keys: settings.dark_mode ? "#4287f5" : "#0000FF", // blue
|
||||
strings: settings.dark_mode ? "#F0A000" : "#FF0000", // orange or red
|
||||
ints: settings.dark_mode ? "#00FF00" : "#005F00", // green
|
||||
|
|
@ -43,10 +43,10 @@ var numWidth = 0;
|
|||
|
||||
// requires the myLocation app
|
||||
function loadLocation() {
|
||||
location = require("Storage").readJSON(LOCATION_FILE,1)||{};
|
||||
location.lat = location.lat||0;
|
||||
location.lon = location.lon||0;
|
||||
location.location = location.location||null;
|
||||
location = require("Storage").readJSON(LOCATION_FILE, 1) || {};
|
||||
location.lat = location.lat || 0;
|
||||
location.lon = location.lon || 0;
|
||||
location.location = location.location || null;
|
||||
}
|
||||
|
||||
function getHr(h) {
|
||||
|
|
@ -59,26 +59,28 @@ function getHr(h) {
|
|||
return [h, amPm];
|
||||
}
|
||||
|
||||
function extractTime(d){
|
||||
function extractTime(d) {
|
||||
const out = getHr(d.getHours());
|
||||
const hr = out[0]; const amPm = out[1];
|
||||
const hr = out[0];
|
||||
const amPm = out[1];
|
||||
const m = d.getMinutes();
|
||||
return `${h}:${("0"+m).substr(-2)}${amPm}`;
|
||||
}
|
||||
}
|
||||
|
||||
function extractDate(d) {
|
||||
function extractDate(d) {
|
||||
const weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
];
|
||||
|
||||
const weekday = weekdays[d.getDay()];
|
||||
const month = months[d.getMonth()];
|
||||
const day = d.getDate();
|
||||
|
||||
return `${weekday} ${month} ${day}`;
|
||||
}
|
||||
}
|
||||
|
||||
function getSteps() {
|
||||
function getSteps() {
|
||||
try {
|
||||
return Bangle.getHealthStatus("day").steps;
|
||||
} catch (e) {
|
||||
|
|
@ -87,9 +89,9 @@ function extractTime(d){
|
|||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getVal(now, loc) {
|
||||
function getVal(now, loc) {
|
||||
const vals = {};
|
||||
const currentDateStr = extractDate(now);
|
||||
if (loc.location) {
|
||||
|
|
@ -105,7 +107,7 @@ function extractTime(d){
|
|||
vals.batt_pct = E.getBattery();
|
||||
vals.steps = getSteps();
|
||||
return vals;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function loadJson() {
|
||||
|
|
@ -153,10 +155,10 @@ function draw() {
|
|||
g.fillRect(90, 0, w, headerHeight);
|
||||
loadJson();
|
||||
g.setColor(clrs.brackets);
|
||||
g.drawString("clockface.json",3,3);
|
||||
g.drawString("clockface.json", 3, 3);
|
||||
|
||||
g.setFont("Vector", buttonHeight);
|
||||
g.drawString("X",buttonX,buttonY);
|
||||
g.drawString("X", buttonX, buttonY);
|
||||
g.setFont("Vector", fontSize);
|
||||
|
||||
for (let i = 0; i < maxLines; i++) {
|
||||
|
|
@ -197,18 +199,20 @@ function redraw() {
|
|||
// Value color
|
||||
if (value.startsWith('"')) {
|
||||
g.setColor(clrs.strings);
|
||||
}
|
||||
else if (value.startsWith('{') || value.startsWith('}')) {
|
||||
} else if (value.startsWith('{') || value.startsWith('}')) {
|
||||
g.setColor(clrs.brackets);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
g.setColor(clrs.ints);
|
||||
}
|
||||
g.drawString(valueText, valueX, y);
|
||||
|
||||
valuePositions.push({ key, x: valueX, y, text: value });
|
||||
}
|
||||
else {
|
||||
valuePositions.push({
|
||||
key,
|
||||
x: valueX,
|
||||
y,
|
||||
text: value
|
||||
});
|
||||
} else {
|
||||
g.setColor(clrs.brackets);
|
||||
g.drawString(line, numWidth, y);
|
||||
}
|
||||
|
|
@ -225,7 +229,7 @@ function clearVals() {
|
|||
});
|
||||
}
|
||||
|
||||
function redrawValues(){
|
||||
function redrawValues() {
|
||||
loadJson();
|
||||
clearVals();
|
||||
redraw();
|
||||
|
|
@ -237,8 +241,8 @@ function redrawValues(){
|
|||
}
|
||||
|
||||
Bangle.on('touch', (zone, e) => {
|
||||
if (e.x >= (buttonY - buttonHeight) && e.x <= (buttonX + buttonHeight)
|
||||
&& (e.y >= (buttonY - buttonHeight) && e.y <= (buttonY + buttonHeight))) {
|
||||
if (e.x >= (buttonY - buttonHeight) && e.x <= (buttonX + buttonHeight) &&
|
||||
(e.y >= (buttonY - buttonHeight) && e.y <= (buttonY + buttonHeight))) {
|
||||
load(); // Exit app
|
||||
}
|
||||
});
|
||||
|
|
@ -251,7 +255,7 @@ Bangle.on('backlight', function(on) {
|
|||
|
||||
Bangle.setUI({
|
||||
mode: "clock",
|
||||
remove: function () {
|
||||
remove: function() {
|
||||
if (drawTimeout) clearTimeout(drawTimeout);
|
||||
drawTimeout = undefined;
|
||||
}
|
||||
|
|
@ -261,4 +265,4 @@ loadLocation();
|
|||
Bangle.loadWidgets();
|
||||
widget_utils.hide();
|
||||
draw();
|
||||
setTimeout(Bangle.drawWidgets,0);
|
||||
setTimeout(Bangle.drawWidgets, 0);
|
||||
Loading…
Reference in New Issue