Updated TimedReset

Allow for any characteristic that is not read-only, which should leave out all string characteristics.

Upon reset, zero out all 8 bytes of UVal memory, instead of simply setting UVal.BOOL to false.  This allows use of TimedReset for any characteristic with a numerical value.
This commit is contained in:
Gregg 2020-08-01 08:32:16 -05:00
parent a595fdf53f
commit 0a07f9666d
3 changed files with 36 additions and 27 deletions

View File

@ -906,7 +906,7 @@ int HAPClient::postPairingsURL(){
case 5: case 5:
LOG1("List...\n"); LOG1("List...\n");
// NEEDS TO BE IMPLEMENTED // NEEDS TO BE IMPLEMENTED - UNSURE IF THIS IS EVER USED BY HOMEKIT
tlv8.clear(); // clear TLV records tlv8.clear(); // clear TLV records
tlv8.val(kTLVType_State,pairState_M2); // set State=<M2> tlv8.val(kTLVType_State,pairState_M2); // set State=<M2>
@ -1127,35 +1127,44 @@ int HAPClient::putCharacteristicsURL(char *json){
void HAPClient::checkNotifications(){ void HAPClient::checkNotifications(){
int n=0; int n=0;
SpanTimedReset *tReset;
for(int i=0;i<homeSpan.TimedResets.size();i++){ // PASS 1: loop through all defined Timed Resets for(int i=0;i<homeSpan.TimedResets.size();i++){ // PASS 1: loop through all defined Timed Resets
SpanTimedReset *pb=homeSpan.TimedResets[i]; tReset=homeSpan.TimedResets[i];
if(!pb->characteristic->value.BOOL){ // characteristic is off if(!tReset->characteristic->value.BOOL){ // characteristic is off
pb->start=false; // ensure timer is not started tReset->start=false; // ensure timer is not started
pb->trigger=false; // turn off trigger tReset->trigger=false; // turn off trigger
} }
else if(!pb->start){ // else characteristic is on but timer is not started else if(!tReset->start){ // else characteristic is on but timer is not started
pb->start=true; // start timer tReset->start=true; // start timer
pb->alarmTime=millis()+pb->waitTime; // set alarm time tReset->alarmTime=millis()+tReset->waitTime; // set alarm time
} }
else if(millis()>pb->alarmTime){ // else characteristic is on, timer is started, and timer is expired else if(millis()>tReset->alarmTime){ // else characteristic is on, timer is started, and timer is expired
pb->trigger=true; // set trigger tReset->trigger=true; // set trigger
n++; // increment number of Push Buttons found that need to be turned off n++; // increment number of Push Buttons found that need to be turned off
} }
} }
if(!n) // nothing to do (either no Push Button characteristics, or none that need to be turned off) if(!n) // nothing to do (either no Timed Reset characteristics, or none that need to be turned off)
return; return;
SpanPut pObj[n]; // use a SpanPut object (for convenience) to load characteristics to be updated SpanPut pObj[n]; // use a SpanPut object (for convenience) to load characteristics to be updated
n=0; // reset number of PBs found that need to be turned off n=0; // reset number of tResets found that need to be turned off
for(int i=0;i<homeSpan.TimedResets.size();i++){ // PASS 2: loop through all defined Timed Resets for(int i=0;i<homeSpan.TimedResets.size();i++){ // PASS 2: loop through all defined Timed Resets
SpanTimedReset *pb=homeSpan.TimedResets[i]; tReset=homeSpan.TimedResets[i];
if(pb->trigger){ // characteristic is triggered if(tReset->trigger){ // characteristic is triggered
pb->characteristic->value.BOOL=false; // turn off characteristic
LOG1("Resetting aid=");
LOG1(tReset->characteristic->aid);
LOG1(" iid=");
LOG1(tReset->characteristic->iid);
LOG1("\n");
memset(&(tReset->characteristic->value),0,sizeof(tReset->characteristic->value));
pObj[n].status=StatusCode::OK; // populate pObj pObj[n].status=StatusCode::OK; // populate pObj
pObj[n].characteristic=pb->characteristic; pObj[n].characteristic=tReset->characteristic;
pObj[n].val=""; // dummy object needed to ensure sprintfNotify knows to consider this "update" pObj[n].val=""; // dummy object needed to ensure sprintfNotify knows to consider this "update"
n++; // increment number of Push Buttons found that need to be turned off n++; // increment number of Push Buttons found that need to be turned off
} }

View File

@ -1064,8 +1064,8 @@ SpanTimedReset::SpanTimedReset(int waitTime){
while(1); while(1);
} }
if(homeSpan.Accessories.back()->Services.back()->Characteristics.back()->format!=SpanCharacteristic::BOOL){ if(!(homeSpan.Accessories.back()->Services.back()->Characteristics.back()->perms&SpanCharacteristic::PW)){
Serial.print("*** FATAL ERROR: Can't create new TimedReset for non-Boolean Characteristic. Program halted!\n\n"); Serial.print("*** FATAL ERROR: Can't create new Timed Reset for Read-Only Characteristic. Program halted!\n\n");
while(1); while(1);
} }

View File

@ -18,7 +18,7 @@ const int MAX_CONNECTIONS=8;
// Verbosity -- controls message output // // Verbosity -- controls message output //
// 0=Minimal, 1=Informative, 2=All // // 0=Minimal, 1=Informative, 2=All //
#define VERBOSITY 1 #define VERBOSITY 2
//-------------------------------------------------// //-------------------------------------------------//