From 8622141df8b12b9e98bdbffa0118fd7ab9fa3447 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Wed, 7 Feb 2024 23:15:40 +0100 Subject: [PATCH] Feature: show power grid usage on display if the power meter is enabled, the display will use every third of every three-second time slot to show the grid consumption. closes #620. --- src/Display_Graphic.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Display_Graphic.cpp b/src/Display_Graphic.cpp index 7f5d94c37..3d2984bfd 100644 --- a/src/Display_Graphic.cpp +++ b/src/Display_Graphic.cpp @@ -4,6 +4,8 @@ */ #include "Display_Graphic.h" #include "Datastore.h" +#include "PowerMeter.h" +#include "Configuration.h" #include #include #include @@ -30,6 +32,9 @@ const uint8_t languages[] = { static const char* const i18n_offline[] = { "Offline", "Offline", "Offline" }; static const char* const i18n_current_power_w[] = { "%.0f W", "%.0f W", "%.0f W" }; static const char* const i18n_current_power_kw[] = { "%.1f kW", "%.1f kW", "%.1f kW" }; +static const char* const i18n_meter_power_w[] = { "%.0f W", "%.0f W", "%.0f W" }; +static const char* const i18n_meter_power_kw[] = { "%.1f kW", "%.1f kW", "%.1f kW" }; +static const char* const i18n_meter_header[] = { "Grid Usage", "Netzbezug", "Util. Reseau" }; static const char* const i18n_yield_today_wh[] = { "today: %4.0f Wh", "Heute: %4.0f Wh", "auj.: %4.0f Wh" }; static const char* const i18n_yield_total_kwh[] = { "total: %.1f kWh", "Ges.: %.1f kWh", "total: %.1f kWh" }; static const char* const i18n_date_format[] = { "%m/%d/%Y %H:%M", "%d.%m.%Y %H:%M", "%d/%m/%Y %H:%M" }; @@ -248,6 +253,34 @@ void DisplayGraphicClass::loop() } } + // the IP and time info in the third line use three-second slots. the + // timing for the power meter is chosen such that every third of those + // three-second slots is used to display the grid usage. + bool timing = (_mExtra % 9) >= 6; + + if (Configuration.get().PowerMeter.Enabled && timing && !displayPowerSave) { + _display->clearBuffer(); + + auto acPower = PowerMeter.getPowerTotal(false); + if (acPower > 999) { + snprintf(_fmtText, sizeof(_fmtText), i18n_meter_power_kw[_display_language], (acPower / 1000)); + } else { + snprintf(_fmtText, sizeof(_fmtText), i18n_meter_power_w[_display_language], acPower); + } + + auto previousDiagramMode = _diagram_mode; + _diagram_mode = DiagramMode_t::Off; // force center text on line 0 + printText(_fmtText, 0); + + // hack header to appear with font for line 0 and centered, but lower + auto previousLineOffset = _lineOffsets[0]; + _lineOffsets[0] = _lineOffsets[1] + 10; + printText(i18n_meter_header[_display_language], 0); + + _diagram_mode = previousDiagramMode; + _lineOffsets[0] = previousLineOffset; + } + _display->sendBuffer(); _mExtra++;