Skip to content

Commit

Permalink
fix(action): sort tags in chronological order
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed May 24, 2023
2 parents 9f511fb + 889e191 commit a3e7439
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 24 deletions.
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ struct CONFIG_T {
bool Display_ScreenSaver;
uint8_t Display_Rotation;
uint8_t Display_Contrast;
uint8_t Display_Language;
};

class ConfigurationClass {
Expand Down
2 changes: 2 additions & 0 deletions include/Display_Graphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DisplayGraphicClass {
void loop();
void setContrast(uint8_t contrast);
void setOrientation(uint8_t rotation = DISPLAY_ROTATION);
void setLanguage(uint8_t language);
void setStartupDisplay();

bool enablePowerSafe = true;
Expand All @@ -33,6 +34,7 @@ class DisplayGraphicClass {
U8G2* _display;

DisplayType_t _display_type = DisplayType_t::None;
uint8_t _display_language = DISPLAY_LANGUAGE;
uint8_t _mExtra;
uint16_t _period = 1000;
uint16_t _interval = 60000; // interval at which to power save (milliseconds)
Expand Down
1 change: 1 addition & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
#define DISPLAY_SCREENSAVER true
#define DISPLAY_ROTATION 2
#define DISPLAY_CONTRAST 60
#define DISPLAY_LANGUAGE 0

#define VEDIRECT_ENABLED false
#define VEDIRECT_UPDATESONLY true
Expand Down
32 changes: 19 additions & 13 deletions lib/Hoymiles/src/inverters/InverterAbstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "crc.h"
#include <cstring>

InverterAbstract::InverterAbstract(HoymilesRadio *radio, uint64_t serial)
InverterAbstract::InverterAbstract(HoymilesRadio* radio, uint64_t serial)
{
_serial.u64 = serial;
_radio = radio;
Expand Down Expand Up @@ -152,26 +152,32 @@ void InverterAbstract::addRxFragment(uint8_t fragment[], uint8_t len)
}

uint8_t fragmentCount = fragment[9];
if (fragmentCount == 0) {
Hoymiles.getMessageOutput()->println("ERROR: fragment number zero received and ignored");

// Packets with 0x81 will be seen as 1
uint8_t fragmentId = fragmentCount & 0b01111111; // fragmentId is 1 based

if (fragmentId == 0) {
Hoymiles.getMessageOutput()->println("ERROR: fragment id zero received and ignored");
return;
}

if (fragmentId >= MAX_RF_FRAGMENT_COUNT) {
Hoymiles.getMessageOutput()->printf("ERROR: fragment id %d is too large for buffer and ignored\r\n", fragmentId);
return;
}

if ((fragmentCount & 0b01111111) < MAX_RF_FRAGMENT_COUNT) {
// Packets with 0x81 will be seen as 1
memcpy(_rxFragmentBuffer[(fragmentCount & 0b01111111) - 1].fragment, &fragment[10], len - 11);
_rxFragmentBuffer[(fragmentCount & 0b01111111) - 1].len = len - 11;
_rxFragmentBuffer[(fragmentCount & 0b01111111) - 1].mainCmd = fragment[0];
_rxFragmentBuffer[(fragmentCount & 0b01111111) - 1].wasReceived = true;
memcpy(_rxFragmentBuffer[fragmentId - 1].fragment, &fragment[10], len - 11);
_rxFragmentBuffer[fragmentId - 1].len = len - 11;
_rxFragmentBuffer[fragmentId - 1].mainCmd = fragment[0];
_rxFragmentBuffer[fragmentId - 1].wasReceived = true;

if ((fragmentCount & 0b01111111) > _rxFragmentLastPacketId) {
_rxFragmentLastPacketId = fragmentCount & 0b01111111;
}
if (fragmentId > _rxFragmentLastPacketId) {
_rxFragmentLastPacketId = fragmentId;
}

// 0b10000000 == 0x80
if ((fragmentCount & 0b10000000) == 0b10000000) {
_rxFragmentMaxPacketId = fragmentCount & 0b01111111;
_rxFragmentMaxPacketId = fragmentId;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ bool ConfigurationClass::write()
display["screensaver"] = config.Display_ScreenSaver;
display["rotation"] = config.Display_Rotation;
display["contrast"] = config.Display_Contrast;
display["language"] = config.Display_Language;

JsonArray inverters = doc.createNestedArray("inverters");
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
Expand Down Expand Up @@ -289,6 +290,7 @@ bool ConfigurationClass::read()
config.Display_ScreenSaver = display["screensaver"] | DISPLAY_SCREENSAVER;
config.Display_Rotation = display["rotation"] | DISPLAY_ROTATION;
config.Display_Contrast = display["contrast"] | DISPLAY_CONTRAST;
config.Display_Language = display["language"] | DISPLAY_LANGUAGE;

JsonArray inverters = doc["inverters"];
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
Expand Down
36 changes: 30 additions & 6 deletions src/Display_Graphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ std::map<DisplayType_t, std::function<U8G2*(uint8_t, uint8_t, uint8_t, uint8_t)>
{ DisplayType_t::SH1106, [](uint8_t reset, uint8_t clock, uint8_t data, uint8_t cs) { return new U8G2_SH1106_128X64_NONAME_F_HW_I2C(U8G2_R0, reset, clock, data); } },
};

// Language defintion, respect order in languages[] and translation lists
#define I18N_LOCALE_EN 0
#define I18N_LOCALE_DE 1
#define I18N_LOCALE_FR 2

// Languages supported. Note: the order is important and must match locale_translations.h
const uint8_t languages[] = {
I18N_LOCALE_EN,
I18N_LOCALE_DE,
I18N_LOCALE_FR
};

static const char* const i18n_offline[] = { "Offline", "Offline", "Offline" };
static const char* const i18n_current_power_w[] = { "%3.0f W", "%3.0f W", "%3.0f W" };
static const char* const i18n_current_power_kw[] = { "%2.1f kW", "%2.1f kW", "%2.1f kW" };
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" };

DisplayGraphicClass::DisplayGraphicClass()
{
}
Expand Down Expand Up @@ -95,6 +114,11 @@ void DisplayGraphicClass::setOrientation(uint8_t rotation)
calcLineHeights();
}

void DisplayGraphicClass::setLanguage(uint8_t language)
{
_display_language = language < sizeof(languages) / sizeof(languages[0]) ? language : DISPLAY_LANGUAGE;
}

void DisplayGraphicClass::setStartupDisplay()
{
if (_display_type == DisplayType_t::None) {
Expand All @@ -120,9 +144,9 @@ void DisplayGraphicClass::loop()
if (Datastore.isAtLeastOneReachable) {
_display->setPowerSave(false);
if (Datastore.totalAcPowerEnabled > 999) {
snprintf(_fmtText, sizeof(_fmtText), "%2.1f kW", (Datastore.totalAcPowerEnabled / 1000));
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_kw[_display_language], (Datastore.totalAcPowerEnabled / 1000));
} else {
snprintf(_fmtText, sizeof(_fmtText), "%3.0f W", Datastore.totalAcPowerEnabled);
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_w[_display_language], Datastore.totalAcPowerEnabled);
}
printText(_fmtText, 0);
_previousMillis = millis();
Expand All @@ -131,7 +155,7 @@ void DisplayGraphicClass::loop()

//=====> Offline ===========
else {
printText("offline", 0);
printText(i18n_offline[_display_language], 0);
// check if it's time to enter power saving mode
if (millis() - _previousMillis >= (_interval * 2)) {
_display->setPowerSave(enablePowerSafe);
Expand All @@ -140,10 +164,10 @@ void DisplayGraphicClass::loop()
//<=======================

//=====> Today & Total Production =======
snprintf(_fmtText, sizeof(_fmtText), "today: %4.0f Wh", Datastore.totalAcYieldDayEnabled);
snprintf(_fmtText, sizeof(_fmtText), i18n_yield_today_wh[_display_language], Datastore.totalAcYieldDayEnabled);
printText(_fmtText, 1);

snprintf(_fmtText, sizeof(_fmtText), "total: %.1f kWh", Datastore.totalAcYieldTotalEnabled);
snprintf(_fmtText, sizeof(_fmtText), i18n_yield_total_kwh[_display_language], Datastore.totalAcYieldTotalEnabled);
printText(_fmtText, 2);
//<=======================

Expand All @@ -153,7 +177,7 @@ void DisplayGraphicClass::loop()
} else {
// Get current time
time_t now = time(nullptr);
strftime(_fmtText, sizeof(_fmtText), "%a %d.%m.%Y %H:%M", localtime(&now));
strftime(_fmtText, sizeof(_fmtText), i18n_date_format[_display_language], localtime(&now));
printText(_fmtText, 3);
}
_display->sendBuffer();
Expand Down
3 changes: 3 additions & 0 deletions src/WebApi_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request)
display["power_safe"] = config.Display_PowerSafe;
display["screensaver"] = config.Display_ScreenSaver;
display["contrast"] = config.Display_Contrast;
display["language"] = config.Display_Language;

JsonObject victronPinObj = curPin.createNestedObject("victron");
victronPinObj[F("rx")] = pin.victron_rx;
Expand Down Expand Up @@ -165,11 +166,13 @@ void WebApiDeviceClass::onDeviceAdminPost(AsyncWebServerRequest* request)
config.Display_PowerSafe = root["display"]["power_safe"].as<bool>();
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>();

Display.setOrientation(config.Display_Rotation);
Display.enablePowerSafe = config.Display_PowerSafe;
Display.enableScreensaver = config.Display_ScreenSaver;
Display.setContrast(config.Display_Contrast);
Display.setLanguage(config.Display_Language);

Configuration.write();

Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void setup()
Display.enablePowerSafe = config.Display_PowerSafe;
Display.enableScreensaver = config.Display_ScreenSaver;
Display.setContrast(config.Display_Contrast);
Display.setLanguage(config.Display_Language);
Display.setStartupDisplay();
MessageOutput.println("done");

Expand Down
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"eslint-plugin-vue": "^9.14.0",
"npm-run-all": "^4.1.5",
"sass": "^1.62.1",
"terser": "^5.17.5",
"terser": "^5.17.6",
"typescript": "^5.0.4",
"vite": "^4.3.8",
"vite-plugin-compression": "^0.5.1",
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@
"Rotation": "Rotation:",
"rot0": "Keine Rotation",
"rot90": "90 Grad Drehung",
"DisplayLanguage": "Displaysprache:",
"en": "Englisch",
"de": "Deutsch",
"fr": "Französisch",
"rot180": "180 Grad Drehung",
"rot270": "270 Grad Drehung",
"Save": "@:dtuadmin.Save"
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@
"rot90": "90 degree rotation",
"rot180": "180 degree rotation",
"rot270": "270 degree rotation",
"DisplayLanguage": "Display language:",
"en": "English",
"de": "German",
"fr": "French",
"Save": "@:dtuadmin.Save"
},
"pininfo": {
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@
"rot90": "90 degree rotation",
"rot180": "180 degree rotation",
"rot270": "270 degree rotation",
"DisplayLanguage": "Langue d'affichage",
"en": "Anglais",
"de": "Allemand",
"fr": "Français",
"Save": "@:dtuadmin.Save"
},
"pininfo": {
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 @@ -5,6 +5,7 @@ export interface Display {
power_safe: boolean;
screensaver: boolean;
contrast: number;
language: number;
}

export interface DeviceConfig {
Expand Down
18 changes: 18 additions & 0 deletions webapp/src/views/DeviceAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
v-model="deviceConfigList.display.screensaver" type="checkbox"
:tooltip="$t('deviceadmin.ScreensaverHint')" />

<div class="row mb-3">
<label class="col-sm-2 col-form-label">
{{ $t('deviceadmin.DisplayLanguage') }}
</label>
<div class="col-sm-10">
<select class="form-select" v-model="deviceConfigList.display.language">
<option v-for="language in displayLanguageList" :key="language.key" :value="language.key">
{{ $t(`deviceadmin.` + language.value) }}
</option>
</select>
</div>
</div>

<div class="row mb-3">
<label class="col-sm-2 col-form-label">
{{ $t('deviceadmin.Rotation') }}
Expand Down Expand Up @@ -123,6 +136,11 @@ export default defineComponent({
{ key: 2, value: 'rot180' },
{ key: 3, value: 'rot270' },
],
displayLanguageList: [
{ key: 0, value: "en" },
{ key: 1, value: "de" },
{ key: 2, value: "fr" },
],
}
},
created() {
Expand Down
8 changes: 4 additions & 4 deletions webapp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2383,10 +2383,10 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

terser@^5.17.5:
version "5.17.5"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.17.5.tgz#557141b662b5978ac3d6a2f3d6455a26267ddcd4"
integrity sha512-NqFkzBX34WExkCbk3K5urmNCpEWqMPZnwGI1pMHwqvJ/zDlXC75u3NI7BrzoR8/pryy8Abx2e1i8ChrWkhH1Hg==
terser@^5.17.6:
version "5.17.6"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.17.6.tgz#d810e75e1bb3350c799cd90ebefe19c9412c12de"
integrity sha512-V8QHcs8YuyLkLHsJO5ucyff1ykrLVsR4dNnS//L5Y3NiSXpbK1J+WMVUs67eI0KTxs9JtHhgEQpXQVHlHI92DQ==
dependencies:
"@jridgewell/source-map" "^0.3.2"
acorn "^8.5.0"
Expand Down
Binary file modified webapp_dist/js/app.js.gz
Binary file not shown.

0 comments on commit a3e7439

Please sign in to comment.