Browse Source

ePaper mittels SW-SPI

pull/961/head
dAjaY85 2 years ago
parent
commit
abb2a43b75
  1. 4
      src/platformio.ini
  2. 20
      src/plugins/Display/Display_ePaper.cpp
  3. 41
      src/plugins/Display/Display_ePaper.h

4
src/platformio.ini

@ -30,7 +30,7 @@ lib_deps =
bblanchon/ArduinoJson @ ^6.21.2 bblanchon/ArduinoJson @ ^6.21.2
https://github.com/JChristensen/Timezone @ ^1.2.4 https://github.com/JChristensen/Timezone @ ^1.2.4
olikraus/U8g2 @ ^2.34.17 olikraus/U8g2 @ ^2.34.17
zinggjm/GxEPD2 @ ^1.5.2 https://github.com/dAjaY85/GxEPD2_SWSPI
[env:esp8266-release] [env:esp8266-release]
@ -151,4 +151,4 @@ build_unflags = -std=gnu++11
monitor_filters = monitor_filters =
;default ; Remove typical terminal control codes from input ;default ; Remove typical terminal control codes from input
time ; Add timestamp with milliseconds for each new line time ; Add timestamp with milliseconds for each new line
;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory ;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory

20
src/plugins/Display/Display_ePaper.cpp

@ -1,9 +1,9 @@
#include "Display_ePaper.h" #include "Display_ePaper.h"
#ifdef ESP8266 #ifdef ESP8266
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#elif defined(ESP32) #elif defined(ESP32)
#include <WiFi.h> #include <WiFi.h>
#endif #endif
#include "../../utils/helper.h" #include "../../utils/helper.h"
#include "imagedata.h" #include "imagedata.h"
@ -21,7 +21,6 @@ DisplayEPaper::DisplayEPaper() {
mHeadFootPadding = 16; mHeadFootPadding = 16;
} }
//*************************************************************************** //***************************************************************************
void DisplayEPaper::init(uint8_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, uint8_t _BUSY, uint8_t _SCK, uint8_t _MOSI, uint32_t *utcTs, const char *version) { void DisplayEPaper::init(uint8_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, uint8_t _BUSY, uint8_t _SCK, uint8_t _MOSI, uint32_t *utcTs, const char *version) {
mUtcTs = utcTs; mUtcTs = utcTs;
@ -29,12 +28,14 @@ void DisplayEPaper::init(uint8_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, u
if (type > 9) { if (type > 9) {
Serial.begin(115200); Serial.begin(115200);
_display = new GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>(GxEPD2_150_BN(_CS, _DC, _RST, _BUSY)); _display = new GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>(GxEPD2_150_BN(_CS, _DC, _RST, _BUSY));
hspi.begin(_SCK, _BUSY, _MOSI, _CS);
#if defined(ESP32) && defined(USE_HSPI_FOR_EPD) #if defined(ESP32) && defined(USE_HSPI_FOR_EPD)
hspi.begin(_SCK, _BUSY, _MOSI, _CS);
_display->epd2.selectSPI(hspi, SPISettings(spiClk, MSBFIRST, SPI_MODE0)); _display->epd2.selectSPI(hspi, SPISettings(spiClk, MSBFIRST, SPI_MODE0));
#endif #endif
_display->init(115200, true, 2, false);
_display->epd2.init(_SCK, _MOSI, 115200, true, 20, false);
_display->init(115200, true, 20, false);
_display->setRotation(mDisplayRotation); _display->setRotation(mDisplayRotation);
_display->setFullWindow(); _display->setFullWindow();
@ -162,8 +163,8 @@ void DisplayEPaper::actualPowerPaged(float totalPower, float totalYieldDay, floa
} else { } else {
snprintf(_fmtText, sizeof(_fmtText), "offline"); snprintf(_fmtText, sizeof(_fmtText), "offline");
} }
if (totalPower == 0){ if (totalPower == 0) {
_display->fillRect(0, mHeadFootPadding, 200,200, GxEPD_BLACK); _display->fillRect(0, mHeadFootPadding, 200, 200, GxEPD_BLACK);
_display->drawBitmap(0, 0, logo, 200, 200, GxEPD_WHITE); _display->drawBitmap(0, 0, logo, 200, 200, GxEPD_WHITE);
} else { } else {
_display->getTextBounds(_fmtText, 0, 0, &tbx, &tby, &tbw, &tbh); _display->getTextBounds(_fmtText, 0, 0, &tbx, &tby, &tbw, &tbh);
@ -197,7 +198,6 @@ void DisplayEPaper::actualPowerPaged(float totalPower, float totalYieldDay, floa
_display->setCursor(10, _display->height() - (mHeadFootPadding + 10)); _display->setCursor(10, _display->height() - (mHeadFootPadding + 10));
snprintf(_fmtText, sizeof(_fmtText), "%d Inverter online", isprod); snprintf(_fmtText, sizeof(_fmtText), "%d Inverter online", isprod);
_display->println(_fmtText); _display->println(_fmtText);
} }
} while (_display->nextPage()); } while (_display->nextPage());
} }
@ -217,10 +217,10 @@ void DisplayEPaper::loop(float totalPower, float totalYieldDay, float totalYield
if ((isprod > 0) && (_changed)) { if ((isprod > 0) && (_changed)) {
_changed = false; _changed = false;
lastUpdatePaged(); lastUpdatePaged();
} else if((0 == totalPower) && (mEnPowerSafe)) } else if ((0 == totalPower) && (mEnPowerSafe))
offlineFooter(); offlineFooter();
_display->powerOff(); _display->powerOff();
} }
//*************************************************************************** //***************************************************************************
#endif // ESP32 #endif // ESP32

