MeshCore/src/helpers/ui/GxEPDDisplay.h

71 lines
2.1 KiB
C
Raw Normal View History

2025-04-15 22:37:50 +02:00
#pragma once
#include <SPI.h>
#include <Wire.h>
#define ENABLE_GxEPD2_GFX 0
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <GxEPD2_4C.h>
#include <GxEPD2_7C.h>
2025-05-31 15:22:59 -07:00
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
2025-04-15 22:37:50 +02:00
#include <epd/GxEPD2_150_BN.h> // 1.54" b/w
2025-09-02 13:56:24 +08:00
#include <epd/GxEPD2_213_B74.h> // 2.13" b/w
2025-09-03 18:17:37 +02:00
#include <CRC32.h>
2025-04-15 22:37:50 +02:00
#include "DisplayDriver.h"
//GxEPD2_BW<GxEPD2_150_BN, 200> display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)); // DEPG0150BN 200x200, SSD1681, TTGO T5 V2.4.1
2025-04-15 22:37:50 +02:00
class GxEPDDisplay : public DisplayDriver {
2025-09-20 21:45:13 +02:00
#if defined(EINK_DISPLAY_MODEL)
2025-09-02 13:56:24 +08:00
GxEPD2_BW<EINK_DISPLAY_MODEL, EINK_DISPLAY_MODEL::HEIGHT> display;
const float scale_x = EINK_SCALE_X;
const float scale_y = EINK_SCALE_Y;
const float offset_x = EINK_X_OFFSET;
const float offset_y = EINK_Y_OFFSET;
#else
2025-04-15 22:37:50 +02:00
GxEPD2_BW<GxEPD2_150_BN, 200> display;
2025-09-02 13:56:24 +08:00
const float scale_x = 1.5625f;
const float scale_y = 1.5625f;
const float offset_x = 0;
const float offset_y = 10;
#endif
2025-04-15 22:37:50 +02:00
bool _init = false;
2025-04-20 17:10:57 +02:00
bool _isOn = false;
2025-08-08 20:01:31 +10:00
uint16_t _curr_color;
2025-09-03 18:17:37 +02:00
CRC32 display_crc;
int last_display_crc_value = 0;
2025-04-15 22:37:50 +02:00
public:
2025-04-20 17:10:57 +02:00
// there is a margin in y...
2025-09-20 21:45:13 +02:00
#if defined(EINK_DISPLAY_MODEL)
2025-09-02 13:56:24 +08:00
GxEPDDisplay() : DisplayDriver(128, 128), display(EINK_DISPLAY_MODEL(PIN_DISPLAY_CS, PIN_DISPLAY_DC, PIN_DISPLAY_RST, PIN_DISPLAY_BUSY)) {}
#else
GxEPDDisplay() : DisplayDriver(128, 128), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) {}
#endif
2025-04-15 22:37:50 +02:00
bool begin();
bool isOn() override {return _isOn;};
2025-04-15 22:37:50 +02:00
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setCursor(int x, int y) override;
void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
uint16_t getTextWidth(const char* str) override;
2025-04-15 22:37:50 +02:00
void endFrame() override;
};