mirror of https://github.com/espruino/BangleApps
Add testing variables
parent
4150874534
commit
9bf6f1f20b
|
@ -1,30 +1,74 @@
|
||||||
const SETTINGSFILE = "smclock.json";
|
const SETTINGSFILE = "smclock.json";
|
||||||
const background = {
|
const background = {
|
||||||
width : 176, height : 176, bpp : 3, transparent : 1,
|
width: 176,
|
||||||
buffer : require("heatshrink").decompress(atob("/4A/AH4ACUb8H9MkyVJAThB/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/INP/AH4A/AAX8Yz4Afn5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/INI="))
|
height: 176,
|
||||||
|
bpp: 3,
|
||||||
|
transparent: 1,
|
||||||
|
buffer: require("heatshrink").decompress(
|
||||||
|
atob(
|
||||||
|
"/4A/AH4ACUb8H9MkyVJAThB/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/INP/AH4A/AAX8Yz4Afn5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/INI="
|
||||||
|
)
|
||||||
|
),
|
||||||
};
|
};
|
||||||
const monthName = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
|
const monthName = [
|
||||||
const weekday = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
|
"Jan",
|
||||||
|
"Feb",
|
||||||
|
"Mar",
|
||||||
|
"Apr",
|
||||||
|
"May",
|
||||||
|
"Jun",
|
||||||
|
"Jul",
|
||||||
|
"Aug",
|
||||||
|
"Sep",
|
||||||
|
"Oct",
|
||||||
|
"Nov",
|
||||||
|
"Dec",
|
||||||
|
];
|
||||||
|
const weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||||
|
|
||||||
// dynamic variables
|
// dynamic variables
|
||||||
var batLevel = -1;
|
var batLevel = -1;
|
||||||
var batColor = [0,0,0];
|
var batColor = [0, 0, 0];
|
||||||
|
|
||||||
|
// settings variables
|
||||||
|
var dateFormat;
|
||||||
|
var drawInterval;
|
||||||
|
var pollInterval;
|
||||||
|
var showAnalogFace;
|
||||||
|
var showWeekInfo;
|
||||||
|
var useVectorFont;
|
||||||
|
|
||||||
|
// load settings
|
||||||
|
function loadSettings() {
|
||||||
|
// Helper function default setting
|
||||||
|
function def(value, def) {
|
||||||
|
return value !== undefined ? value : def;
|
||||||
|
}
|
||||||
|
var settings = require("Storage").readJSON(SETTINGSFILE, true) || {};
|
||||||
|
|
||||||
|
dateFormat = def(settings.dateFormat, "Short");
|
||||||
|
drawInterval = def(settings.drawInterval, 10);
|
||||||
|
pollInterval = def(settings.pollInterval, 60);
|
||||||
|
showAnalogFace = def(settings.showAnalogFace, false);
|
||||||
|
showWeekInfo = def(settings.showWeekInfo, false);
|
||||||
|
useVectorFont = def(settings.useVectorFont, false);
|
||||||
|
}
|
||||||
|
|
||||||
// copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
|
// copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
|
||||||
function ISO8601_week_no(date) {
|
function ISO8601_week_no(date) {
|
||||||
var tdt = new Date(date.valueOf());
|
var tdt = new Date(date.valueOf());
|
||||||
var dayn = (date.getDay() + 6) % 7;
|
var dayn = (date.getDay() + 6) % 7;
|
||||||
tdt.setDate(tdt.getDate() - dayn + 3);
|
tdt.setDate(tdt.getDate() - dayn + 3);
|
||||||
var firstThursday = tdt.valueOf();
|
var firstThursday = tdt.valueOf();
|
||||||
tdt.setMonth(0, 1);
|
tdt.setMonth(0, 1);
|
||||||
if (tdt.getDay() !== 4) {
|
if (tdt.getDay() !== 4) {
|
||||||
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
|
tdt.setMonth(0, 1 + ((4 - tdt.getDay() + 7) % 7));
|
||||||
}
|
}
|
||||||
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
|
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function d02(value) {
|
function d02(value) {
|
||||||
return ('0' + value).substr(-2);
|
return ("0" + value).substr(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pollBattery() {
|
function pollBattery() {
|
||||||
|
@ -37,16 +81,16 @@ function getBatteryColor(level) {
|
||||||
pollBattery();
|
pollBattery();
|
||||||
level = batLevel;
|
level = batLevel;
|
||||||
}
|
}
|
||||||
if(level>80) {
|
if (level > 80) {
|
||||||
color = [0,0,1];
|
color = [0, 0, 1];
|
||||||
} else if(level>60) {
|
} else if (level > 60) {
|
||||||
color = [0,1,1];
|
color = [0, 1, 1];
|
||||||
} else if(level>40) {
|
} else if (level > 40) {
|
||||||
color = [0,1,0];
|
color = [0, 1, 0];
|
||||||
} else if(level>20) {
|
} else if (level > 20) {
|
||||||
color = [1,1,0];
|
color = [1, 1, 0];
|
||||||
} else {
|
} else {
|
||||||
color = [1,0,0];
|
color = [1, 0, 0];
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +102,7 @@ function draw() {
|
||||||
const bat = d02(E.getBattery()) + "%";
|
const bat = d02(E.getBattery()) + "%";
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
const day = d.getDate();
|
const day = d.getDate();
|
||||||
const month = (d.getMonth() + 1);
|
const month = d.getMonth() + 1;
|
||||||
const week = d02(ISO8601_week_no(d));
|
const week = d02(ISO8601_week_no(d));
|
||||||
const date1 = d02(day) + "/" + d02(month);
|
const date1 = d02(day) + "/" + d02(month);
|
||||||
const date2 = weekday[d.getDay()] + " " + d02(week);
|
const date2 = weekday[d.getDay()] + " " + d02(week);
|
||||||
|
@ -69,7 +113,12 @@ function draw() {
|
||||||
g.reset();
|
g.reset();
|
||||||
|
|
||||||
g.setColor(0, 0, 0);
|
g.setColor(0, 0, 0);
|
||||||
g.setFont("Vector", 20);
|
console.log(useVectorFont, dateFormat);
|
||||||
|
if (useVectorFont == true && dateFormat == "Short") {
|
||||||
|
g.setFont("Vector", 20);
|
||||||
|
} else {
|
||||||
|
g.setFont("6x8", 2);
|
||||||
|
}
|
||||||
g.drawString(date1, 105, 20, false);
|
g.drawString(date1, 105, 20, false);
|
||||||
g.setFont("Vector", 16);
|
g.setFont("Vector", 16);
|
||||||
g.drawString(date2, 105, 55, false);
|
g.drawString(date2, 105, 55, false);
|
||||||
|
@ -85,6 +134,8 @@ function draw() {
|
||||||
g.drawString(bat, 52, 22, false);
|
g.drawString(bat, 52, 22, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
g.clear();
|
g.clear();
|
||||||
|
|
||||||
pollBattery();
|
pollBattery();
|
||||||
|
@ -94,7 +145,7 @@ var batInterval = setInterval(pollBattery, 60000);
|
||||||
var drawInterval = setInterval(draw, 10000);
|
var drawInterval = setInterval(draw, 10000);
|
||||||
|
|
||||||
// Stop updates when LCD is off, restart when on
|
// Stop updates when LCD is off, restart when on
|
||||||
Bangle.on('lcdPower',on=>{
|
Bangle.on("lcdPower", (on) => {
|
||||||
if (batInterval) clearInterval(batInterval);
|
if (batInterval) clearInterval(batInterval);
|
||||||
batInterval = undefined;
|
batInterval = undefined;
|
||||||
if (drawInterval) clearInterval(drawInterval);
|
if (drawInterval) clearInterval(drawInterval);
|
||||||
|
|
|
@ -8,10 +8,12 @@
|
||||||
// assign default values if it doesn't exist
|
// assign default values if it doesn't exist
|
||||||
var settings = Object.assign(
|
var settings = Object.assign(
|
||||||
{
|
{
|
||||||
dateFormat: "short",
|
dateFormat: "Short",
|
||||||
|
drawInterval: 10,
|
||||||
|
pollInterval: 60,
|
||||||
showAnalogFace: false,
|
showAnalogFace: false,
|
||||||
showWeekInfo: false,
|
showWeekInfo: false,
|
||||||
useVectorFont: true,
|
useVectorFont: false,
|
||||||
},
|
},
|
||||||
require("Storage").readJSON(FILE, true) || {}
|
require("Storage").readJSON(FILE, true) || {}
|
||||||
);
|
);
|
||||||
|
@ -57,7 +59,21 @@
|
||||||
writeSettings();
|
writeSettings();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Date: stringInSettings("dateOnMain", ["Long", "Short", "ISO8601"]),
|
Date: stringInSettings("dateFormat", ["Long", "Short", "ISO8601"]),
|
||||||
|
"Draw Interval": {
|
||||||
|
value: settings.drawInterval,
|
||||||
|
onchange: (v) => {
|
||||||
|
settings.drawInterval = v;
|
||||||
|
writeSettings();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Poll Interval": {
|
||||||
|
value: settings.pollInterval,
|
||||||
|
onchange: (v) => {
|
||||||
|
settings.pollInterval = v;
|
||||||
|
writeSettings();
|
||||||
|
},
|
||||||
|
},
|
||||||
"Week Info": {
|
"Week Info": {
|
||||||
value:
|
value:
|
||||||
settings.showWeekInfo !== undefined ? settings.showWeekInfo : false,
|
settings.showWeekInfo !== undefined ? settings.showWeekInfo : false,
|
||||||
|
@ -72,7 +88,11 @@
|
||||||
settings.useVectorFont !== undefined ? settings.useVectorFont : false,
|
settings.useVectorFont !== undefined ? settings.useVectorFont : false,
|
||||||
format: (v) => (v ? "On" : "Off"),
|
format: (v) => (v ? "On" : "Off"),
|
||||||
onchange: (v) => {
|
onchange: (v) => {
|
||||||
settings.useVectorFont = v;
|
if (v == "On") {
|
||||||
|
settings.useVectorFont = true;
|
||||||
|
} else {
|
||||||
|
settings.useVectorFont = false;
|
||||||
|
}
|
||||||
writeSettings();
|
writeSettings();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue