Compare commits

..

3 Commits

Author SHA1 Message Date
Xuan Son Nguyen
181588c068 missing startDeepSleep in one place 2026-01-23 23:25:20 +01:00
Xuan Son Nguyen
6db4f60080 clang format 2026-01-23 23:16:59 +01:00
Xuan Son Nguyen
6abb4e3b30 fix build 2026-01-23 23:10:04 +01:00
8 changed files with 33 additions and 79 deletions

View File

@ -49,8 +49,7 @@ void GfxRenderer::drawPixel(const int x, const int y, const bool state) const {
rotateCoordinates(x, y, &rotatedX, &rotatedY);
// Bounds checking against physical panel dimensions
if (rotatedX < 0 || rotatedX >= HalDisplay::DISPLAY_WIDTH || rotatedY < 0 ||
rotatedY >= HalDisplay::DISPLAY_HEIGHT) {
if (rotatedX < 0 || rotatedX >= HalDisplay::DISPLAY_WIDTH || rotatedY < 0 || rotatedY >= HalDisplay::DISPLAY_HEIGHT) {
Serial.printf("[%lu] [GFX] !! Outside range (%d, %d) -> (%d, %d)\n", millis(), x, y, rotatedX, rotatedY);
return;
}
@ -397,9 +396,7 @@ void GfxRenderer::invertScreen() const {
}
}
void GfxRenderer::displayBuffer(const HalDisplay::RefreshMode refreshMode) const {
display.displayBuffer(refreshMode);
}
void GfxRenderer::displayBuffer(const HalDisplay::RefreshMode refreshMode) const { display.displayBuffer(refreshMode); }
std::string GfxRenderer::truncatedText(const int fontId, const char* text, const int maxWidth,
const EpdFontFamily::Style style) const {

View File

@ -1,7 +1,7 @@
#pragma once
#include <HalDisplay.h>
#include <EpdFontFamily.h>
#include <HalDisplay.h>
#include <map>

View File

@ -7,15 +7,12 @@ HalDisplay::HalDisplay() : einkDisplay(EPD_SCLK, EPD_MOSI, EPD_CS, EPD_DC, EPD_R
HalDisplay::~HalDisplay() {}
void HalDisplay::begin() {
einkDisplay.begin();
}
void HalDisplay::begin() { einkDisplay.begin(); }
void HalDisplay::clearScreen(uint8_t color) const {
einkDisplay.clearScreen(color);
}
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 {
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);
}
@ -31,38 +28,24 @@ EInkDisplay::RefreshMode convertRefreshMode(HalDisplay::RefreshMode mode) {
}
}
void HalDisplay::displayBuffer(HalDisplay::RefreshMode mode) {
einkDisplay.displayBuffer(convertRefreshMode(mode));
}
void HalDisplay::displayBuffer(HalDisplay::RefreshMode mode) { einkDisplay.displayBuffer(convertRefreshMode(mode)); }
void HalDisplay::refreshDisplay(HalDisplay::RefreshMode mode, bool turnOffScreen) {
einkDisplay.refreshDisplay(convertRefreshMode(mode), turnOffScreen);
}
void HalDisplay::deepSleep() {
einkDisplay.deepSleep();
}
void HalDisplay::deepSleep() { einkDisplay.deepSleep(); }
uint8_t* HalDisplay::getFrameBuffer() const {
return einkDisplay.getFrameBuffer();
}
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::copyGrayscaleLsbBuffers(const uint8_t* lsbBuffer) { einkDisplay.copyGrayscaleLsbBuffers(lsbBuffer); }
void HalDisplay::copyGrayscaleMsbBuffers(const uint8_t* msbBuffer) {
einkDisplay.copyGrayscaleMsbBuffers(msbBuffer);
}
void HalDisplay::copyGrayscaleMsbBuffers(const uint8_t* msbBuffer) { einkDisplay.copyGrayscaleMsbBuffers(msbBuffer); }
void HalDisplay::cleanupGrayscaleBuffers(const uint8_t* bwBuffer) {
einkDisplay.cleanupGrayscaleBuffers(bwBuffer);
}
void HalDisplay::cleanupGrayscaleBuffers(const uint8_t* bwBuffer) { einkDisplay.cleanupGrayscaleBuffers(bwBuffer); }
void HalDisplay::displayGrayBuffer() {
einkDisplay.displayGrayBuffer();
}
void HalDisplay::displayGrayBuffer() { einkDisplay.displayGrayBuffer(); }

View File

@ -1,6 +1,6 @@
#pragma once
#include <EInkDisplay.h>
#include <Arduino.h>
#include <EInkDisplay.h>
class HalDisplay {
public:
@ -28,7 +28,8 @@ class HalDisplay {
// Frame buffer operations
void clearScreen(uint8_t color = 0xFF) const;
void drawImage(const uint8_t* imageData, uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool fromProgmem = false) const;
void drawImage(const uint8_t* imageData, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
bool fromProgmem = false) const;
void displayBuffer(RefreshMode mode = RefreshMode::FAST_REFRESH);
void refreshDisplay(RefreshMode mode = RefreshMode::FAST_REFRESH, bool turnOffScreen = false);

View File

@ -9,33 +9,19 @@ void HalGPIO::begin() {
pinMode(UART0_RXD, INPUT);
}
void HalGPIO::update() {
inputMgr.update();
}
void HalGPIO::update() { inputMgr.update(); }
bool HalGPIO::isPressed(uint8_t buttonIndex) const {
return inputMgr.isPressed(buttonIndex);
}
bool HalGPIO::isPressed(uint8_t buttonIndex) const { return inputMgr.isPressed(buttonIndex); }
bool HalGPIO::wasPressed(uint8_t buttonIndex) const {
return inputMgr.wasPressed(buttonIndex);
}
bool HalGPIO::wasPressed(uint8_t buttonIndex) const { return inputMgr.wasPressed(buttonIndex); }
bool HalGPIO::wasAnyPressed() const {
return inputMgr.wasAnyPressed();
}
bool HalGPIO::wasAnyPressed() const { return inputMgr.wasAnyPressed(); }
bool HalGPIO::wasReleased(uint8_t buttonIndex) const {
return inputMgr.wasReleased(buttonIndex);
}
bool HalGPIO::wasReleased(uint8_t buttonIndex) const { return inputMgr.wasReleased(buttonIndex); }
bool HalGPIO::wasAnyReleased() const {
return inputMgr.wasAnyReleased();
}
bool HalGPIO::wasAnyReleased() const { return inputMgr.wasAnyReleased(); }
unsigned long HalGPIO::getHeldTime() const {
return inputMgr.getHeldTime();
}
unsigned long HalGPIO::getHeldTime() const { return inputMgr.getHeldTime(); }
void HalGPIO::startDeepSleep() {
esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW);

View File

@ -1,8 +1,8 @@
#pragma once
#include <Arduino.h>
#include <InputManager.h>
#include <BatteryMonitor.h>
#include <InputManager.h>
// Display SPI pins (custom pins for XteinkX4, not hardware SPI defaults)
#define EPD_SCLK 8 // SPI Clock
@ -12,11 +12,11 @@
#define EPD_RST 5 // Reset
#define EPD_BUSY 6 // Busy
#define SPI_MISO 7 // SPI MISO, shared between SD card and display (Master In Slave Out)
#define SPI_MISO 7 // SPI MISO, shared between SD card and display (Master In Slave Out)
#define BAT_GPIO0 0 // Battery voltage
#define UART0_RXD 20 // Used for USB connection detection
#define UART0_RXD 20 // Used for USB connection detection
class HalGPIO {
#if CROSSPOINT_EMULATED == 0
@ -55,14 +55,4 @@ class HalGPIO {
static constexpr uint8_t BTN_UP = 4;
static constexpr uint8_t BTN_DOWN = 5;
static constexpr uint8_t BTN_POWER = 6;
private:
// emulation state
uint8_t currentState;
uint8_t lastState;
uint8_t pressedEvents;
uint8_t releasedEvents;
unsigned long lastDebounceTime;
unsigned long buttonPressStart;
unsigned long buttonPressFinish;
};

View File

@ -1,6 +1,6 @@
#pragma once
#include <HalDisplay.h>
#include <EpdFontFamily.h>
#include <HalDisplay.h>
#include <string>
#include <utility>

View File

@ -1,9 +1,9 @@
#include <Arduino.h>
#include <Epub.h>
#include <GfxRenderer.h>
#include <SDCardManager.h>
#include <HalGPIO.h>
#include <HalDisplay.h>
#include <HalGPIO.h>
#include <SDCardManager.h>
#include <SPI.h>
#include <builtinFonts/all.h>
@ -171,8 +171,7 @@ void verifyWakeupLongPress() {
if (abort) {
// Button released too early. Returning to sleep.
// IMPORTANT: Re-arm the wakeup trigger before sleeping again
esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW);
esp_deep_sleep_start();
gpio.startDeepSleep();
}
}
@ -341,8 +340,7 @@ void loop() {
// Check for any user activity (button press or release) or active background work
static unsigned long lastActivityTime = millis();
if (gpio.wasAnyPressed() || gpio.wasAnyReleased() ||
(currentActivity && currentActivity->preventAutoSleep())) {
if (gpio.wasAnyPressed() || gpio.wasAnyReleased() || (currentActivity && currentActivity->preventAutoSleep())) {
lastActivityTime = millis(); // Reset inactivity timer
}
@ -354,8 +352,7 @@ void loop() {
return;
}
if (gpio.isPressed(HalGPIO::BTN_POWER) &&
gpio.getHeldTime() > SETTINGS.getPowerButtonDuration()) {
if (gpio.isPressed(HalGPIO::BTN_POWER) && gpio.getHeldTime() > SETTINGS.getPowerButtonDuration()) {
enterDeepSleep();
// This should never be hit as `enterDeepSleep` calls esp_deep_sleep_start
return;