Merge pull request #3687 from fdlamotte/display_prefs

ui: add some parameters to the cli (mostly regarding eink behaviour)
This commit is contained in:
fdlamotte authored and GitHub committed 2026-10-29 08:35:36 -04:00
commit bd4be350c5
12 files changed
+784 -133

No files matched your search

+2 -2
View File
@@ -25,9 +25,9 @@ public:
virtual bool isEink() { return false; } // default to non-eink, override in eink drivers
virtual void forceFullRefresh() {} // next refresh will be full for eink
virtual void turnOn() = 0;
virtual void turnOn(int max_partial) { turnOn(); }
virtual void turnOff() = 0;
virtual void blankScreen() {} // to cleanly erase screen before turning off
virtual void powerOff() {}
virtual void turnOff(bool blank) { turnOff(); }
virtual void clear() = 0;
virtual void startFrame(ColorVal bkg = UIColor::window_bkg) = 0;
virtual void setTextSize(int sz) = 0;
+43 -28
View File
@@ -1,11 +1,6 @@
#include "GxEPDDisplay.h"
#ifdef EXP_PIN_BACKLIGHT
#include <PCA9557.h>
extern PCA9557 expander;
#endif
#ifndef DISPLAY_ROTATION
#define DISPLAY_ROTATION 3
#endif
@@ -52,7 +47,7 @@ bool GxEPDDisplay::begin() {
}
display.setPartialWindow(0, 0, display.width(), display.height());
resetPartialRefreshCounter();
_partial_refresh_count = 0;
#if DISP_BACKLIGHT
digitalWrite(DISP_BACKLIGHT, LOW);
@@ -65,26 +60,43 @@ bool GxEPDDisplay::begin() {
void GxEPDDisplay::turnOn() {
if (!_init) begin();
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
digitalWrite(DISP_BACKLIGHT, HIGH);
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
expander.digitalWrite(EXP_PIN_BACKLIGHT, HIGH);
#endif
if (!_isOn) {
_isOn = true;
}
}
void GxEPDDisplay::powerOff() {
display.hibernate();
void GxEPDDisplay::turnOn(int max_partial) {
setMaxPartialRefresh(max_partial);
turnOn();
}
void GxEPDDisplay::turnOff() { // Only stops refresh
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
digitalWrite(DISP_BACKLIGHT, LOW);
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
expander.digitalWrite(EXP_PIN_BACKLIGHT, LOW);
#endif
// 24x24 sleep icon, MSB-first (matches GxEPDDisplay::drawXbm)
static const uint8_t sleep_icon_24x24[] = {
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xe0, 0x0e, 0x03, 0xc0, 0x18,
0x0f, 0x80, 0x70, 0x1f, 0x80, 0xff, 0x3f, 0x80, 0xff, 0x3f, 0x00, 0x00,
0x7f, 0x3f, 0x00, 0x7f, 0x3f, 0x00, 0xff, 0x0e, 0x00, 0xff, 0x1c, 0x7c,
0xff, 0xbf, 0x7c, 0xff, 0xbf, 0x38, 0xff, 0xc0, 0x7c, 0xff, 0xe0, 0x7c,
0xff, 0xf0, 0x00, 0x7f, 0xfc, 0x00, 0x7f, 0xff, 0xf8, 0x3f, 0xff, 0xf0,
0x1f, 0xff, 0xf0, 0x0f, 0xff, 0xe0, 0x07, 0xff, 0x80, 0x01, 0xff, 0x00
};
void GxEPDDisplay::drawSleepIcon() {
const int W = 24, H = 24;
int x = (int)(display.width() / scale_x) - W; // top-right, logical coordinates
int y = 0;
display.fillRect((x - 5) * scale_x - 1, y * scale_y, (W+5) * scale_x + 2, (H-2) * scale_y + 1, GxEPD_WHITE);
_curr_color = GxEPD_BLACK;
drawXbm(x, y, sleep_icon_24x24, W, H);
display.display(true);
}
void GxEPDDisplay::turnOff(bool blank) {
if (blank) {
blankScreen();
} else {
drawSleepIcon();
}
_isOn = false;
last_display_crc_value=0;
}
@@ -94,8 +106,10 @@ void GxEPDDisplay::blankScreen() {
// no full refresh needed at wakeup
display.clearScreen(0xFF); // Clears microcontroller side RAM
display.writeScreenBuffer(0xFF); // Forces 0xFF (White) into the display controller's history registers
resetPartialRefreshCounter();
last_display_crc_value=0;
_partial_refresh_count = 0;
last_display_crc_value = 0;
// we can hibernate as screen has been cleaned
display.hibernate();
}
void GxEPDDisplay::clear() {
@@ -108,15 +122,18 @@ void GxEPDDisplay::startFrame(ColorVal bkg) {
display.fillScreen(bkg);
display.setTextColor(_curr_color = UIColor::primary_txt);
display_crc.reset();
if (_cycles_before_full_refresh != 0) {
display.setPartialWindow(0, 0, display.width(), display.height());
} else {
if (_force_full_refresh
|| (_max_partial_refresh > 0
&& _partial_refresh_count >= _max_partial_refresh)) {
// forces a full wipe of the screen ...
display.clearScreen(0xFF); // Clears microcontroller side RAM
display.writeScreenBuffer(0xFF); // Forces 0xFF (White) into the display controller's history registers
// we'll need a partial refresh after that (whatever crc value is)
last_display_crc_value = 0;
resetPartialRefreshCounter();
_partial_refresh_count = 0;
_force_full_refresh = false;
} else {
display.setPartialWindow(0, 0, display.width(), display.height());
}
}
@@ -223,9 +240,7 @@ void GxEPDDisplay::endFrame() {
uint32_t crc = display_crc.finalize();
if (crc != last_display_crc_value) {
display.display(true);
if (_cycles_before_full_refresh > 0) {
_cycles_before_full_refresh--;
}
_partial_refresh_count++;
}
last_display_crc_value = crc;
}
+10 -13
View File
@@ -16,12 +16,6 @@
#include "DisplayDriver.h"
#ifndef EINK_MAX_PARTIAL_REFRESH
// 60 to prevent ghosting when refreshing every minute ...
// set to -1 to disable the counter
#define EINK_MAX_PARTIAL_REFRESH -1
#endif
class GxEPDDisplay : public DisplayDriver {
#if defined(EINK_DISPLAY_MODEL)
@@ -42,8 +36,9 @@ class GxEPDDisplay : public DisplayDriver {
uint16_t _curr_color;
CRC32 display_crc;
int last_display_crc_value = 0;
int _cycles_before_full_refresh;
int max_partial_refresh = EINK_MAX_PARTIAL_REFRESH; // so this can be changed by an option after
bool _force_full_refresh = false;
int _partial_refresh_count = 0;
int _max_partial_refresh = 0;
public:
#if defined(EINK_DISPLAY_MODEL)
@@ -56,12 +51,13 @@ public:
bool isOn() override { return _isOn; }
bool isEink() override { return true; }
void forceFullRefresh() override { _cycles_before_full_refresh = 0; };
void resetPartialRefreshCounter() { _cycles_before_full_refresh = max_partial_refresh; };
void forceFullRefresh() override { _force_full_refresh = true; }
void turnOn(int max_partial) override;
void turnOn() override;
void turnOff() override;
void blankScreen() override;
void powerOff() override;
void turnOff(bool blank) override;
void turnOff() override { turnOff(false); }
virtual void blankScreen();
virtual void setMaxPartialRefresh(int count) {_max_partial_refresh = count; }
void clear() override;
void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override;
@@ -71,6 +67,7 @@ public:
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
void drawSleepIcon();
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
};