Merge pull request #701 from Tutturuuu/patch-2

Made Date more visible
master
Gordon Williams 2021-03-23 09:18:05 +00:00 committed by GitHub
commit aba2be6c58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 10 deletions

View File

@ -5,7 +5,7 @@ require("Font7x11Numeric7Seg").add(Graphics);
var is12Hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]; var is12Hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"];
// position on screen // position on screen
const X = 160, Y = 140; const X = 160, Y = 140;
function draw() { function draw() {
// work out how to display the current time // work out how to display the current time
var d = new Date(); var d = new Date();
@ -23,15 +23,15 @@ function draw() {
g.drawString(time, X, Y, true /*clear background*/); g.drawString(time, X, Y, true /*clear background*/);
// draw the seconds (2x size 7 segment) // draw the seconds (2x size 7 segment)
g.setFont("7x11Numeric7Seg",2); g.setFont("7x11Numeric7Seg",2);
g.drawString(("0"+d.getSeconds()).substr(-2), X+30, Y, true /*clear background*/); g.drawString(("0"+d.getSeconds()).substr(-2), X+35, Y, true /*clear background*/);
// draw the date, in a normal font // draw the date, in a normal font
g.setFont("6x8"); g.setFont("6x8", 3);
g.setFontAlign(0,1); // align center bottom g.setFontAlign(0,1); // align center bottom
// pad the date - this clears the background if the date were to change length // pad the date - this clears the background if the date were to change length
var dateStr = " "+require("locale").date(d)+" "; var dateStr = " "+require("locale").date(d)+" ";
g.drawString(dateStr, g.getWidth()/2, Y+15, true /*clear background*/); g.drawString(dateStr, g.getWidth()/2, Y+35, 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
@ -51,7 +51,7 @@ 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" });
// ====================================== Vibration // ====================================== Vibration
// vibrate 0..9 // vibrate 0..9
function vibrateDigit(num) { function vibrateDigit(num) {
@ -74,24 +74,24 @@ function vibrateNumber(num) {
}); });
}); });
} }
var vibrateBusy; var vibrateBusy;
function vibrateTime() { function vibrateTime() {
if (vibrateBusy) return; if (vibrateBusy) return;
vibrateBusy = true; vibrateBusy = true;
var d = new Date(); var d = new Date();
var hours = d.getHours(), minutes = d.getMinutes(); var hours = d.getHours(), minutes = d.getMinutes();
if (is12Hour) { if (is12Hour) {
if (hours == 0) hours = 12; if (hours == 0) hours = 12;
else if (hours>12) hours -= 12; else if (hours>12) hours -= 12;
} }
vibrateNumber(hours.toString()). vibrateNumber(hours.toString()).
then(() => new Promise(resolve=>setTimeout(resolve,500))). then(() => new Promise(resolve=>setTimeout(resolve,500))).
then(() => vibrateNumber(minutes.toString())). then(() => vibrateNumber(minutes.toString())).
then(() => vibrateBusy=false); then(() => vibrateBusy=false);
} }
// when BTN1 pressed, vibrate // when BTN1 pressed, vibrate
setWatch(vibrateTime, BTN1, {repeat:true,edge:"rising"}); setWatch(vibrateTime, BTN1, {repeat:true,edge:"rising"});