Skip to content

Commit

Permalink
Fix: Prevent hiding text on display if it's too long
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Mar 1, 2024
1 parent 9b7df71 commit 50abcd1
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Display_Graphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ 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_yield_today_wh[] = { "today: %4.0f Wh", "Heute: %4.0f Wh", "auj.: %4.0f Wh" };
static const char* const i18n_yield_today_kwh[] = { "today: %.1f kWh", "Heute: %.1f kWh", "auj.: %.1f kWh" };

static const char* const i18n_yield_total_kwh[] = { "total: %.1f kWh", "Ges.: %.1f kWh", "total: %.1f kWh" };
static const char* const i18n_yield_total_mwh[] = { "total: %.0f kWh", "Ges.: %.0f kWh", "total: %.0f kWh" };

static const char* const i18n_date_format[] = { "%m/%d/%Y %H:%M", "%d.%m.%Y %H:%M", "%d/%m/%Y %H:%M" };

DisplayGraphicClass::DisplayGraphicClass()
Expand Down Expand Up @@ -129,6 +134,10 @@ void DisplayGraphicClass::printText(const char* text, const uint8_t line)
offset -= (_isLarge ? 5 : 0); // oscillate around center on large screens
dispX += offset;
}

if (dispX > _display->getDisplayWidth()) {
dispX = 0;
}
_display->drawStr(dispX, _lineOffsets[line], text);
}

Expand Down Expand Up @@ -237,15 +246,20 @@ void DisplayGraphicClass::loop()
//<=======================

if (showText) {
//=====> Today & Total Production =======
snprintf(_fmtText, sizeof(_fmtText), i18n_yield_today_wh[_display_language], Datastore.getTotalAcYieldDayEnabled());
// Daily production
float wattsToday = Datastore.getTotalAcYieldDayEnabled();
if (wattsToday >= 10000) {
snprintf(_fmtText, sizeof(_fmtText), i18n_yield_today_kwh[_display_language], wattsToday / 1000);
} else {
snprintf(_fmtText, sizeof(_fmtText), i18n_yield_today_wh[_display_language], wattsToday);
}
printText(_fmtText, 1);

const float watts = Datastore.getTotalAcYieldTotalEnabled();
auto const format = (watts >= 1000) ? i18n_yield_total_mwh : i18n_yield_total_kwh;
snprintf(_fmtText, sizeof(_fmtText), format[_display_language], watts);
// Total production
const float wattsTotal = Datastore.getTotalAcYieldTotalEnabled();
auto const format = (wattsTotal >= 1000) ? i18n_yield_total_mwh : i18n_yield_total_kwh;
snprintf(_fmtText, sizeof(_fmtText), format[_display_language], wattsTotal);
printText(_fmtText, 2);
//<=======================

//=====> IP or Date-Time ========
// Change every 3 seconds
Expand Down

0 comments on commit 50abcd1

Please sign in to comment.