Skip to content

Commit

Permalink
Merge remote-tracking branch 'tbnobody/OpenDTU/master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Jan 16, 2024
2 parents b8fcdf3 + 4741727 commit 63205f8
Show file tree
Hide file tree
Showing 49 changed files with 2,323 additions and 1,508 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# http://editorconfig.org
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// for the documentation about the extensions.json format
"recommendations": [
"DavidAnson.vscode-markdownlint",
"EditorConfig.EditorConfig",
"Vue.volar",
"Vue.vscode-typescript-vue-plugin",
"platformio.platformio-ide"
Expand Down
10 changes: 7 additions & 3 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <cstdint>

#define CONFIG_FILENAME "/config.json"
#define CONFIG_VERSION 0x00011a00 // 0.1.26 // make sure to clean all after change
#define CONFIG_VERSION 0x00011b00 // 0.1.27 // make sure to clean all after change

#define WIFI_MAX_SSID_STRLEN 32
#define WIFI_MAX_PASSWORD_STRLEN 64
Expand Down Expand Up @@ -152,6 +152,7 @@ struct CONFIG_T {
struct {
int8_t PaLevel;
uint32_t Frequency;
uint8_t CountryMode;
} Cmt;
bool VerboseLogging;
} Dtu;
Expand All @@ -167,7 +168,10 @@ struct CONFIG_T {
uint8_t Rotation;
uint8_t Contrast;
uint8_t Language;
uint32_t DiagramDuration;
struct {
uint32_t Duration;
uint8_t Mode;
} Diagram;
} Display;

struct {
Expand Down Expand Up @@ -256,4 +260,4 @@ class ConfigurationClass {
INVERTER_CONFIG_T* getInverterConfig(const uint64_t serial);
};

extern ConfigurationClass Configuration;
extern ConfigurationClass Configuration;
23 changes: 20 additions & 3 deletions include/Display_Graphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
#include <TaskSchedulerDeclarations.h>
#include <U8g2lib.h>

#define CHART_HEIGHT 20 // chart area hight in pixels
#define CHART_WIDTH 47 // chart area width in pixels

// Left-Upper position of diagram is drawn
// (text of Y-axis is display left of that pos)
#define CHART_POSX 80
#define CHART_POSY 0

enum DisplayType_t {
None,
PCD8544,
Expand All @@ -15,6 +23,13 @@ enum DisplayType_t {
DisplayType_Max,
};

enum DiagramMode_t {
Off,
Small,
Fullscreen,
DisplayMode_Max,
};

class DisplayGraphicClass {
public:
DisplayGraphicClass();
Expand All @@ -25,6 +40,7 @@ class DisplayGraphicClass {
void setStatus(const bool turnOn);
void setOrientation(const uint8_t rotation = DISPLAY_ROTATION);
void setLanguage(const uint8_t language);
void setDiagramMode(DiagramMode_t mode);
void setStartupDisplay();

DisplayGraphicDiagramClass& Diagram();
Expand All @@ -47,14 +63,15 @@ class DisplayGraphicClass {
bool _displayTurnedOn;

DisplayType_t _display_type = DisplayType_t::None;
DiagramMode_t _diagram_mode = DiagramMode_t::Off;
uint8_t _display_language = DISPLAY_LANGUAGE;
uint8_t _mExtra;
uint16_t _period = 1000;
uint16_t _interval = 60000; // interval at which to power save (milliseconds)
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];
};

extern DisplayGraphicClass Display;
extern DisplayGraphicClass Display;
16 changes: 6 additions & 10 deletions include/Display_Graphic_Diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,32 @@
#include <U8g2lib.h>
#include <array>

#define CHART_HEIGHT 20 // chart area hight in pixels
#define CHART_WIDTH 47 // chart area width in pixels

// Left-Upper position of diagram is drawn
// (text of Y-axis is display left of that pos)
#define DIAG_POSX 80
#define DIAG_POSY 0
#define MAX_DATAPOINTS 128

class DisplayGraphicDiagramClass {
public:
DisplayGraphicDiagramClass();

void init(Scheduler& scheduler, U8G2* display);
void redraw(uint8_t screenSaverOffsetX);
void redraw(uint8_t screenSaverOffsetX, uint8_t xPos, uint8_t yPos, uint8_t width, uint8_t height, bool isFullscreen);

void updatePeriod();

private:
void averageLoop();
void dataPointLoop();

static uint32_t getSecondsPerDot();
uint32_t getSecondsPerDot();

Task _averageTask;
Task _dataPointTask;

U8G2* _display = nullptr;
std::array<float, CHART_WIDTH> _graphValues = {};
std::array<float, MAX_DATAPOINTS> _graphValues = {};
uint8_t _graphValuesCount = 0;

uint8_t _chartWidth = MAX_DATAPOINTS;

float _iRunningAverage = 0;
uint16_t _iRunningAverageCnt = 0;
};
3 changes: 2 additions & 1 deletion include/WebApi_dtu.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class WebApiDtuClass {
void onDtuAdminPost(AsyncWebServerRequest* request);

AsyncWebServer* _server;
};
bool _performReload = false;
};
3 changes: 2 additions & 1 deletion include/WebApi_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum WebApiError {
DtuPollZero,
DtuInvalidPowerLevel,
DtuInvalidCmtFrequency,
DtuInvalidCmtCountry,

ConfigBase = 3000,
ConfigNotDeleted,
Expand Down Expand Up @@ -89,4 +90,4 @@ enum WebApiError {

HardwareBase = 12000,
HardwarePinMappingLength,
};
};
54 changes: 52 additions & 2 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
#define DTU_POLL_INTERVAL 5U
#define DTU_NRF_PA_LEVEL 0U
#define DTU_CMT_PA_LEVEL 0
#define DTU_CMT_FREQUENCY 865000U
#define DTU_CMT_FREQUENCY 865000000U
#define DTU_CMT_COUNTRY_MODE 0U

#define MQTT_HASS_ENABLED false
#define MQTT_HASS_EXPIRE true
Expand All @@ -99,9 +100,58 @@
#define DISPLAY_CONTRAST 60U
#define DISPLAY_LANGUAGE 0U
#define DISPLAY_DIAGRAM_DURATION (10UL * 60UL * 60UL)
#define DISPLAY_DIAGRAM_MODE 1U

#define REACHABLE_THRESHOLD 2U

#define MAX_INVERTER_LIMIT 2250
#define VEDIRECT_ENABLED false
#define VEDIRECT_VERBOSE_LOGGING false
#define VEDIRECT_UPDATESONLY true

#define POWERMETER_ENABLED false
#define POWERMETER_INTERVAL 10
#define POWERMETER_SOURCE 2
#define POWERMETER_SDMBAUDRATE 9600
#define POWERMETER_SDMADDRESS 1


#define POWERLIMITER_ENABLED false
#define POWERLIMITER_SOLAR_PASSTHROUGH_ENABLED true
#define POWERLIMITER_SOLAR_PASSTHROUGH_LOSSES 3
#define POWERLIMITER_BATTERY_DRAIN_STRATEGY 0
#define POWERLIMITER_INTERVAL 10
#define POWERLIMITER_IS_INVERTER_BEHIND_POWER_METER true
#define POWERLIMITER_INVERTER_ID 0
#define POWERLIMITER_INVERTER_CHANNEL_ID 0
#define POWERLIMITER_TARGET_POWER_CONSUMPTION 0
#define POWERLIMITER_TARGET_POWER_CONSUMPTION_HYSTERESIS 0
#define POWERLIMITER_LOWER_POWER_LIMIT 10
#define POWERLIMITER_UPPER_POWER_LIMIT 800
#define POWERLIMITER_BATTERY_SOC_START_THRESHOLD 80
#define POWERLIMITER_BATTERY_SOC_STOP_THRESHOLD 20
#define POWERLIMITER_VOLTAGE_START_THRESHOLD 50.0
#define POWERLIMITER_VOLTAGE_STOP_THRESHOLD 49.0
#define POWERLIMITER_VOLTAGE_LOAD_CORRECTION_FACTOR 0.001
#define POWERLIMITER_RESTART_HOUR -1
#define POWERLIMITER_FULL_SOLAR_PASSTHROUGH_SOC 100
#define POWERLIMITER_FULL_SOLAR_PASSTHROUGH_START_VOLTAGE 100.0
#define POWERLIMITER_FULL_SOLAR_PASSTHROUGH_STOP_VOLTAGE 100.0

#define BATTERY_ENABLED false
#define BATTERY_PROVIDER 0 // Pylontech CAN receiver
#define BATTERY_JKBMS_INTERFACE 0
#define BATTERY_JKBMS_POLLING_INTERVAL 5

#define HUAWEI_ENABLED false
#define HUAWEI_CAN_CONTROLLER_FREQUENCY 8000000UL
#define HUAWEI_AUTO_POWER_VOLTAGE_LIMIT 42.0
#define HUAWEI_AUTO_POWER_ENABLE_VOLTAGE_LIMIT 42.0
#define HUAWEI_AUTO_POWER_LOWER_POWER_LIMIT 150
#define HUAWEI_AUTO_POWER_UPPER_POWER_LIMIT 2000

#define VERBOSE_LOGGING true

#define LED_BRIGHTNESS 100U

#define MAX_INVERTER_LIMIT 2250
Expand Down Expand Up @@ -154,4 +204,4 @@

#define LED_BRIGHTNESS 100U

#define MAX_INVERTER_LIMIT 2250
#define MAX_INVERTER_LIMIT 2250
Loading

0 comments on commit 63205f8

Please sign in to comment.