<img width="605" height="454" alt="image" src="https://github.com/user-attachments/assets/bfd84afe-3b58-436e-9a5d-539af3ec3d4e" /> Actualized "Last" sleep screen setting from previous PRs, rebranded as a ~~`Seamless Sleep`~~ `Page as Sleep Screen` option with more improvements. https://github.com/user-attachments/assets/59029ba6-007e-4841-abfa-f680d7e98b79 --- New option: `Page as Sleep Screen` - `Never (default)`, `After Timeout`, `Always` When enabled, it seamlessly sleeps on timeout or power off, making a fast refresh for the moon icon. When waking up, we still show the last page, instead of the boot screen, making it fully seamless. I tried different icons such as "refresh arrow" and others, but they looked not as nice as 3 simple dots. With this mode, the device turns off 4 seconds faster. And has 6 seconds less delay when turning back on. Much more responsive. Previously, even a 10-minute timeout sometimes wasn't enough, and I'd worry about seeing the book cover. It's now easier to use a shorter sleep timeout: if I get distracted during a reading session but don't want to stop, the new screen is much more inviting to come back to. --- Did you use AI tools to help write this code? _**PARTIALLY**_. --- Test v1.3.0 firmware.bin file [download](https://github.com/user-attachments/files/28015193/firmware.zip) Based on PRs #410 and #495 Closes #400, #1649 --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
95 lines
3.3 KiB
C++
95 lines
3.3 KiB
C++
#include <HalDisplay.h>
|
|
#include <HalGPIO.h>
|
|
|
|
// Global HalDisplay instance
|
|
HalDisplay display;
|
|
|
|
#define SD_SPI_MISO 7
|
|
|
|
HalDisplay::HalDisplay() : einkDisplay(EPD_SCLK, EPD_MOSI, EPD_CS, EPD_DC, EPD_RST, EPD_BUSY) {}
|
|
|
|
HalDisplay::~HalDisplay() {}
|
|
|
|
void HalDisplay::begin(bool seamless) {
|
|
// Set X3-specific panel mode before initializing.
|
|
if (gpio.deviceIsX3()) {
|
|
einkDisplay.setDisplayX3();
|
|
}
|
|
|
|
einkDisplay.begin();
|
|
|
|
// Request resync after specific wakeup events to ensure clean display state.
|
|
// Skip when seamless=true so the current screen content is preserved.
|
|
if (!seamless) {
|
|
const auto wakeupReason = gpio.getWakeupReason();
|
|
if (wakeupReason == HalGPIO::WakeupReason::PowerButton || wakeupReason == HalGPIO::WakeupReason::AfterFlash ||
|
|
wakeupReason == HalGPIO::WakeupReason::Other) {
|
|
einkDisplay.requestResync();
|
|
}
|
|
}
|
|
}
|
|
|
|
void HalDisplay::clearScreen(uint8_t color) const { einkDisplay.clearScreen(color); }
|
|
|
|
void HalDisplay::drawImage(const uint8_t* imageData, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
|
|
bool fromProgmem) const {
|
|
einkDisplay.drawImage(imageData, x, y, w, h, fromProgmem);
|
|
}
|
|
|
|
void HalDisplay::drawImageTransparent(const uint8_t* imageData, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
|
|
bool fromProgmem) const {
|
|
einkDisplay.drawImageTransparent(imageData, x, y, w, h, fromProgmem);
|
|
}
|
|
|
|
EInkDisplay::RefreshMode convertRefreshMode(HalDisplay::RefreshMode mode) {
|
|
switch (mode) {
|
|
case HalDisplay::FULL_REFRESH:
|
|
return EInkDisplay::FULL_REFRESH;
|
|
case HalDisplay::HALF_REFRESH:
|
|
return EInkDisplay::HALF_REFRESH;
|
|
case HalDisplay::FAST_REFRESH:
|
|
default:
|
|
return EInkDisplay::FAST_REFRESH;
|
|
}
|
|
}
|
|
|
|
void HalDisplay::displayBuffer(HalDisplay::RefreshMode mode, bool turnOffScreen) {
|
|
if (gpio.deviceIsX3() && mode == RefreshMode::HALF_REFRESH) {
|
|
einkDisplay.requestResync(1);
|
|
}
|
|
|
|
einkDisplay.displayBuffer(convertRefreshMode(mode), turnOffScreen);
|
|
}
|
|
|
|
void HalDisplay::refreshDisplay(HalDisplay::RefreshMode mode, bool turnOffScreen) {
|
|
if (gpio.deviceIsX3() && mode == RefreshMode::HALF_REFRESH) {
|
|
einkDisplay.requestResync(1);
|
|
}
|
|
|
|
einkDisplay.refreshDisplay(convertRefreshMode(mode), turnOffScreen);
|
|
}
|
|
|
|
void HalDisplay::deepSleep() { einkDisplay.deepSleep(); }
|
|
|
|
uint8_t* HalDisplay::getFrameBuffer() const { return einkDisplay.getFrameBuffer(); }
|
|
|
|
void HalDisplay::copyGrayscaleBuffers(const uint8_t* lsbBuffer, const uint8_t* msbBuffer) {
|
|
einkDisplay.copyGrayscaleBuffers(lsbBuffer, msbBuffer);
|
|
}
|
|
|
|
void HalDisplay::copyGrayscaleLsbBuffers(const uint8_t* lsbBuffer) { einkDisplay.copyGrayscaleLsbBuffers(lsbBuffer); }
|
|
|
|
void HalDisplay::copyGrayscaleMsbBuffers(const uint8_t* msbBuffer) { einkDisplay.copyGrayscaleMsbBuffers(msbBuffer); }
|
|
|
|
void HalDisplay::cleanupGrayscaleBuffers(const uint8_t* bwBuffer) { einkDisplay.cleanupGrayscaleBuffers(bwBuffer); }
|
|
|
|
void HalDisplay::displayGrayBuffer(bool turnOffScreen) { einkDisplay.displayGrayBuffer(turnOffScreen); }
|
|
|
|
uint16_t HalDisplay::getDisplayWidth() const { return einkDisplay.getDisplayWidth(); }
|
|
|
|
uint16_t HalDisplay::getDisplayHeight() const { return einkDisplay.getDisplayHeight(); }
|
|
|
|
uint16_t HalDisplay::getDisplayWidthBytes() const { return einkDisplay.getDisplayWidthBytes(); }
|
|
|
|
uint32_t HalDisplay::getBufferSize() const { return einkDisplay.getBufferSize(); }
|