feat: two-tier factory reset, WiFi fallback chain, SettingsWebServer

Factory reset (F-015):
- InputManager gains MEDIUM_PRESSED state with mediumPressMs=5000
- 5s hold: wipe WiFi credentials only, restart on release
- 10s hold: full factory reset (WiFi wipe already done at 5s mark)
- New callbacks: setFactoryResetMediumPressCallback,
  setFactoryResetMediumPressReleaseCallback

WiFi fallback chain (F-016):
- Connection now cycles: saved creds → hardcoded failsafe → portal
- MAX_WIFI_FAILURES reduced 3→2 per stage
- Portal now reboots after saving credentials (fixes port 80 conflict
  between WiFiManager and AsyncWebServer)
- AP SSID sourced from netConfig.apSsid instead of hardcoded pattern
- clearWiFiCredentials() added to Networking for 5s reset gesture

SettingsWebServer (F-017):
- Instantiated in main.cpp alongside CommunicationRouter
- begin() called when network becomes ready (both WiFi paths)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 09:52:17 +03:00
co-authored by Claude Sonnet 4.6
parent ee73d4d2c4
commit df8426fce6
5 changed files with 183 additions and 124 deletions
+64 -39
View File
@@ -14,8 +14,8 @@ InputManager::InputManager()
: _initialized(false)
, _inputTaskHandle(nullptr) {
// Initialize factory reset button configuration
// GPIO 0, Active LOW (pull-up), 50ms debounce, 10s long press
_factoryResetButton.config = ButtonConfig(0, false, 50, 10000);
// GPIO 0, Active LOW (pull-up), 50ms debounce, 5s medium press, 10s long press
_factoryResetButton.config = ButtonConfig(0, false, 50, 5000, 10000);
_instance = this;
}
@@ -40,6 +40,7 @@ bool InputManager::begin() {
_factoryResetButton.lastRawState = false;
_factoryResetButton.stateChangeTime = millis();
_factoryResetButton.pressStartTime = 0;
_factoryResetButton.mediumPressTriggered = false;
_factoryResetButton.longPressTriggered = false;
// Create FreeRTOS task for input polling
@@ -81,6 +82,16 @@ void InputManager::setFactoryResetPressCallback(ButtonCallback callback) {
LOG_DEBUG(TAG, "InputManager: Factory reset press callback registered");
}
void InputManager::setFactoryResetMediumPressCallback(ButtonCallback callback) {
_factoryResetButton.config.onMediumPress = callback;
LOG_DEBUG(TAG, "InputManager: Factory reset medium press callback registered");
}
void InputManager::setFactoryResetMediumPressReleaseCallback(ButtonCallback callback) {
_factoryResetButton.config.onMediumPressRelease = callback;
LOG_DEBUG(TAG, "InputManager: Factory reset medium press release callback registered");
}
void InputManager::setFactoryResetLongPressCallback(ButtonCallback callback) {
_factoryResetButton.config.onLongPress = callback;
LOG_DEBUG(TAG, "InputManager: Factory reset long press callback registered");
@@ -175,94 +186,108 @@ bool InputManager::readButtonState(const ButtonData& button) const {
void InputManager::updateButton(ButtonData& button) {
uint32_t now = millis();
bool currentState = readButtonState(button);
// State machine for button handling
switch (button.state) {
case ButtonState::IDLE:
// Waiting for button press
if (currentState && !button.lastRawState) {
// Button just pressed - start debouncing
button.state = ButtonState::DEBOUNCING_PRESS;
button.stateChangeTime = now;
LOG_DEBUG(TAG, "InputManager: Button press detected on GPIO %d - debouncing",
LOG_DEBUG(TAG, "InputManager: Button press detected on GPIO %d - debouncing",
button.config.pin);
}
break;
case ButtonState::DEBOUNCING_PRESS:
// Debouncing press
if (!currentState) {
// Button released during debounce - false trigger
button.state = ButtonState::IDLE;
LOG_DEBUG(TAG, "InputManager: False trigger on GPIO %d (released during debounce)",
LOG_DEBUG(TAG, "InputManager: False trigger on GPIO %d (released during debounce)",
button.config.pin);
} else if (now - button.stateChangeTime >= button.config.debounceMs) {
// Debounce time passed - confirm press
button.state = ButtonState::LONG_PRESS_PENDING;
button.pressStartTime = now;
button.mediumPressTriggered = false;
button.longPressTriggered = false;
LOG_INFO(TAG, "InputManager: Button press confirmed on GPIO %d",
LOG_INFO(TAG, "InputManager: Button press confirmed on GPIO %d",
button.config.pin);
}
break;
case ButtonState::LONG_PRESS_PENDING:
// Button is pressed, waiting to see if it's a long press
if (!currentState) {
// Button released before long press threshold - it's a short press
// Released before medium press threshold — short press
button.state = ButtonState::DEBOUNCING_RELEASE;
button.stateChangeTime = now;
LOG_INFO(TAG, "InputManager: Short press detected on GPIO %d (held for %lums)",
LOG_INFO(TAG, "InputManager: Short press on GPIO %d (held %lums)",
button.config.pin, now - button.pressStartTime);
} else if (now - button.pressStartTime >= button.config.mediumPressMs) {
// Medium press threshold reached
button.state = ButtonState::MEDIUM_PRESSED;
button.mediumPressTriggered = true;
LOG_WARNING(TAG, "InputManager: MEDIUM PRESS on GPIO %d (held %lums)",
button.config.pin, now - button.pressStartTime);
if (button.config.onMediumPress) {
button.config.onMediumPress();
}
}
break;
case ButtonState::MEDIUM_PRESSED:
if (!currentState) {
// Released between medium and long threshold
button.state = ButtonState::DEBOUNCING_RELEASE;
button.stateChangeTime = now;
LOG_INFO(TAG, "InputManager: Medium press released on GPIO %d (held %lums)",
button.config.pin, now - button.pressStartTime);
} else if (now - button.pressStartTime >= button.config.longPressMs) {
// Long press threshold reached
button.state = ButtonState::LONG_PRESSED;
button.longPressTriggered = true;
LOG_WARNING(TAG, "InputManager: LONG PRESS DETECTED on GPIO %d (held for %lums)",
LOG_WARNING(TAG, "InputManager: LONG PRESS on GPIO %d (held %lums)",
button.config.pin, now - button.pressStartTime);
// Trigger long press callback
if (button.config.onLongPress) {
button.config.onLongPress();
}
}
break;
case ButtonState::LONG_PRESSED:
// Long press has been triggered, waiting for release
if (!currentState) {
button.state = ButtonState::DEBOUNCING_RELEASE;
button.stateChangeTime = now;
LOG_INFO(TAG, "InputManager: Long press released on GPIO %d (total duration: %lums)",
LOG_INFO(TAG, "InputManager: Long press released on GPIO %d (held %lums)",
button.config.pin, now - button.pressStartTime);
}
break;
case ButtonState::DEBOUNCING_RELEASE:
// Debouncing release
if (currentState) {
// Button pressed again during release debounce - go back to pressed state
// Re-pressed during release debounce
button.state = ButtonState::LONG_PRESS_PENDING;
LOG_DEBUG(TAG, "InputManager: Button re-pressed during release debounce on GPIO %d",
LOG_DEBUG(TAG, "InputManager: Button re-pressed during release debounce on GPIO %d",
button.config.pin);
} else if (now - button.stateChangeTime >= button.config.debounceMs) {
// Debounce time passed - confirm release
button.state = ButtonState::IDLE;
// If it was a short press (not long press), trigger the press callback
if (!button.longPressTriggered && button.config.onPress) {
LOG_INFO(TAG, "InputManager: Triggering press callback for GPIO %d",
button.config.pin);
button.config.onPress();
if (!button.mediumPressTriggered && !button.longPressTriggered) {
// Short press
if (button.config.onPress) {
LOG_INFO(TAG, "InputManager: Short press callback for GPIO %d", button.config.pin);
button.config.onPress();
}
} else if (button.mediumPressTriggered && !button.longPressTriggered) {
// Released between medium and long threshold
if (button.config.onMediumPressRelease) {
LOG_INFO(TAG, "InputManager: Medium press release callback for GPIO %d", button.config.pin);
button.config.onMediumPressRelease();
}
}
LOG_DEBUG(TAG, "InputManager: Button release confirmed on GPIO %d",
button.config.pin);
// Long press: action already fired at threshold, no release callback needed
LOG_DEBUG(TAG, "InputManager: Button release confirmed on GPIO %d", button.config.pin);
}
break;
}
// Store last raw state for edge detection
button.lastRawState = currentState;
}