Converted SpanUserCommand to class from struct

Also cleaned up some code by moving a few HAPClient routines into Span polling function.
This commit is contained in:
Gregg 2022-05-29 06:42:38 -05:00
parent 86a0c1cf75
commit 2b25acf2e1
4 changed files with 16 additions and 15 deletions

View File

@ -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;i<homeSpan.Loops.size();i++) // loop over all services with over-ridden loop() methods
homeSpan.Loops[i]->loop(); // call the loop() method
}
//////////////////////////////////////
void HAPClient::checkNotifications(){
if(!homeSpan.Notifications.empty()){ // if there are Notifications to process

View File

@ -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

View File

@ -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();

View File

@ -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);
};