Use the base class to optimize screen display code.

This commit is contained in:
Quency-D
2025-08-14 17:43:46 +08:00
parent fad4a7fb51
commit aa7f9d8df6
2 changed files with 40 additions and 91 deletions

View File

@@ -2,7 +2,7 @@
#include "../../MeshCore.h" #include "../../MeshCore.h"
EInkDetectionResult E213Display::detectEInk() BaseDisplay* E213Display::detectEInk()
{ {
// Test 1: Logic of BUSY pin // Test 1: Logic of BUSY pin
@@ -23,38 +23,37 @@ EInkDetectionResult E213Display::detectEInk()
// Test complete. Release pin // Test complete. Release pin
pinMode(DISP_RST, INPUT); pinMode(DISP_RST, INPUT);
if (busyLogic == LOW) if (busyLogic == LOW) {
return V_LCMEN213EFC1; #ifdef VISION_MASTER_E213
else // busy HIGH return new EInkDisplay_VisionMasterE213 ;
return V_E0213A367; #else
return new EInkDisplay_WirelessPaperV1_1 ;
#endif
} else {// busy HIGH
#ifdef VISION_MASTER_E213
return new EInkDisplay_VisionMasterE213V1_1 ;
#else
return new EInkDisplay_WirelessPaperV1_1_1 ;
#endif
}
} }
bool E213Display::begin() { bool E213Display::begin() {
if (_init) return true; if (_init) return true;
powerOn(); powerOn();
_version = detectEInk(); if(display==NULL) {
if(_version==V_LCMEN213EFC1) { display = detectEInk();
display.begin();
// Set to landscape mode rotated 180 degrees
display.setRotation(3);
} else{
display1.begin();
// Set to landscape mode rotated 180 degrees
display1.setRotation(3);
} }
display->begin();
// Set to landscape mode rotated 180 degrees
display->setRotation(3);
_init = true; _init = true;
_isOn = true; _isOn = true;
clear(); clear();
if(_version==V_LCMEN213EFC1) { display->fastmodeOn(); // Enable fast mode for quicker (partial) updates
display.fastmodeOn(); // Enable fast mode for quicker (partial) updates
} else{
display1.fastmodeOn(); // Enable fast mode for quicker (partial) updates
}
return true; return true;
} }
@@ -93,37 +92,23 @@ void E213Display::turnOff() {
} }
void E213Display::clear() { void E213Display::clear() {
if(_version==V_LCMEN213EFC1) { display->clear();
display.clear();
} else{
display1.clear();
}
} }
void E213Display::startFrame(Color bkg) { void E213Display::startFrame(Color bkg) {
// Fill screen with white first to ensure clean background // Fill screen with white first to ensure clean background
if(_version==V_LCMEN213EFC1) { display->fillRect(0, 0, width(), height(), WHITE);
display.fillRect(0, 0, width(), height(), WHITE);
} else{
display1.fillRect(0, 0, width(), height(), WHITE);
}
if (bkg == LIGHT) { if (bkg == LIGHT) {
// Fill with black if light background requested (inverted for e-ink) // Fill with black if light background requested (inverted for e-ink)
if(_version==V_LCMEN213EFC1) { display->fillRect(0, 0, width(), height(), BLACK);
display.fillRect(0, 0, width(), height(), BLACK);
} else{
display1.fillRect(0, 0, width(), height(), BLACK);
}
} }
} }
void E213Display::setTextSize(int sz) { void E213Display::setTextSize(int sz) {
// The library handles text size internally // The library handles text size internally
if(_version==V_LCMEN213EFC1) { display->setTextSize(sz);
display.setTextSize(sz);
} else{
display1.setTextSize(sz);
}
} }
void E213Display::setColor(Color c) { void E213Display::setColor(Color c) {
@@ -131,35 +116,19 @@ void E213Display::setColor(Color c) {
} }
void E213Display::setCursor(int x, int y) { void E213Display::setCursor(int x, int y) {
if(_version==V_LCMEN213EFC1) { display->setCursor(x, y);
display.setCursor(x, y);
} else{
display1.setCursor(x, y);
}
} }
void E213Display::print(const char *str) { void E213Display::print(const char *str) {
if(_version==V_LCMEN213EFC1) { display->print(str);
display.print(str);
} else {
display1.print(str);
}
} }
void E213Display::fillRect(int x, int y, int w, int h) { void E213Display::fillRect(int x, int y, int w, int h) {
if(_version==V_LCMEN213EFC1) { display->fillRect(x, y, w, h, BLACK);
display.fillRect(x, y, w, h, BLACK);
} else {
display1.fillRect(x, y, w, h, BLACK);
}
} }
void E213Display::drawRect(int x, int y, int w, int h) { void E213Display::drawRect(int x, int y, int w, int h) {
if(_version==V_LCMEN213EFC1) { display->drawRect(x, y, w, h, BLACK);
display.drawRect(x, y, w, h, BLACK);
} else {
display1.drawRect(x, y, w, h, BLACK);
}
} }
void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) { void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
@@ -177,11 +146,7 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
// If the bit is set, draw the pixel // If the bit is set, draw the pixel
if (bitSet) { if (bitSet) {
if(_version==V_LCMEN213EFC1) { display->drawPixel(x + bx, y + by, BLACK);
display.drawPixel(x + bx, y + by, BLACK);
} else {
display1.drawPixel(x + bx, y + by, BLACK);
}
} }
} }
} }
@@ -190,18 +155,10 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
uint16_t E213Display::getTextWidth(const char *str) { uint16_t E213Display::getTextWidth(const char *str) {
int16_t x1, y1; int16_t x1, y1;
uint16_t w, h; uint16_t w, h;
if(_version==V_LCMEN213EFC1) { display->getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
} else {
display1.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
}
return w; return w;
} }
void E213Display::endFrame() { void E213Display::endFrame() {
if(_version==V_LCMEN213EFC1) { display->update();
display.update();
} else {
display1.update();
}
} }

View File

@@ -6,27 +6,19 @@
#include <Wire.h> #include <Wire.h>
#include <heltec-eink-modules.h> #include <heltec-eink-modules.h>
enum EInkDetectionResult {
V_LCMEN213EFC1 = 0, // Initial version
V_E0213A367 = 1, // E213 PCB marked V1.1 (Mid 2025)
};
// Display driver for E213 e-ink display // Display driver for E213 e-ink display
class E213Display : public DisplayDriver { class E213Display : public DisplayDriver {
#ifdef VISION_MASTER_E213 BaseDisplay* display=NULL;
EInkDisplay_VisionMasterE213 display;
EInkDisplay_VisionMasterE213V1_1 display1;
#else
EInkDisplay_WirelessPaperV1_1 display;
EInkDisplay_WirelessPaperV1_1_1 display1;
#endif
EInkDetectionResult _version =V_LCMEN213EFC1;
bool _init = false; bool _init = false;
bool _isOn = false; bool _isOn = false;
public: public:
E213Display() : DisplayDriver(250, 122) {} E213Display() : DisplayDriver(250, 122) {}
~E213Display(){
if(display!=NULL) {
delete display;
}
}
bool begin(); bool begin();
bool isOn() override { return _isOn; } bool isOn() override { return _isOn; }
void turnOn() override; void turnOn() override;
@@ -44,7 +36,7 @@ public:
void endFrame() override; void endFrame() override;
private: private:
EInkDetectionResult detectEInk(); BaseDisplay* detectEInk();
void powerOn(); void powerOn();
void powerOff(); void powerOff();
}; };