Skip to content

Commit

Permalink
Merge upstream tag 'v24.11.7' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
schlimmchen committed Nov 11, 2024
2 parents 827a272 + 3dc70ab commit 4f6f0fd
Show file tree
Hide file tree
Showing 69 changed files with 2,922 additions and 706 deletions.
29 changes: 25 additions & 4 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include "PinMapping.h"
#include <cstdint>
#include <ArduinoJson.h>
#include <TaskSchedulerDeclarations.h>
#include <mutex>
#include <condition_variable>

#define CONFIG_FILENAME "/config.json"
#define CONFIG_VERSION 0x00011c00 // 0.1.28 // make sure to clean all after change
#define CONFIG_VERSION 0x00011d00 // 0.1.29 // make sure to clean all after change

#define WIFI_MAX_SSID_STRLEN 32
#define WIFI_MAX_PASSWORD_STRLEN 64
Expand All @@ -33,6 +36,7 @@
#define CHAN_MAX_NAME_STRLEN 31

#define DEV_MAX_MAPPING_NAME_STRLEN 63
#define LOCALE_STRLEN 2

#define HTTP_REQUEST_MAX_URL_STRLEN 1024
#define HTTP_REQUEST_MAX_USERNAME_STRLEN 64
Expand Down Expand Up @@ -253,7 +257,7 @@ struct CONFIG_T {
bool ScreenSaver;
uint8_t Rotation;
uint8_t Contrast;
uint8_t Language;
char Locale[LOCALE_STRLEN + 1];
struct {
uint32_t Duration;
uint8_t Mode;
Expand Down Expand Up @@ -333,11 +337,23 @@ struct CONFIG_T {

class ConfigurationClass {
public:
void init();
void init(Scheduler& scheduler);
bool read();
bool write();
void migrate();
CONFIG_T& get();
CONFIG_T const& get();

class WriteGuard {
public:
WriteGuard();
CONFIG_T& getConfig();
~WriteGuard();

private:
std::unique_lock<std::mutex> _lock;
};

WriteGuard getWriteGuard();

INVERTER_CONFIG_T* getFreeInverterSlot();
INVERTER_CONFIG_T* getInverterConfig(const uint64_t serial);
Expand All @@ -356,6 +372,11 @@ class ConfigurationClass {
static void deserializePowerMeterHttpJsonConfig(JsonObject const& source, PowerMeterHttpJsonConfig& target);
static void deserializePowerMeterHttpSmlConfig(JsonObject const& source, PowerMeterHttpSmlConfig& target);
static void deserializeBatteryConfig(JsonObject const& source, BatteryConfig& target);

private:
void loop();

Task _loopTask;
};

extern ConfigurationClass Configuration;
13 changes: 11 additions & 2 deletions include/Display_Graphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DisplayGraphicClass {
void setContrast(const uint8_t contrast);
void setStatus(const bool turnOn);
void setOrientation(const uint8_t rotation = DISPLAY_ROTATION);
void setLanguage(const uint8_t language);
void setLocale(const String& locale);
void setDiagramMode(DiagramMode_t mode);
void setStartupDisplay();

Expand All @@ -65,14 +65,23 @@ class DisplayGraphicClass {

DisplayType_t _display_type = DisplayType_t::None;
DiagramMode_t _diagram_mode = DiagramMode_t::Off;
uint8_t _display_language = DISPLAY_LANGUAGE;
String _display_language = DISPLAY_LOCALE;
uint8_t _mExtra;
const uint16_t _period = 1000;
const uint16_t _interval = 60000; // interval at which to power save (milliseconds)
uint32_t _previousMillis = 0;
char _fmtText[32];
bool _isLarge = false;
uint8_t _lineOffsets[5];

String _i18n_offline;
String _i18n_yield_today_kwh;
String _i18n_yield_today_wh;
String _i18n_date_format;
String _i18n_current_power_kw;
String _i18n_current_power_w;
String _i18n_yield_total_mwh;
String _i18n_yield_total_kwh;
};

extern DisplayGraphicClass Display;
35 changes: 35 additions & 0 deletions include/I18n.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <TaskSchedulerDeclarations.h>
#include <WString.h>
#include <list>

struct LanguageInfo_t {
String code;
String name;
String filename;
};

class I18nClass {
public:
I18nClass();
void init(Scheduler& scheduler);
std::list<LanguageInfo_t> getAvailableLanguages();
String getFilenameByLocale(const String& locale) const;
void readDisplayStrings(
const String& locale,
String& date_format,
String& offline,
String& power_w, String& power_kw,
String& yield_today_wh, String& yield_today_kwh,
String& yield_total_kwh, String& yield_total_mwh);

private:
void readLangPacks();
void readConfig(String file);

std::list<LanguageInfo_t> _availLanguages;
};

extern I18nClass I18n;
3 changes: 3 additions & 0 deletions include/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma once

#include <ArduinoJson.h>
#include <LittleFS.h>
#include <cstdint>
#include <utility>

Expand All @@ -12,6 +13,8 @@ class Utils {
static int getTimezoneOffset();
static bool checkJsonAlloc(const JsonDocument& doc, const char* function, const uint16_t line);
static void removeAllFiles();
static String generateMd5FromFile(String file);
static void skipBom(File& f);

/* OpenDTU-OnBatter-specific utils go here: */
template<typename T>
Expand Down
6 changes: 4 additions & 2 deletions include/WebApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#pragma once

#include "WebApi_battery.h"
#include "WebApi_config.h"
#include "WebApi_device.h"
#include "WebApi_devinfo.h"
#include "WebApi_dtu.h"
#include "WebApi_errors.h"
#include "WebApi_eventlog.h"
#include "WebApi_file.h"
#include "WebApi_firmware.h"
#include "WebApi_gridprofile.h"
#include "WebApi_i18n.h"
#include "WebApi_inverter.h"
#include "WebApi_limit.h"
#include "WebApi_maintenance.h"
Expand Down Expand Up @@ -55,13 +56,14 @@ class WebApiClass {
AsyncWebServer _server;

WebApiBatteryClass _webApiBattery;
WebApiConfigClass _webApiConfig;
WebApiDeviceClass _webApiDevice;
WebApiDevInfoClass _webApiDevInfo;
WebApiDtuClass _webApiDtu;
WebApiEventlogClass _webApiEventlog;
WebApiFileClass _webApiFile;
WebApiFirmwareClass _webApiFirmware;
WebApiGridProfileClass _webApiGridprofile;
WebApiI18nClass _webApiI18n;
WebApiInverterClass _webApiInverter;
WebApiLimitClass _webApiLimit;
WebApiMaintenanceClass _webApiMaintenance;
Expand Down
17 changes: 0 additions & 17 deletions include/WebApi_config.h

This file was deleted.

7 changes: 4 additions & 3 deletions include/WebApi_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ enum WebApiError {
DtuInvalidCmtFrequency,
DtuInvalidCmtCountry,

ConfigBase = 3000,
ConfigNotDeleted,
ConfigSuccess,
FileBase = 3000,
FileNotDeleted,
FileSuccess,
FileDeleteSuccess,

InverterBase = 4000,
InverterSerialZero,
Expand Down
18 changes: 18 additions & 0 deletions include/WebApi_file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <ESPAsyncWebServer.h>
#include <TaskSchedulerDeclarations.h>

class WebApiFileClass {
public:
void init(AsyncWebServer& server, Scheduler& scheduler);

private:
void onFileGet(AsyncWebServerRequest* request);
void onFileDelete(AsyncWebServerRequest* request);
void onFileDeleteAll(AsyncWebServerRequest* request);
void onFileListGet(AsyncWebServerRequest* request);
void onFileUploadFinish(AsyncWebServerRequest* request);
void onFileUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final);
};
14 changes: 14 additions & 0 deletions include/WebApi_i18n.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <ESPAsyncWebServer.h>
#include <TaskSchedulerDeclarations.h>

class WebApiI18nClass {
public:
void init(AsyncWebServer& server, Scheduler& scheduler);

private:
void onI18nLanguages(AsyncWebServerRequest* request);
void onI18nLanguage(AsyncWebServerRequest* request);
};
4 changes: 3 additions & 1 deletion include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
#define DISPLAY_SCREENSAVER true
#define DISPLAY_ROTATION 2U
#define DISPLAY_CONTRAST 60U
#define DISPLAY_LANGUAGE 0U
#define DISPLAY_LOCALE "en"
#define DISPLAY_DIAGRAM_DURATION (10UL * 60UL * 60UL)
#define DISPLAY_DIAGRAM_MODE 1U

Expand All @@ -112,6 +112,8 @@

#define MAX_INVERTER_LIMIT 2250

#define LANG_PACK_SUFFIX ".lang.json"

// values specific to downstream project OpenDTU-OnBattery start here:
#define VEDIRECT_ENABLED false
#define VEDIRECT_VERBOSE_LOGGING false
Expand Down
9 changes: 9 additions & 0 deletions lang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Language Packs

This folder contains language packs for OpenDTU which can be uploaded to the
device using the "Config Management" function.
Select "Language Pack" in the restore section, select a `.json` file containing
your language and press "Restore". Afterwards all language selection drop down
menues contain the new language.

Create a pull to request to share your own language pack (or corrections) with the community.
Loading

0 comments on commit 4f6f0fd

Please sign in to comment.