Skip to content

Commit

Permalink
0.8.92
Browse files Browse the repository at this point in the history
* added language to display on compile time #1484, #1255, #1479
  • Loading branch information
lumapu committed Mar 10, 2024
1 parent 19693d0 commit c1a9860
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/plugins/Display/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/Display/Display_Mono_128X32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/Display/Display_Mono_128X64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/Display/Display_Mono_64X48.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/Display/Display_Mono_84X48.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)) {
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/Display/Display_ePaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../../utils/helper.h"
#include "imagedata.h"
#include "defines.h"
#include "../plugin_lang.h"

#if defined(ESP32)

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
44 changes: 44 additions & 0 deletions src/plugins/plugin_lang.h
Original file line number Diff line number Diff line change
@@ -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__*/
31 changes: 31 additions & 0 deletions src/utils/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/utils/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c1a9860

Please sign in to comment.