Skip to content

Commit

Permalink
Feature: show power grid usage on display
Browse files Browse the repository at this point in the history
if the power meter is enabled, the display will use two of three out
of every three-second time slot to show the grid consumption.

closes #620.
  • Loading branch information
schlimmchen committed Feb 10, 2024
1 parent b794f46 commit 7dfe477
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/Display_Graphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#include "Display_Graphic.h"
#include "Datastore.h"
#include "PowerMeter.h"
#include "Configuration.h"
#include <NetworkSettings.h>
#include <map>
#include <time.h>
Expand Down Expand Up @@ -31,6 +33,8 @@ 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[] = { "grid: %.0f W", "Netz: %.0f W", "reseau: %.0f W" };
static const char* const i18n_meter_power_kw[] = { "grid: %.1f kW", "Netz: %.1f kW", "reseau: %.1f kW" };
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" };
Expand Down Expand Up @@ -67,11 +71,15 @@ void DisplayGraphicClass::init(Scheduler& scheduler, const DisplayType_t type, c

void DisplayGraphicClass::calcLineHeights()
{
uint8_t yOff = 0;
uint8_t yOff = (_isLarge?2:0); // as much space as possible for diagram
for (uint8_t i = 0; i < 4; i++) {
setFont(i);
yOff += (_display->getMaxCharHeight());
yOff += _display->getAscent();
_lineOffsets[i] = yOff;
yOff += (_isLarge?3:2); // margin between lines
// the descent is a negative value and
// moves the *next* line's baseline
yOff -= _display->getDescent();
}
}

Expand Down Expand Up @@ -252,6 +260,32 @@ 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 NOT overwrite the total inverter energy.
bool timing = (_mExtra % 9) >= 3;

if (showText && Configuration.get().PowerMeter.Enabled && timing && !displayPowerSave) {
// erase the third line and print the power meter value instead.
// we do it this way to touch as least upstream code as possible
// to make maintenance easier.
setFont(2);
auto lineHeight = _display->getAscent() - _display->getDescent();
auto y = _lineOffsets[2] - _display->getAscent();
_display->setDrawColor(0);
_display->drawBox(0, y, _display->getDisplayWidth(), lineHeight);
_display->setDrawColor(1);

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);
}

printText(_fmtText, 2);
}

_display->sendBuffer();

_mExtra++;
Expand Down

0 comments on commit 7dfe477

Please sign in to comment.