Implemented Reset Button

Allows for reset of HAP (press for 5 seconds, but less than 10) or Factory reset (press for 10 second).  Use  setResetPin to change from default of pint 21.
This commit is contained in:
Gregg 2020-08-23 08:14:31 -05:00
parent 2172ac1ce6
commit b42dd9dfba
3 changed files with 38 additions and 4 deletions

View File

@ -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;

View File

@ -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

View File

@ -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(){}