1
0
Fork 0

Update app.js

master
Ephraim Amiel Yusi 2020-05-27 16:37:44 +10:00 committed by GitHub
parent f3f5da0cd2
commit d8d520e3e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 18 deletions

View File

@ -1,51 +1,54 @@
// NOTE: 240 x 240 // NOTE: 240 x 240
// Load fonts // Load fonts
require("Font7x11Numeric7Seg").add(Graphics); require("Font8x12").add(Graphics);
function draw() { function drawTimeDate() {
// work out how to display the current time // work out how to display the current time
var d = new Date(); var d = new Date();
var h = d.getHours(), m = d.getMinutes(), day = d.getDate(), month = d.getMonth(), weekDay = d.getDay(); var h = d.getHours(), m = d.getMinutes(), day = d.getDate(), month = d.getMonth(), weekDay = d.getDay();
var daysOfWeek = ["MON", "TUE","WED","THUR","FRI","SAT","SUN"]; var daysOfWeek = ["MON", "TUE","WED","THU","FRI","SAT","SUN"];
var hours = h; var hours = h;
var mins= ("0"+m).substr(-2); var mins= ("0"+m).substr(-2);
var date = `${daysOfWeek[weekDay]}\n\n${day}/${month}`; var date = `${daysOfWeek[weekDay]}|${day}|${("0"+(month+1)).substr(-2)}`;
// Reset the state of the graphics library // Reset the state of the graphics library
g.reset(); g.reset();
// draw the current time (4x size 7 segment) // draw the current time (4x size 7 segment)
g.setFont("7x11Numeric7Seg",6); g.setFont("8x12",9);
g.setFontAlign(-1,0); // align right bottom g.setFontAlign(-1,0); // align right bottom
g.drawString(hours, 55, 80, true /*clear background*/); g.drawString(hours, 25, 65, true /*clear background*/);
g.drawString(mins, 55, 155, true /*clear background*/); g.drawString(mins, 25, 155, true /*clear background*/);
// draw the date (2x size 7 segment) // draw the date (2x size 7 segment)
g.setFont("6x8",2); g.setFont("6x8",2);
g.setFontAlign(-1,0); // align right bottom g.setFontAlign(-1,0); // align right bottom
g.drawString(date, 145, 100, true /*clear background*/); g.drawString(date, 20, 215, true /*clear background*/);
} }
// Clear the screen once, at startup // Clear the screen once, at startup
g.clear(); g.clear();
// draw immediately at first // draw immediately at first
draw(); drawTimeDate();
var secondInterval = setInterval(draw, 5000); var secondInterval = setInterval(drawTimeDate, 5000);
// 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 (secondInterval) clearInterval(secondInterval); if (secondInterval) clearInterval(secondInterval);
secondInterval = undefined; secondInterval = undefined;
if (on) { if (on) {
setInterval(draw, 5000); setInterval(drawTimeDate, 5000);
draw(); // draw immediately drawTimeDate(); // draw immediately
} }
}); });
// Load widgets // Load widgets
Bangle.loadWidgets(); //Bangle.loadWidgets();
Bangle.drawWidgets(); //Bangle.drawWidgets();
// Show launcher when middle button pressed // Show launcher when middle button pressed
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" }); setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });