created STATUS_UPDATE macro
Combines statusLED updates with statusCallback updates
This commit is contained in:
parent
d55dad1529
commit
645c169a5e
|
|
@ -194,14 +194,10 @@ 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");
|
||||||
statusLED->start(LED_WIFI_NEEDED);
|
STATUS_UPDATE(start(LED_WIFI_NEEDED),HS_WIFI_NEEDED);
|
||||||
if(statusCallback)
|
|
||||||
statusCallback(HS_WIFI_NEEDED);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
statusLED->start(LED_WIFI_CONNECTING);
|
STATUS_UPDATE(start(LED_WIFI_CONNECTING),HS_WIFI_CONNECTING);
|
||||||
if(statusCallback)
|
|
||||||
statusCallback(HS_WIFI_CONNECTING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(controlButton)
|
if(controlButton)
|
||||||
|
|
@ -300,11 +296,11 @@ void Span::pollTask() {
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
|
|
||||||
if(controlButton && controlButton->primed())
|
if(controlButton && controlButton->primed())
|
||||||
statusLED->start(LED_ALERT);
|
STATUS_UPDATE(start(LED_ALERT),HS_ENTERING_CONFIG_MODE);
|
||||||
|
|
||||||
if(controlButton && controlButton->triggered(3000,10000)){
|
if(controlButton && controlButton->triggered(3000,10000)){
|
||||||
statusLED->off();
|
|
||||||
if(controlButton->type()==PushButton::LONG){
|
if(controlButton->type()==PushButton::LONG){
|
||||||
|
STATUS_UPDATE(off(),HS_FACTORY_RESET);
|
||||||
controlButton->wait();
|
controlButton->wait();
|
||||||
processSerialCommand("F"); // FACTORY RESET
|
processSerialCommand("F"); // FACTORY RESET
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -337,12 +333,10 @@ void Span::commandMode(){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print("*** ENTERING COMMAND MODE ***\n\n");
|
Serial.print("*** COMMAND MODE ***\n\n");
|
||||||
int mode=1;
|
int mode=1;
|
||||||
boolean done=false;
|
boolean done=false;
|
||||||
statusLED->start(500,0.3,mode,1000);
|
STATUS_UPDATE(start(500,0.3,mode,1000),static_cast<HS_STATUS>(HS_ENTERING_CONFIG_MODE+mode));
|
||||||
if(statusCallback)
|
|
||||||
statusCallback(HS_CONFIG_MODE_EXIT);
|
|
||||||
unsigned long alarmTime=millis()+comModeLife;
|
unsigned long alarmTime=millis()+comModeLife;
|
||||||
|
|
||||||
while(!done){
|
while(!done){
|
||||||
|
|
@ -352,17 +346,13 @@ void Span::commandMode(){
|
||||||
Serial.print(" seconds).\n\n");
|
Serial.print(" seconds).\n\n");
|
||||||
mode=1;
|
mode=1;
|
||||||
done=true;
|
done=true;
|
||||||
statusLED->start(LED_ALERT);
|
|
||||||
delay(2000);
|
|
||||||
} else
|
} else
|
||||||
if(controlButton->triggered(10,3000)){
|
if(controlButton->triggered(10,3000)){
|
||||||
if(controlButton->type()==PushButton::SINGLE){
|
if(controlButton->type()==PushButton::SINGLE){
|
||||||
mode++;
|
mode++;
|
||||||
if(mode==6)
|
if(mode==6)
|
||||||
mode=1;
|
mode=1;
|
||||||
statusLED->start(500,0.3,mode,1000);
|
STATUS_UPDATE(start(500,0.3,mode,1000),static_cast<HS_STATUS>(HS_ENTERING_CONFIG_MODE+mode));
|
||||||
if(statusCallback)
|
|
||||||
statusCallback((HS_STATUS)(HS_CONFIG_MODE_EXIT+mode-1));
|
|
||||||
} else {
|
} else {
|
||||||
done=true;
|
done=true;
|
||||||
}
|
}
|
||||||
|
|
@ -412,9 +402,7 @@ void Span::checkConnect(){
|
||||||
connected++;
|
connected++;
|
||||||
waitTime=60000;
|
waitTime=60000;
|
||||||
alarmConnect=0;
|
alarmConnect=0;
|
||||||
statusLED->start(LED_WIFI_CONNECTING);
|
STATUS_UPDATE(start(LED_WIFI_CONNECTING),HS_WIFI_CONNECTING);
|
||||||
if(statusCallback)
|
|
||||||
statusCallback(HS_WIFI_CONNECTING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(WiFi.status()!=WL_CONNECTED){
|
if(WiFi.status()!=WL_CONNECTED){
|
||||||
|
|
@ -869,7 +857,6 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
case 'F': {
|
case 'F': {
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -879,8 +866,6 @@ void Span::processSerialCommand(const char *c){
|
||||||
nvs_erase_all(otaNVS);
|
nvs_erase_all(otaNVS);
|
||||||
nvs_commit(otaNVS);
|
nvs_commit(otaNVS);
|
||||||
WiFi.begin("none");
|
WiFi.begin("none");
|
||||||
if(statusCallback)
|
|
||||||
statusCallback(HS_FACTORY_RESET);
|
|
||||||
Serial.print("\n*** FACTORY RESET! Restarting...\n\n");
|
Serial.print("\n*** FACTORY RESET! Restarting...\n\n");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,14 @@ enum {
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
|
#define STATUS_UPDATE(LED_UPDATE,MESSAGE_UPDATE) {statusLED->LED_UPDATE;if(statusCallback)statusCallback(MESSAGE_UPDATE);}
|
||||||
|
|
||||||
enum HS_STATUS {
|
enum HS_STATUS {
|
||||||
HS_WIFI_NEEDED,
|
HS_WIFI_NEEDED,
|
||||||
HS_WIFI_CONNECTING,
|
HS_WIFI_CONNECTING,
|
||||||
HS_PAIRING_NEEDED,
|
HS_PAIRING_NEEDED,
|
||||||
HS_PAIRED,
|
HS_PAIRED,
|
||||||
|
HS_ENTERING_CONFIG_MODE,
|
||||||
HS_CONFIG_MODE_EXIT,
|
HS_CONFIG_MODE_EXIT,
|
||||||
HS_CONFIG_MODE_REBOOT,
|
HS_CONFIG_MODE_REBOOT,
|
||||||
HS_CONFIG_MODE_LAUNCH_AP,
|
HS_CONFIG_MODE_LAUNCH_AP,
|
||||||
|
|
@ -223,7 +226,7 @@ class Span{
|
||||||
void (*pairCallback)(boolean isPaired)=NULL; // optional callback function to invoke when pairing is established (true) or lost (false)
|
void (*pairCallback)(boolean isPaired)=NULL; // optional callback function to invoke when pairing is established (true) or lost (false)
|
||||||
boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found
|
boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found
|
||||||
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
|
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
|
||||||
void (*statusCallback)(HS_STATUS status)=NULL; // optional callback when HomeSpan status changes
|
void (*statusCallback)(HS_STATUS status)=NULL; // optional callback when HomeSpan status changes
|
||||||
|
|
||||||
WiFiServer *hapServer; // pointer to the HAP Server connection
|
WiFiServer *hapServer; // pointer to the HAP Server connection
|
||||||
Blinker *statusLED; // indicates HomeSpan status
|
Blinker *statusLED; // indicates HomeSpan status
|
||||||
|
|
@ -306,7 +309,7 @@ class Span{
|
||||||
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
|
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
|
||||||
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
|
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
|
||||||
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
||||||
void setStatusCallback(void (*f)(HS_STATUS status)){statusCallback=f;} // sets an optional user-defined function to call when HomeSpan status changes
|
void setStatusCallback(void (*f)(HS_STATUS status)){statusCallback=f;} // sets an optional user-defined function to call when HomeSpan status changes
|
||||||
|
|
||||||
void setPairingCode(const char *s){sprintf(pairingCodeCommand,"S %9s",s);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
void setPairingCode(const char *s){sprintf(pairingCodeCommand,"S %9s",s);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
||||||
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue