Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ CRGB leds2[FASTLED_IND_NUM_LEDS];
#define InitialMQTTConnectionTimeout 10 // time estimated (s) before the board is connected to MQTT
#define subjectSYStoMQTT "/SYStoMQTT"
#define subjectMQTTtoSYSset "/commands/MQTTtoSYS/config"

#define TimeToResetAtStart 5000 // Time we allow the user at start for the reset command by button press
/*-------------------DEFINE LOG LEVEL----------------------*/
#ifndef LOG_LEVEL
# define LOG_LEVEL LOG_LEVEL_NOTICE
Expand Down
26 changes: 20 additions & 6 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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() {}
Expand Down