Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: allow to select ISO 8601 date format for display #1730

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/Display_Graphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DisplayGraphicClass {

bool enablePowerSafe = true;
bool enableScreensaver = true;
bool useIsoDate = false;

private:
void loop();
Expand Down
1 change: 1 addition & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion src/Display_Graphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/WebApi_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -158,6 +159,7 @@ void WebApiDeviceClass::onDeviceAdminPost(AsyncWebServerRequest* request)
config.Display.ScreenSaver = root["display"]["screensaver"].as<bool>();
config.Display.Contrast = root["display"]["contrast"].as<uint8_t>();
config.Display.Language = root["display"]["language"].as<uint8_t>();
config.Display.IsoDate = root["display"]["isodate"].as<bool>();
config.Display.Diagram.Duration = root["display"]["diagramduration"].as<uint32_t>();
config.Display.Diagram.Mode = root["display"]["diagrammode"].as<DiagramMode_t>();

Expand All @@ -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<DiagramMode_t>(config.Display.Diagram.Mode));
Display.Diagram().updatePeriod();

Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiagramMode_t>(config.Display.Diagram.Mode));
Display.setStartupDisplay();
MessageOutput.println("done");
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/types/DeviceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Display {
screensaver: boolean;
contrast: number;
language: number;
isodate: boolean;
diagramduration: number;
diagrammode: number;
}
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/views/DeviceAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
</div>
</div>

<InputElement :label="$t('deviceadmin.IsoDate')"
v-model="deviceConfigList.display.isodate" type="checkbox" />

<div class="row mb-3">
<label class="col-sm-2 col-form-label">
{{ $t('deviceadmin.Rotation') }}
Expand Down
Loading