barclock: simplify redraw logic
parent
346eb8f77b
commit
de3feaff45
|
|
@ -110,19 +110,17 @@ const drawBar = function(date) {
|
||||||
g.setColor(g.theme.fg2).fillRect(0, b.top, width, b.top+b.thickness);
|
g.setColor(g.theme.fg2).fillRect(0, b.top, width, b.top+b.thickness);
|
||||||
};
|
};
|
||||||
|
|
||||||
const clearScreen = function() {
|
|
||||||
const timeTop = settings.time.middle-(settings.time.size*4);
|
|
||||||
g.clearRect(0, timeTop, screen.width, screen.height);
|
|
||||||
};
|
|
||||||
|
|
||||||
let lastSeconds, tTick;
|
let lastSeconds;
|
||||||
const tick = function() {
|
const draw = function(redraw) {
|
||||||
|
if (!Bangle.isLCDOn()) {return;}
|
||||||
g.reset();
|
g.reset();
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const seconds = date.getSeconds();
|
const seconds = date.getSeconds();
|
||||||
if (lastSeconds>seconds) {
|
if (redraw||lastSeconds>seconds) {
|
||||||
// new minute
|
// force redraw at start of new minute
|
||||||
clearScreen();
|
g.clear();
|
||||||
|
Bangle.drawWidgets();
|
||||||
drawDateTime(date);
|
drawDateTime(date);
|
||||||
}
|
}
|
||||||
// the bar only gets larger, so drawing on top of the previous one is fine
|
// the bar only gets larger, so drawing on top of the previous one is fine
|
||||||
|
|
@ -130,32 +128,17 @@ const tick = function() {
|
||||||
lastSeconds = seconds;
|
lastSeconds = seconds;
|
||||||
// schedule next update
|
// schedule next update
|
||||||
const millis = date.getMilliseconds();
|
const millis = date.getMilliseconds();
|
||||||
tTick = setTimeout(tick, 1000-millis);
|
setTimeout(draw, 1000-millis);
|
||||||
};
|
};
|
||||||
|
|
||||||
const start = function() {
|
|
||||||
lastSeconds = 99; // force redraw
|
|
||||||
tick();
|
|
||||||
};
|
|
||||||
const stop = function() {
|
|
||||||
if (tTick) {
|
|
||||||
clearTimeout(tTick);
|
|
||||||
tTick = undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// clean app screen
|
|
||||||
g.clear();
|
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
|
||||||
// Show launcher when button pressed
|
// Show launcher when button pressed
|
||||||
Bangle.setUI("clock");
|
Bangle.setUI("clock");
|
||||||
|
|
||||||
Bangle.on("lcdPower", function(on) {
|
Bangle.on("lcdPower", function(on) {
|
||||||
if (on) {
|
if (on) {
|
||||||
start();
|
draw(true);
|
||||||
} else {
|
|
||||||
stop();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
start();
|
draw(true);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue