2020-05-27 03:58:47 +00:00
|
|
|
// NOTE: 240 x 240
|
|
|
|
// Load fonts
|
|
|
|
require("Font7x11Numeric7Seg").add(Graphics);
|
|
|
|
|
|
|
|
|
|
|
|
function draw() {
|
|
|
|
// work out how to display the current time
|
|
|
|
var d = new Date();
|
2020-05-27 04:58:21 +00:00
|
|
|
var h = d.getHours(), m = d.getMinutes(), day = d.getDate(), month = d.getMonth(), weekDay = d.getDay();
|
2020-05-27 04:12:45 +00:00
|
|
|
|
|
|
|
var daysOfWeek = ["MON", "TUE","WED","THUR","FRI","SAT","SUN"];
|
|
|
|
|
2020-05-27 04:58:21 +00:00
|
|
|
var hours = h;
|
2020-05-27 03:58:47 +00:00
|
|
|
var mins= ("0"+m).substr(-2);
|
|
|
|
var date = `${daysOfWeek[weekDay]}\n\n${day}/${month}`;
|
2020-05-27 04:12:45 +00:00
|
|
|
|
2020-05-27 03:58:47 +00:00
|
|
|
// Reset the state of the graphics library
|
|
|
|
g.reset();
|
2020-05-27 04:12:45 +00:00
|
|
|
// draw the current time (4x size 7 segment)
|
|
|
|
g.setFont("7x11Numeric7Seg",6);
|
2020-05-27 03:58:47 +00:00
|
|
|
g.setFontAlign(-1,0); // align right bottom
|
2020-05-27 05:21:03 +00:00
|
|
|
g.drawString(hours, 55, 80, true /*clear background*/);
|
|
|
|
g.drawString(mins, 55, 155, true /*clear background*/);
|
2020-05-27 04:12:45 +00:00
|
|
|
|
2020-05-27 03:58:47 +00:00
|
|
|
// draw the date (2x size 7 segment)
|
2020-05-27 04:12:45 +00:00
|
|
|
g.setFont("6x8",2);
|
2020-05-27 03:58:47 +00:00
|
|
|
g.setFontAlign(-1,0); // align right bottom
|
2020-05-27 05:21:03 +00:00
|
|
|
g.drawString(date, 145, 100, true /*clear background*/);
|
2020-05-27 03:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the screen once, at startup
|
|
|
|
g.clear();
|
|
|
|
// draw immediately at first
|
|
|
|
draw();
|
|
|
|
var secondInterval = setInterval(draw, 5000);
|
|
|
|
|
|
|
|
// Stop updates when LCD is off, restart when on
|
|
|
|
Bangle.on('lcdPower',on=>{
|
|
|
|
if (secondInterval) clearInterval(secondInterval);
|
|
|
|
secondInterval = undefined;
|
|
|
|
if (on) {
|
|
|
|
setInterval(draw, 5000);
|
|
|
|
draw(); // draw immediately
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Load widgets
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
Bangle.drawWidgets();
|
|
|
|
// Show launcher when middle button pressed
|
|
|
|
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
|
2020-05-27 04:58:21 +00:00
|
|
|
|
2020-05-27 04:44:45 +00:00
|
|
|
Bangle.on('touch', function(button) {
|
|
|
|
if(button == 1 || button == 2) Bangle.showLauncher();
|
|
|
|
});
|