Remove display flash every interval

Add variable to remember previous value of hidx, and check to see if it has changed before we redraw the watchface
master
Bzly 2020-05-04 20:31:12 +01:00 committed by GitHub
parent 0dbbce2134
commit ab321e5e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 23 deletions

View File

@ -46,6 +46,8 @@ const passivColor = 0x3186 /*grey*/ ;
const activeColorNight = 0xF800 /*red*/ ;
const activeColorDay = 0xFFFF /* white */;
var hidxPrev;
function drawWordClock() {
@ -65,19 +67,6 @@ function drawWordClock() {
g.setColor(passivColor);
g.setFontAlign(0, -1, 0);
// draw allWords
var c;
var y = ys;
var x = xs;
allWords.forEach((line) => {
x = xs;
for (c in line) {
g.drawString(line[c], x, y);
x += dx;
}
y += dy;
});
// Switch case isn't good for this in Js apparently so...
if(h < 3){
@ -125,6 +114,21 @@ function drawWordClock() {
hidx = 10;
}
// check whether we need to redraw the watchface
if (hidx !== hidxPrev) {
// draw allWords
var c;
var y = ys;
var x = xs;
allWords.forEach((line) => {
x = xs;
for (c in line) {
g.drawString(line[c], x, y);
x += dx;
}
y += dy;
});
// write hour in active color
g.setColor(activeColor);
timeOfDay[hidx][0].split('').forEach((c, pos) => {
@ -132,16 +136,17 @@ function drawWordClock() {
y = ys + (timeOfDay[hidx][pos + 1] % 10) * dy;
g.drawString(c, x, y);
});
hidxPrev = hidx;
}
// Display digital time while button 1 is pressed
g.clearRect(0, 215, 240, 240);
if (BTN1.read()){
g.setColor(activeColor);
g.clearRect(0, 215, 240, 240);
g.drawString(time, 120, 215);
} else { g.clearRect(0, 215, 240, 240); }
}
}
Bangle.on('lcdPower', function(on) {
if (on) drawWordClock();