2019-11-10 09:47:13 +00:00
|
|
|
/* jshint esversion: 6 */
|
2020-01-17 11:43:26 +00:00
|
|
|
const timeFontSize = 6;
|
|
|
|
const dateFontSize = 3;
|
|
|
|
const gmtFontSize = 2;
|
|
|
|
const font = "6x8";
|
2019-11-10 09:47:13 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
const xyCenter = g.getWidth() / 2;
|
|
|
|
const yposTime = 75;
|
|
|
|
const yposDate = 130;
|
|
|
|
const yposYear = 175;
|
|
|
|
const yposGMT = 220;
|
2019-11-10 09:47:13 +00:00
|
|
|
|
2020-02-07 14:02:00 +00:00
|
|
|
// Check settings for what type our clock should be
|
|
|
|
var is12Hour = (require("Storage").readJSON("@setting")||{})["12hour"];
|
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
function drawSimpleClock() {
|
2020-01-23 10:04:53 +00:00
|
|
|
// get date
|
|
|
|
var d = new Date();
|
|
|
|
var da = d.toString().split(" ");
|
|
|
|
|
|
|
|
// drawSting centered
|
|
|
|
g.setFontAlign(0, 0);
|
|
|
|
|
|
|
|
// draw time
|
|
|
|
var time = da[4].substr(0, 5).split(":");
|
|
|
|
var hours = time[0],
|
|
|
|
minutes = time[1];
|
2020-02-07 14:02:00 +00:00
|
|
|
var meridian = "";
|
|
|
|
if (is12Hour) {
|
|
|
|
hours = parseInt(hours,10);
|
|
|
|
meridian = "AM";
|
|
|
|
if (hours == 0) {
|
|
|
|
hours = 12;
|
|
|
|
meridian = "AM";
|
|
|
|
} else if (hours >= 12) {
|
|
|
|
meridian = "PM";
|
|
|
|
if (hours>12) hours -= 12;
|
|
|
|
}
|
|
|
|
hours = (" "+hours).substr(-2);
|
|
|
|
}
|
|
|
|
|
2020-01-23 10:04:53 +00:00
|
|
|
g.setFont(font, timeFontSize);
|
|
|
|
g.drawString(`${hours}:${minutes}`, xyCenter, yposTime, true);
|
2020-02-07 14:02:00 +00:00
|
|
|
g.setFont(font, gmtFontSize);
|
|
|
|
g.drawString(meridian, xyCenter + 102, yposTime + 10, true);
|
2020-01-23 10:04:53 +00:00
|
|
|
|
|
|
|
// draw Day, name of month, Date
|
|
|
|
var date = [da[0], da[1], da[2]].join(" ");
|
|
|
|
g.setFont(font, dateFontSize);
|
|
|
|
|
|
|
|
g.drawString(date, xyCenter, yposDate, true);
|
|
|
|
|
|
|
|
// draw year
|
|
|
|
g.setFont(font, dateFontSize);
|
|
|
|
g.drawString(d.getFullYear(), xyCenter, yposYear, true);
|
|
|
|
|
|
|
|
// draw gmt
|
|
|
|
var gmt = da[5];
|
|
|
|
g.setFont(font, gmtFontSize);
|
|
|
|
g.drawString(gmt, xyCenter, yposGMT, true);
|
2020-01-17 11:43:26 +00:00
|
|
|
}
|
2019-11-10 09:47:13 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
// handle switch display on by pressing BTN1
|
|
|
|
Bangle.on('lcdPower', function(on) {
|
|
|
|
if (on) drawSimpleClock();
|
|
|
|
});
|
2019-11-10 09:47:13 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
// clean app screen
|
|
|
|
g.clear();
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
Bangle.drawWidgets();
|
2019-11-11 10:56:12 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
// refesh every 15 sec
|
|
|
|
setInterval(drawSimpleClock, 15E3);
|
2019-11-11 10:56:12 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
// draw now
|
|
|
|
drawSimpleClock();
|
2019-11-10 09:47:13 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
// Show launcher when middle button pressed
|
|
|
|
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
|