| 238 | } |
| 239 | |
| 240 | void HalGPIO::verifyPowerButtonWakeup(uint16_t requiredDurationMs, bool shortPressAllowed) { |
| 241 | if (shortPressAllowed) { |
| 242 | // Fast path - no duration check needed |
| 243 | return; |
| 244 | } |
| 245 | // TODO: Intermittent edge case remains: a single tap followed by another single tap |
| 246 | // can still power on the device. Tighten wake debounce/state handling here. |
| 247 | |
| 248 | // Calibrate: subtract boot time already elapsed, assuming button held since boot |
| 249 | const uint16_t calibration = millis(); |
| 250 | const uint16_t calibratedDuration = (calibration < requiredDurationMs) ? (requiredDurationMs - calibration) : 1; |
| 251 | |
| 252 | const auto start = millis(); |
| 253 | inputMgr.update(); |
| 254 | // inputMgr.isPressed() may take up to ~500ms to return correct state |
| 255 | while (!inputMgr.isPressed(BTN_POWER) && millis() - start < 1000) { |
| 256 | delay(10); |
| 257 | inputMgr.update(); |
| 258 | } |
| 259 | if (inputMgr.isPressed(BTN_POWER)) { |
| 260 | do { |
| 261 | delay(10); |
| 262 | inputMgr.update(); |
| 263 | } while (inputMgr.isPressed(BTN_POWER) && inputMgr.getPowerButtonHeldTime() < calibratedDuration); |
| 264 | if (inputMgr.getPowerButtonHeldTime() < calibratedDuration) { |
| 265 | startDeepSleep(); |
| 266 | } |
| 267 | } else { |
| 268 | startDeepSleep(); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | bool HalGPIO::isUsbConnected() const { |
| 273 | if (deviceIsX3()) { |
no test coverage detected