From 40820c07f2b9717518c00fea10be0383f268c584 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Sun, 21 May 2023 22:40:32 +0200 Subject: [PATCH] Use the new data store in the graphic display class. With this patch, the display turns off if no inverter is reachable anymore. Previously it turned off if the production was zero. This fixes #933 --- src/Display_Graphic.cpp | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/src/Display_Graphic.cpp b/src/Display_Graphic.cpp index eac532c..765ee95 100644 --- a/src/Display_Graphic.cpp +++ b/src/Display_Graphic.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "Display_Graphic.h" -#include +#include "Datastore.h" #include #include #include @@ -113,38 +113,16 @@ void DisplayGraphicClass::loop() } if ((millis() - _lastDisplayUpdate) > _period) { - float totalPower = 0; - float totalYieldDay = 0; - float totalYieldTotal = 0; - - uint8_t isprod = 0; - - for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) { - auto inv = Hoymiles.getInverterByPos(i); - if (inv == nullptr) { - continue; - } - - if (inv->isProducing()) { - isprod++; - } - - for (auto& c : inv->Statistics()->getChannelsByType(TYPE_AC)) { - totalPower += inv->Statistics()->getChannelFieldValue(TYPE_AC, c, FLD_PAC); - totalYieldDay += inv->Statistics()->getChannelFieldValue(TYPE_AC, c, FLD_YD); - totalYieldTotal += inv->Statistics()->getChannelFieldValue(TYPE_AC, c, FLD_YT); - } - } _display->clearBuffer(); //=====> Actual Production ========== - if ((totalPower > 0) && (isprod > 0)) { + if (Datastore.isAtLeastOneReachable) { _display->setPowerSave(false); - if (totalPower > 999) { - snprintf(_fmtText, sizeof(_fmtText), "%2.1f kW", (totalPower / 1000)); + if (Datastore.totalAcPowerEnabled > 999) { + snprintf(_fmtText, sizeof(_fmtText), "%2.1f kW", (Datastore.totalAcPowerEnabled / 1000)); } else { - snprintf(_fmtText, sizeof(_fmtText), "%3.0f W", totalPower); + snprintf(_fmtText, sizeof(_fmtText), "%3.0f W", Datastore.totalAcPowerEnabled); } printText(_fmtText, 0); _previousMillis = millis(); @@ -162,10 +140,10 @@ void DisplayGraphicClass::loop() //<======================= //=====> Today & Total Production ======= - snprintf(_fmtText, sizeof(_fmtText), "today: %4.0f Wh", totalYieldDay); + snprintf(_fmtText, sizeof(_fmtText), "today: %4.0f Wh", Datastore.totalAcYieldDayEnabled); printText(_fmtText, 1); - snprintf(_fmtText, sizeof(_fmtText), "total: %.1f kWh", totalYieldTotal); + snprintf(_fmtText, sizeof(_fmtText), "total: %.1f kWh", Datastore.totalAcYieldTotalEnabled); printText(_fmtText, 2); //<=======================