stub input HAL

This commit is contained in:
Xuan Son Nguyen 2026-01-23 16:25:02 +01:00
parent 5783faed33
commit fa05eba8a1
4 changed files with 129 additions and 9 deletions

85
lib/hal/HalInput.cpp Normal file
View File

@ -0,0 +1,85 @@
#include "HalInput.h"
#include <esp_sleep.h>
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
}

40
lib/hal/HalInput.h Normal file
View File

@ -0,0 +1,40 @@
#pragma once
#include <Arduino.h>
#if CROSSPOINT_EMULATED == 0
#include <InputManager.h>
#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

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <InputManager.h> #include <HalInput.h>
class MappedInputManager { class MappedInputManager {
public: public:

View File

@ -2,7 +2,7 @@
#include <HalDisplay.h> #include <HalDisplay.h>
#include <Epub.h> #include <Epub.h>
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include <InputManager.h> #include <HalInput.h>
#include <HalStorage.h> #include <HalStorage.h>
#include <SPI.h> #include <SPI.h>
#include <builtinFonts/all.h> #include <builtinFonts/all.h>
@ -184,8 +184,7 @@ void verifyWakeupLongPress() {
if (abort) { if (abort) {
// Button released too early. Returning to sleep. // Button released too early. Returning to sleep.
// IMPORTANT: Re-arm the wakeup trigger before sleeping again // 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); inputManager.setupGpioWakeup();
esp_deep_sleep_start();
} }
} }
@ -208,11 +207,7 @@ void enterDeepSleep() {
einkDisplay.deepSleep(); einkDisplay.deepSleep();
Serial.printf("[%lu] [ ] Power button press calibration value: %lu ms\n", millis(), t2 - t1); Serial.printf("[%lu] [ ] Power button press calibration value: %lu ms\n", millis(), t2 - t1);
Serial.printf("[%lu] [ ] Entering deep sleep.\n", millis()); Serial.printf("[%lu] [ ] Entering deep sleep.\n", millis());
esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW); inputManager.setupGpioWakeup();
// 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();
} }
void onGoHome(); void onGoHome();