41
src/plugins/Display/Display_ePaper.h

@ -4,7 +4,7 @@
#if defined(ESP32) #if defined(ESP32)
// uncomment next line to use HSPI for EPD (and VSPI for SD), e.g. with Waveshare ESP32 Driver Board // 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_EPD
/// uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX, to use less code and ram /// uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX, to use less code and ram
// #include <GFX.h> // #include <GFX.h>
@ -28,27 +28,26 @@
class DisplayEPaper { class DisplayEPaper {
public: public:
DisplayEPaper(); DisplayEPaper();
void fullRefresh(); void fullRefresh();
void init(uint8_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, uint8_t _BUSY, uint8_t _SCK, uint8_t _MOSI, uint32_t *utcTs, const char* version); void init(uint8_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, uint8_t _BUSY, uint8_t _SCK, uint8_t _MOSI, uint32_t* utcTs, const char* version);
void config(uint8_t rotation, bool enPowerSafe); void config(uint8_t rotation, bool enPowerSafe);
void loop(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod); void loop(float totalPower, float totalYieldDay, float totalYieldTotal, uint8_t isprod);
private: private:
void headlineIP(); void headlineIP();
void actualPowerPaged(float _totalPower, float _totalYieldDay, float _totalYieldTotal, uint8_t _isprod); void actualPowerPaged(float _totalPower, float _totalYieldDay, float _totalYieldTotal, uint8_t _isprod);
void lastUpdatePaged(); void lastUpdatePaged();
void offlineFooter(); void offlineFooter();
uint8_t mDisplayRotation; uint8_t mDisplayRotation;
bool _changed = false; bool _changed = false;
char _fmtText[35]; char _fmtText[35];
const char* _settedIP; const char* _settedIP;
uint8_t mHeadFootPadding; uint8_t mHeadFootPadding;
GxEPD2_GFX* _display; GxEPD2_GFX* _display;
uint32_t *mUtcTs; uint32_t* mUtcTs;
bool mEnPowerSafe; bool mEnPowerSafe;
}; };
#endif // ESP32 #endif // ESP32

Loading…
Cancel
Save