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