From cd89d1059d584e22da64b23fc5993ae5c5682582 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Sat, 10 Feb 2024 14:44:35 +0100 Subject: [PATCH] Feature: allow to select ISO 8601 date format for display --- include/Configuration.h | 1 + include/Display_Graphic.h | 1 + include/defaults.h | 1 + src/Configuration.cpp | 2 ++ src/Display_Graphic.cpp | 5 ++++- src/WebApi_device.cpp | 3 +++ src/main.cpp | 1 + webapp/src/locales/de.json | 1 + webapp/src/locales/en.json | 1 + webapp/src/locales/fr.json | 1 + webapp/src/types/DeviceConfig.ts | 1 + webapp/src/views/DeviceAdminView.vue | 3 +++ 12 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/Configuration.h b/include/Configuration.h index 4ae77a55f..eaf1ae0c8 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -144,6 +144,7 @@ struct CONFIG_T { uint8_t Rotation; uint8_t Contrast; uint8_t Language; + bool IsoDate; struct { uint32_t Duration; uint8_t Mode; diff --git a/include/Display_Graphic.h b/include/Display_Graphic.h index e49bf9f61..61680d422 100644 --- a/include/Display_Graphic.h +++ b/include/Display_Graphic.h @@ -48,6 +48,7 @@ class DisplayGraphicClass { bool enablePowerSafe = true; bool enableScreensaver = true; + bool useIsoDate = false; private: void loop(); diff --git a/include/defaults.h b/include/defaults.h index ac871fc99..f3f72cce2 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -99,6 +99,7 @@ #define DISPLAY_ROTATION 2U #define DISPLAY_CONTRAST 60U #define DISPLAY_LANGUAGE 0U +#define DISPLAY_ISODATE false #define DISPLAY_DIAGRAM_DURATION (10UL * 60UL * 60UL) #define DISPLAY_DIAGRAM_MODE 1U diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 5181ebe4c..a82c302a9 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -110,6 +110,7 @@ bool ConfigurationClass::write() display["rotation"] = config.Display.Rotation; display["contrast"] = config.Display.Contrast; display["language"] = config.Display.Language; + display["isodate"] = config.Display.IsoDate; display["diagram_duration"] = config.Display.Diagram.Duration; display["diagram_mode"] = config.Display.Diagram.Mode; @@ -279,6 +280,7 @@ bool ConfigurationClass::read() config.Display.Rotation = display["rotation"] | DISPLAY_ROTATION; config.Display.Contrast = display["contrast"] | DISPLAY_CONTRAST; config.Display.Language = display["language"] | DISPLAY_LANGUAGE; + config.Display.IsoDate = display["isodate"] | DISPLAY_ISODATE; config.Display.Diagram.Duration = display["diagram_duration"] | DISPLAY_DIAGRAM_DURATION; config.Display.Diagram.Mode = display["diagram_mode"] | DISPLAY_DIAGRAM_MODE; diff --git a/src/Display_Graphic.cpp b/src/Display_Graphic.cpp index 12b2aa56e..667633950 100644 --- a/src/Display_Graphic.cpp +++ b/src/Display_Graphic.cpp @@ -34,6 +34,7 @@ static const char* const i18n_current_power_kw[] = { "%.1f kW", "%.1f kW", "%.1f 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" }; +static const char iso_date_format[] = { "%Y-%m-%d %H:%M" }; DisplayGraphicClass::DisplayGraphicClass() : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&DisplayGraphicClass::loop, this)) @@ -247,7 +248,9 @@ void DisplayGraphicClass::loop() } else { // Get current time time_t now = time(nullptr); - strftime(_fmtText, sizeof(_fmtText), i18n_date_format[_display_language], localtime(&now)); + auto dateTimeFormat = i18n_date_format[_display_language]; + if (useIsoDate) { dateTimeFormat = iso_date_format; } + strftime(_fmtText, sizeof(_fmtText), dateTimeFormat, localtime(&now)); printText(_fmtText, 3); } } diff --git a/src/WebApi_device.cpp b/src/WebApi_device.cpp index 5f43b37dc..423ca8f93 100644 --- a/src/WebApi_device.cpp +++ b/src/WebApi_device.cpp @@ -79,6 +79,7 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request) display["screensaver"] = config.Display.ScreenSaver; display["contrast"] = config.Display.Contrast; display["language"] = config.Display.Language; + display["isodate"] = config.Display.IsoDate; display["diagramduration"] = config.Display.Diagram.Duration; display["diagrammode"] = config.Display.Diagram.Mode; @@ -158,6 +159,7 @@ void WebApiDeviceClass::onDeviceAdminPost(AsyncWebServerRequest* request) config.Display.ScreenSaver = root["display"]["screensaver"].as(); config.Display.Contrast = root["display"]["contrast"].as(); config.Display.Language = root["display"]["language"].as(); + config.Display.IsoDate = root["display"]["isodate"].as(); config.Display.Diagram.Duration = root["display"]["diagramduration"].as(); config.Display.Diagram.Mode = root["display"]["diagrammode"].as(); @@ -171,6 +173,7 @@ void WebApiDeviceClass::onDeviceAdminPost(AsyncWebServerRequest* request) Display.enableScreensaver = config.Display.ScreenSaver; Display.setContrast(config.Display.Contrast); Display.setLanguage(config.Display.Language); + Display.useIsoDate = config.Display.IsoDate; Display.setDiagramMode(static_cast(config.Display.Diagram.Mode)); Display.Diagram().updatePeriod(); diff --git a/src/main.cpp b/src/main.cpp index c3aea787d..a1d4f3f69 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -125,6 +125,7 @@ void setup() Display.enableScreensaver = config.Display.ScreenSaver; Display.setContrast(config.Display.Contrast); Display.setLanguage(config.Display.Language); + Display.useIsoDate = config.Display.IsoDate; Display.setDiagramMode(static_cast(config.Display.Diagram.Mode)); Display.setStartupDisplay(); MessageOutput.println("done"); diff --git a/webapp/src/locales/de.json b/webapp/src/locales/de.json index 0767472a2..a4ea17d38 100644 --- a/webapp/src/locales/de.json +++ b/webapp/src/locales/de.json @@ -601,6 +601,7 @@ "rot180": "180 Grad Drehung", "rot270": "270 Grad Drehung", "DisplayLanguage": "Displaysprache:", + "IsoDate": "ISO 8601 Datumsformat:", "en": "Englisch", "de": "Deutsch", "fr": "Französisch", diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index 71ba094fb..9ebb2a522 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -601,6 +601,7 @@ "rot180": "180 degree rotation", "rot270": "270 degree rotation", "DisplayLanguage": "Display language:", + "IsoDate": "ISO 8601 date format:", "en": "English", "de": "German", "fr": "French", diff --git a/webapp/src/locales/fr.json b/webapp/src/locales/fr.json index a763e206d..b800394a9 100644 --- a/webapp/src/locales/fr.json +++ b/webapp/src/locales/fr.json @@ -601,6 +601,7 @@ "rot180": "Rotation de 180 degrés", "rot270": "Rotation de 270 degrés", "DisplayLanguage": "Langue d'affichage", + "IsoDate": "Format de date ISO 8601:", "en": "Anglais", "de": "Allemand", "fr": "Français", diff --git a/webapp/src/types/DeviceConfig.ts b/webapp/src/types/DeviceConfig.ts index 3f699e182..7e9aad945 100644 --- a/webapp/src/types/DeviceConfig.ts +++ b/webapp/src/types/DeviceConfig.ts @@ -6,6 +6,7 @@ export interface Display { screensaver: boolean; contrast: number; language: number; + isodate: boolean; diagramduration: number; diagrammode: number; } diff --git a/webapp/src/views/DeviceAdminView.vue b/webapp/src/views/DeviceAdminView.vue index c74500873..2ba63b519 100644 --- a/webapp/src/views/DeviceAdminView.vue +++ b/webapp/src/views/DeviceAdminView.vue @@ -98,6 +98,9 @@ + +