Skip to content

Commit

Permalink
Merge branch 'tbnobody:master' into AlarmMessageType
Browse files Browse the repository at this point in the history
  • Loading branch information
mattreim authored Feb 17, 2025
2 parents d07f91c + a07a027 commit 03a8cd9
Show file tree
Hide file tree
Showing 146 changed files with 7,288 additions and 3,678 deletions.
2 changes: 1 addition & 1 deletion docs/UpgradePartition.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Upgrade Partition

This documentation will has been moved and can be found here: <https://tbnobody.github.io/OpenDTU-docs/firmware/howto/upgrade_partition/>
This documentation has been moved and can be found here: <https://tbnobody.github.io/OpenDTU-docs/firmware/howto/upgrade_partition/>
29 changes: 25 additions & 4 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

#include "PinMapping.h"
#include <cstdint>
#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 @@ -30,6 +33,7 @@
#define CHAN_MAX_NAME_STRLEN 31

#define DEV_MAX_MAPPING_NAME_STRLEN 63
#define LOCALE_STRLEN 2

struct CHANNEL_CONFIG_T {
uint16_t MaxChannelPower;
Expand Down Expand Up @@ -144,7 +148,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 All @@ -161,15 +165,32 @@ 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);
void deleteInverterById(const uint8_t id);

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;
2 changes: 1 addition & 1 deletion include/MqttSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MqttSettingsClass {
void unsubscribe(const String& topic);

String getPrefix() const;
String getClientId();
String getClientId() const;

private:
void NetworkEvent(network_event event);
Expand Down
4 changes: 4 additions & 0 deletions include/PinMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class PinMappingClass {
bool init(const String& deviceMapping);
PinMapping_t& get();

bool isMappingSelected() const { return _mappingSelected; }

bool isValidNrf24Config() const;
bool isValidCmt2300Config() const;
bool isValidW5500Config() const;
Expand All @@ -68,6 +70,8 @@ class PinMappingClass {

private:
PinMapping_t _pinMapping;

bool _mappingSelected = false;
};

extern PinMappingClass PinMapping;
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>

class Utils {
Expand All @@ -11,4 +12,6 @@ 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);
};
6 changes: 4 additions & 2 deletions include/WebApi.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#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 @@ -46,13 +47,14 @@ class WebApiClass {
private:
AsyncWebServer _server;

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: 4 additions & 0 deletions include/WebApi_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

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

private:
void onNetworkStatus(AsyncWebServerRequest* request);
void onNetworkAdminGet(AsyncWebServerRequest* request);
void onNetworkAdminPost(AsyncWebServerRequest* request);

Task _applyDataTask;
void applyDataTaskCb();
};
2 changes: 1 addition & 1 deletion include/WebApi_ws_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WebApiWsConsoleClass {

private:
AsyncWebSocket _ws;
AuthenticationMiddleware _simpleDigestAuth;
AsyncAuthenticationMiddleware _simpleDigestAuth;

Task _wsCleanupTask;
void wsCleanupTaskCb();
Expand Down
2 changes: 1 addition & 1 deletion include/WebApi_ws_live.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WebApiWsLiveClass {
void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);

AsyncWebSocket _ws;
AuthenticationMiddleware _simpleDigestAuth;
AsyncAuthenticationMiddleware _simpleDigestAuth;

uint32_t _lastPublishStats[INV_MAX_COUNT] = { 0 };

Expand Down
4 changes: 3 additions & 1 deletion include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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 @@ -108,3 +108,5 @@
#define LED_BRIGHTNESS 100U

#define MAX_INVERTER_LIMIT 2250

#define LANG_PACK_SUFFIX ".lang.json"
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 03a8cd9

Please sign in to comment.