@@ -59,44 +59,58 @@ bool E213Display::begin() {
5959}
6060
6161void E213Display::powerOn () {
62+ if (_periph_power) {
63+ _periph_power->claim ();
64+ } else {
6265#ifdef PIN_VEXT_EN
63- pinMode (PIN_VEXT_EN, OUTPUT);
66+ pinMode (PIN_VEXT_EN, OUTPUT);
6467#ifdef PIN_VEXT_EN_ACTIVE
65- digitalWrite (PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
68+ digitalWrite (PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE);
6669#else
67- digitalWrite (PIN_VEXT_EN, LOW); // Active low
70+ digitalWrite (PIN_VEXT_EN, LOW); // Active low
6871#endif
69- delay (50 ); // Allow power to stabilize
7072#endif
73+ }
74+ delay (50 ); // Allow power to stabilize
7175}
7276
7377void E213Display::powerOff () {
78+ if (_periph_power) {
79+ _periph_power->release ();
80+ } else {
7481#ifdef PIN_VEXT_EN
7582#ifdef PIN_VEXT_EN_ACTIVE
76- digitalWrite (PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE);
83+ digitalWrite (PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE);
7784#else
78- digitalWrite (PIN_VEXT_EN, HIGH); // Turn off power
85+ digitalWrite (PIN_VEXT_EN, HIGH); // Turn off power
7986#endif
8087#endif
88+ }
8189}
8290
8391void E213Display::turnOn () {
8492 if (!_init) begin ();
85- powerOn ();
93+ else if (!_isOn) {
94+ powerOn ();
95+ display->fastmodeOn (); // Reinitialize display controller after power was cut
96+ }
8697 _isOn = true ;
8798}
8899
89100void E213Display::turnOff () {
90- powerOff ();
91- _isOn = false ;
101+ if (_isOn) {
102+ powerOff ();
103+ _isOn = false ;
104+ }
92105}
93106
94107void E213Display::clear () {
95108 display->clear ();
96-
97109}
98110
99111void E213Display::startFrame (Color bkg) {
112+ display_crc.reset ();
113+
100114 // Fill screen with white first to ensure clean background
101115 display->fillRect (0 , 0 , width (), height (), WHITE);
102116
@@ -107,31 +121,50 @@ void E213Display::startFrame(Color bkg) {
107121}
108122
109123void E213Display::setTextSize (int sz) {
124+ display_crc.update <int >(sz);
110125 // The library handles text size internally
111126 display->setTextSize (sz);
112127}
113128
114129void E213Display::setColor (Color c) {
130+ display_crc.update <Color>(c);
115131 // implemented in individual display methods
116132}
117133
118134void E213Display::setCursor (int x, int y) {
135+ display_crc.update <int >(x);
136+ display_crc.update <int >(y);
119137 display->setCursor (x, y);
120138}
121139
122140void E213Display::print (const char *str) {
141+ display_crc.update <char >(str, strlen (str));
123142 display->print (str);
124143}
125144
126145void E213Display::fillRect (int x, int y, int w, int h) {
146+ display_crc.update <int >(x);
147+ display_crc.update <int >(y);
148+ display_crc.update <int >(w);
149+ display_crc.update <int >(h);
127150 display->fillRect (x, y, w, h, BLACK);
128151}
129152
130153void E213Display::drawRect (int x, int y, int w, int h) {
154+ display_crc.update <int >(x);
155+ display_crc.update <int >(y);
156+ display_crc.update <int >(w);
157+ display_crc.update <int >(h);
131158 display->drawRect (x, y, w, h, BLACK);
132159}
133160
134161void E213Display::drawXbm (int x, int y, const uint8_t *bits, int w, int h) {
162+ display_crc.update <int >(x);
163+ display_crc.update <int >(y);
164+ display_crc.update <int >(w);
165+ display_crc.update <int >(h);
166+ display_crc.update <uint8_t >(bits, w * h / 8 );
167+
135168 // Width in bytes for bitmap processing
136169 uint16_t widthInBytes = (w + 7 ) / 8 ;
137170
@@ -160,5 +193,9 @@ uint16_t E213Display::getTextWidth(const char *str) {
160193}
161194
162195void E213Display::endFrame () {
196+ uint32_t crc = display_crc.finalize ();
197+ if (crc != last_display_crc_value) {
163198 display->update ();
199+ last_display_crc_value = crc;
200+ }
164201}
0 commit comments