From c1a9860daa07a916b68f09bc2ef78c3f7a904382 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 10 Mar 2024 14:39:21 +0100 Subject: [PATCH] 0.8.92 * added language to display on compile time #1484, #1255, #1479 --- src/CHANGES.md | 1 + src/plugins/Display/Display.h | 1 + src/plugins/Display/Display_Mono_128X32.h | 8 ++--- src/plugins/Display/Display_Mono_128X64.h | 6 ++-- src/plugins/Display/Display_Mono_64X48.h | 4 +-- src/plugins/Display/Display_Mono_84X48.h | 9 +++-- src/plugins/Display/Display_ePaper.cpp | 11 +++--- src/plugins/plugin_lang.h | 44 +++++++++++++++++++++++ src/utils/helper.cpp | 31 ++++++++++++++++ src/utils/helper.h | 1 + 10 files changed, 97 insertions(+), 19 deletions(-) create mode 100644 src/plugins/plugin_lang.h diff --git a/src/CHANGES.md b/src/CHANGES.md index a699d696..e6e0ff70 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -3,6 +3,7 @@ ## 0.8.92 - 2024-03-10 * fix read back of limit value, now with one decimal place * added grid profile for Mexico #1493 +* added language to display on compile time #1484, #1255, #1479 ## 0.8.91 - 2024-03-05 * fix javascript issues #1480 diff --git a/src/plugins/Display/Display.h b/src/plugins/Display/Display.h index b2c88b05..e263d667 100644 --- a/src/plugins/Display/Display.h +++ b/src/plugins/Display/Display.h @@ -9,6 +9,7 @@ #include "../../hm/hmSystem.h" #include "../../hm/hmRadio.h" #include "../../utils/helper.h" +#include "../plugin_lang.h" #include "Display_Mono.h" #include "Display_Mono_128X32.h" #include "Display_Mono_128X64.h" diff --git a/src/plugins/Display/Display_Mono_128X32.h b/src/plugins/Display/Display_Mono_128X32.h index 6262e3f6..def87507 100644 --- a/src/plugins/Display/Display_Mono_128X32.h +++ b/src/plugins/Display/Display_Mono_128X32.h @@ -40,20 +40,20 @@ class DisplayMono128X32 : public DisplayMono { printText(mFmtText, 0); } else { - printText("offline", 0); + printText(STR_OFFLINE, 0); } - snprintf(mFmtText, DISP_FMT_TEXT_LEN, "today: %4.0f Wh", mDisplayData->totalYieldDay); + snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%s: %4.0f Wh", STR_TODAY, mDisplayData->totalYieldDay); printText(mFmtText, 1); - snprintf(mFmtText, DISP_FMT_TEXT_LEN, "total: %.1f kWh", mDisplayData->totalYieldTotal); + snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%s: %.1f kWh", STR_TOTAL, mDisplayData->totalYieldTotal); printText(mFmtText, 2); IPAddress ip = WiFi.localIP(); if (!(mExtra % 10) && (ip)) printText(ip.toString().c_str(), 3); else if (!(mExtra % 5)) { - snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%d Inverter on", mDisplayData->nrProducing); + snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%s: %d", STR_ACTIVE_INVERTERS, mDisplayData->nrProducing); printText(mFmtText, 3); } else if (0 != mDisplayData->utcTs) printText(ah::getTimeStr(mDisplayData->utcTs).c_str(), 3); diff --git a/src/plugins/Display/Display_Mono_128X64.h b/src/plugins/Display/Display_Mono_128X64.h index c63f0b22..c93c5c1a 100644 --- a/src/plugins/Display/Display_Mono_128X64.h +++ b/src/plugins/Display/Display_Mono_128X64.h @@ -93,7 +93,7 @@ class DisplayMono128X64 : public DisplayMono { // print Date and time if (0 != mDisplayData->utcTs) - printText(ah::getDateTimeStrShort(mDisplayData->utcTs).c_str(), l_Time, 0xff); + printText(ah::getDateTimeStrShort_i18n(mDisplayData->utcTs).c_str(), l_Time, 0xff); if (showLine(l_Status)) { // alternatively: @@ -108,7 +108,7 @@ class DisplayMono128X64 : public DisplayMono { int8_t moon_pos = -1; setLineFont(l_Status); if (0 == mDisplayData->nrSleeping + mDisplayData->nrProducing) - snprintf(mFmtText, DISP_FMT_TEXT_LEN, "no inverter"); + snprintf(mFmtText, DISP_FMT_TEXT_LEN, STR_NO_INVERTER); else if (0 == mDisplayData->nrSleeping) { snprintf(mFmtText, DISP_FMT_TEXT_LEN, " "); sun_pos = 0; @@ -145,7 +145,7 @@ class DisplayMono128X64 : public DisplayMono { printText(mFmtText, l_TotalPower, 0xff); } else { - printText("offline", l_TotalPower, 0xff); + printText(STR_OFFLINE, l_TotalPower, 0xff); } } diff --git a/src/plugins/Display/Display_Mono_64X48.h b/src/plugins/Display/Display_Mono_64X48.h index 7f98cae5..799d787e 100644 --- a/src/plugins/Display/Display_Mono_64X48.h +++ b/src/plugins/Display/Display_Mono_64X48.h @@ -42,7 +42,7 @@ class DisplayMono64X48 : public DisplayMono { printText(mFmtText, 0); } else { - printText("offline", 0); + printText(STR_OFFLINE, 0); } snprintf(mFmtText, DISP_FMT_TEXT_LEN, "D: %4.0f Wh", mDisplayData->totalYieldDay); @@ -55,7 +55,7 @@ class DisplayMono64X48 : public DisplayMono { if (!(mExtra % 10) && (ip)) printText(ip.toString().c_str(), 3); else if (!(mExtra % 5)) { - snprintf(mFmtText, DISP_FMT_TEXT_LEN, "active Inv: %d", mDisplayData->nrProducing); + snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%s: %d", STR_ACTIVE_INVERTERS, mDisplayData->nrProducing); printText(mFmtText, 3); } else if (0 != mDisplayData->utcTs) printText(ah::getTimeStr(mDisplayData->utcTs).c_str(), 3); diff --git a/src/plugins/Display/Display_Mono_84X48.h b/src/plugins/Display/Display_Mono_84X48.h index b5daacd5..ccbc8083 100644 --- a/src/plugins/Display/Display_Mono_84X48.h +++ b/src/plugins/Display/Display_Mono_84X48.h @@ -78,7 +78,7 @@ class DisplayMono84X48 : public DisplayMono { // print Date and time if (0 != mDisplayData->utcTs) - printText(ah::getDateTimeStrShort(mDisplayData->utcTs).c_str(), l_Time, 0xff); + printText(ah::getDateTimeStrShort_i18n(mDisplayData->utcTs).c_str(), l_Time, 0xff); if (showLine(l_Status)) { // alternatively: @@ -90,7 +90,7 @@ class DisplayMono84X48 : public DisplayMono { // print status of inverters else { if (0 == mDisplayData->nrSleeping + mDisplayData->nrProducing) - snprintf(mFmtText, DISP_FMT_TEXT_LEN, "no inverter"); + snprintf(mFmtText, DISP_FMT_TEXT_LEN, STR_NO_INVERTER); else if (0 == mDisplayData->nrSleeping) snprintf(mFmtText, DISP_FMT_TEXT_LEN, "\x86"); // sun symbol else if (0 == mDisplayData->nrProducing) @@ -110,9 +110,8 @@ class DisplayMono84X48 : public DisplayMono { snprintf(mFmtText, DISP_FMT_TEXT_LEN, "%.0f W", mDisplayData->totalPower); printText(mFmtText, l_TotalPower, 0xff); - } else { - printText("offline", l_TotalPower, 0xff); - } + } else + printText(STR_OFFLINE, l_TotalPower, 0xff); } if (showLine(l_YieldDay)) { diff --git a/src/plugins/Display/Display_ePaper.cpp b/src/plugins/Display/Display_ePaper.cpp index 087d784b..6d9d929e 100644 --- a/src/plugins/Display/Display_ePaper.cpp +++ b/src/plugins/Display/Display_ePaper.cpp @@ -8,6 +8,7 @@ #include "../../utils/helper.h" #include "imagedata.h" #include "defines.h" +#include "../plugin_lang.h" #if defined(ESP32) @@ -120,7 +121,7 @@ void DisplayEPaper::headlineIP() { if ((WiFi.isConnected() == true) && (WiFi.localIP() > 0)) { snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, "%s", WiFi.localIP().toString().c_str()); } else { - snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, "WiFi not connected"); + snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, STR_NO_WIFI); } _display->getTextBounds(_fmtText, 0, 0, &tbx, &tby, &tbw, &tbh); uint16_t x = ((_display->width() - tbw) / 2) - tbx; @@ -162,7 +163,7 @@ void DisplayEPaper::versionFooter() { _display->setPartialWindow(0, _display->height() - mHeadFootPadding, _display->width(), mHeadFootPadding); _display->fillScreen(GxEPD_BLACK); do { - snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, "Version: %s", _version); + snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, "%s: %s", STR_VERSION, _version); _display->getTextBounds(_fmtText, 0, 0, &tbx, &tby, &tbw, &tbh); uint16_t x = ((_display->width() - tbw) / 2) - tbx; @@ -183,7 +184,7 @@ void DisplayEPaper::offlineFooter() { _display->fillScreen(GxEPD_BLACK); do { if (NULL != mUtcTs) { - snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, "offline"); + snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, STR_OFFLINE); _display->getTextBounds(_fmtText, 0, 0, &tbx, &tby, &tbw, &tbh); uint16_t x = ((_display->width() - tbw) / 2) - tbx; @@ -213,7 +214,7 @@ void DisplayEPaper::actualPowerPaged(float totalPower, float totalYieldDay, floa snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, "%.0f W", totalPower); _changed = true; } else - snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, "offline"); + snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, STR_OFFLINE); if ((totalPower == 0) && (mEnPowerSave)) { _display->fillRect(0, mHeadFootPadding, 200, 200, GxEPD_BLACK); @@ -268,7 +269,7 @@ void DisplayEPaper::actualPowerPaged(float totalPower, float totalYieldDay, floa // Inverter online _display->setFont(&FreeSans12pt7b); y = _display->height() - (mHeadFootPadding + 10); - snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, " %d online", isprod); + snprintf(_fmtText, EPAPER_MAX_TEXT_LEN, " %d %s", isprod, STR_ONLINE); _display->getTextBounds(_fmtText, 0, 0, &tbx, &tby, &tbw, &tbh); _display->drawInvertedBitmap(10, y - tbh, myWR, 20, 20, GxEPD_BLACK); x = ((_display->width() - tbw - 20) / 2) - tbx; diff --git a/src/plugins/plugin_lang.h b/src/plugins/plugin_lang.h new file mode 100644 index 00000000..035f2afc --- /dev/null +++ b/src/plugins/plugin_lang.h @@ -0,0 +1,44 @@ +//----------------------------------------------------------------------------- +// 2024 Ahoy, https://ahoydtu.de +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed +//----------------------------------------------------------------------------- + +#ifndef __PLUGIN_LANG_H__ +#define __PLUGIN_LANG_H__ + +#ifdef LANG_DE + #define STR_MONTHNAME_3_CHAR_LIST "ErrJanFebMrzAprMaiJunJulAugSepOktNovDez" + #define STR_DAYNAME_3_CHAR_LIST "ErrSonMonDieMitDonFreSam" + #define STR_OFFLINE "aus" + #define STR_ONLINE "aktiv" + #define STR_NO_INVERTER "kein inverter" + #define STR_NO_WIFI "WLAN nicht verbunden" + #define STR_VERSION "Version" + #define STR_ACTIVE_INVERTERS "aktive WR" + #define STR_TODAY "heute" + #define STR_TODAY "Gesamt" +#elif LANG_FR + #define STR_MONTHNAME_3_CHAR_LIST "ErrJanFevMarAvrMaiJunJulAouSepOctNovDec" + #define STR_DAYNAME_3_CHAR_LIST "ErrDimLunMarMerJeuVenSam" + #define STR_OFFLINE "eteint" + #define STR_ONLINE "online" + #define STR_NO_INVERTER "pas d'onduleur" + #define STR_NO_WIFI "WiFi not connected" + #define STR_VERSION "Version" + #define STR_ACTIVE_INVERTERS "active Inv" + #define STR_TODAY "today" + #define STR_TODAY "total" +#else + #define STR_MONTHNAME_3_CHAR_LIST "ErrJanFebMarAprMayJunJulAugSepOctNovDec" + #define STR_DAYNAME_3_CHAR_LIST "ErrSunMonTueWedThuFriSat" + #define STR_OFFLINE "offline" + #define STR_ONLINE "online" + #define STR_NO_INVERTER "no inverter" + #define STR_NO_WIFI "WiFi not connected" + #define STR_VERSION "Version" + #define STR_ACTIVE_INVERTERS "active Inv" + #define STR_TODAY "today" + #define STR_TODAY "total" +#endif + +#endif /*__PLUGIN_LANG_H__*/ diff --git a/src/utils/helper.cpp b/src/utils/helper.cpp index c49e6159..edb9b9b9 100644 --- a/src/utils/helper.cpp +++ b/src/utils/helper.cpp @@ -5,6 +5,12 @@ #include "helper.h" #include "dbg.h" +#include "../plugins/plugin_lang.h" + +#define dt_SHORT_STR_LEN_i18n 3 // the length of short strings +static char buffer_i18n[dt_SHORT_STR_LEN_i18n + 1]; // must be big enough for longest string and the terminating null +const char monthShortNames_P[] PROGMEM = STR_MONTHNAME_3_CHAR_LIST; +const char dayShortNames_P[] PROGMEM = STR_DAYNAME_3_CHAR_LIST; namespace ah { void ip2Arr(uint8_t ip[], const char *ipStr) { @@ -86,6 +92,31 @@ namespace ah { return String(str); } + static char* monthShortStr_i18n(uint8_t month) { + for (int i=0; i < dt_SHORT_STR_LEN_i18n; i++) + buffer_i18n[i] = pgm_read_byte(&(monthShortNames_P[i + month * dt_SHORT_STR_LEN_i18n])); + buffer_i18n[dt_SHORT_STR_LEN_i18n] = 0; + return buffer_i18n; + } + + static char* dayShortStr_i18n(uint8_t day) { + for (int i=0; i < dt_SHORT_STR_LEN_i18n; i++) + buffer_i18n[i] = pgm_read_byte(&(dayShortNames_P[i + day * dt_SHORT_STR_LEN_i18n])); + buffer_i18n[dt_SHORT_STR_LEN_i18n] = 0; + return buffer_i18n; + } + + String getDateTimeStrShort_i18n(time_t t) { + char str[20]; + if(0 == t) + sprintf(str, "n/a"); + else { + sprintf(str, "%3s ", dayShortStr_i18n(dayOfWeek(t))); + sprintf(str+4, "%2d.%3s %02d:%02d", day(t), monthShortStr_i18n(month(t)), hour(t), minute(t)); + } + return String(str); + } + uint64_t Serial2u64(const char *val) { char tmp[3]; uint64_t ret = 0ULL; diff --git a/src/utils/helper.h b/src/utils/helper.h index 5683cdfa..ff1a9aed 100644 --- a/src/utils/helper.h +++ b/src/utils/helper.h @@ -43,6 +43,7 @@ namespace ah { double round3(double value); String getDateTimeStr(time_t t); String getDateTimeStrShort(time_t t); + String getDateTimeStrShort_i18n(time_t t); String getDateTimeStrFile(time_t t); String getTimeStr(time_t t); String getTimeStrMs(uint64_t t);