From fa05eba8a1ca1fca07160a21c5f95eb6aa56c27c Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Fri, 23 Jan 2026 16:25:02 +0100 Subject: [PATCH] stub input HAL --- lib/hal/HalInput.cpp | 85 ++++++++++++++++++++++++++++++++++++++++ lib/hal/HalInput.h | 40 +++++++++++++++++++ src/MappedInputManager.h | 2 +- src/main.cpp | 11 ++---- 4 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 lib/hal/HalInput.cpp create mode 100644 lib/hal/HalInput.h diff --git a/lib/hal/HalInput.cpp b/lib/hal/HalInput.cpp new file mode 100644 index 00000000..0c55f1e7 --- /dev/null +++ b/lib/hal/HalInput.cpp @@ -0,0 +1,85 @@ +#include "HalInput.h" +#include + +void HalInput::begin() { +#if CROSSPOINT_EMULATED == 0 + inputMgr.begin(); +#endif +} + +void HalInput::update() { +#if CROSSPOINT_EMULATED == 0 + inputMgr.update(); +#else + // TODO +#endif +} + +bool HalInput::isPressed(uint8_t buttonIndex) const { +#if CROSSPOINT_EMULATED == 0 + return inputMgr.isPressed(buttonIndex); +#else + // TODO + return false; +#endif +} + +bool HalInput::wasPressed(uint8_t buttonIndex) const { +#if CROSSPOINT_EMULATED == 0 + return inputMgr.wasPressed(buttonIndex); +#else + // TODO + return false; +#endif +} + +bool HalInput::wasAnyPressed() const { +#if CROSSPOINT_EMULATED == 0 + return inputMgr.wasAnyPressed(); +#else + // TODO + return false; +#endif +} + +bool HalInput::wasReleased(uint8_t buttonIndex) const { +#if CROSSPOINT_EMULATED == 0 + return inputMgr.wasReleased(buttonIndex); +#else + // TODO + return false; +#endif +} + +bool HalInput::wasAnyReleased() const { +#if CROSSPOINT_EMULATED == 0 + return inputMgr.wasAnyReleased(); +#else + // TODO + return false; +#endif +} + +unsigned long HalInput::getHeldTime() const { +#if CROSSPOINT_EMULATED == 0 + return inputMgr.getHeldTime(); +#else + // TODO + return 0; +#endif +} + +void HalInput::setupGpioWakeup() { +#if CROSSPOINT_EMULATED == 0 + esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW); + // Ensure that the power button has been released to avoid immediately turning back on if you're holding it + while (isPressed(InputManager::BTN_POWER)) { + delay(50); + update(); + } + // Enter Deep Sleep + esp_deep_sleep_start(); +#else + // TODO +#endif +} diff --git a/lib/hal/HalInput.h b/lib/hal/HalInput.h new file mode 100644 index 00000000..a06771b4 --- /dev/null +++ b/lib/hal/HalInput.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +#if CROSSPOINT_EMULATED == 0 +#include +#endif + +class HalInput { +#if CROSSPOINT_EMULATED == 0 + InputManager inputMgr; +#endif + + public: + HalInput() = default; + void begin(); + + void update(); + bool isPressed(uint8_t buttonIndex) const; + bool wasPressed(uint8_t buttonIndex) const; + bool wasAnyPressed() const; + bool wasReleased(uint8_t buttonIndex) const; + bool wasAnyReleased() const; + unsigned long getHeldTime() const; + + void setupGpioWakeup(); + + // Button indices + static constexpr uint8_t BTN_BACK = 0; + static constexpr uint8_t BTN_CONFIRM = 1; + static constexpr uint8_t BTN_LEFT = 2; + static constexpr uint8_t BTN_RIGHT = 3; + static constexpr uint8_t BTN_UP = 4; + static constexpr uint8_t BTN_DOWN = 5; + static constexpr uint8_t BTN_POWER = 6; +}; + +#if CROSSPOINT_EMULATED == 1 +using InputManager = HalInput; +#endif diff --git a/src/MappedInputManager.h b/src/MappedInputManager.h index 62065fe9..66573915 100644 --- a/src/MappedInputManager.h +++ b/src/MappedInputManager.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class MappedInputManager { public: diff --git a/src/main.cpp b/src/main.cpp index 89b800a0..82d9a0c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include @@ -184,8 +184,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(); + inputManager.setupGpioWakeup(); } } @@ -208,11 +207,7 @@ void enterDeepSleep() { einkDisplay.deepSleep(); Serial.printf("[%lu] [ ] Power button press calibration value: %lu ms\n", millis(), t2 - t1); Serial.printf("[%lu] [ ] Entering deep sleep.\n", millis()); - esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW); - // Ensure that the power button has been released to avoid immediately turning back on if you're holding it - waitForPowerRelease(); - // Enter Deep Sleep - esp_deep_sleep_start(); + inputManager.setupGpioWakeup(); } void onGoHome();