|
| 1 | +#include "E213Display.h" |
| 2 | + |
| 3 | +#include "../../MeshCore.h" |
| 4 | + |
| 5 | +bool E213Display::begin() { |
| 6 | + if (_init) return true; |
| 7 | + |
| 8 | + powerOn(); |
| 9 | + display.begin(); |
| 10 | + |
| 11 | + // Set to landscape mode rotated 180 degrees |
| 12 | + display.setRotation(3); |
| 13 | + |
| 14 | + _init = true; |
| 15 | + _isOn = true; |
| 16 | + |
| 17 | + clear(); |
| 18 | + display.fastmodeOn(); // Enable fast mode for quicker (partial) updates |
| 19 | + |
| 20 | + return true; |
| 21 | +} |
| 22 | + |
| 23 | +void E213Display::powerOn() { |
| 24 | +#ifdef PIN_VEXT_EN |
| 25 | + pinMode(PIN_VEXT_EN, OUTPUT); |
| 26 | + digitalWrite(PIN_VEXT_EN, LOW); // Active low |
| 27 | + delay(50); // Allow power to stabilize |
| 28 | +#endif |
| 29 | +} |
| 30 | + |
| 31 | +void E213Display::powerOff() { |
| 32 | +#ifdef PIN_VEXT_EN |
| 33 | + digitalWrite(PIN_VEXT_EN, HIGH); // Turn off power |
| 34 | +#endif |
| 35 | +} |
| 36 | + |
| 37 | +void E213Display::turnOn() { |
| 38 | + if (!_init) begin(); |
| 39 | + powerOn(); |
| 40 | + _isOn = true; |
| 41 | +} |
| 42 | + |
| 43 | +void E213Display::turnOff() { |
| 44 | + powerOff(); |
| 45 | + _isOn = false; |
| 46 | +} |
| 47 | + |
| 48 | +void E213Display::clear() { |
| 49 | + display.clear(); |
| 50 | +} |
| 51 | + |
| 52 | +void E213Display::startFrame(Color bkg) { |
| 53 | + // Fill screen with white first to ensure clean background |
| 54 | + display.fillRect(0, 0, width(), height(), WHITE); |
| 55 | + if (bkg == LIGHT) { |
| 56 | + // Fill with black if light background requested (inverted for e-ink) |
| 57 | + display.fillRect(0, 0, width(), height(), BLACK); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +void E213Display::setTextSize(int sz) { |
| 62 | + // The library handles text size internally |
| 63 | + display.setTextSize(sz); |
| 64 | +} |
| 65 | + |
| 66 | +void E213Display::setColor(Color c) { |
| 67 | + // implemented in individual display methods |
| 68 | +} |
| 69 | + |
| 70 | +void E213Display::setCursor(int x, int y) { |
| 71 | + display.setCursor(x, y); |
| 72 | +} |
| 73 | + |
| 74 | +void E213Display::print(const char *str) { |
| 75 | + display.print(str); |
| 76 | +} |
| 77 | + |
| 78 | +void E213Display::fillRect(int x, int y, int w, int h) { |
| 79 | + display.fillRect(x, y, w, h, BLACK); |
| 80 | +} |
| 81 | + |
| 82 | +void E213Display::drawRect(int x, int y, int w, int h) { |
| 83 | + display.drawRect(x, y, w, h, BLACK); |
| 84 | +} |
| 85 | + |
| 86 | +void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) { |
| 87 | + // Width in bytes for bitmap processing |
| 88 | + uint16_t widthInBytes = (w + 7) / 8; |
| 89 | + |
| 90 | + // Process the bitmap row by row |
| 91 | + for (int by = 0; by < h; by++) { |
| 92 | + // Scan across the row bit by bit |
| 93 | + for (int bx = 0; bx < w; bx++) { |
| 94 | + // Get the current bit using MSB ordering (like GxEPDDisplay) |
| 95 | + uint16_t byteOffset = (by * widthInBytes) + (bx / 8); |
| 96 | + uint8_t bitMask = 0x80 >> (bx & 7); |
| 97 | + bool bitSet = bits[byteOffset] & bitMask; |
| 98 | + |
| 99 | + // If the bit is set, draw the pixel |
| 100 | + if (bitSet) { |
| 101 | + display.drawPixel(x + bx, y + by, BLACK); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +uint16_t E213Display::getTextWidth(const char *str) { |
| 108 | + int16_t x1, y1; |
| 109 | + uint16_t w, h; |
| 110 | + display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h); |
| 111 | + return w; |
| 112 | +} |
| 113 | + |
| 114 | +void E213Display::endFrame() { |
| 115 | + display.update(); |
| 116 | +} |
0 commit comments