widclk 0.06: Use 7 segment font, update *on* the minute, use less memory
parent
e53099aea6
commit
48d8031442
|
|
@ -1187,7 +1187,7 @@
|
||||||
{ "id": "widclk",
|
{ "id": "widclk",
|
||||||
"name": "Digital clock widget",
|
"name": "Digital clock widget",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"version":"0.05",
|
"version":"0.06",
|
||||||
"description": "A simple digital clock widget",
|
"description": "A simple digital clock widget",
|
||||||
"tags": "widget,clock",
|
"tags": "widget,clock",
|
||||||
"type":"widget",
|
"type":"widget",
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@
|
||||||
0.03: Ensure redrawing works with variable size widget system
|
0.03: Ensure redrawing works with variable size widget system
|
||||||
0.04: Fix regression stopping correct widget updates
|
0.04: Fix regression stopping correct widget updates
|
||||||
0.05: Don't show clock widget if already showing clock app
|
0.05: Don't show clock widget if already showing clock app
|
||||||
|
0.06: Use 7 segment font, update *on* the minute, use less memory
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,16 @@
|
||||||
(function() {
|
/* Simple clock that appears in the widget bar if no other clock
|
||||||
// don't show widget if we know we have a clock app running
|
is running. We update once per minute, but don't bother stopping
|
||||||
if (Bangle.CLOCK) return;
|
if the */
|
||||||
|
|
||||||
let intervalRef = null;
|
// don't show widget if we know we have a clock app running
|
||||||
var width = 5 * 6*2
|
if (!Bangle.CLOCK) WIDGETS["wdclk"]={area:"tl",width:52/* g.stringWidth("00:00") */,draw:function() {
|
||||||
|
g.reset().setFontCustom(atob("AAAAAAAAAAIAAAQCAQAAAd0BgMBdwAAAAAAAdwAB0RiMRcAAAERiMRdwAcAQCAQdwAcERiMRBwAd0RiMRBwAAEAgEAdwAd0RiMRdwAcERiMRdwAFAAd0QiEQdwAdwRCIRBwAd0BgMBAAABwRCIRdwAd0RiMRAAAd0QiEQAAAAAAAAAA="), 32, atob("BgAAAAAAAAAAAAAAAAYCAAYGBgYGBgYGBgYCAAAAAAAABgYGBgYG"), 512+9);
|
||||||
function draw() {
|
var time = require("locale").time(new Date(),1);
|
||||||
g.reset().setFont("6x8", 2).setFontAlign(-1, 0);
|
g.drawString(time, this.x, this.y+3, true); // 5 * 6*2 = 60
|
||||||
var time = require("locale").time(new Date(),1);
|
// queue draw in one minute
|
||||||
g.drawString(time, this.x, this.y+11, true); // 5 * 6*2 = 60
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
}
|
this.drawTimeout = setTimeout(()=>{
|
||||||
function clearTimers(){
|
this.drawTimeout = undefined;
|
||||||
if(intervalRef) {
|
this.draw();
|
||||||
clearInterval(intervalRef);
|
}, 60000 - (Date.now() % 60000));
|
||||||
intervalRef = null;
|
}};
|
||||||
}
|
|
||||||
}
|
|
||||||
function startTimers(){
|
|
||||||
intervalRef = setInterval(()=>WIDGETS["wdclk"].draw(), 60*1000);
|
|
||||||
WIDGETS["wdclk"].draw();
|
|
||||||
}
|
|
||||||
Bangle.on('lcdPower', (on) => {
|
|
||||||
clearTimers();
|
|
||||||
if (on) startTimers();
|
|
||||||
});
|
|
||||||
|
|
||||||
WIDGETS["wdclk"]={area:"tr",width:width,draw:draw};
|
|
||||||
if (Bangle.isLCDOn) intervalRef = setInterval(()=>WIDGETS["wdclk"].draw(), 60*1000);
|
|
||||||
})()
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue