Hallo
ich benutze einen Waveshare display und habe eines der Beispiele zum laufen bekommen.
// GxEPD2_HelloWorld.ino by Jean-Marc Zingg
// see GxEPD2_wiring_examples.h for wiring suggestions and examples
// if you use a different wiring, you need to adapt the constructor parameters!
// uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
//#include <GFX.h>
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeMonoBold9pt7b.h>
// select the display class and display driver class in the following file (new style):
#include "GxEPD2_display_selection_new_style.h"
const char HelloWorld[] = "Hello World!";
void setup()
{
Serial.begin(9600);
display.init();
Serial.println("GxEPD_RED");
helloWorld(GxEPD_RED);
delay(25000);
Serial.println("GxEPD_BLACK");
helloWorld(GxEPD_BLACK);
delay(25000);
Serial.println("GxEPD_WHITE");
helloWorld(GxEPD_WHITE);
//display.hibernate();
Serial.println("display.hibernate()");
delay(50000);
}
void loop()
{
Serial.println("Loop");
Serial.println("GxEPD_BLACK");
Blank(GxEPD_BLACK);
delay(25000);
Serial.println("GxEPD_WHITE");
Blank(GxEPD_WHITE);
delay(30000);
}
void helloWorld(uint16_t color)
{
display.setRotation(1);
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
// center the bounding box by transposition of the origin:
uint16_t x = ((display.width() - tbw) / 2) - tbx;
uint16_t y = ((display.height() - tbh) / 2) - tby;
display.setFullWindow();
display.firstPage();
do
{
display.fillScreen(color);
display.setCursor(x, y);
display.print(HelloWorld);
}
while (display.nextPage());
}
void Blank(uint16_t color)
{
display.setRotation(1);
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
// center the bounding box by transposition of the origin:
uint16_t x = ((display.width() - tbw) / 2) - tbx;
uint16_t y = ((display.height() - tbh) / 2) - tby;
display.setFullWindow();
display.firstPage();
do
{
display.fillScreen(color);
display.setCursor(x, y);
display.print("");
}
while (display.nextPage());
}
GxEPD2_display_selection_new_style.h
#ifndef GxEPD2_DISPLAY_CLASS
#define GxEPD2_DISPLAY_CLASS GxEPD2_3C
#endif
#ifndef GxEPD2_DRIVER_CLASS
#define GxEPD2_DRIVER_CLASS GxEPD2_290c
#endif
//
#ifndef EPD_CS
#define EPD_CS 9
#endif
//
#ifndef EPD_DC
#define EPD_DC 8
#endif
//
#ifndef EPD_RST
#define EPD_RST 7
#endif
//
#ifndef EPD_BUSY
#define EPD_BUSY 6
#endif
#if defined(GxEPD2_DISPLAY_CLASS) && defined(GxEPD2_DRIVER_CLASS)
// somehow there should be an easier way to do this
#define GxEPD2_3C_IS_GxEPD2_3C true
#define IS_GxEPD(c, x) (c##x)
#define IS_GxEPD2_3C(x) IS_GxEPD(GxEPD2_3C_IS_, x)
#if defined(ARDUINO_ARCH_SAM)
#define MAX_DISPLAY_BUFFER_SIZE 32768ul // e.g., up to 96k
#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
// adapt the constructor parameters to your wiring
GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(EPD_CS, EPD_DC , EPD_RST , EPD_BUSY ));
#endif
#endif
Wie gesagt, der Code läuft und alles.
Was ich nicht hinbekomme ist das ganze in .cpp/.h Datein um zu bauen.
Für mein Projekt würde ich gerne eine eigene Library/Klasse bauen.
Nur bekomme ich die Referenz/Pointer auf display nicht hin.
Ich stelle mir das im Prinzip so vor:
Display.h
#pragma once
#ifndef Display_h
#define Display_h
#include "Arduino.h"
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#ifndef GxEPD2_DISPLAY_CLASS
#define GxEPD2_DISPLAY_CLASS GxEPD2_3C
#endif
#ifndef GxEPD2_DRIVER_CLASS
#define GxEPD2_DRIVER_CLASS GxEPD2_290c // GDEW029Z10 128x296
#endif
//
#ifndef EPD_CS
#define EPD_CS 9
#endif
//
#ifndef EPD_DC
#define EPD_DC 8
#endif
//
#ifndef EPD_RST
#define EPD_RST 7
#endif
//
#ifndef EPD_BUSY
#define EPD_BUSY 6
#endif
#if defined(GxEPD2_DISPLAY_CLASS) && defined(GxEPD2_DRIVER_CLASS)
// somehow there should be an easier way to do this
#define GxEPD2_3C_IS_GxEPD2_3C true
#define IS_GxEPD(c, x) (c##x)
#define IS_GxEPD2_3C(x) IS_GxEPD(GxEPD2_3C_IS_, x)
#if defined(ARDUINO_ARCH_SAM)
#define MAX_DISPLAY_BUFFER_SIZE 32768ul // e.g., up to 96k
#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
// adapt the constructor parameters to your wiring
//GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(EPD_CS, EPD_DC , EPD_RST , EPD_BUSY ));
#endif
#endif
class Display
{
public:
Display();
void Display_write(String str_In, uint16_t colorText, uint16_t colorBack);
private:
GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> *display;
};
#endif
#include "Display.h"
Display::Display()
{
//GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=77*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
display = new GxEPD2_3C(GxEPD2_DRIVER_CLASS( 9, 8, 7, 6));
display->init();
}
void Display_write(String str_In, uint16_t colorText, uint16_t colorBack)
{
int int_Len = str_In.length();
char chr_Text[int_Len];
str_In.toCharArray(chr_Text, int_Len);
display->setRotation(1);
display->setFont(&FreeMonoBold9pt7b);
display->setTextColor(colorText);
int16_t tbx, tby; uint16_t tbw, tbh;
display->getTextBounds(chr_Text, 0, 0, &tbx, &tby, &tbw, &tbh);
// center the bounding box by transposition of the origin:
uint16_t x = ((display->width() - tbw) / 2) - tbx;
uint16_t y = ((display->height() - tbh) / 2) - tby;
display->setFullWindow();
display->firstPage();
do
{
display->fillScreen(colorBack);
display->setCursor(x, y);
display->print(chr_Text);
}
while (display->nextPage());
}
Doch wenn ich das kompilliere habe ich folgende Fehlermeldung:
sketch\Display.cpp: In constructor 'Display::Display()':
Display.cpp:14:17: error: expected type-specifier before 'GxEPD2_3C'
display = new GxEPD2_3C(GxEPD2_DRIVER_CLASS( 9, 8, 7, 6));
^
Display.cpp:14:17: error: expected ';' before 'GxEPD2_3C'
sketch\Display.cpp: In function 'void Display_write(String, uint16_t, uint16_t)':
Display.cpp:22:3: error: 'display' was not declared in this scope
display->setRotation(1);
^
exit status 1
expected type-specifier before 'GxEPD2_3C'
Ich weiß das ich mich ziemlich blöde anstelle aber ich bekomme es einfach nicht hin und denke das ich den Wald vor lauter Bäumen nicht sehe.
Es gibt auch eine Englische Frage dazu. GxEPD2 How to declare/initialize in my own .cpp/.h - Displays - Arduino Forum aber keine Lösung.
Auf Git steht das das irgendwie gehen soll:
Version 1.0.4
- add GxEPD2_GFX base class support (optional, selectable, uses slightly more code)
- base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter
Aber ich finde keine Erklärung oder Beispiel.
Schon mal danke und so....