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:
parent
2172ac1ce6
commit
b42dd9dfba
|
|
@ -155,6 +155,37 @@ void Span::poll() {
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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(){}
|
||||
|
|
|
|||
Loading…
Reference in New Issue