beebclock: Avoid clearTimeout() usage, as it may break other widgets
parent
11b7000259
commit
05bc9f5b07
|
|
@ -3,3 +3,4 @@
|
||||||
0.03: Remove hardcoded hour buzz (you can install widchime if you miss it)
|
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.04: Update to use Bangle.setUI instead of setWatch
|
||||||
0.05: Avoid 'loadWidgets' at LCD on, which will cause memory leak
|
0.05: Avoid 'loadWidgets' at LCD on, which will cause memory leak
|
||||||
|
Avoid clearTimeout() usage, as it may break other widgets
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
const storage = require("Storage");
|
const storage = require("Storage");
|
||||||
const filename = 'beebjson';
|
const filename = 'beebjson';
|
||||||
|
var timeout;
|
||||||
|
|
||||||
require('FontTeletext10x18Ascii').add(Graphics);
|
require('FontTeletext10x18Ascii').add(Graphics);
|
||||||
|
|
||||||
|
|
@ -153,15 +154,21 @@ let hours, minutes, seconds, date;
|
||||||
// Schedule event for calling at the start of the next second
|
// Schedule event for calling at the start of the next second
|
||||||
const inOneSecond = (cb) => {
|
const inOneSecond = (cb) => {
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
clearTimeout();
|
if (timeout) clearTimeout(timeout);
|
||||||
setTimeout(cb, 1000 - now.getMilliseconds());
|
timeout = setTimeout(function() {
|
||||||
|
timeout = undefined;
|
||||||
|
cb();
|
||||||
|
}, 1000 - now.getMilliseconds());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Schedule event for calling at the start of the next minute
|
// Schedule event for calling at the start of the next minute
|
||||||
const inOneMinute = (cb) => {
|
const inOneMinute = (cb) => {
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
clearTimeout();
|
if (timeout) clearTimeout(timeout);
|
||||||
setTimeout(cb, 60000 - (now.getSeconds() * 1000 + now.getMilliseconds()));
|
timeout = setTimeout(function() {
|
||||||
|
timeout = undefined;
|
||||||
|
cb();
|
||||||
|
}, 60000 - (now.getSeconds() * 1000 + now.getMilliseconds()));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Draw a fat hour/minute hand
|
// Draw a fat hour/minute hand
|
||||||
|
|
@ -376,6 +383,7 @@ Bangle.on('lcdPower', (on) => {
|
||||||
if (on) {
|
if (on) {
|
||||||
drawAll();
|
drawAll();
|
||||||
} else {
|
} else {
|
||||||
clearTimeout();
|
if (timeout) clearTimeout(timeout);
|
||||||
|
timeout = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue