Преглед изворни кода

* ST7789Display: now with SCALE_X,SCALE_Y
* fix for GxEPDDisplay

Scott Powell пре 1 година
родитељ
комит
791da53c7b
3 измењених фајлова са 13 додато и 12 уклоњено
  1. 1 2
      src/helpers/ui/GxEPDDisplay.h
  2. 11 8
      src/helpers/ui/ST7789Display.cpp
  3. 1 2
      src/helpers/ui/ST7789Display.h

+ 1 - 2
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();

+ 11 - 8
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() {

+ 1 - 2
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; }