From 7b30f971e2e55e04c03a1deb74248f64d9dcde6e Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 1 May 2022 09:24:45 -0500 Subject: [PATCH] Continued refactoring of 'i' CLI command --- src/HomeSpan.cpp | 73 ++++++++++++++++++++++-------------------------- src/HomeSpan.h | 5 ++-- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 53a4da3..8b93d12 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -947,7 +947,9 @@ void Span::processSerialCommand(const char *c){ Serial.printf(" \u21e8 Characteristic %s(%s): IID=%d, %sUUID=\"%s\"",(*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type); if((*chr)->format!=FORMAT::STRING && (*chr)->format!=FORMAT::BOOL){ - if((*chr)->uvGet((*chr)->stepValue)>0) + if((*chr)->validValues) + Serial.printf(", Valid Values=%s",(*chr)->validValues); + else if((*chr)->uvGet((*chr)->stepValue)>0) Serial.printf(", %sRange=[%s,%s,%s]",(*chr)->customRange?"Custom-":"",(*chr)->uvPrint((*chr)->minValue).c_str(),(*chr)->uvPrint((*chr)->maxValue).c_str(),(*chr)->uvPrint((*chr)->stepValue).c_str()); else Serial.printf(", %sRange=[%s,%s]",(*chr)->customRange?"Custom-":"",(*chr)->uvPrint((*chr)->minValue).c_str(),(*chr)->uvPrint((*chr)->maxValue).c_str()); @@ -969,6 +971,9 @@ void Span::processSerialCommand(const char *c){ if((*chr)->setRangeError) Serial.printf(" *** WARNING! Attempt to set Custom Range for this Characteristic ignored ***\n"); + if((*chr)->setValidValuesError) + Serial.printf(" *** WARNING! Attempt to set Custom Valid Values for this Characteristic ignored ***\n"); + if((*chr)->format!=STRING && ((*chr)->uvGet((*chr)->value) < (*chr)->uvGet((*chr)->minValue) || (*chr)->uvGet((*chr)->value) > (*chr)->uvGet((*chr)->maxValue))) Serial.printf(" *** WARNING! Value of %llg is out of range [%llg,%llg] ***\n",(*chr)->uvGet((*chr)->value),(*chr)->uvGet((*chr)->minValue),(*chr)->uvGet((*chr)->maxValue)); @@ -980,6 +985,15 @@ void Span::processSerialCommand(const char *c){ if(hapChar.find(*req)==hapChar.end()) Serial.printf(" *** WARNING! Required '%s' Characteristic for this Service not found ***\n",(*req)->hapName); } + + for(auto button=PushButtons.begin(); button!=PushButtons.end(); button++){ + if((*button)->service==(*svc)){ + Serial.printf(" \u25bc SpanButton: Pin=%d, Single=%ums, Double=%ums, Long=%ums\n",(*button)->pin,(*button)->singleTime,(*button)->doubleTime,(*button)->longTime); + + if((void(*)(int,int))((*svc)->*(&SpanService::button))==(void(*)(int,int))(&SpanService::button)) + Serial.printf(" *** WARNING! No button() method defined in this Service ***\n"); + } + } } // Services @@ -1775,35 +1789,26 @@ unsigned long SpanCharacteristic::timeVal(){ /////////////////////////////// SpanCharacteristic *SpanCharacteristic::setValidValues(int n, ...){ - char c[256]; - String *s = new String("["); + + if(format!=UINT8){ + setValidValuesError=true; + return(this); + } + + String s="["; va_list vl; va_start(vl,n); for(int i=0;ic_str(); - sprintf(c,": ValidValues=%s\n",validValues); - } - - homeSpan.configLog+=c; return(this); } @@ -1814,8 +1819,9 @@ SpanCharacteristic *SpanCharacteristic::setValidValues(int n, ...){ SpanRange::SpanRange(int min, int max, int step){ if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty() || homeSpan.Accessories.back()->Services.back()->Characteristics.empty() ){ - homeSpan.configLog+=" \u2718 SpanRange: *** ERROR! Can't create new Range without a defined Characteristic! ***\n"; - homeSpan.nFatalErrors++; + Serial.printf("\nFATAL ERROR! Can't create new SpanRange(%d,%d,%d) without a defined Characteristic ***\n",min,max,step); + Serial.printf("\n=== PROGRAM HALTED ==="); + while(1); } else { homeSpan.Accessories.back()->Services.back()->Characteristics.back()->setRange(min,max,step); } @@ -1827,32 +1833,19 @@ SpanRange::SpanRange(int min, int max, int step){ SpanButton::SpanButton(int pin, uint16_t longTime, uint16_t singleTime, uint16_t doubleTime){ - homeSpan.configLog+=" \u25bc SpanButton: Pin=" + String(pin) + ", Single=" + String(singleTime) + "ms, Double=" + String(doubleTime) + "ms, Long=" + String(longTime) + "ms"; - if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){ - homeSpan.configLog+=" *** ERROR! Can't create new PushButton without a defined Service! ***\n"; - homeSpan.nFatalErrors++; - return; + Serial.printf("\nFATAL ERROR! Can't create new SpanButton(%d,%u,%u,%u) without a defined Service ***\n",pin,longTime,singleTime,doubleTime); + Serial.printf("\n=== PROGRAM HALTED ==="); + while(1); } - Serial.print("Configuring PushButton: Pin="); // initialization message - Serial.print(pin); - Serial.print("\n"); - this->pin=pin; this->longTime=longTime; this->singleTime=singleTime; this->doubleTime=doubleTime; service=homeSpan.Accessories.back()->Services.back(); - if((void(*)(int,int))(service->*(&SpanService::button))==(void(*)(int,int))(&SpanService::button)){ - homeSpan.configLog+=" *** WARNING: No button() method defined for this PushButton! ***"; - homeSpan.nWarnings++; - } - pushButton=new PushButton(pin); // create underlying PushButton - - homeSpan.configLog+="\n"; homeSpan.PushButtons.push_back(this); } diff --git a/src/HomeSpan.h b/src/HomeSpan.h index ff76397..28abf49 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -346,11 +346,12 @@ struct SpanCharacteristic{ UVal stepValue; // Characteristic step size (not applicable for STRING) boolean staticRange; // Flag that indicates whether Range is static and cannot be changed with setRange() boolean customRange=false; // Flag for custom ranges - const char *validValues=NULL; // Optional JSON array of valid values. Applicable only to uint8 Characteristics + char *validValues=NULL; // Optional JSON array of valid values. Applicable only to uint8 Characteristics boolean *ev; // Characteristic Event Notify Enable (per-connection) char *nvsKey=NULL; // key for NVS storage of Characteristic value boolean isCustom; // flag to indicate this is a Custom Characteristic - boolean setRangeError=false; // flag to indicate attempt to set range on Characteristic that does not support changes to range + boolean setRangeError=false; // flag to indicate attempt to set Range on Characteristic that does not support changes to Range + boolean setValidValuesError=false; // flag to indicate attempt to set Valid Values on Characteristic that does not support changes to Valid Values uint32_t 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