22
33#include " ../../MeshCore.h"
44
5+ BaseDisplay* E213Display::detectEInk ()
6+ {
7+ // Test 1: Logic of BUSY pin
8+
9+ // Determines controller IC manufacturer
10+ // Fitipower: busy when LOW
11+ // Solomon Systech: busy when HIGH
12+
13+ // Force display BUSY by holding reset pin active
14+ pinMode (DISP_RST, OUTPUT);
15+ digitalWrite (DISP_RST, LOW);
16+
17+ delay (10 );
18+
19+ // Read whether pin is HIGH or LOW while busy
20+ pinMode (DISP_BUSY, INPUT);
21+ bool busyLogic = digitalRead (DISP_BUSY);
22+
23+ // Test complete. Release pin
24+ pinMode (DISP_RST, INPUT);
25+
26+ if (busyLogic == LOW) {
27+ #ifdef VISION_MASTER_E213
28+ return new EInkDisplay_VisionMasterE213 ;
29+ #else
30+ return new EInkDisplay_WirelessPaperV1_1 ;
31+ #endif
32+ } else {// busy HIGH
33+ #ifdef VISION_MASTER_E213
34+ return new EInkDisplay_VisionMasterE213V1_1 ;
35+ #else
36+ return new EInkDisplay_WirelessPaperV1_1_1 ;
37+ #endif
38+ }
39+ }
40+
541bool E213Display::begin () {
642 if (_init) return true ;
743
844 powerOn ();
9- display.begin ();
10-
45+ if (display==NULL ) {
46+ display = detectEInk ();
47+ }
48+ display->begin ();
1149 // Set to landscape mode rotated 180 degrees
12- display. setRotation (3 );
50+ display-> setRotation (3 );
1351
1452 _init = true ;
1553 _isOn = true ;
1654
1755 clear ();
18- display. fastmodeOn (); // Enable fast mode for quicker (partial) updates
56+ display-> fastmodeOn (); // Enable fast mode for quicker (partial) updates
1957
2058 return true ;
2159}
2260
2361void E213Display::powerOn () {
2462#ifdef PIN_VEXT_EN
2563 pinMode (PIN_VEXT_EN, OUTPUT);
64+ #ifdef PIN_VEXT_EN_ACTIVE
65+ digitalWrite (PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
66+ #else
2667 digitalWrite (PIN_VEXT_EN, LOW); // Active low
68+ #endif
2769 delay (50 ); // Allow power to stabilize
2870#endif
2971}
3072
3173void E213Display::powerOff () {
3274#ifdef PIN_VEXT_EN
75+ #ifdef PIN_VEXT_EN_ACTIVE
76+ digitalWrite (PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE);
77+ #else
3378 digitalWrite (PIN_VEXT_EN, HIGH); // Turn off power
3479#endif
80+ #endif
3581}
3682
3783void E213Display::turnOn () {
@@ -46,41 +92,43 @@ void E213Display::turnOff() {
4692}
4793
4894void E213Display::clear () {
49- display.clear ();
95+ display->clear ();
96+
5097}
5198
5299void E213Display::startFrame (Color bkg) {
53100 // Fill screen with white first to ensure clean background
54- display.fillRect (0 , 0 , width (), height (), WHITE);
101+ display->fillRect (0 , 0 , width (), height (), WHITE);
102+
55103 if (bkg == LIGHT) {
56104 // Fill with black if light background requested (inverted for e-ink)
57- display. fillRect (0 , 0 , width (), height (), BLACK);
105+ display-> fillRect (0 , 0 , width (), height (), BLACK);
58106 }
59107}
60108
61109void E213Display::setTextSize (int sz) {
62110 // The library handles text size internally
63- display. setTextSize (sz);
111+ display-> setTextSize (sz);
64112}
65113
66114void E213Display::setColor (Color c) {
67115 // implemented in individual display methods
68116}
69117
70118void E213Display::setCursor (int x, int y) {
71- display. setCursor (x, y);
119+ display-> setCursor (x, y);
72120}
73121
74122void E213Display::print (const char *str) {
75- display. print (str);
123+ display-> print (str);
76124}
77125
78126void E213Display::fillRect (int x, int y, int w, int h) {
79- display. fillRect (x, y, w, h, BLACK);
127+ display-> fillRect (x, y, w, h, BLACK);
80128}
81129
82130void E213Display::drawRect (int x, int y, int w, int h) {
83- display. drawRect (x, y, w, h, BLACK);
131+ display-> drawRect (x, y, w, h, BLACK);
84132}
85133
86134void E213Display::drawXbm (int x, int y, const uint8_t *bits, int w, int h) {
@@ -98,7 +146,7 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
98146
99147 // If the bit is set, draw the pixel
100148 if (bitSet) {
101- display. drawPixel (x + bx, y + by, BLACK);
149+ display-> drawPixel (x + bx, y + by, BLACK);
102150 }
103151 }
104152 }
@@ -107,10 +155,10 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
107155uint16_t E213Display::getTextWidth (const char *str) {
108156 int16_t x1, y1;
109157 uint16_t w, h;
110- display. getTextBounds (str, 0 , 0 , &x1, &y1, &w, &h);
158+ display-> getTextBounds (str, 0 , 0 , &x1, &y1, &w, &h);
111159 return w;
112160}
113161
114162void E213Display::endFrame () {
115- display. update ();
163+ display-> update ();
116164}
0 commit comments