Skip to content

Commit

Permalink
Update OpenDTU ePaper with SW-SPI to be able to
Browse files Browse the repository at this point in the history
use the other SPI channels for Inverter communication.

adjust the Display Class, there is now a Display main Class
and another Class for ePapers and MonoDisplays.
  • Loading branch information
dAjaY85 committed Jun 19, 2023
1 parent 0a56dc2 commit 126bf56
Show file tree
Hide file tree
Showing 21 changed files with 1,440 additions and 254 deletions.
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct CONFIG_T {
uint8_t Display_Rotation;
uint8_t Display_Contrast;
uint8_t Display_Language;
uint16_t Display_UpdatePeriod;
};

class ConfigurationClass {
Expand Down
4 changes: 4 additions & 0 deletions include/Datastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class DatastoreClass {
// True if all enabled inverters are reachable
bool getIsAllEnabledReachable();

// Sum of all Producing Inverters
uint8_t getTotalProducing();

private:
TimeoutHelper _updateTimeout;
SemaphoreHandle_t _xSemaphore;
Expand All @@ -75,6 +78,7 @@ class DatastoreClass {
bool _isAtLeastOneProducing = false;
bool _isAllEnabledProducing = false;
bool _isAllEnabledReachable = false;
uint8_t _isProducing = 0;
};

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

#include "Display_helper.h"
#include "defaults.h"
#include <Arduino.h>

class DisplayClass {
public:
void init(DisplayType_t _type, uint8_t _data, uint8_t _clk, uint8_t _cs, uint8_t _reset, uint8_t _busy, uint8_t _dc);
void loop();

bool enablePowerSafe;
bool enableScreensaver;
void setContrast(uint8_t contrast);
void setOrientation(uint8_t rotation = DISPLAY_ROTATION);
void setLanguage(uint8_t language);
void setUpdatePeriod(uint16_t updatePeriod);

private:
DisplayType_t _display_type = DisplayType_t::None;
uint32_t _lastDisplayUpdate = 0;
time_t now = time(nullptr);
uint16_t counterEPaper;
uint16_t _setUpdatePeriod; // Achtung, max 65535
};

extern DisplayClass Display;
48 changes: 0 additions & 48 deletions include/Display_Graphic.h

This file was deleted.

48 changes: 48 additions & 0 deletions include/Display_Mono.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include "Display_helper.h"
#include "defaults.h"
#include <U8g2lib.h>

class DisplayMonoClass {
public:
DisplayMonoClass();
~DisplayMonoClass();

void init(DisplayType_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, uint8_t _BUSY, uint8_t _SCK, uint8_t _MOSI);
void loop(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod);

void setContrast(uint8_t contrast);
void setOrientation(uint8_t rotation);
void setLanguage(uint8_t language);
void setStartupDisplay();

bool enablePowerSafe = true;
bool enableScreensaver = true;

private:
void calcLineHeights();
void setFont(uint8_t line);
void printText(const char* text, uint8_t line, uint8_t dispX);

U8G2* _display;

bool _mIsLarge = false;
uint8_t mLoopCnt;
uint32_t* mUtcTs;
uint8_t mLineOffsets[5];

uint16_t _dispY = 0;
uint32_t _previousMillis = 0;
uint8_t _display_language = DISPLAY_LANGUAGE;

uint8_t _mExtra;
uint16_t _mTimeout; // interval at which to power save (milliseconds)
char _fmtText[32];

const u8g2_cb_t* disp_rotation = U8G2_R2;
uint8_t contrast = 60;
};

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

// uncomment next line to use HSPI for EPD (and VSPI for SD), e.g. with Waveshare ESP32 Driver Board
// #define USE_HSPI_FOR_EPD
#define USE_HSPI_FOR_DCMT

/// uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX, to use less code and ram
// #include <GFX.h>
// base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
// enable GxEPD2_GFX base class
#define ENABLE_GxEPD2_GFX 1

#include <SPI.h>
#include <map>

#include <GxEPD2_3C.h>
#include <GxEPD2_BW.h>
// FreeFonts from Adafruit_GFX
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
#include <Fonts/FreeSans24pt7b.h>
#include <Fonts/FreeSans9pt7b.h>

#include "Display_helper.h"
#include "imagedata.h"

// GDEW027C44 2.7 " b/w/r 176x264, IL91874
// GDEH0154D67 1.54" b/w 200x200

class DisplayEPaperClass {
public:
DisplayEPaperClass();
~DisplayEPaperClass();
void fullRefresh();
void init(DisplayType_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, uint8_t _BUSY, uint8_t _SCK, uint8_t _MOSI);
void loop(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod);
void setOrientation(uint8_t rotation);

private:
void headlineIP();
void actualPowerPaged(float _totalPower, float _totalYieldDay, float _totalYieldTotal, uint8_t _isprod);
void lastUpdatePaged();

uint8_t _displayRotation = 2;
bool _changed = false;
char _fmtText[35];
const char* _settedIP;
uint8_t headfootline = 16;
GxEPD2_GFX* _display;
};

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

enum DisplayType_t
{
None,
PCD8544,
SSD1306,
SH1106,
SSD1309,
ePaper154
};
2 changes: 2 additions & 0 deletions include/PinMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct PinMapping_t {
uint8_t display_clk;
uint8_t display_cs;
uint8_t display_reset;
uint8_t display_busy;
uint8_t display_dc;
int8_t led[PINMAPPING_LED_COUNT];
};

Expand Down
1 change: 1 addition & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@
#define DISPLAY_SCREENSAVER true
#define DISPLAY_ROTATION 2
#define DISPLAY_CONTRAST 60
#define DISPLAY_UPDATE 10000
#define DISPLAY_LANGUAGE 0
10 changes: 10 additions & 0 deletions include/imagedata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

extern const unsigned char AhoyLogo[];
extern const unsigned char OpenDTULogo[];
extern const unsigned char myHoy[];
extern const unsigned char mySigma[];
extern const unsigned char mySun[];
extern const unsigned char myToday[];
extern const unsigned char myWR[];
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ lib_deps =
nrf24/RF24 @ ^1.4.7
olikraus/U8g2 @ ^2.34.18
buelowp/sunset @ ^1.1.7
https://github.com/dAjaY85/GxEPD2_SWSPI

extra_scripts =
pre:pio-scripts/auto_firmware_version.py
Expand Down
4 changes: 3 additions & 1 deletion src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ bool ConfigurationClass::write()
display["screensaver"] = config.Display_ScreenSaver;
display["rotation"] = config.Display_Rotation;
display["contrast"] = config.Display_Contrast;
display["update"] = config.Display_UpdatePeriod;
display["language"] = config.Display_Language;

JsonArray inverters = doc.createNestedArray("inverters");
Expand Down Expand Up @@ -241,6 +242,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_UpdatePeriod = display["update"] | DISPLAY_UPDATE;
config.Display_Language = display["language"] | DISPLAY_LANGUAGE;

JsonArray inverters = doc["inverters"];
Expand Down Expand Up @@ -300,7 +302,7 @@ void ConfigurationClass::migrate()
config.Mqtt_PublishInterval = mqtt["publish_invterval"];
}

if (config.Cfg_Version < 0x00011900) {
if (config.Cfg_Version < 0x00011900) {
JsonObject dtu = doc["dtu"];
config.Dtu_NrfPaLevel = dtu["pa_level"];
}
Expand Down
15 changes: 12 additions & 3 deletions src/Datastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ void DatastoreClass::loop()
{
if (Hoymiles.isAllRadioIdle() && _updateTimeout.occured()) {

uint8_t isProducing = 0;
uint8_t isReachable = 0;

DAT_SEMAPHORE_TAKE();

_isProducing = 0;

_totalAcYieldTotalEnabled = 0;
_totalAcYieldTotalDigits = 0;

Expand Down Expand Up @@ -63,7 +64,7 @@ void DatastoreClass::loop()
}

if (inv->isProducing()) {
isProducing++;
_isProducing++;
} else {
if (inv->getEnablePolling()) {
_isAllEnabledProducing = false;
Expand Down Expand Up @@ -105,7 +106,7 @@ void DatastoreClass::loop()
}
}

_isAtLeastOneProducing = isProducing > 0;
_isAtLeastOneProducing = _isProducing > 0;
_isAtLeastOneReachable = isReachable > 0;

_totalDcIrradiation = _totalDcIrradiationInstalled > 0 ? _totalDcPowerIrradiation / _totalDcIrradiationInstalled * 100.0f : 0;
Expand Down Expand Up @@ -235,3 +236,11 @@ bool DatastoreClass::getIsAllEnabledReachable()
DAT_SEMAPHORE_GIVE();
return retval;
}

uint8_t DatastoreClass::getTotalProducing()
{
DAT_SEMAPHORE_TAKE();
bool retval = _isProducing;
DAT_SEMAPHORE_GIVE();
return retval;
}
Loading

0 comments on commit 126bf56

Please sign in to comment.