Modified range checks so that "NAN" gets picked up as error for FLOAT Characteristics

This commit is contained in:
Gregg 2024-01-11 21:57:42 -06:00
parent ba240ea4d7
commit b5dcfbbd7d
3 changed files with 8 additions and 3 deletions

View File

@ -912,7 +912,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<double>((*chr)->value) < (*chr)->uvGet<double>((*chr)->minValue) || (*chr)->uvGet<double>((*chr)->value) > (*chr)->uvGet<double>((*chr)->maxValue)))
if((*chr)->format!=STRING && (!(((*chr)->uvGet<double>((*chr)->value) >= (*chr)->uvGet<double>((*chr)->minValue)) && ((*chr)->uvGet<double>((*chr)->value) <= (*chr)->uvGet<double>((*chr)->maxValue)))))
LOG0(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet<double>((*chr)->value),(*chr)->uvGet<double>((*chr)->minValue),(*chr)->uvGet<double>((*chr)->maxValue));
} // Characteristics

View File

@ -740,7 +740,7 @@ class SpanCharacteristic{
return;
}
if(val < uvGet<T>(minValue) || val > uvGet<T>(maxValue)){
if(!((val >= uvGet<T>(minValue)) && (val <= uvGet<T>(maxValue)))){
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal(%g) is out of range [%g,%g]. This may cause device to become non-responsive!\n\n",
hapName,(double)val,uvGet<double>(minValue),uvGet<double>(maxValue));
}

View File

@ -29,6 +29,8 @@
#define MAX_LIGHTS 2
SpanCharacteristic *brightness[2];
void setup() {
Serial.begin(115200);
@ -50,11 +52,14 @@ void setup() {
sprintf(c,"Light-%d",i);
new Characteristic::Name(c);
new Service::LightBulb();
new Characteristic::On(0,false);
new Characteristic::On(0,true);
brightness[i]=new Characteristic::Saturation(0,true);
WEBLOG("Configuring %s\n",c);
}
new SpanUserCommand('w', " - get web log test",webLogTest); // simulate getting an HTTPS request for weblog
new SpanUserCommand('b', " - change brightness to fraction",[](const char *buf){brightness[0]->setVal(atof(buf+1));}); // simulate getting an HTTPS request for weblog
new SpanUserCommand('c', " - change brightness to fraction",[](const char *buf){brightness[1]->setVal(atof(buf+1));}); // simulate getting an HTTPS request for weblog
}