From 2b25acf2e114ba1c8650ef51bba9c2d2072adf55 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 29 May 2022 06:42:38 -0500 Subject: [PATCH] Converted SpanUserCommand to class from struct Also cleaned up some code by moving a few HAPClient routines into Span polling function. --- src/HAP.cpp | 10 ---------- src/HAP.h | 1 - src/HomeSpan.cpp | 5 ++++- src/HomeSpan.h | 15 ++++++++++++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/HAP.cpp b/src/HAP.cpp index 4f7a09b..66f5893 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -1313,16 +1313,6 @@ int HAPClient::getStatusURL(){ ////////////////////////////////////// -void HAPClient::callServiceLoops(){ - - homeSpan.snapTime=millis(); // snap the current time for use in ALL loop routines - - for(int i=0;iloop(); // call the loop() method -} - -////////////////////////////////////// - void HAPClient::checkNotifications(){ if(!homeSpan.Notifications.empty()){ // if there are Notifications to process diff --git a/src/HAP.h b/src/HAP.h index b26d7f0..8ed6db1 100644 --- a/src/HAP.h +++ b/src/HAP.h @@ -142,7 +142,6 @@ struct HAPClient { static void removeControllers(); // removes all Controllers (sets allocated flags to false for all slots) static void removeController(uint8_t *id); // removes specific Controller. If no remaining admin Controllers, remove all others (if any) as per HAP requirements. static void printControllers(); // prints IDs of all allocated (paired) Controller - static void callServiceLoops(); // call the loop() method for any Service with that over-rode the default method 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 8e050aa..bb2cb3c 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -276,7 +276,10 @@ void Span::pollTask() { } // process HAP Client } // for-loop over connection slots - HAPClient::callServiceLoops(); + snapTime=millis(); // snap the current time for use in ALL loop routines + + for(auto it=Loops.begin();it!=Loops.end();it++) // call loop() for all Services with over-ridden loop() methods + (*it)->loop(); for(auto it=PushButtons.begin();it!=PushButtons.end();it++) // check for SpanButton presses (*it)->check(); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index d14636a..8fbebd7 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -77,7 +77,9 @@ struct SpanUserCommand; extern Span homeSpan; -/////////////////////////////// +//////////////////////////////////////////////////////// +// INTERNAL HOMESPAN STRUCTURES - NOT FOR USER ACCESS // +//////////////////////////////////////////////////////// struct SpanPartition{ char magicCookie[32]; @@ -145,7 +147,9 @@ struct SpanOTA{ // manages OTA process static void error(ota_error_t err); }; -/////////////////////////////// +////////////////////////////////////// +// USER API CLASSES BEGINS HERE // +////////////////////////////////////// struct Span{ @@ -693,12 +697,17 @@ class SpanButton{ /////////////////////////////// -struct SpanUserCommand { +class SpanUserCommand { + + friend class Span; + const char *s; // description of command void (*userFunction1)(const char *v)=NULL; // user-defined function to call void (*userFunction2)(const char *v, void *arg)=NULL; // user-defined function to call with user-defined arg void *userArg; + public: + SpanUserCommand(char c, const char *s, void (*f)(const char *)); SpanUserCommand(char c, const char *s, void (*f)(const char *, void *), void *arg); };