word-clock

Dispaly Time as Text
pull/5/head
MaBecker 2019-11-07 22:44:05 +01:00
parent 26114902d4
commit 292d6ab5c9
5 changed files with 162 additions and 0 deletions

View File

@ -216,5 +216,16 @@
{"name":"+route"},
{"name":"=route"}
]
},
{ "id": "wclock",
"name": "Word Clock",
"icon": "word-clock.png",
"description": "Display Time as Text",
"tags": "",
"storage": [
{"name":"+wclock","url":"word-clock.json"},
{"name":"-wclock","url":"word-clock.js"},
{"name":"*wclock","url":"word-clock-icon.js","evaluate":true}
]
}
]

1
apps/word-clock-icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("AAsRwEAkFBvE/wFgmHD/kwgFAmGBgAFFn4FBjOB/AFDgOACIUbgIXDh4FDsEOgf8iALBg0B/hBFjwvD/gpBsE5AoMxwFAj4IBnACBh4CBBANAhwFBg4RBBYUhAoMbAoIdCjJoBNYUx4FgHAUgQY8/zHin/BgEuxnmn53BgkM80wMoIFB8gFDhu0CIcF3gLDg8cAokYAoOAAoQvB/A9H4BBDwPwX4P4nEDnAFBEAMGFIPDhk4g0MAoN8n4FD/ARBAoODuAFBjExwYdBEYMZwYOBgPwh8DhhBHACo="))

145
apps/word-clock.js Normal file
View File

@ -0,0 +1,145 @@
/* jshint esversion: 6 */
(function() {
var buf = Graphics.createArrayBuffer(240, 240, 2, { msb: true });
function flip() {
g.drawImage({ width: buf.getWidth(), height: buf.getHeight(), bpp: 2, transparent: 0, buffer: buf.buffer }, 0, 0);
}
const allWords = [
"ATWENTYD",
"QUARTERY",
"FIVEHALF",
"DPASTORO",
"FIVEIGHT",
"SIXTHREE",
"TWELEVEN",
"FOURNINE"
];
const hours = {
0: ["", 0, 0],
1: ["ONE", 17, 47, 77],
2: ["TWO", 06, 16, 17],
3: ["THREE", 35, 45, 55, 65, 75],
4: ["FOUR", 07, 17, 27, 37],
5: ["FIVE", 04, 14, 24, 34],
6: ["SIX", 05, 15, 25],
7: ["SEVEN", 05, 46, 56, 66, 67],
8: ["EIGHT", 34, 44, 54, 64, 74],
9: ["NINE", 47, 57, 67, 77],
10: ["TEN", 74, 75, 76],
11: ["ELEVEN", 26, 36, 46, 56, 66, 76],
12: ["TWELVE", 06, 16, 26, 36, 56, 66]
};
const mins = {
0: ["A", 0, 0],
1: ["FIVE", 02, 12, 22, 32],
2: ["TEN", 10, 30, 40],
3: ["QUARTER", 01, 11, 21, 31, 41, 51, 61],
4: ["TWENTY", 10, 20, 30, 40, 50, 60],
5: ["HALF", 42, 52, 62, 72],
6: ["PAST", 13, 23, 33, 43],
7: ["TO", 43, 53]
};
// offsets and incerments
const xs = 30;
const ys = 20;
const dy = 22;
const dx = 25;
// font size and color
const wordFontSize = 20;
const timeFontSize = 30;
const passivColor = 1;
const activeColor = 2;
function drawWordClock() {
// get time
var t = new Date();
var h = t.getHours();
var m = t.getMinutes();
var time = ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2);
var hidx;
var midx;
var midxA;
buf.clear();
buf.setFontVector(wordFontSize);
buf.setColor(passivColor);
buf.setFontAlign(0, -1, 0);
// draw allWords
var c;
var y = ys;
var x = xs;
allWords.forEach((line) => {
x = xs;
for (c in line) {
buf.drawString(line[c], x, y);
x += dx;
}
y += dy;
});
// calc indexes
midx = Math.round(m / 5);
hidx = h % 12;
if (hidx === 0) { hidx = 12; }
if (midx > 6) {
if (midx == 12) { midx = 0; }
hidx++;
}
if (midx !== 0) {
if (midx <= 6) {
midxA = [midx, 6];
} else {
midxA = [12 - midx, 7];
}
}
// write hour in active color
buf.setColor(activeColor);
buf.setFontVector(wordFontSize);
hours[hidx][0].split('').forEach((c, pos) => {
x = xs + (hours[hidx][pos + 1] / 10 | 0) * dx;
y = ys + (hours[hidx][pos + 1] % 10) * dy;
buf.drawString(c, x, y);
});
// write min words in active color
midxA.forEach(idx => {
mins[idx][0].split('').forEach((c, pos) => {
x = xs + (mins[idx][pos + 1] / 10 | 0) * dx;
y = ys + (mins[idx][pos + 1] % 10) * dy;
buf.drawString(c, x, y);
});
});
// display digital time
buf.setColor(activeColor);
buf.setFontVector(timeFontSize);
buf.drawString(time, 120, 200);
// display buf
flip();
}
Bangle.on('lcdPower', function(on) {
if (on) {
drawWordClock();
drawWidgets();
}
});
g.clear();
setInterval(drawWordClock, 1E4);
drawWordClock();
})();

5
apps/word-clock.json Normal file
View File

@ -0,0 +1,5 @@
{
"name":"Word Clock",
"icon":"*wclock",
"src":"-wclock"
}

BIN
apps/word-clock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B