diff --git a/src/HAP.cpp b/src/HAP.cpp index 2f051c2..f716a13 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -1175,6 +1175,16 @@ void HAPClient::callServiceLoops(){ ////////////////////////////////////// +void HAPClient::checkNotifications(){ + + if(!homeSpan.Notifications.empty()){ // if there are Notifications to process + eventNotify(&homeSpan.Notifications[0],homeSpan.Notifications.size()); // transmit EVENT Notifications + homeSpan.Notifications.clear(); // clear Notifications vector + } +} + +////////////////////////////////////// + void HAPClient::checkEvents(){ unsigned long cTime=millis(); // current time diff --git a/src/HAP.h b/src/HAP.h index d80c341..681eb57 100644 --- a/src/HAP.h +++ b/src/HAP.h @@ -115,6 +115,7 @@ struct HAPClient { static void checkTimedResets(); // checks for Timed Resets and reports to controllers as needed (HAP Section 6.8) static void callServiceLoops(); // call the loop() method for any Service with that over-rode the default method static void checkEvents(); // checks for Event Notifications and reports to controllers as needed (HAP Section 6.8) + static void checkNotifications(); // checks for Event Notifications and reports to controllers as needed (HAP Section 6.8) static void checkTimedWrites(); // checks for expired Timed Write PIDs, and clears any found (HAP Section 6.7.2.4) static void eventNotify(SpanBuf *pObj, int nObj, int ignoreClient=-1); // transmits EVENT Notifications for nObj SpanBuf objects, pObj, with optional flag to ignore a specific client }; diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 713619b..6f82de7 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -149,7 +149,7 @@ void Span::poll() { HAPClient::checkTimedResets(); HAPClient::callServiceLoops(); - HAPClient::checkEvents(); + HAPClient::checkNotifications(); HAPClient::checkTimedWrites(); } // poll @@ -575,6 +575,8 @@ int Span::updateCharacteristics(char *buf, SpanBuf *pObj){ } // parse objects + snapTime=millis(); // timestamp for this series of updates, assigned to each characteristic in loadUpdate() + for(int i=0;i TimedResets; // vector of pointers to all TimedResets vector Events; // vector of pointer to all Events vector Loops; // vector of pointer to all Services that have over-ridden loop() methods + vector Notifications; // vector of SpanBuf objects that store info for Characteristics that are updated with setVal() and require a Notification Event unordered_map TimedWrites; // map of timed-write PIDs and Alarm Times (based on TTLs) void begin(Category catID, @@ -157,7 +158,8 @@ struct SpanCharacteristic{ boolean ev[MAX_CONNECTIONS]={false}; // Characteristic Event Notify Enable (per-connection) int aid=0; // Accessory ID - passed through from Service containing this Characteristic - boolean isUpdated=false; // set to true when new value has been requested by PUT /characteristic, or when value is updated with setVal() + boolean isUpdated=false; // set to true when new value has been requested by PUT /characteristic + unsigned long updateTime; // last time value was updated (in millis) either by PUT /characteristic OR by setVal() UVal newValue; // the updated value requested by PUT /characteristic SpanService *service=NULL; // pointer to Service containing this Characteristic @@ -182,6 +184,7 @@ struct SpanCharacteristic{ void setVal(double value); // sets value of UVal value for FLOAT Characteristic type boolean updated(){return(isUpdated);} // returns isUpdated + int timeVal(); // returns time elapsed (in millis) since value was last updated };