mirror of https://github.com/espruino/BangleApps
Merge pull request #2835 from npbreland/master
New Swatch Internet Time widget (widswatchbeats)pull/2837/head
commit
be5fcdd185
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"id": "widswatchbeats",
|
||||
"name": "Swatch Internet Time Widget",
|
||||
"icon": "widget-icon.png",
|
||||
"type": "widget",
|
||||
"version": "0.01",
|
||||
"description": "Displays the current .beat (e.g. @500 for midday)",
|
||||
"tags": "widget,time,swatch,internet,beat,.beat,clock",
|
||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||
"storage": [
|
||||
{"name": "widswatchbeats.wid.js","url": "widget.js"}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 403 B |
|
@ -0,0 +1,41 @@
|
|||
(function() {
|
||||
const WIDTH = 50;
|
||||
const SEC_PER_BEAT = 86.4;
|
||||
|
||||
let drawTimeout;
|
||||
|
||||
function getSecondsSinceMidnight() {
|
||||
const now = new Date();
|
||||
return now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
|
||||
}
|
||||
|
||||
function queueDraw() {
|
||||
if (drawTimeout) clearTimeout(drawTimeout);
|
||||
const nextSecond = SEC_PER_BEAT - (getSecondsSinceMidnight() % SEC_PER_BEAT);
|
||||
drawTimeout = setTimeout(function() {
|
||||
drawTimeout = undefined;
|
||||
WIDGETS.widswatchbeats.draw();
|
||||
}, nextSecond * 1000 + 1); // Add one ms to ensure we're past the beat
|
||||
}
|
||||
|
||||
function draw() {
|
||||
const now = new Date();
|
||||
const seconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
|
||||
const beats = Math.floor(seconds / SEC_PER_BEAT);
|
||||
const beatsString = '@' + beats.toString().padStart(3, '0');
|
||||
|
||||
g.reset();
|
||||
g.setFontAlign(0, 0);
|
||||
g.clearRect(this.x, this.y, this.x + WIDTH, this.y+22);
|
||||
g.setFont("6x8", 2);
|
||||
g.drawString(beatsString, this.x+WIDTH/2, this.y+12);
|
||||
queueDraw();
|
||||
}
|
||||
|
||||
WIDGETS.widswatchbeats = {
|
||||
area: "tl",
|
||||
width: WIDTH,
|
||||
draw
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in New Issue