Updates to X3-specific display and power button handling

Centralize display initialization and power button verification for X3 devices
This commit is contained in:
Justin Mitchell
2026-02-15 19:58:37 -05:00
parent 961a704aaa
commit cd4303a8fb
5 changed files with 89 additions and 99 deletions
+13 -3
View File
@@ -30,13 +30,18 @@ class HalGPIO {
DeviceType _deviceType = DeviceType::X4;
int _detectAdcValue = 0;
int _batteryPin = BAT_GPIO0;
bool _useI2C = false;
uint8_t _i2cAddr = 0;
uint8_t _socRegister = 0;
// I2C fuel gauge configuration for X3 battery monitoring
bool _batteryUseI2C = false; // Whether to use I2C fuel gauge (X3) vs ADC (X4)
uint8_t _batteryI2cAddr = 0; // I2C address of fuel gauge chip
uint8_t _batterySocRegister = 0; // Register address for state-of-charge
public:
HalGPIO() = default;
// Inline device type helpers for cleaner downstream checks
inline bool deviceIsX3() const { return _deviceType == DeviceType::X3; }
inline bool deviceIsX4() const { return _deviceType == DeviceType::X4; }
// Start button GPIO and setup SPI for screen and SD card
void begin();
@@ -52,6 +57,11 @@ class HalGPIO {
// Setup wake up GPIO and enter deep sleep
void startDeepSleep();
// Verify power button was held long enough after wakeup.
// If verification fails, enters deep sleep and does not return.
// Should only be called when wakeup reason is PowerButton.
void verifyPowerButtonWakeup(uint16_t requiredDurationMs, bool shortPressAllowed);
// Get battery percentage (range 0-100)
int getBatteryPercentage() const;