diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index f0b0b15..3c2928e 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -157,6 +157,8 @@ void Span::poll() { homeSpan.Accessories.back()->validate(); } + checkRanges(); + if(nWarnings>0){ configLog+="\n*** CAUTION: There " + String((nWarnings>1?"are ":"is ")) + String(nWarnings) + " WARNING" + (nWarnings>1?"S":"") + " associated with this configuration that may lead to the device becoming non-responsive, or operating in an unexpected manner. ***\n"; } @@ -1347,6 +1349,37 @@ int Span::sprintfAttributes(char **ids, int numIDs, int flags, char *cBuf){ return(nChars); } +/////////////////////////////// + +void Span::checkRanges(){ + + boolean okay=true; + homeSpan.configLog+="\nRange Check:"; + + for(int i=0;iServices.size();j++){ + for(int k=0;kServices[j]->Characteristics.size();k++){ + SpanCharacteristic *chr=Accessories[i]->Services[j]->Characteristics[k]; + + if(chr->format!=STRING && (chr->uvGet(chr->value) < chr->uvGet(chr->minValue) || chr->uvGet(chr->value) > chr->uvGet(chr->maxValue))){ + char c[256]; + sprintf(c,"\n \u2718 Characteristic %s with AID=%d, IID=%d: Initial value of %lg is out of range [%llg,%llg]", + chr->hapName,chr->aid,chr->iid,chr->uvGet(chr->value),chr->uvGet(chr->minValue),chr->uvGet(chr->maxValue)); + if(okay) + homeSpan.configLog+="\n"; + homeSpan.configLog+=c; + homeSpan.nWarnings++; + okay=false; + } + } + } + } + + if(okay) + homeSpan.configLog+=" No Warnings"; + homeSpan.configLog+="\n\n"; +} + /////////////////////////////// // SpanAccessory // /////////////////////////////// @@ -1411,18 +1444,6 @@ void SpanAccessory::validate(){ foundProtocol=true; else if(aid==1) // this is an Accessory with aid=1, but it has more than just AccessoryInfo and HAPProtocolInformation. So... homeSpan.isBridge=false; // ...this is not a bridge device - - for(int j=0;jCharacteristics.size();j++){ // check that initial values are all in range of mix/max (which may have been modified by setRange) - SpanCharacteristic *chr=Services[i]->Characteristics[j]; - - if(chr->format!=STRING && (chr->uvGet(chr->value) < chr->uvGet(chr->minValue) || chr->uvGet(chr->value) > chr->uvGet(chr->maxValue))){ - char c[256]; - sprintf(c," \u2718 Characteristic %s with IID=%d *** WARNING: Initial value of %lg is out of range [%llg,%llg]. ***\n", - chr->hapName,chr->iid,chr->uvGet(chr->value),chr->uvGet(chr->minValue),chr->uvGet(chr->maxValue)); - homeSpan.configLog+=c; - homeSpan.nWarnings++; - } - } } if(!foundInfo){ diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 19f6918..828fab2 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -156,6 +156,7 @@ struct Span{ void checkConnect(); // check WiFi connection; connect if needed void commandMode(); // allows user to control and reset HomeSpan settings with the control button void processSerialCommand(const char *c); // process command 'c' (typically from readSerial, though can be called with any 'c') + void checkRanges(); // checks values of all Characteristics to ensure they are each within range int sprintfAttributes(char *cBuf); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL void prettyPrint(char *buf, int nsp=2); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces diff --git a/src/src.ino b/src/src.ino index 68b3b06..b381edd 100644 --- a/src/src.ino +++ b/src/src.ino @@ -45,8 +45,8 @@ void setup() { new Service::LightBulb(); new Characteristic::On(0); - SpanCharacteristic *active = new Characteristic::CustomActive(2); - new Characteristic::Brightness(500); + SpanCharacteristic *active = new Characteristic::CustomActive(); + new Characteristic::Brightness(50); new Characteristic::Name("Light 1"); new Characteristic::ColorTemperature(); new Characteristic::Active(); @@ -57,7 +57,7 @@ void setup() { new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments - active->setRange(0,10,3); +// active->setRange(0,10,3); new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, which has 6 required Characteristics new Characteristic::Name("HomeSpan Test"); // Name of the Accessory, which shows up on the HomeKit "tiles", and should be unique across Accessories new Characteristic::Manufacturer("HomeSpan"); // Manufacturer of the Accessory (arbitrary text string, and can be the same for every Accessory)