|
| 1 | + |
| 2 | +#include "GxEPDDisplay.h" |
| 3 | + |
| 4 | +bool GxEPDDisplay::begin() { |
| 5 | + display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0)); |
| 6 | + SPI1.begin(); |
| 7 | + display.init(115200, true, 2, false); |
| 8 | + display.setRotation(3); |
| 9 | + #ifdef TECHO_ZOOM |
| 10 | + display.setFont(&FreeMono9pt7b); |
| 11 | + #endif |
| 12 | + display.setPartialWindow(0, 0, display.width(), display.height()); |
| 13 | + |
| 14 | + display.fillScreen(GxEPD_WHITE); |
| 15 | + display.display(true); |
| 16 | + #if DISP_BACKLIGHT |
| 17 | + pinMode(DISP_BACKLIGHT, OUTPUT); |
| 18 | + #endif |
| 19 | + _init = true; |
| 20 | + return true; |
| 21 | +} |
| 22 | + |
| 23 | +void GxEPDDisplay::turnOn() { |
| 24 | + if (!_init) begin(); |
| 25 | +#if DISP_BACKLIGHT |
| 26 | + digitalWrite(DISP_BACKLIGHT, HIGH); |
| 27 | + _isOn = true; |
| 28 | +#endif |
| 29 | +} |
| 30 | + |
| 31 | +void GxEPDDisplay::turnOff() { |
| 32 | +#if DISP_BACKLIGHT |
| 33 | + digitalWrite(DISP_BACKLIGHT, LOW); |
| 34 | +#endif |
| 35 | + _isOn = false; |
| 36 | +} |
| 37 | + |
| 38 | +void GxEPDDisplay::clear() { |
| 39 | + display.fillScreen(GxEPD_WHITE); |
| 40 | + display.setTextColor(GxEPD_BLACK); |
| 41 | +} |
| 42 | + |
| 43 | +void GxEPDDisplay::startFrame(Color bkg) { |
| 44 | + display.fillScreen(GxEPD_WHITE); |
| 45 | +} |
| 46 | + |
| 47 | +void GxEPDDisplay::setTextSize(int sz) { |
| 48 | + display.setTextSize(sz); |
| 49 | +} |
| 50 | + |
| 51 | +void GxEPDDisplay::setColor(Color c) { |
| 52 | + display.setTextColor(GxEPD_BLACK); |
| 53 | +} |
| 54 | + |
| 55 | +void GxEPDDisplay::setCursor(int x, int y) { |
| 56 | +#ifdef TECHO_ZOOM |
| 57 | + x = x + (x >> 1); |
| 58 | + y = y + (y >> 1); |
| 59 | +#endif |
| 60 | + display.setCursor(x, (y+10)); |
| 61 | +} |
| 62 | + |
| 63 | +void GxEPDDisplay::print(const char* str) { |
| 64 | + display.print(str); |
| 65 | +} |
| 66 | + |
| 67 | +void GxEPDDisplay::fillRect(int x, int y, int w, int h) { |
| 68 | +#ifdef TECHO_ZOOM |
| 69 | + x = x + (x >> 1); |
| 70 | + y = y + (y >> 1); |
| 71 | + w = w + (w >> 1); |
| 72 | + h = h + (h >> 1); |
| 73 | +#endif |
| 74 | + display.fillRect(x, y, w, h, GxEPD_BLACK); |
| 75 | +} |
| 76 | + |
| 77 | +void GxEPDDisplay::drawRect(int x, int y, int w, int h) { |
| 78 | +#ifdef TECHO_ZOOM |
| 79 | + x = x + (x >> 1); |
| 80 | + y = y + (y >> 1); |
| 81 | + w = w + (w >> 1); |
| 82 | + h = h + (h >> 1); |
| 83 | +#endif |
| 84 | + display.drawRect(x, y, w, h, GxEPD_BLACK); |
| 85 | +} |
| 86 | + |
| 87 | +void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { |
| 88 | +#ifdef TECHO_ZOOM |
| 89 | + x = x + (x >> 1); |
| 90 | + y = y + (y >> 1); |
| 91 | + w = w + (w >> 1); |
| 92 | + h = h + (h >> 1); |
| 93 | +#endif |
| 94 | + display.drawBitmap(x*1.5, (y*1.5) + 10, bits, w, h, GxEPD_BLACK); |
| 95 | +} |
| 96 | + |
| 97 | +void GxEPDDisplay::endFrame() { |
| 98 | + display.display(true); |
| 99 | +} |
0 commit comments