From 791da53c7b6799e37d729c015f0687aeefff4953 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 5 May 2025 15:54:31 +1000 Subject: [PATCH] * ST7789Display: now with SCALE_X,SCALE_Y * fix for GxEPDDisplay --- src/helpers/ui/GxEPDDisplay.h | 3 +-- src/helpers/ui/ST7789Display.cpp | 19 +++++++++++-------- src/helpers/ui/ST7789Display.h | 3 +-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/helpers/ui/GxEPDDisplay.h b/src/helpers/ui/GxEPDDisplay.h index d772d13..88aecaa 100644 --- a/src/helpers/ui/GxEPDDisplay.h +++ b/src/helpers/ui/GxEPDDisplay.h @@ -29,8 +29,7 @@ class GxEPDDisplay : public DisplayDriver { public: // there is a margin in y... - GxEPDDisplay() : DisplayDriver(200, 200-10), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) { - + GxEPDDisplay() : DisplayDriver(128, 64), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) { } bool begin(); diff --git a/src/helpers/ui/ST7789Display.cpp b/src/helpers/ui/ST7789Display.cpp index cc52215..d1a4aed 100644 --- a/src/helpers/ui/ST7789Display.cpp +++ b/src/helpers/ui/ST7789Display.cpp @@ -10,6 +10,9 @@ #define Y_OFFSET 1 // Vertical offset to prevent top row cutoff #endif +#define SCALE_X 1.875f // 240 / 128 +#define SCALE_Y 2.109375f // 135 / 64 + bool ST7789Display::begin() { if(!_isOn) { pinMode(PIN_TFT_VDD_CTL, OUTPUT); @@ -50,13 +53,13 @@ void ST7789Display::startFrame(Color bkg) { void ST7789Display::setTextSize(int sz) { switch(sz) { case 1 : - display.setFont(ArialMT_Plain_10); + display.setFont(ArialMT_Plain_16); break; case 2 : display.setFont(ArialMT_Plain_24); break; default: - display.setFont(ArialMT_Plain_10); + display.setFont(ArialMT_Plain_16); } } @@ -91,8 +94,8 @@ void ST7789Display::setColor(Color c) { } void ST7789Display::setCursor(int x, int y) { - _x = x + X_OFFSET; - _y = y + Y_OFFSET; + _x = x*SCALE_X + X_OFFSET; + _y = y*SCALE_Y + Y_OFFSET; } void ST7789Display::print(const char* str) { @@ -100,19 +103,19 @@ void ST7789Display::print(const char* str) { } void ST7789Display::fillRect(int x, int y, int w, int h) { - display.fillRect(x + X_OFFSET, y + Y_OFFSET, w, h); + display.fillRect(x*SCALE_X + X_OFFSET, y*SCALE_Y + Y_OFFSET, w*SCALE_X, h*SCALE_Y); } void ST7789Display::drawRect(int x, int y, int w, int h) { - display.drawRect(x + X_OFFSET, y + Y_OFFSET, w, h); + display.drawRect(x*SCALE_X + X_OFFSET, y*SCALE_Y + Y_OFFSET, w*SCALE_X, h*SCALE_Y); } void ST7789Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { - display.drawBitmap(x + X_OFFSET, y + Y_OFFSET, w, h, bits); + display.drawBitmap(x*SCALE_X + X_OFFSET, y*SCALE_Y + Y_OFFSET, w, h, bits); } uint16_t ST7789Display::getTextWidth(const char* str) { - return display.getStringWidth(str); + return display.getStringWidth(str) / SCALE_X; } void ST7789Display::endFrame() { diff --git a/src/helpers/ui/ST7789Display.h b/src/helpers/ui/ST7789Display.h index 338399f..b267a2c 100644 --- a/src/helpers/ui/ST7789Display.h +++ b/src/helpers/ui/ST7789Display.h @@ -14,9 +14,8 @@ class ST7789Display : public DisplayDriver { bool i2c_probe(TwoWire& wire, uint8_t addr); public: - ST7789Display() : DisplayDriver(240, 135), display(&SPI1, PIN_TFT_RST, PIN_TFT_DC, PIN_TFT_CS, GEOMETRY_RAWMODE, 240, 135) {_isOn = false;} + ST7789Display() : DisplayDriver(128, 64), display(&SPI1, PIN_TFT_RST, PIN_TFT_DC, PIN_TFT_CS, GEOMETRY_RAWMODE, 240, 135) {_isOn = false;} -// ST7789Display() : DisplayDriver(135, 240), display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST) { _isOn = false; } bool begin(); bool isOn() override { return _isOn; }