Implemented Blinker statusLED
Replaced manual blinking with automated Blinker statusLED
This commit is contained in:
parent
9952b48950
commit
2172ac1ce6
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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 <return>' to reset WiFi data)...\n");
|
||||
long sTime=millis();
|
||||
while(millis()-sTime<delayTime){
|
||||
digitalWrite(LED_BUILTIN,((millis()-sTime)/blinkTime)%2);
|
||||
if(Serial.available()){
|
||||
readSerial(buf,1);
|
||||
if(buf[0]=='W'){
|
||||
|
|
@ -251,7 +256,6 @@ void Span::initWifi(){
|
|||
}
|
||||
} // WiFi not yet connected
|
||||
|
||||
digitalWrite(LED_BUILTIN,HIGH);
|
||||
Serial.print("Success! IP: ");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.print("\n");
|
||||
|
|
@ -292,6 +296,8 @@ void Span::initWifi(){
|
|||
Serial.print(MAX_CONNECTIONS);
|
||||
Serial.print(" simultaneous connections...\n\n");
|
||||
hapServer.begin();
|
||||
|
||||
statusLED.stop();
|
||||
|
||||
} // initWiFi
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include <unordered_map>
|
||||
|
||||
#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<SpanAccessory *> Accessories; // vector of pointers to all Accessories
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue