Merge pull request #211 from fdlamotte/techo-display

Techo display
This commit is contained in:
ripplebiz 2025-04-21 16:44:52 +10:00 committed by GitHub
commit a81e8b4b54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 176 additions and 4 deletions

View file

@ -0,0 +1,99 @@
#include "GxEPDDisplay.h"
bool GxEPDDisplay::begin() {
display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0));
SPI1.begin();
display.init(115200, true, 2, false);
display.setRotation(3);
#ifdef TECHO_ZOOM
display.setFont(&FreeMono9pt7b);
#endif
display.setPartialWindow(0, 0, display.width(), display.height());
display.fillScreen(GxEPD_WHITE);
display.display(true);
#if DISP_BACKLIGHT
pinMode(DISP_BACKLIGHT, OUTPUT);
#endif
_init = true;
return true;
}
void GxEPDDisplay::turnOn() {
if (!_init) begin();
#if DISP_BACKLIGHT
digitalWrite(DISP_BACKLIGHT, HIGH);
_isOn = true;
#endif
}
void GxEPDDisplay::turnOff() {
#if DISP_BACKLIGHT
digitalWrite(DISP_BACKLIGHT, LOW);
#endif
_isOn = false;
}
void GxEPDDisplay::clear() {
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
}
void GxEPDDisplay::startFrame(Color bkg) {
display.fillScreen(GxEPD_WHITE);
}
void GxEPDDisplay::setTextSize(int sz) {
display.setTextSize(sz);
}
void GxEPDDisplay::setColor(Color c) {
display.setTextColor(GxEPD_BLACK);
}
void GxEPDDisplay::setCursor(int x, int y) {
#ifdef TECHO_ZOOM
x = x + (x >> 1);
y = y + (y >> 1);
#endif
display.setCursor(x, (y+10));
}
void GxEPDDisplay::print(const char* str) {
display.print(str);
}
void GxEPDDisplay::fillRect(int x, int y, int w, int h) {
#ifdef TECHO_ZOOM
x = x + (x >> 1);
y = y + (y >> 1);
w = w + (w >> 1);
h = h + (h >> 1);
#endif
display.fillRect(x, y, w, h, GxEPD_BLACK);
}
void GxEPDDisplay::drawRect(int x, int y, int w, int h) {
#ifdef TECHO_ZOOM
x = x + (x >> 1);
y = y + (y >> 1);
w = w + (w >> 1);
h = h + (h >> 1);
#endif
display.drawRect(x, y, w, h, GxEPD_BLACK);
}
void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
#ifdef TECHO_ZOOM
x = x + (x >> 1);
y = y + (y >> 1);
w = w + (w >> 1);
h = h + (h >> 1);
#endif
display.drawBitmap(x*1.5, (y*1.5) + 10, bits, w, h, GxEPD_BLACK);
}
void GxEPDDisplay::endFrame() {
display.display(true);
}

View file

@ -0,0 +1,51 @@
#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>
#include <Fonts/FreeMono9pt7b.h>
#define GxEPD2_DISPLAY_CLASS GxEPD2_BW
#define GxEPD2_DRIVER_CLASS GxEPD2_150_BN // DEPG0150BN 200x200, SSD1681, (FPC8101), TTGO T5 V2.4.1
#include <epd/GxEPD2_150_BN.h> // 1.54" b/w
#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
class GxEPDDisplay : public DisplayDriver {
GxEPD2_BW<GxEPD2_150_BN, 200> display;
bool _init = false;
bool _isOn = false;
public:
// there is a margin in y...
GxEPDDisplay() : DisplayDriver(200, 200-10), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) {
}
bool begin();
bool isOn() override {return _isOn;};
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;
void endFrame() override;
};