diff --git a/src/Blinker.cpp b/src/Blinker.cpp index a0e3a08..4872132 100644 --- a/src/Blinker.cpp +++ b/src/Blinker.cpp @@ -82,3 +82,13 @@ void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){ void Blinker::stop(){ timer_pause(group,idx); } + +void Blinker::on(){ + stop(); + digitalWrite(pin,1); +} + +void Blinker::off(){ + stop(); + digitalWrite(pin,0); +} diff --git a/src/Blinker.h b/src/Blinker.h index 7f57ccf..17cbc93 100644 --- a/src/Blinker.h +++ b/src/Blinker.h @@ -50,4 +50,12 @@ class Blinker { // Stops current blinking pattern. + void on(); + +// Stops current blinknig pattern and turns on LED + + void off(); + +// Stops current blinknig pattern and turns off LED + }; diff --git a/src/HAP.cpp b/src/HAP.cpp index 1fb55b3..781a25d 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -582,6 +582,7 @@ int HAPClient::postPairSetupURL(){ mdns_service_txt_item_set("_hap","_tcp","sf","0"); // broadcast new status LOG1("\n*** ACCESSORY PAIRED! ***\n"); + homeSpan.statusLED.on(); return(1); @@ -1494,6 +1495,7 @@ void HAPClient::removeController(uint8_t *id){ removeControllers(); LOG1("That was last Admin Controller! Removing any remaining Regular Controllers and unpairing Accessory\n"); mdns_service_txt_item_set("_hap","_tcp","sf","1"); // set Status Flag = 1 (Table 6-8) + homeSpan.statusLED.start(500,0.5,2,1000); } LOG2("\n"); diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 02c4fbd..677c591 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -23,8 +23,7 @@ void Span::begin(Category catID, char *displayName, char *hostNameBase, char *mo this->hostNameBase=hostNameBase; this->modelName=modelName; sprintf(this->category,"%d",catID); - - pinMode(LED_BUILTIN,OUTPUT); + pinMode(resetPin,INPUT_PULLUP); delay(2000); @@ -78,8 +77,12 @@ void Span::poll() { HAPClient::init(); // read NVS and load HAP settings initWifi(); // initialize WiFi - if(!HAPClient::nAdminControllers()) + if(!HAPClient::nAdminControllers()){ Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n"); + statusLED.start(500,0.5,2,1000); + } else { + statusLED.on(); + } Serial.print(displayName); Serial.print(" is READY!\n\n"); @@ -186,6 +189,8 @@ void Span::initWifi(){ if(!nvs_get_blob(wifiHandle,"WIFIDATA",NULL,&len)){ // if found WiFi data in NVS nvs_get_blob(wifiHandle,"WIFIDATA",&wifiData,&len); // retrieve data } else { + statusLED.start(300,0.3); + Serial.print("Please configure network...\n"); sprintf(wifiData.ssid,"MyNetwork"); sprintf(wifiData.pwd,"MyPassword"); @@ -218,6 +223,8 @@ void Span::initWifi(){ sprintf(hostName,"%s-%.2s_%.2s_%.2s_%.2s_%.2s_%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15); int nTries=0; + + statusLED.start(1000); while(WiFi.status()!=WL_CONNECTED){ Serial.print("Connecting to: "); @@ -227,14 +234,12 @@ void Span::initWifi(){ if(WiFi.begin(wifiData.ssid,wifiData.pwd)!=WL_CONNECTED){ int delayTime=nTries%6?5000:60000; - int blinkTime=nTries%6?500:1000; char buf[8]=""; Serial.print("Can't connect. Re-trying in "); Serial.print(delayTime/1000); Serial.print(" seconds (or type 'W ' to reset WiFi data)...\n"); long sTime=millis(); while(millis()-sTime #include "Settings.h" +#include "Blinker.h" using std::vector; using std::unordered_map; @@ -45,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 + + Blinker statusLED=Blinker(LED_BUILTIN); // indicates HomeSpan status SpanConfig hapConfig; // track configuration changes to the HAP Accessory database; used to increment the configuration number (c#) when changes found vector Accessories; // vector of pointers to all Accessories diff --git a/src/Utils.cpp b/src/Utils.cpp index b6d7862..f364a30 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -5,13 +5,9 @@ char *Utils::readSerial(char *c, int max){ int i=0; char buf; - long sTime=millis(); - while(1){ - while(!Serial.available()){ // wait until there is a new character - digitalWrite(LED_BUILTIN,((millis()-sTime)/200)%2); - } + while(!Serial.available()); // wait until there is a new character buf=Serial.read(); @@ -27,8 +23,6 @@ char *Utils::readSerial(char *c, int max){ i++; } // while(1) - - digitalWrite(LED_BUILTIN,LOW); } // readSerial