[TRIGGER] Enable reset at start when InputGPIO is used (#1447)

TimeToResetAtStart defines the start period
This commit is contained in:
Florian authored and GitHub committed 2023-02-10 17:04:58 -06:00
1 parent 799d8e2e85
commit 159d362f2a
2 files changed
+21 -7

No files matched your search

+20 -6
View File
@@ -1113,13 +1113,11 @@ void saveConfigCallback() {
}
# ifdef TRIGGER_GPIO
void checkButton() { // Check if button is pressed so as to reset the credentials and parameters stored into the flash, code from tzapu/wifimanager examples
# if defined(INPUT_GPIO) && defined(ZsensorGPIOInput) && INPUT_GPIO == TRIGGER_GPIO
MeasureGPIOInput();
# else
// check for button press
/**
* Identify a long button press to trigger a reset
* */
void blockingWaitForReset() {
if (digitalRead(TRIGGER_GPIO) == LOW) {
// poor mans debounce/press-hold, code not ideal for production
delay(50);
if (digitalRead(TRIGGER_GPIO) == LOW) {
Log.trace(F("Trigger button Pressed" CR));
@@ -1131,7 +1129,23 @@ void checkButton() { // Check if button is pressed so as to reset the credential
}
}
}
}
/**
* Check if button is pressed so as to reset the credentials and parameters stored into the flash
* */
void checkButton() {
unsigned long timeFromStart = millis();
// Identify if the reset button is pushed at start
if (timeFromStart < TimeToResetAtStart) {
blockingWaitForReset();
} else { // When we are not at start we either check the button as a regular input (ZsensorGPIOInput used) or for a reset
# if defined(INPUT_GPIO) && defined(ZsensorGPIOInput) && INPUT_GPIO == TRIGGER_GPIO
MeasureGPIOInput();
# else
blockingWaitForReset();
# endif
}
}
# else
void checkButton() {}