From 5452a827817b1b9a03edd17a3a77974583e9c534 Mon Sep 17 00:00:00 2001 From: Benoit Leforestier Date: Sat, 14 Dec 2024 11:56:48 +0100 Subject: [PATCH] Merge with v24.11.7 --- include/Display_Graphic.h | 4 ++++ include/I18n.h | 4 +++- src/Display_Graphic.cpp | 48 +++++++++++++++++++++++---------------- src/I18n.cpp | 20 +++++++++++++++- src/MqttHandleHass.cpp | 2 +- src/main.cpp | 13 ----------- 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/include/Display_Graphic.h b/include/Display_Graphic.h index 2f3287ca..81fcba3b 100644 --- a/include/Display_Graphic.h +++ b/include/Display_Graphic.h @@ -82,6 +82,10 @@ private: String _i18n_current_power_w; String _i18n_yield_total_mwh; String _i18n_yield_total_kwh; + String _i18n_powermeter_power_w; + String _i18n_powermeter_power_kw; + String _i18n_pm_positive_today_kwh; + String _i18n_pm_negative_today_kwh; }; extern DisplayGraphicClass Display; diff --git a/include/I18n.h b/include/I18n.h index 7187184d..4c9f488e 100644 --- a/include/I18n.h +++ b/include/I18n.h @@ -23,7 +23,9 @@ public: String& offline, String& power_w, String& power_kw, String& yield_today_wh, String& yield_today_kwh, - String& yield_total_kwh, String& yield_total_mwh); + String& yield_total_kwh, String& yield_total_mwh, + String& yield_powermeter_power_w, String& yield_powermeter_power_kw, + String& yield_pm_positive_today_kwh, String& yield_pm_negative_today_kwh); private: void readLangPacks(); diff --git a/src/Display_Graphic.cpp b/src/Display_Graphic.cpp index b06dc662..df433412 100644 --- a/src/Display_Graphic.cpp +++ b/src/Display_Graphic.cpp @@ -4,8 +4,8 @@ */ #include "Display_Graphic.h" #include "Datastore.h" -#include "JsyMk.h" #include "I18n.h" +#include "JsyMk.h" #include #include #include @@ -185,6 +185,10 @@ void DisplayGraphicClass::setLocale(const String& locale) _i18n_yield_today_kwh = i18n_yield_today_kwh[idx]; _i18n_yield_total_kwh = i18n_yield_total_kwh[idx]; _i18n_yield_total_mwh = i18n_yield_total_mwh[idx]; + _i18n_powermeter_power_w = i18n_powermeter_power_w[idx]; + _i18n_powermeter_power_kw = i18n_powermeter_power_kw[idx]; + _i18n_pm_positive_today_kwh = i18n_pm_positive_today_kwh[idx]; + _i18n_pm_negative_today_kwh = i18n_pm_negative_today_kwh[idx]; I18n.readDisplayStrings(locale, _i18n_date_format, @@ -194,7 +198,11 @@ void DisplayGraphicClass::setLocale(const String& locale) _i18n_yield_today_wh, _i18n_yield_today_kwh, _i18n_yield_total_kwh, - _i18n_yield_total_mwh); + _i18n_yield_total_mwh, + _i18n_powermeter_power_w, + _i18n_powermeter_power_kw, + _i18n_pm_positive_today_kwh, + _i18n_pm_negative_today_kwh); } void DisplayGraphicClass::setDiagramMode(DiagramMode_t mode) @@ -235,9 +243,11 @@ void DisplayGraphicClass::loop() const char direction = (JsyMk.getFieldValue(0, JsyMkClass::Field_t::NEGATIVE) > 0) ? 'O' : 'I'; if (watts > 999) { - snprintf(_fmtText, sizeof(_fmtText), i18n_powermeter_power_kw[_display_language], direction, watts / 1000); + // snprintf(_fmtText, sizeof(_fmtText), i18n_powermeter_power_kw[_display_language], direction, watts / 1000); + snprintf(_fmtText, sizeof(_fmtText), _i18n_powermeter_power_kw.c_str(), direction, watts / 1000); } else { - snprintf(_fmtText, sizeof(_fmtText), i18n_powermeter_power_w[_display_language], direction, watts); + // snprintf(_fmtText, sizeof(_fmtText), i18n_powermeter_power_w[_display_language], direction, watts); + snprintf(_fmtText, sizeof(_fmtText), _i18n_powermeter_power_w.c_str(), direction, watts); } printText(_fmtText, 0); } @@ -288,28 +298,28 @@ void DisplayGraphicClass::loop() if (displayPowerMeter) { // Daily Input float wattsInput = JsyMk.getFieldValue(0, JsyMkClass::Field_t::TODAY_POSITIVE_ENERGY); - snprintf(_fmtText, sizeof(_fmtText), i18n_pm_positive_today_kwh[_display_language], wattsInput); + snprintf(_fmtText, sizeof(_fmtText), _i18n_pm_positive_today_kwh.c_str(), wattsInput); printText(_fmtText, 1); // Daily Output float wattsOutput = JsyMk.getFieldValue(0, JsyMkClass::Field_t::TODAY_NEGATIVE_ENERGY); - snprintf(_fmtText, sizeof(_fmtText), i18n_pm_negative_today_kwh[_display_language], wattsOutput); + snprintf(_fmtText, sizeof(_fmtText), _i18n_pm_negative_today_kwh.c_str(), wattsOutput); printText(_fmtText, 2); } else { - // Daily production - float wattsToday = Datastore.getTotalAcYieldDayEnabled(); - if (wattsToday >= 10000) { - snprintf(_fmtText, sizeof(_fmtText), _i18n_yield_today_kwh.c_str(), wattsToday / 1000); - } else { - snprintf(_fmtText, sizeof(_fmtText), _i18n_yield_today_wh.c_str(), wattsToday); - } - printText(_fmtText, 1); + // Daily production + float wattsToday = Datastore.getTotalAcYieldDayEnabled(); + if (wattsToday >= 10000) { + snprintf(_fmtText, sizeof(_fmtText), _i18n_yield_today_kwh.c_str(), wattsToday / 1000); + } else { + snprintf(_fmtText, sizeof(_fmtText), _i18n_yield_today_wh.c_str(), wattsToday); + } + printText(_fmtText, 1); - // 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.c_str(), wattsTotal); - printText(_fmtText, 2); + // 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.c_str(), wattsTotal); + printText(_fmtText, 2); } //=====> IP or Date-Time ======== diff --git a/src/I18n.cpp b/src/I18n.cpp index 60bbf423..147cfbc3 100644 --- a/src/I18n.cpp +++ b/src/I18n.cpp @@ -44,7 +44,9 @@ void I18nClass::readDisplayStrings( String& offline, String& power_w, String& power_kw, String& yield_today_wh, String& yield_today_kwh, - String& yield_total_kwh, String& yield_total_mwh) + String& yield_total_kwh, String& yield_total_mwh, + String& yield_powermeter_power_w, String& yield_powermeter_power_kw, + String& yield_pm_positive_today_kwh, String& yield_pm_negative_today_kwh) { auto filename = getFilenameByLocale(locale); if (filename == "") { @@ -104,6 +106,22 @@ void I18nClass::readDisplayStrings( yield_total_mwh = displayData["yield_total_mwh"].as(); } + if (displayData["yield_powermeter_power_w"].as() != "null") { + yield_powermeter_power_w = displayData["yield_powermeter_power_w"].as(); + } + + if (displayData["yield_powermeter_power_kw"].as() != "null") { + yield_powermeter_power_kw = displayData["yield_powermeter_power_kw"].as(); + } + + if (displayData["yield_pm_positive_today_kwh"].as() != "null") { + yield_pm_positive_today_kwh = displayData["yield_pm_positive_today_kwh"].as(); + } + + if (displayData["yield_pm_negative_today_kwh"].as() != "null") { + yield_pm_negative_today_kwh = displayData["yield_pm_negative_today_kwh"].as(); + } + f.close(); } diff --git a/src/MqttHandleHass.cpp b/src/MqttHandleHass.cpp index 782372ef..93080878 100644 --- a/src/MqttHandleHass.cpp +++ b/src/MqttHandleHass.cpp @@ -304,7 +304,7 @@ void MqttHandleHassClass::publishPowerMeterField(size_t channel, JsyMkClass::Fie serializeJson(root, buffer); publish(configTopic, buffer); } else { - publish(configTopic, {}); + publish(configTopic, String {}); } } diff --git a/src/main.cpp b/src/main.cpp index d6f582a2..7b09e7a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -157,19 +157,6 @@ void setup() JsyMk.init(scheduler); MessageOutput.println("done"); - // Check for default DTU serial - MessageOutput.print("Check for default DTU serial... "); - if (config.Dtu.Serial == DTU_SERIAL) { - MessageOutput.print("generate serial based on ESP chip id: "); - const uint64_t dtuId = Utils::generateDtuSerial(); - MessageOutput.printf("%0x%08x... ", - ((uint32_t)((dtuId >> 32) & 0xFFFFFFFF)), - ((uint32_t)(dtuId & 0xFFFFFFFF))); - config.Dtu.Serial = dtuId; - Configuration.write(); - } - MessageOutput.println("done"); - InverterSettings.init(scheduler); Datastore.init(scheduler);