mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 15:17:37 +03:00
60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
#include <HalGPIO.h>
|
|
#include <SPI.h>
|
|
#include <esp_sleep.h>
|
|
|
|
void HalGPIO::begin() {
|
|
inputMgr.begin();
|
|
SPI.begin(EPD_SCLK, SPI_MISO, EPD_MOSI, EPD_CS);
|
|
pinMode(BAT_GPIO0, INPUT);
|
|
pinMode(UART0_RXD, INPUT);
|
|
}
|
|
|
|
void HalGPIO::update() {
|
|
inputMgr.update();
|
|
}
|
|
|
|
bool HalGPIO::isPressed(uint8_t buttonIndex) const {
|
|
return inputMgr.isPressed(buttonIndex);
|
|
}
|
|
|
|
bool HalGPIO::wasPressed(uint8_t buttonIndex) const {
|
|
return inputMgr.wasPressed(buttonIndex);
|
|
}
|
|
|
|
bool HalGPIO::wasAnyPressed() const {
|
|
return inputMgr.wasAnyPressed();
|
|
}
|
|
|
|
bool HalGPIO::wasReleased(uint8_t buttonIndex) const {
|
|
return inputMgr.wasReleased(buttonIndex);
|
|
}
|
|
|
|
bool HalGPIO::wasAnyReleased() const {
|
|
return inputMgr.wasAnyReleased();
|
|
}
|
|
|
|
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);
|
|
// Ensure that the power button has been released to avoid immediately turning back on if you're holding it
|
|
while (inputMgr.isPressed(BTN_POWER)) {
|
|
delay(50);
|
|
inputMgr.update();
|
|
}
|
|
// Enter Deep Sleep
|
|
esp_deep_sleep_start();
|
|
}
|
|
|
|
int HalGPIO::getBatteryPercentage() const {
|
|
static const BatteryMonitor battery = BatteryMonitor(BAT_GPIO0);
|
|
return battery.readPercentage();
|
|
}
|
|
|
|
bool HalGPIO::isUsbConnected() const {
|
|
// U0RXD/GPIO20 reads HIGH when USB is connected
|
|
return digitalRead(UART0_RXD) == HIGH;
|
|
}
|