2020-05-23 16:42:52 +00:00
|
|
|
// Berlin Clock see https://en.wikipedia.org/wiki/Mengenlehreuhr
|
2020-05-24 16:22:44 +00:00
|
|
|
// https://github.com/eska-muc/BangleApps
|
2020-05-24 11:54:32 +00:00
|
|
|
const fields = [4, 4, 11, 4];
|
|
|
|
const offset = 20;
|
|
|
|
const width = g.getWidth() - 2 * offset;
|
|
|
|
const height = g.getHeight() - 2 * offset;
|
|
|
|
const rowHeight = height / 4;
|
2020-05-23 16:42:52 +00:00
|
|
|
|
2020-05-24 13:05:11 +00:00
|
|
|
var show_date = false;
|
2020-05-24 16:22:44 +00:00
|
|
|
var show_time = false;
|
2020-05-23 16:42:52 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
rowlights = [];
|
2020-05-24 16:22:44 +00:00
|
|
|
time_digit = [];
|
2019-12-09 21:06:47 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
function drawBerlinClock() {
|
2020-05-24 16:45:38 +00:00
|
|
|
try {
|
2020-05-24 11:54:32 +00:00
|
|
|
g.clear();
|
|
|
|
var now = new Date();
|
2020-05-24 12:39:12 +00:00
|
|
|
|
2020-05-24 16:22:44 +00:00
|
|
|
// show date below the clock
|
2020-05-24 11:54:32 +00:00
|
|
|
if (show_date) {
|
|
|
|
var yr = now.getFullYear();
|
|
|
|
var month = now.getMonth() + 1;
|
|
|
|
var day = now.getDate();
|
2020-05-24 12:11:42 +00:00
|
|
|
var dateString = `${yr}-${month < 10 ? '0' : ''}${month}-${day < 10 ? '0' : ''}${day}`;
|
2020-05-24 11:54:32 +00:00
|
|
|
var strWidth = g.stringWidth(dateString);
|
|
|
|
g.setColor(1, 1, 1);
|
2020-05-24 16:22:44 +00:00
|
|
|
g.setFontAlign(-1,-1);
|
|
|
|
g.drawString(dateString, ( g.getWidth() - strWidth ) / 2, height + offset + 4);
|
2020-05-24 11:54:32 +00:00
|
|
|
}
|
2020-05-24 12:39:12 +00:00
|
|
|
|
2020-05-24 11:54:32 +00:00
|
|
|
rowlights[0] = Math.floor(now.getHours() / 5);
|
|
|
|
rowlights[1] = now.getHours() % 5;
|
|
|
|
rowlights[2] = Math.floor(now.getMinutes() / 5);
|
|
|
|
rowlights[3] = now.getMinutes() % 5;
|
2020-01-17 11:43:26 +00:00
|
|
|
|
2020-05-24 16:22:44 +00:00
|
|
|
time_digit[0] = Math.floor(now.getHours() / 10);
|
|
|
|
time_digit[1] = now.getHours() % 10;
|
|
|
|
time_digit[2] = Math.floor(now.getMinutes() / 10);
|
|
|
|
time_digit[3] = now.getMinutes() % 10;
|
|
|
|
|
2020-05-24 11:54:32 +00:00
|
|
|
g.drawRect(offset, offset, width + offset, height + offset);
|
|
|
|
for (row = 0; row < 4; row++) {
|
|
|
|
nfields = fields[row];
|
|
|
|
boxWidth = width / nfields;
|
2020-01-17 11:43:26 +00:00
|
|
|
|
2020-05-24 11:54:32 +00:00
|
|
|
for (col = 0; col < nfields; col++) {
|
|
|
|
x1 = col * boxWidth + offset;
|
|
|
|
y1 = row * rowHeight + offset;
|
|
|
|
x2 = (col + 1) * boxWidth + offset;
|
|
|
|
y2 = (row + 1) * rowHeight + offset;
|
2020-01-17 11:43:26 +00:00
|
|
|
|
2020-05-24 11:54:32 +00:00
|
|
|
g.setColor(1, 1, 1);
|
|
|
|
g.drawRect(x1, y1, x2, y2);
|
|
|
|
if (col < rowlights[row]) {
|
|
|
|
if (row === 2) {
|
|
|
|
if (((col + 1) % 3) === 0) {
|
|
|
|
g.setColor(1, 0, 0);
|
2020-01-17 11:43:26 +00:00
|
|
|
} else {
|
2020-05-24 11:54:32 +00:00
|
|
|
g.setColor(1, 1, 0);
|
2019-12-09 21:06:47 +00:00
|
|
|
}
|
2020-05-24 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
g.setColor(1, 0, 0);
|
2019-12-09 21:06:47 +00:00
|
|
|
}
|
2020-05-24 16:22:44 +00:00
|
|
|
g.fillRect(x1 + 2, y1 + 2, x2 - 2, y2 - 2);
|
|
|
|
}
|
|
|
|
if (row == 3 && show_time) {
|
|
|
|
g.setColor(1,1,1);
|
2020-05-24 16:45:38 +00:00
|
|
|
g.setFontAlign(0,0);
|
2020-05-24 16:22:44 +00:00
|
|
|
g.drawString(time_digit[col],(x1+x2)/2,(y1+y2)/2);
|
2020-01-17 11:43:26 +00:00
|
|
|
}
|
2019-12-09 21:06:47 +00:00
|
|
|
}
|
2020-05-24 11:54:32 +00:00
|
|
|
}
|
2020-05-24 16:45:38 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
console.trace()
|
|
|
|
}
|
2020-01-17 11:43:26 +00:00
|
|
|
}
|
2019-12-09 21:06:47 +00:00
|
|
|
|
2020-05-24 16:22:44 +00:00
|
|
|
function toggleDate() {
|
|
|
|
show_date = ! show_date;
|
|
|
|
drawBerlinClock();
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleTime() {
|
|
|
|
show_time = ! show_time;
|
|
|
|
drawBerlinClock();
|
|
|
|
}
|
2020-05-24 13:05:11 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
// special function to handle display switch on
|
|
|
|
Bangle.on('lcdPower', (on) => {
|
|
|
|
g.clear();
|
|
|
|
if (on) {
|
2020-05-24 11:54:32 +00:00
|
|
|
Bangle.drawWidgets();
|
|
|
|
// call your app function here
|
|
|
|
drawBerlinClock();
|
|
|
|
}
|
|
|
|
});
|
2019-12-09 21:06:47 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
// refesh every 15 sec
|
|
|
|
setInterval(drawBerlinClock, 15E3);
|
2019-12-09 21:06:47 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
g.clear();
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
Bangle.drawWidgets();
|
|
|
|
drawBerlinClock();
|
2020-05-24 16:22:44 +00:00
|
|
|
// Toggle date display, when BTN3 is pressed
|
|
|
|
setWatch(toggleTime,BTN1, { repeat : true, edge: "falling"});
|
|
|
|
// Toggle date display, when BTN3 is pressed
|
|
|
|
setWatch(toggleDate,BTN3, { repeat : true, edge: "falling"});
|
2020-01-17 11:43:26 +00:00
|
|
|
// Show launcher when middle button pressed
|
2020-05-24 11:54:32 +00:00
|
|
|
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
|