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