Allow trigger gpio and input gpio to be the same pin.

This will provide the expected funtionality for the reset trigger when the button is pressed for more than 10 seconds.
Also allows the same pin to be used as an actuator/relay trigger if pressed for less than 10 seconds.
This commit is contained in:
h2zero authored and Florian committed 2021-07-09 21:52:40 -05:00
1 parent 45a0184320
commit 5e11690b69
3 files changed
+23 -4

No files matched your search

+16 -1
View File
@@ -29,7 +29,9 @@
#include "User_config.h"
#ifdef ZsensorGPIOInput
# if defined(TRIGGER_GPIO) && INPUT_GPIO == TRIGGER_GPIO
unsigned long resetTime = 0;
# endif
unsigned long lastDebounceTime = 0;
int InputState = 3; // Set to 3 so that it reads on startup
int lastInputState = 3;
@@ -57,6 +59,19 @@ void MeasureGPIOInput() {
// delay, so take it as the actual current state:
# if defined(ESP8266) || defined(ESP32)
yield();
# endif
# if defined(TRIGGER_GPIO) && INPUT_GPIO == TRIGGER_GPIO
if (reading == LOW) {
if (resetTime == 0) {
resetTime = millis();
} else if ((millis() - resetTime) > 10000) {
Log.trace(F("Button Held" CR));
Log.notice(F("Erasing ESP Config, restarting" CR));
setup_wifimanager(true);
}
} else {
resetTime = 0;
}
# endif
// if the Input state has changed:
if (reading != InputState) {
+3 -3
View File
@@ -37,13 +37,13 @@ extern void MQTTtoONOFF(char* topicOri, JsonObject& RFdata);
#define ONKey "setON"
#define OFFKey "setOFF"
#ifndef ACTUATOR_ON
# define ACTUATOR_ON LOW
# define ACTUATOR_ON LOW // 0 or 1, set to the output level of the gpio pin to turn the actuator on.
#endif
#ifndef ACTUATOR_ONOFF_DEFAULT
# define ACTUATOR_ONOFF_DEFAULT !ACTUATOR_ON
# define ACTUATOR_ONOFF_DEFAULT !ACTUATOR_ON // ACTUATOR_ON or !ACTUATOR_ON, set to the state desired on reset.
#endif
#ifndef ACTUATOR_BUTTON_TRIGGER_LEVEL
# define ACTUATOR_BUTTON_TRIGGER_LEVEL LOW
# define ACTUATOR_BUTTON_TRIGGER_LEVEL LOW // 0 or 1, set to the sensing level which to detect a button press to change the actuator state.
#endif
/*-------------------PIN DEFINITIONS----------------------*/
+4
View File
@@ -969,6 +969,9 @@ void saveConfigCallback() {
# ifdef TRIGGER_GPIO
void checkButton() { // code from tzapu/wifimanager examples
# if defined(INPUT_GPIO) && defined(ZsensorGPIOInput) && INPUT_GPIO == TRIGGER_GPIO
MeasureGPIOInput();
# else
// check for button press
if (digitalRead(TRIGGER_GPIO) == LOW) {
// poor mans debounce/press-hold, code not ideal for production
@@ -984,6 +987,7 @@ void checkButton() { // code from tzapu/wifimanager examples
}
}
}
# endif
}
# else
void checkButton() {}