Skip to content

Commit

Permalink
Feature: Added option to disable the diagram at the display
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Jan 8, 2024
1 parent 265a44c commit 637d4f0
Show file tree
Hide file tree
Showing 13 changed files with 841 additions and 784 deletions.
7 changes: 5 additions & 2 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,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 All @@ -166,4 +169,4 @@ class ConfigurationClass {
INVERTER_CONFIG_T* getInverterConfig(const uint64_t serial);
};

extern ConfigurationClass Configuration;
extern ConfigurationClass Configuration;
10 changes: 9 additions & 1 deletion include/Display_Graphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ enum DisplayType_t {
DisplayType_Max,
};

enum DiagramMode_t {
Off,
Small,
DisplayMode_Max,
};

class DisplayGraphicClass {
public:
DisplayGraphicClass();
Expand All @@ -25,6 +31,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,6 +54,7 @@ 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;
Expand All @@ -57,4 +65,4 @@ class DisplayGraphicClass {
uint8_t _lineOffsets[5];
};

extern DisplayGraphicClass Display;
extern DisplayGraphicClass Display;
3 changes: 2 additions & 1 deletion include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@
#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 LED_BRIGHTNESS 100U

#define MAX_INVERTER_LIMIT 2250
#define MAX_INVERTER_LIMIT 2250
10 changes: 6 additions & 4 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2022 Thomas Basler and others
* Copyright (C) 2022-2024 Thomas Basler and others
*/
#include "Configuration.h"
#include "MessageOutput.h"
Expand Down Expand Up @@ -109,7 +109,8 @@ bool ConfigurationClass::write()
display["rotation"] = config.Display.Rotation;
display["contrast"] = config.Display.Contrast;
display["language"] = config.Display.Language;
display["diagram_duration"] = config.Display.DiagramDuration;
display["diagram_duration"] = config.Display.Diagram.Duration;
display["diagram_mode"] = config.Display.Diagram.Mode;

JsonArray leds = device.createNestedArray("led");
for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) {
Expand Down Expand Up @@ -276,7 +277,8 @@ 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.DiagramDuration = display["diagram_duration"] | DISPLAY_DIAGRAM_DURATION;
config.Display.Diagram.Duration = display["diagram_duration"] | DISPLAY_DIAGRAM_DURATION;
config.Display.Diagram.Mode = display["diagram_mode"] | DISPLAY_DIAGRAM_MODE;

JsonArray leds = device["led"];
for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) {
Expand Down Expand Up @@ -397,4 +399,4 @@ INVERTER_CONFIG_T* ConfigurationClass::getInverterConfig(const uint64_t serial)
return nullptr;
}

ConfigurationClass Configuration;
ConfigurationClass Configuration;
18 changes: 15 additions & 3 deletions src/Display_Graphic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2023 Thomas Basler and others
* Copyright (C) 2023-2024 Thomas Basler and others
*/
#include "Display_Graphic.h"
#include "Datastore.h"
Expand Down Expand Up @@ -98,7 +98,12 @@ void DisplayGraphicClass::printText(const char* text, const uint8_t line)
if (!_isLarge) {
dispX = (line == 0) ? 5 : 0;
} else {
dispX = (line == 0) ? 10 : 5;
if (_diagram_mode == DiagramMode_t::Small) {
dispX = (line == 0) ? 10 : 5;
} else {
dispX = (line == 0) ? 20 : 5;
}

}
setFont(line);

Expand Down Expand Up @@ -136,6 +141,13 @@ void DisplayGraphicClass::setLanguage(const uint8_t language)
_display_language = language < sizeof(languages) / sizeof(languages[0]) ? language : DISPLAY_LANGUAGE;
}

void DisplayGraphicClass::setDiagramMode(DiagramMode_t mode)
{
if (mode < DiagramMode_t::DisplayMode_Max) {
_diagram_mode = mode;
}
}

void DisplayGraphicClass::setStartupDisplay()
{
if (!isValidDisplay()) {
Expand All @@ -162,7 +174,7 @@ void DisplayGraphicClass::loop()
//=====> Actual Production ==========
if (Datastore.getIsAtLeastOneReachable()) {
displayPowerSave = false;
if (_isLarge) {
if (_isLarge && _diagram_mode == DiagramMode_t::Small) {
uint8_t screenSaverOffsetX = enableScreensaver ? (_mExtra % 7) : 0;
_diagram.redraw(screenSaverOffsetX);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Display_Graphic_Diagram.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2023 Thomas Basler and others
* Copyright (C) 2023-2024 Thomas Basler and others
*/
#include "Display_Graphic_Diagram.h"
#include "Configuration.h"
Expand Down Expand Up @@ -52,7 +52,7 @@ void DisplayGraphicDiagramClass::dataPointLoop()

uint32_t DisplayGraphicDiagramClass::getSecondsPerDot()
{
return Configuration.get().Display.DiagramDuration / CHART_WIDTH;
return Configuration.get().Display.Diagram.Duration / CHART_WIDTH;
}

void DisplayGraphicDiagramClass::updatePeriod()
Expand Down
9 changes: 6 additions & 3 deletions src/WebApi_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request)
display["screensaver"] = config.Display.ScreenSaver;
display["contrast"] = config.Display.Contrast;
display["language"] = config.Display.Language;
display["diagramduration"] = config.Display.DiagramDuration;
display["diagramduration"] = config.Display.Diagram.Duration;
display["diagrammode"] = config.Display.Diagram.Mode;

auto leds = root.createNestedArray("led");
for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) {
Expand Down Expand Up @@ -161,7 +162,8 @@ 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.DiagramDuration = root["display"]["diagramduration"].as<uint32_t>();
config.Display.Diagram.Duration = root["display"]["diagramduration"].as<uint32_t>();
config.Display.Diagram.Mode = root["display"]["diagrammode"].as<DiagramMode_t>();

for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) {
config.Led_Single[i].Brightness = root["led"][i]["brightness"].as<uint8_t>();
Expand All @@ -173,6 +175,7 @@ void WebApiDeviceClass::onDeviceAdminPost(AsyncWebServerRequest* request)
Display.enableScreensaver = config.Display.ScreenSaver;
Display.setContrast(config.Display.Contrast);
Display.setLanguage(config.Display.Language);
Display.setDiagramMode(static_cast<DiagramMode_t>(config.Display.Diagram.Mode));
Display.Diagram().updatePeriod();

WebApi.writeConfig(retMsg);
Expand All @@ -183,4 +186,4 @@ void WebApiDeviceClass::onDeviceAdminPost(AsyncWebServerRequest* request)
if (performRestart) {
Utils::restartDtu();
}
}
}
Loading

0 comments on commit 637d4f0

Please sign in to comment.