Skip to content

Commit

Permalink
[TRIGGER] Enable reset at start when InputGPIO is used (#1447)
Browse files Browse the repository at this point in the history
TimeToResetAtStart defines the start period
  • Loading branch information
1technophile authored Feb 10, 2023
1 parent 799d8e2 commit 159d362
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
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

0 comments on commit 159d362

Please sign in to comment.