* ST7789Display: now with SCALE_X,SCALE_Y
* fix for GxEPDDisplay
This commit is contained in:
@@ -29,8 +29,7 @@ class GxEPDDisplay : public DisplayDriver {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// there is a margin in y...
|
// 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();
|
bool begin();
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
#define Y_OFFSET 1 // Vertical offset to prevent top row cutoff
|
#define Y_OFFSET 1 // Vertical offset to prevent top row cutoff
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SCALE_X 1.875f // 240 / 128
|
||||||
|
#define SCALE_Y 2.109375f // 135 / 64
|
||||||
|
|
||||||
bool ST7789Display::begin() {
|
bool ST7789Display::begin() {
|
||||||
if(!_isOn) {
|
if(!_isOn) {
|
||||||
pinMode(PIN_TFT_VDD_CTL, OUTPUT);
|
pinMode(PIN_TFT_VDD_CTL, OUTPUT);
|
||||||
@@ -50,13 +53,13 @@ void ST7789Display::startFrame(Color bkg) {
|
|||||||
void ST7789Display::setTextSize(int sz) {
|
void ST7789Display::setTextSize(int sz) {
|
||||||
switch(sz) {
|
switch(sz) {
|
||||||
case 1 :
|
case 1 :
|
||||||
display.setFont(ArialMT_Plain_10);
|
display.setFont(ArialMT_Plain_16);
|
||||||
break;
|
break;
|
||||||
case 2 :
|
case 2 :
|
||||||
display.setFont(ArialMT_Plain_24);
|
display.setFont(ArialMT_Plain_24);
|
||||||
break;
|
break;
|
||||||
default:
|
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) {
|
void ST7789Display::setCursor(int x, int y) {
|
||||||
_x = x + X_OFFSET;
|
_x = x*SCALE_X + X_OFFSET;
|
||||||
_y = y + Y_OFFSET;
|
_y = y*SCALE_Y + Y_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ST7789Display::print(const char* str) {
|
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) {
|
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) {
|
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) {
|
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) {
|
uint16_t ST7789Display::getTextWidth(const char* str) {
|
||||||
return display.getStringWidth(str);
|
return display.getStringWidth(str) / SCALE_X;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ST7789Display::endFrame() {
|
void ST7789Display::endFrame() {
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ class ST7789Display : public DisplayDriver {
|
|||||||
|
|
||||||
bool i2c_probe(TwoWire& wire, uint8_t addr);
|
bool i2c_probe(TwoWire& wire, uint8_t addr);
|
||||||
public:
|
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 begin();
|
||||||
|
|
||||||
bool isOn() override { return _isOn; }
|
bool isOn() override { return _isOn; }
|
||||||
|
|||||||
Reference in New Issue
Block a user