Hi
I'm less experienced in writing C++ code. To keep my code clean I wanted to encapsulate the ePaper API in my own .cpp/.h file.
Because of GxEPD2_3C
doesn't have a default constructor I don't know how to declare the display
variable in my header file. Since C++ doesn't allow declaration without initialization I tried to initialize it in a dummy way and override it later.
What I tried is using a point instead: GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display
But know I have to treat with the variable deletion and use of ->
instead of .
to reference class members. If this is the way to go, then it is...
But, going this way results in mirrored output. If I print display.print("Hello");
then the out put is mirrored (letter order is reversed and letter itself is mirrored). I guess this is due to a byte-order issue.
What I have so far without the pointer stuff:
sketch.ino
#include "EPaper.h"
DisplayPins displayPins = {
15, // CS
27, // DC
26, // RST
25, // BUSY
13, // SCK
12, // MISO
14 // MOSI
};
EPaper epaper = EPaper(displayPins);
void setup() {
while (!epaper.setup()) {
Serial.println("E-Paper display not ready");
delay(1000);
}
epaper.test();
}
void loop() {
}
EPaper.h
#ifndef EPAPER_H
#define EPAPER_H
#define ENABLE_GxEPD2_GFX 0
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
typedef struct {
int cs;
int dc;
int rst;
int busy;
int sck;
int miso;
int mosi;
} DisplayPins;
class EPaper
{
public:
const bool hasDeepSleepSupport = true;
EPaper(DisplayPins displayPins);
bool setup(void);
void test(void);
void clear(uint16_t color);
private:
DisplayPins displayPins;
GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display; // Doesn't work, no default constructor
};
#endif
EPaper.cpp
#include "EPaper.h"
EPaper::EPaper(DisplayPins pins) {
displayPins = pins;
display(GxEPD2_154c(displayPins.cs, displayPins.dc, displayPins.rst, displayPins.busy)); // Doesn't work
}
bool EPaper::setup(void) {
display.init(115200);
SPI.end();
SPI.begin(EPaper::displayPins.sck, EPaper::displayPins.miso, EPaper::displayPins.mosi, EPaper::displayPins.cs);
return true;
}
void EPaper::test(void) {
display.setRotation(1);
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
display.setFullWindow();
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.setCursor(50, 50);
display.print("Test");
} while (display.nextPage());
}
Thank you for pointing me into the right direction.
Cheers Danny