Updated rest of code to reflect latest version of statusLED
Removed all checks to see if statusLED is defined, since it will now ALWAYS be defined, even if the statusDevice is set to NULL.
This commit is contained in:
parent
f2e1f5bc70
commit
355a2dfd4d
|
|
@ -638,8 +638,7 @@ int HAPClient::postPairSetupURL(){
|
||||||
|
|
||||||
LOG1("\n*** ACCESSORY PAIRED! ***\n");
|
LOG1("\n*** ACCESSORY PAIRED! ***\n");
|
||||||
|
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->on();
|
||||||
homeSpan.statusLED->on();
|
|
||||||
|
|
||||||
if(homeSpan.pairCallback) // if set, invoke user-defined Pairing Callback to indicate device has been paired
|
if(homeSpan.pairCallback) // if set, invoke user-defined Pairing Callback to indicate device has been paired
|
||||||
homeSpan.pairCallback(true);
|
homeSpan.pairCallback(true);
|
||||||
|
|
@ -1638,8 +1637,7 @@ void HAPClient::removeController(uint8_t *id){
|
||||||
removeControllers();
|
removeControllers();
|
||||||
LOG1("That was last Admin Controller! Removing any remaining Regular Controllers and unpairing Accessory\n");
|
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)
|
mdns_service_txt_item_set("_hap","_tcp","sf","1"); // set Status Flag = 1 (Table 6-8)
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->start(LED_PAIRING_NEEDED);
|
||||||
homeSpan.statusLED->start(LED_PAIRING_NEEDED);
|
|
||||||
if(homeSpan.pairCallback) // if set, invoke user-defined Pairing Callback to indicate device has been paired
|
if(homeSpan.pairCallback) // if set, invoke user-defined Pairing Callback to indicate device has been paired
|
||||||
homeSpan.pairCallback(false);
|
homeSpan.pairCallback(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
||||||
this->modelName=modelName;
|
this->modelName=modelName;
|
||||||
sprintf(this->category,"%d",(int)catID);
|
sprintf(this->category,"%d",(int)catID);
|
||||||
|
|
||||||
statusLED=new Blinker(statusDevice,autoOffLED);
|
statusLED=new Blinker(statusDevice,autoOffLED); // create Status LED, even is statusDevice is NULL
|
||||||
|
|
||||||
esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(0)); // required to avoid watchdog timeout messages from ESP32-C3
|
esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(0)); // required to avoid watchdog timeout messages from ESP32-C3
|
||||||
|
|
||||||
|
|
@ -189,10 +189,9 @@ void Span::pollTask() {
|
||||||
processSerialCommand("A");
|
processSerialCommand("A");
|
||||||
} else {
|
} else {
|
||||||
Serial.print("YOU MAY CONFIGURE BY TYPING 'W <RETURN>'.\n\n");
|
Serial.print("YOU MAY CONFIGURE BY TYPING 'W <RETURN>'.\n\n");
|
||||||
if(statusLED)
|
statusLED->start(LED_WIFI_NEEDED);
|
||||||
statusLED->start(LED_WIFI_NEEDED);
|
|
||||||
}
|
}
|
||||||
} else if(statusLED) {
|
} else {
|
||||||
statusLED->start(LED_WIFI_CONNECTING);
|
statusLED->start(LED_WIFI_CONNECTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,12 +290,11 @@ void Span::pollTask() {
|
||||||
if(spanOTA.enabled)
|
if(spanOTA.enabled)
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
|
|
||||||
if(controlButton && controlButton->primed() && statusLED)
|
if(controlButton && controlButton->primed())
|
||||||
statusLED->start(LED_ALERT);
|
statusLED->start(LED_ALERT);
|
||||||
|
|
||||||
if(controlButton && controlButton->triggered(3000,10000)){
|
if(controlButton && controlButton->triggered(3000,10000)){
|
||||||
if(statusLED)
|
statusLED->off();
|
||||||
statusLED->off();
|
|
||||||
if(controlButton->type()==PushButton::LONG){
|
if(controlButton->type()==PushButton::LONG){
|
||||||
controlButton->wait();
|
controlButton->wait();
|
||||||
processSerialCommand("F"); // FACTORY RESET
|
processSerialCommand("F"); // FACTORY RESET
|
||||||
|
|
@ -305,8 +303,7 @@ void Span::pollTask() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(statusLED)
|
statusLED->check();
|
||||||
statusLED->check();
|
|
||||||
|
|
||||||
} // poll
|
} // poll
|
||||||
|
|
||||||
|
|
@ -326,7 +323,7 @@ int Span::getFreeSlot(){
|
||||||
|
|
||||||
void Span::commandMode(){
|
void Span::commandMode(){
|
||||||
|
|
||||||
if(!statusLED){
|
if(!statusDevice){
|
||||||
Serial.print("*** ERROR: CAN'T ENTER COMMAND MODE WITHOUT A DEFINED STATUS LED***\n\n");
|
Serial.print("*** ERROR: CAN'T ENTER COMMAND MODE WITHOUT A DEFINED STATUS LED***\n\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -409,8 +406,7 @@ void Span::checkConnect(){
|
||||||
connected++;
|
connected++;
|
||||||
waitTime=60000;
|
waitTime=60000;
|
||||||
alarmConnect=0;
|
alarmConnect=0;
|
||||||
if(statusLED)
|
statusLED->start(LED_WIFI_CONNECTING);
|
||||||
statusLED->start(LED_WIFI_CONNECTING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(WiFi.status()!=WL_CONNECTED){
|
if(WiFi.status()!=WL_CONNECTED){
|
||||||
|
|
@ -437,12 +433,10 @@ void Span::checkConnect(){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(statusLED){
|
if(!HAPClient::nAdminControllers())
|
||||||
if(!HAPClient::nAdminControllers())
|
statusLED->start(LED_PAIRING_NEEDED);
|
||||||
statusLED->start(LED_PAIRING_NEEDED);
|
else
|
||||||
else
|
statusLED->on();
|
||||||
statusLED->on();
|
|
||||||
}
|
|
||||||
|
|
||||||
connected++;
|
connected++;
|
||||||
|
|
||||||
|
|
@ -767,12 +761,10 @@ void Span::processSerialCommand(const char *c){
|
||||||
Serial.print("\nDEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n");
|
Serial.print("\nDEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n");
|
||||||
mdns_service_txt_item_set("_hap","_tcp","sf","1"); // set Status Flag = 1 (Table 6-8)
|
mdns_service_txt_item_set("_hap","_tcp","sf","1"); // set Status Flag = 1 (Table 6-8)
|
||||||
|
|
||||||
if(statusLED){
|
if(strlen(network.wifiData.ssid)==0)
|
||||||
if(strlen(network.wifiData.ssid)==0)
|
statusLED->start(LED_WIFI_NEEDED);
|
||||||
statusLED->start(LED_WIFI_NEEDED);
|
else
|
||||||
else
|
statusLED->start(LED_PAIRING_NEEDED);
|
||||||
statusLED->start(LED_PAIRING_NEEDED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -789,8 +781,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data
|
nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data
|
||||||
nvs_commit(wifiNVS); // commit to NVS
|
nvs_commit(wifiNVS); // commit to NVS
|
||||||
Serial.print("\n*** WiFi Credentials SAVED! Re-starting ***\n\n");
|
Serial.print("\n*** WiFi Credentials SAVED! Re-starting ***\n\n");
|
||||||
if(statusLED)
|
statusLED->off();
|
||||||
statusLED->off();
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
@ -823,8 +814,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print("\n*** Re-starting ***\n\n");
|
Serial.print("\n*** Re-starting ***\n\n");
|
||||||
if(statusLED)
|
statusLED->off();
|
||||||
statusLED->off();
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
ESP.restart(); // re-start device
|
ESP.restart(); // re-start device
|
||||||
}
|
}
|
||||||
|
|
@ -832,8 +822,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
case 'X': {
|
case 'X': {
|
||||||
|
|
||||||
if(statusLED)
|
statusLED->off();
|
||||||
statusLED->off();
|
|
||||||
nvs_erase_all(wifiNVS);
|
nvs_erase_all(wifiNVS);
|
||||||
nvs_commit(wifiNVS);
|
nvs_commit(wifiNVS);
|
||||||
Serial.print("\n*** WiFi Credentials ERASED! Re-starting...\n\n");
|
Serial.print("\n*** WiFi Credentials ERASED! Re-starting...\n\n");
|
||||||
|
|
@ -852,8 +841,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
case 'H': {
|
case 'H': {
|
||||||
|
|
||||||
if(statusLED)
|
statusLED->off();
|
||||||
statusLED->off();
|
|
||||||
nvs_erase_all(HAPClient::hapNVS);
|
nvs_erase_all(HAPClient::hapNVS);
|
||||||
nvs_commit(HAPClient::hapNVS);
|
nvs_commit(HAPClient::hapNVS);
|
||||||
Serial.print("\n*** HomeSpan Device ID and Pairing Data DELETED! Restarting...\n\n");
|
Serial.print("\n*** HomeSpan Device ID and Pairing Data DELETED! Restarting...\n\n");
|
||||||
|
|
@ -864,8 +852,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
case 'R': {
|
case 'R': {
|
||||||
|
|
||||||
if(statusLED)
|
statusLED->off();
|
||||||
statusLED->off();
|
|
||||||
Serial.print("\n*** Restarting...\n\n");
|
Serial.print("\n*** Restarting...\n\n");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
|
@ -874,8 +861,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
case 'F': {
|
case 'F': {
|
||||||
|
|
||||||
if(statusLED)
|
statusLED->off();
|
||||||
statusLED->off();
|
|
||||||
nvs_erase_all(HAPClient::hapNVS);
|
nvs_erase_all(HAPClient::hapNVS);
|
||||||
nvs_commit(HAPClient::hapNVS);
|
nvs_commit(HAPClient::hapNVS);
|
||||||
nvs_erase_all(wifiNVS);
|
nvs_erase_all(wifiNVS);
|
||||||
|
|
@ -892,8 +878,7 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
case 'E': {
|
case 'E': {
|
||||||
|
|
||||||
if(statusLED)
|
statusLED->off();
|
||||||
statusLED->off();
|
|
||||||
nvs_flash_erase();
|
nvs_flash_erase();
|
||||||
Serial.print("\n*** ALL DATA ERASED! Restarting...\n\n");
|
Serial.print("\n*** ALL DATA ERASED! Restarting...\n\n");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
@ -2117,8 +2102,7 @@ void SpanOTA::start(){
|
||||||
Serial.printf("\n*** Current Partition: %s\n*** New Partition: %s\n*** OTA Starting..",
|
Serial.printf("\n*** Current Partition: %s\n*** New Partition: %s\n*** OTA Starting..",
|
||||||
esp_ota_get_running_partition()->label,esp_ota_get_next_update_partition(NULL)->label);
|
esp_ota_get_running_partition()->label,esp_ota_get_next_update_partition(NULL)->label);
|
||||||
otaPercent=0;
|
otaPercent=0;
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->start(LED_OTA_STARTED);
|
||||||
homeSpan.statusLED->start(LED_OTA_STARTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -2127,8 +2111,7 @@ void SpanOTA::end(){
|
||||||
nvs_set_u8(homeSpan.otaNVS,"OTA_REQUIRED",safeLoad);
|
nvs_set_u8(homeSpan.otaNVS,"OTA_REQUIRED",safeLoad);
|
||||||
nvs_commit(homeSpan.otaNVS);
|
nvs_commit(homeSpan.otaNVS);
|
||||||
Serial.printf(" DONE! Rebooting...\n");
|
Serial.printf(" DONE! Rebooting...\n");
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->off();
|
||||||
homeSpan.statusLED->off();
|
|
||||||
delay(100); // make sure commit it finished before reboot
|
delay(100); // make sure commit it finished before reboot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ class Span{
|
||||||
void setStatusPin(uint8_t pin){statusDevice=new LED(pin);} // sets Status Device to a simple LED on specified pin
|
void setStatusPin(uint8_t pin){statusDevice=new LED(pin);} // sets Status Device to a simple LED on specified pin
|
||||||
void setStatusDevice(Blinkable *dev){statusDevice=dev;} // sets Status Device to generic Blinkable object
|
void setStatusDevice(Blinkable *dev){statusDevice=dev;} // sets Status Device to generic Blinkable object
|
||||||
void setStatusAutoOff(uint16_t duration){autoOffLED=duration;} // sets Status LED auto off (seconds)
|
void setStatusAutoOff(uint16_t duration){autoOffLED=duration;} // sets Status LED auto off (seconds)
|
||||||
int getStatusPin(){return(statusLED?statusLED->getPin():-1);} // get Status Pin (returns -1 if undefined)
|
int getStatusPin(){return(statusLED->getPin());} // get Status Pin (getPin will return -1 if underlying statusDevice is undefined)
|
||||||
int getControlPin(){return(controlButton?controlButton->getPin():-1);} // get Control Pin (returns -1 if undefined)
|
int getControlPin(){return(controlButton?controlButton->getPin():-1);} // get Control Pin (returns -1 if undefined)
|
||||||
void setApSSID(const char *ssid){network.apSSID=ssid;} // sets Access Point SSID
|
void setApSSID(const char *ssid){network.apSSID=ssid;} // sets Access Point SSID
|
||||||
void setApPassword(const char *pwd){network.apPassword=pwd;} // sets Access Point Password
|
void setApPassword(const char *pwd){network.apPassword=pwd;} // sets Access Point Password
|
||||||
|
|
|
||||||
|
|
@ -116,8 +116,7 @@ void Network::apConfigure(){
|
||||||
Serial.print(apPassword);
|
Serial.print(apPassword);
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->start(LED_AP_STARTED);
|
||||||
homeSpan.statusLED->start(LED_AP_STARTED);
|
|
||||||
|
|
||||||
Serial.print("\nScanning for Networks...\n\n");
|
Serial.print("\nScanning for Networks...\n\n");
|
||||||
|
|
||||||
|
|
@ -155,12 +154,10 @@ void Network::apConfigure(){
|
||||||
|
|
||||||
if(homeSpan.controlButton && homeSpan.controlButton->triggered(9999,3000)){
|
if(homeSpan.controlButton && homeSpan.controlButton->triggered(9999,3000)){
|
||||||
Serial.print("\n*** Access Point Terminated.");
|
Serial.print("\n*** Access Point Terminated.");
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->start(LED_ALERT);
|
||||||
homeSpan.statusLED->start(LED_ALERT);
|
|
||||||
homeSpan.controlButton->wait();
|
homeSpan.controlButton->wait();
|
||||||
Serial.print(" Restarting... \n\n");
|
Serial.print(" Restarting... \n\n");
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->off();
|
||||||
homeSpan.statusLED->off();
|
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,11 +176,9 @@ void Network::apConfigure(){
|
||||||
Serial.print("\n*** Access Point: Configuration Canceled.");
|
Serial.print("\n*** Access Point: Configuration Canceled.");
|
||||||
}
|
}
|
||||||
Serial.print(" Restarting...\n\n");
|
Serial.print(" Restarting...\n\n");
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->start(LED_ALERT);
|
||||||
homeSpan.statusLED->start(LED_ALERT);
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->off();
|
||||||
homeSpan.statusLED->off();
|
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -278,8 +273,7 @@ void Network::processRequest(char *body, char *formData){
|
||||||
getFormValue(formData,"network",wifiData.ssid,MAX_SSID);
|
getFormValue(formData,"network",wifiData.ssid,MAX_SSID);
|
||||||
getFormValue(formData,"pwd",wifiData.pwd,MAX_PWD);
|
getFormValue(formData,"pwd",wifiData.pwd,MAX_PWD);
|
||||||
|
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->start(LED_WIFI_CONNECTING);
|
||||||
homeSpan.statusLED->start(LED_WIFI_CONNECTING);
|
|
||||||
|
|
||||||
responseBody+="<meta http-equiv = \"refresh\" content = \"" + String(waitTime) + "; url = /wifi-status\" />"
|
responseBody+="<meta http-equiv = \"refresh\" content = \"" + String(waitTime) + "; url = /wifi-status\" />"
|
||||||
"<p>Initiating WiFi connection to:</p><p><b>" + String(wifiData.ssid) + "</p>";
|
"<p>Initiating WiFi connection to:</p><p><b>" + String(wifiData.ssid) + "</p>";
|
||||||
|
|
@ -326,8 +320,7 @@ void Network::processRequest(char *body, char *formData){
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->start(LED_AP_CONNECTED); // slow double-blink
|
||||||
homeSpan.statusLED->start(LED_AP_CONNECTED); // slow double-blink
|
|
||||||
|
|
||||||
responseBody+="<p>SUCCESS! Connected to:</p><p><b>" + String(wifiData.ssid) + "</b></p>";
|
responseBody+="<p>SUCCESS! Connected to:</p><p><b>" + String(wifiData.ssid) + "</b></p>";
|
||||||
responseBody+="<p>You may enter new 8-digit Setup Code below, or leave blank to retain existing code.</p>";
|
responseBody+="<p>You may enter new 8-digit Setup Code below, or leave blank to retain existing code.</p>";
|
||||||
|
|
@ -347,8 +340,7 @@ void Network::processRequest(char *body, char *formData){
|
||||||
|
|
||||||
LOG1("In Landing Page...\n");
|
LOG1("In Landing Page...\n");
|
||||||
|
|
||||||
if(homeSpan.statusLED)
|
homeSpan.statusLED->start(LED_AP_CONNECTED);
|
||||||
homeSpan.statusLED->start(LED_AP_CONNECTED);
|
|
||||||
waitTime=2;
|
waitTime=2;
|
||||||
|
|
||||||
responseBody+="<p>Welcome to HomeSpan! This page allows you to configure the above HomeSpan device to connect to your WiFi network.</p>"
|
responseBody+="<p>Welcome to HomeSpan! This page allows you to configure the above HomeSpan device to connect to your WiFi network.</p>"
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,6 @@ void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
|
||||||
this->nBlinks=nBlinks;
|
this->nBlinks=nBlinks;
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
Serial.printf("Starting Blink Task\n");
|
|
||||||
xTaskCreate( blinkTask, "BlinkTask", 1024, (void *)this, 2, &blinkHandle );
|
xTaskCreate( blinkTask, "BlinkTask", 1024, (void *)this, 2, &blinkHandle );
|
||||||
|
|
||||||
pauseTime=millis();
|
pauseTime=millis();
|
||||||
|
|
@ -89,7 +88,6 @@ void Blinker::stop(){
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(blinkHandle!=NULL){
|
if(blinkHandle!=NULL){
|
||||||
Serial.printf("Deleting Blink Task\n");
|
|
||||||
vTaskDelete(blinkHandle);
|
vTaskDelete(blinkHandle);
|
||||||
blinkHandle=NULL;
|
blinkHandle=NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue