diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 677c591..99746aa 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -154,6 +154,37 @@ void Span::poll() { HAPClient::checkPushButtons(); HAPClient::checkNotifications(); HAPClient::checkTimedWrites(); + + switch(resetPressed){ + case 0: + if(!digitalRead(resetPin)){ + resetPressed=1; + resetTime=millis()+5000; + } + break; + + case 1: + if(digitalRead(resetPin)){ + resetPressed=0; + } else + if(millis()>resetTime){ + resetPressed=2; + statusLED.start(200,0.5,4,800); + resetTime=millis()+6000; + } + break; + + case 2: + if(digitalRead(resetPin)){ + statusLED.off(); + processSerialCommand("H"); + } else + if(millis()>resetTime){ + statusLED.off(); + processSerialCommand("F"); + } + break; + } // switch } // poll @@ -379,7 +410,7 @@ void Span::processSerialCommand(char *c){ nvs_erase_all(HAPClient::nvsHandle); nvs_commit(HAPClient::nvsHandle); Serial.print("\n** HomeKit Pairing Data DELETED **\n** Restarting...\n\n"); - delay(2000); + delay(1000); ESP.restart(); } break; @@ -387,7 +418,7 @@ void Span::processSerialCommand(char *c){ case 'F': { nvs_flash_erase(); Serial.print("\n** FACTORY RESET **\n** Restarting...\n\n"); - delay(2000); + delay(1000); ESP.restart(); } break; diff --git a/src/HomeSpan.h b/src/HomeSpan.h index a054e1f..66ba284 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -46,6 +46,8 @@ struct Span{ unsigned long snapTime; // current time (in millis) snapped before entering Service loops() or updates() int resetPin=21; // drive this pin low to "factory" reset NVS data on start-up + int resetPressed=0; // tracks pressing of reset button + unsigned long resetTime; // tracks time once reset button is pressed Blinker statusLED=Blinker(LED_BUILTIN); // indicates HomeSpan status diff --git a/src/src.ino b/src/src.ino index 0ee2e57..3ac41a3 100644 --- a/src/src.ino +++ b/src/src.ino @@ -1,5 +1,6 @@ -#error THIS IS NOT COMPILABLE CODE - // This is a dummy .ino file that allows you to easily edit the contents of this library using the Arduino IDE. // The code is NOT designed to be compiled from this point. Compile and test the library using one of the examples. + +void setup(){} +void loop(){}