beebclock: Avoid clearTimeout() usage, as it may break other widgets

master
Gordon Williams 2021-09-01 08:46:26 +01:00
parent 11b7000259
commit 05bc9f5b07
2 changed files with 14 additions and 5 deletions

View File

@ -3,3 +3,4 @@
0.03: Remove hardcoded hour buzz (you can install widchime if you miss it)
0.04: Update to use Bangle.setUI instead of setWatch
0.05: Avoid 'loadWidgets' at LCD on, which will cause memory leak
Avoid clearTimeout() usage, as it may break other widgets

View File

@ -5,6 +5,7 @@
const storage = require("Storage");
const filename = 'beebjson';
var timeout;
require('FontTeletext10x18Ascii').add(Graphics);
@ -153,15 +154,21 @@ let hours, minutes, seconds, date;
// Schedule event for calling at the start of the next second
const inOneSecond = (cb) => {
let now = new Date();
clearTimeout();
setTimeout(cb, 1000 - now.getMilliseconds());
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function() {
timeout = undefined;
cb();
}, 1000 - now.getMilliseconds());
};
// Schedule event for calling at the start of the next minute
const inOneMinute = (cb) => {
let now = new Date();
clearTimeout();
setTimeout(cb, 60000 - (now.getSeconds() * 1000 + now.getMilliseconds()));
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function() {
timeout = undefined;
cb();
}, 60000 - (now.getSeconds() * 1000 + now.getMilliseconds()));
};
// Draw a fat hour/minute hand
@ -376,6 +383,7 @@ Bangle.on('lcdPower', (on) => {
if (on) {
drawAll();
} else {
clearTimeout();
if (timeout) clearTimeout(timeout);
timeout = undefined;
}
});