Skip to content

Commit

Permalink
Define displayShowValues() independient to EINKBOARDGDEM0213B74 board…
Browse files Browse the repository at this point in the history
… and forceRedraw all values in partial updates
  • Loading branch information
Coscolin committed May 1, 2024
1 parent 966afc1 commit 28ab663
Showing 1 changed file with 62 additions and 7 deletions.
69 changes: 62 additions & 7 deletions CO2_Gadget_EINK.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,12 @@ void testRedrawValues(bool randomNumbers = false) {
lastTimeDrawn = millis();
}

#ifdef EINKBOARDGDEM0213B74
void displayShowValues(bool forceRedraw = false) {
static uint32_t lastDisplayUpdate = 0;
if (isDownloadingBLE) return; // Do not update display while downloading BLE data to MyAmbiance
// Return if last update less than 15 seconds ago
if (!forceRedraw && (millis() - lastDisplayUpdate < 15000)) {
if (!forceRedraw && (millis() - lastDisplayUpdate < 10000)) {
return;
}

Expand All @@ -675,15 +676,13 @@ void displayShowValues(bool forceRedraw = false) {
#endif
}

#ifdef EINKBOARDGDEM0213B74
display.firstPage();
do {
#endif
if (forceRedraw) {
display.setFullWindow();
display.fillScreen(GxEPD_WHITE);
}

forceRedraw = true; // force to print all values
// testRedrawValues(true);
showCO2(co2, elementPosition.co2X, elementPosition.co2Y, forceRedraw);
showTemperature(temp, elementPosition.tempXValue, elementPosition.tempYValue, forceRedraw);
Expand All @@ -695,15 +694,70 @@ void displayShowValues(bool forceRedraw = false) {
showEspNowIcon(elementPosition.espNowIconX, elementPosition.espNowIconY, forceRedraw);
// display.hibernate();

#ifdef EINKBOARDGDEM0213B74
} while (display.nextPage());
#else

#ifdef TIMEDEBUG
uint32_t elapsed = timer.read();
if (elapsed > 10) {
Serial.println("-->[EINK] Time used to showValues: " + String(elapsed));
}
#endif
}

#else // ALL OTHER NOT EINKBOARDGDEM0213B74 BOARDS

void displayShowValues(bool forceRedraw = false) {
static uint32_t lastDisplayUpdate = 0;
if (isDownloadingBLE) return; // Do not update display while downloading BLE data to MyAmbiance
// Return if last update less than 15 seconds ago
if (!forceRedraw && (millis() - lastDisplayUpdate < 15000)) {
return;
}

if ((!forceRedraw) && (co2 == 0)) {
return;
}

lastDisplayUpdate = millis();

#ifdef TIMEDEBUG
timer.start();
#endif

if (cyclesLeftToRedrawDisplay > 0) {
cyclesLeftToRedrawDisplay--;
#ifdef DEBUG_EINK
Serial.println("-->[EINK] Cycles left to full refresh of display: " + String(cyclesLeftToRedrawDisplay));
#endif
} else {
cyclesLeftToRedrawDisplay = redrawDisplayEveryCycles;
forceRedraw = true;
#ifdef DEBUG_EINK
Serial.println("-->[EINK] Forcing full refresh of display");
#endif
}

if (forceRedraw) {
display.setFullWindow();
display.fillScreen(GxEPD_WHITE);
}

// testRedrawValues(true);
showCO2(co2, elementPosition.co2X, elementPosition.co2Y, forceRedraw);
showTemperature(temp, elementPosition.tempXValue, elementPosition.tempYValue, forceRedraw);
showHumidity(hum, elementPosition.humidityXValue, elementPosition.humidityYValue, forceRedraw);
showBatteryIcon(elementPosition.batteryIconX, elementPosition.batteryIconY, true);
showWiFiIcon(elementPosition.wifiIconX, elementPosition.wifiIconY, forceRedraw);
showMQTTIcon(elementPosition.mqttIconX, elementPosition.mqttIconY, forceRedraw);
showBLEIcon(elementPosition.bleIconX, elementPosition.bleIconY, forceRedraw);
showEspNowIcon(elementPosition.espNowIconX, elementPosition.espNowIconY, forceRedraw);
// display.hibernate();

if (forceRedraw) {
display.display(); // Full update
} else {
display.displayWindow(0, 0, display.width(), display.height()); // Refresh screen in partial mode
}
#endif

#ifdef TIMEDEBUG
uint32_t elapsed = timer.read();
Expand All @@ -712,6 +766,7 @@ void displayShowValues(bool forceRedraw = false) {
}
#endif
}
#endif

#endif // SUPPORT_EINK
#endif // CO2_Gadget_EINK_h

0 comments on commit 28ab663

Please sign in to comment.