Started homeSpan.setEventCallback()
This commit is contained in:
parent
f8be2847bd
commit
5b38c6a04a
|
|
@ -195,9 +195,13 @@ void Span::pollTask() {
|
||||||
} 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);
|
statusLED->start(LED_WIFI_NEEDED);
|
||||||
|
if(hsEventCallback)
|
||||||
|
hsEventCallback(HS_WIFI_NEEDED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
statusLED->start(LED_WIFI_CONNECTING);
|
statusLED->start(LED_WIFI_CONNECTING);
|
||||||
|
if(hsEventCallback)
|
||||||
|
hsEventCallback(HS_WIFI_CONNECTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(controlButton)
|
if(controlButton)
|
||||||
|
|
@ -328,8 +332,8 @@ int Span::getFreeSlot(){
|
||||||
|
|
||||||
void Span::commandMode(){
|
void Span::commandMode(){
|
||||||
|
|
||||||
if(!statusDevice){
|
if(!statusDevice && !hsEventCallback){
|
||||||
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 OR EVENT HANDLER CALLBACK***\n\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,13 @@ enum {
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
|
enum HS_EVENT {
|
||||||
|
HS_WIFI_NEEDED,
|
||||||
|
HS_WIFI_CONNECTING
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
// Forward-Declarations
|
// Forward-Declarations
|
||||||
|
|
||||||
struct Span;
|
struct Span;
|
||||||
|
|
@ -203,6 +210,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 (*hsEventCallback)(HS_EVENT hsEvent)=NULL; // optional callback for various HomeSpan events
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -284,6 +292,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 setEventCallback(void (*f)(HS_EVENT hsEvent)){hsEventCallback=f;} // sets an optional user-defined function to call for various HomeSpan Events
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ void setup() {
|
||||||
homeSpan.setSketchVersion("OTA Test 8");
|
homeSpan.setSketchVersion("OTA Test 8");
|
||||||
homeSpan.setWifiCallback(wifiEstablished);
|
homeSpan.setWifiCallback(wifiEstablished);
|
||||||
|
|
||||||
|
homeSpan.setEventCallback(hsEvents);
|
||||||
|
|
||||||
new SpanUserCommand('d',"- My Description",userCom1);
|
new SpanUserCommand('d',"- My Description",userCom1);
|
||||||
new SpanUserCommand('e',"- My second Description",userCom2);
|
new SpanUserCommand('e',"- My second Description",userCom2);
|
||||||
|
|
||||||
|
|
@ -162,3 +164,9 @@ void userCom1(const char *v){
|
||||||
void userCom2(const char *v){
|
void userCom2(const char *v){
|
||||||
Serial.printf("In User Command 2: '%s'\n\n",v);
|
Serial.printf("In User Command 2: '%s'\n\n",v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////
|
||||||
|
|
||||||
|
void hsEvents(HS_EVENT event){
|
||||||
|
Serial.printf("\n*** HOMESPAN EVENT: %d\n",event);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue