Added homeSpan.setPairCallback() method

Callback function must be of type void()(boolean isPaired).  Will be called when device is paired and when device is unpaired.  Allows for user-defineable actions upon device pairing/unpairing.
This commit is contained in:
Gregg 2022-02-06 08:39:47 -06:00
parent 9e40666231
commit f955ff689b
3 changed files with 7 additions and 1 deletions

View File

@ -661,6 +661,9 @@ int HAPClient::postPairSetupURL(){
LOG1("\n*** ACCESSORY PAIRED! ***\n");
homeSpan.statusLED.on();
if(homeSpan.pairCallback) // if set, invoke user-defined Pairing Callback to indicate device has been paired
homeSpan.pairCallback(true);
return(1);
break;
@ -1592,6 +1595,8 @@ void HAPClient::removeController(uint8_t *id){
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(LED_PAIRING_NEEDED);
if(homeSpan.pairCallback) // if set, invoke user-defined Pairing Callback to indicate device has been paired
homeSpan.pairCallback(false);
}
LOG2("\n");

View File

@ -131,6 +131,7 @@ struct Span{
char otaPwd[33]; // MD5 Hash of OTA password, represented as a string of hexidecimal characters
boolean otaAuth; // OTA requires password when set to true
void (*wifiCallback)()=NULL; // optional callback function to invoke once WiFi connectivity is established
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
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
@ -191,6 +192,7 @@ struct Span{
void setSketchVersion(const char *sVer){sketchVersion=sVer;} // set optional sketch version number
const char *getSketchVersion(){return sketchVersion;} // get sketch version number
void setWifiCallback(void (*f)()){wifiCallback=f;} // sets an optional user-defined function to call once WiFi connectivity is established
void setPairCallback(void (*f)(boolean isPaired)){pairCallback=f;} // sets an optional user-defined function to call when Pairing is established (true) or lost (false)
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
void protectPinISR(uint8_t pin){ProtectedGPIOs[pin]=0;} // protects ISR on pin from NVS operations

View File

@ -50,7 +50,6 @@ void setup() {
new Characteristic::On(0);
new Characteristic::LightMode("HELLO");
new Characteristic::DarkMode();
new Characteristic::DarkMode("OVERRIDE");
new Characteristic::Brightness(50);
new Characteristic::Name("Light 1");
new Characteristic::ColorTemperature();