From d7847427454bdcb92cc1a2ccdd63a705552e7b5d Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Tue, 23 Jul 2024 22:46:51 +0200 Subject: [PATCH] Better numeric display, less flicker --- ThermoBeaconDisplay.ino | 73 +++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/ThermoBeaconDisplay.ino b/ThermoBeaconDisplay.ino index a35052e..02cfb1c 100644 --- a/ThermoBeaconDisplay.ino +++ b/ThermoBeaconDisplay.ino @@ -52,6 +52,7 @@ void dbgEntry(struct entry *entry) void dbgOp(int pos, String str1, struct entry *entry1, String str2, struct entry *entry2) { +#if 0 Serial.print("pos "); Serial.print(pos); Serial.print(" "); @@ -65,38 +66,60 @@ void dbgOp(int pos, String str1, struct entry *entry1, dbgEntry(entry2); } Serial.println(); +#endif } -void display(int pos, entry *oldval, entry *newval) -{ - if (!newval) - return; - tft.setViewport(pos * (tft.width() / 2) + 4, 4, - tft.width() / 2 - 8, tft.height() - 8); - tft.fillScreen(TFT_BLACK); +void dbgVal(int oldv, int newv, int xpos, int yf, int yt, int colour) { +#if 0 + Serial.print("oldv "); + Serial.print(oldv); + Serial.print(" newv "); + Serial.print(newv); + Serial.print(" xpos "); + Serial.print(xpos); + Serial.print(" yf "); + Serial.print(yf); + Serial.print(" yt "); + Serial.print(yt); + Serial.print(" colour "); + Serial.print(colour); + Serial.println(); +#endif +} + +void dispel(int oldv, int newv, int xpos, int yf, int yt, int colour) { + dbgVal(oldv, newv, xpos, yf, yt, colour); + if (oldv == newv) return; + tft.setViewport(xpos * (tft.width() / 2) + 10, yf + 2, + tft.width() / 2 - 12, yt - 2); tft.setCursor(0, 0, 4); - tft.setTextColor(TFT_WHITE); - tft.setTextSize(1); - tft.println(newval->addr + 3); - tft.setTextColor(TFT_RED); tft.setTextSize(2); - tft.print(newval->tmp / 10); - tft.print("."); - tft.println(newval->tmp % 10); - tft.setTextColor(TFT_BLUE); - tft.print(newval->hum / 10); - tft.print("."); - tft.println(newval->hum % 10); - // tft.setTextColor(TFT_GREEN); - // tft.setTextSize(1); - // tft.print(newval->bat / 100); - // tft.print("."); - // tft.print(newval->bat % 100); - // tft.print(" "); - // tft.println(newval->rssi); + if (oldv) { + tft.fillScreen(TFT_BLACK); +// tft.setTextColor(TFT_BLACK); +// tft.print(oldv / 10); +// tft.print("."); +// tft.print(oldv % 10); + } + if (newv) { + tft.setTextColor(colour); + tft.print(newv / 10); + tft.print("."); + tft.print(newv % 10); + } else { + tft.fillScreen(TFT_BLACK); + } tft.resetViewport(); } +#define FL(st, fl) (st ? st->fl : 0) + +void display(int pos, entry *oldval, entry *newval) +{ + dispel(FL(oldval, tmp), FL(newval, tmp), pos, 30, 50, TFT_YELLOW); + dispel(FL(oldval, hum), FL(newval, hum), pos, 80, 50, TFT_BLUE); +} + void updateCache(struct entry *newentry) { struct elem **cur_p = &head; -- 2.43.0