diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 0b48a7e..10319b8 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -155,15 +155,21 @@ void Span::poll() { HAPClient::checkNotifications(); HAPClient::checkTimedWrites(); - if(controlButton.triggered(2000,10000)){ + if(controlButton.primed()){ + statusLED.start(500); + } + + if(controlButton.triggered(3000,10000)){ if(controlButton.longPress()){ statusLED.start(200); delay(2000); - processSerialCommand("W"); // Delete WiFi Data and Restart + statusLED.off(); + ESP.restart(); + processSerialCommand("W"); // DELETE WiFi Data and Restart } else { statusLED.off(); controlButton.reset(); - processSerialCommand("U"); // UPAIR Device + processSerialCommand("U"); // UNPAIR Device } } @@ -470,7 +476,7 @@ void Span::processSerialCommand(char *c){ break; case 'W': { - + nvs_erase_all(HAPClient::wifiNVS); nvs_commit(HAPClient::wifiNVS); Serial.print("\n** WIFI Network Data DELETED **\n** Restarting...\n\n"); diff --git a/src/Settings.h b/src/Settings.h index 500ec4e..07d6e65 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -12,8 +12,8 @@ // DEFAULT SETTINGS #define DEFAULT_SETUP_CODE "46637726" // changed during network setup or with 'S' command -#define DEFAULT_CONTROL_PIN 21 // changed with homeSpan.setControlPin(pin) -#define DEFAULT_STATUS_PIN LED_BUILTIN // changed with homeSpan.setStatusPin(pin) +#define DEFAULT_CONTROL_PIN 21 // change with homeSpan.setControlPin(pin) +#define DEFAULT_STATUS_PIN LED_BUILTIN // change with homeSpan.setStatusPin(pin) ////////////////////////////////////////////////////// // Maximum number of simultaenous IP connections // diff --git a/src/Utils.cpp b/src/Utils.cpp index 1fe2db4..2c179a9 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -89,6 +89,7 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){ break; case 1: + case 2: if(digitalRead(pin)){ // button is released status=0; if(millis()>shortAlarm){ @@ -98,13 +99,13 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){ } else if(millis()>longAlarm){ // button is long-pressed - status=2; + status=3; isLongPress=true; return(true); } break; - case 2: + case 3: if(digitalRead(pin)) // button has been released after a long press status=0; break; @@ -116,6 +117,18 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){ ////////////////////////////////////// +boolean PushButton::primed(){ + + if(millis()>shortAlarm && status==1){ + status=2; + return(true); + } + + return(false); +} + +////////////////////////////////////// + boolean PushButton::longPress(){ return(isLongPress); } diff --git a/src/Utils.h b/src/Utils.h index e7316d1..dc54710 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -86,6 +86,11 @@ class PushButton{ // return false until there is a new trigger. After a Long Press, the button must be released to permit a subsequent // trigger. + boolean primed(); + +// Returns true if button has been pressed and held for greater than shortTime, but has not yet been released. +// After returning true, subsequent calls will always return false until the button has been released and reset. + boolean longPress(); // Returns true if last trigger event was a Long Press, or false if last trigger was a Short Press diff --git a/src/src.ino b/src/src.ino index 7217adc..c9de91a 100644 --- a/src/src.ino +++ b/src/src.ino @@ -7,8 +7,6 @@ void setup() { Serial.begin(115200); - - homeSpan.setStatusPin(22); homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");