From 1b74564baf9c9da504c7862a44ec735fb178c672 Mon Sep 17 00:00:00 2001 From: Gregg Date: Fri, 29 Mar 2024 09:19:06 -0500 Subject: [PATCH] More TLV updates --- src/HomeSpan.cpp | 10 ++++++---- src/HomeSpan.h | 6 +++--- src/src.ino | 37 +++++-------------------------------- 3 files changed, 14 insertions(+), 39 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 1364b59..73973fb 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -896,7 +896,7 @@ void Span::processSerialCommand(const char *c){ LOG0("%s%s",(foundPerms++)?"+":"",pNames[i]); } - if((*chr)->format!=FORMAT::STRING && (*chr)->format!=FORMAT::BOOL && (*chr)->format!=FORMAT::DATA){ + if((*chr)->formatformat!=FORMAT::BOOL){ if((*chr)->validValues) LOG0(", Valid Values=%s",(*chr)->validValues); else if((*chr)->uvGet((*chr)->stepValue)>0) @@ -937,7 +937,7 @@ void Span::processSerialCommand(const char *c){ if((*chr)->setValidValuesError) LOG0(" *** WARNING #%d! Attempt to set Custom Valid Values for this Characteristic ignored ***\n",++nWarnings); - if((*chr)->format!=STRING && (!(((*chr)->uvGet((*chr)->value) >= (*chr)->uvGet((*chr)->minValue)) && ((*chr)->uvGet((*chr)->value) <= (*chr)->uvGet((*chr)->maxValue))))) + if((*chr)->formatuvGet((*chr)->value) >= (*chr)->uvGet((*chr)->minValue)) && ((*chr)->uvGet((*chr)->value) <= (*chr)->uvGet((*chr)->maxValue))))) LOG0(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet((*chr)->value),(*chr)->uvGet((*chr)->minValue),(*chr)->uvGet((*chr)->maxValue)); } // Characteristics @@ -1457,7 +1457,7 @@ int Span::updateCharacteristics(char *buf, SpanBuf *pObj){ if(status==StatusCode::OK){ // if status is okay pObj[j].characteristic->uvSet(pObj[j].characteristic->value,pObj[j].characteristic->newValue); // update characteristic value with new value if(pObj[j].characteristic->nvsKey){ // if storage key found - if(pObj[j].characteristic->format!=FORMAT::STRING && pObj[j].characteristic->format!=FORMAT::DATA) + if(pObj[j].characteristic->formatnvsKey,pObj[j].characteristic->value.UINT64); // store data as uint64_t regardless of actual type (it will be read correctly when access through uvGet()) else nvs_set_str(charNVS,pObj[j].characteristic->nvsKey,pObj[j].characteristic->value.STRING); // store data @@ -1833,7 +1833,7 @@ SpanCharacteristic::~SpanCharacteristic(){ free(validValues); free(nvsKey); - if(format==FORMAT::STRING || format==FORMAT::DATA){ + if(format>=FORMAT::STRING){ free(value.STRING); free(newValue.STRING); } @@ -2005,6 +2005,8 @@ StatusCode SpanCharacteristic::loadUpdate(char *val, char *ev, boolean wr){ break; case STRING: + case DATA: + case TLV_ENC: uvSet(newValue,(const char *)val); break; diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 99865a7..e10c32a 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -675,12 +675,12 @@ class SpanCharacteristic{ void setString(const char *val, boolean notify=true){ if(!((perms&EV) || (updateFlag==2))){ - LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. No EVENT NOTIFICATION (EV) permission on this characteristic\n\n",hapName); + LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setString() ignored. No EVENT NOTIFICATION (EV) permission on this characteristic\n\n",hapName); return; } if(updateFlag==1) - LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal() within update() while it is being updated by Home App. This may cause device to become non-responsive!\n\n",hapName); + LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setString() within update() while it is being updated by Home App. This may cause device to become non-responsive!\n\n",hapName); uvSet(value,val); uvSet(newValue,value); @@ -763,7 +763,7 @@ class SpanCharacteristic{ template void setVal(T val, boolean notify=true){ if(!((perms&EV) || (updateFlag==2))){ - LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. No EVENT NOTIFICATION (EV) permission on this characteristic\n\n",hapName); + LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal() ignored. No EVENT NOTIFICATION (EV) permission on this characteristic\n\n",hapName); return; } diff --git a/src/src.ino b/src/src.ino index e92ce80..19677e5 100644 --- a/src/src.ino +++ b/src/src.ino @@ -30,41 +30,11 @@ #define MAX_LIGHTS 1 +CUSTOM_CHAR_DATA(UserData, AAAAAAAA-BBBB-AAAA-AAAA-AAAAAAAAAAAA, PR+PW+EV); + void setup() { Serial.begin(115200); - delay(1000); - Serial.printf("\n\nREADY\n\n"); - - TLV8 tlv, tlv2; - - const size_t nMax=257; - uint8_t c[nMax]; - for(int i=0;isetDescription("Custom Data")->setData(x,5); char c[30]; sprintf(c,"Light-%d",i); new Characteristic::Name(c); @@ -93,6 +65,7 @@ void setup() { void loop(){ homeSpan.poll(); + delay(100000); }