From 3b40aeec74ca6e6043536bae8d114fc4ec2ec0f5 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 6 Mar 2021 08:30:09 -0600 Subject: [PATCH] Added check to throw error is setRange is called twice on same Characteristic --- examples/12-ServiceLoops/DEV_Sensors.h | 2 ++ src/HomeSpan.h | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/12-ServiceLoops/DEV_Sensors.h b/examples/12-ServiceLoops/DEV_Sensors.h index 86f0cff..f33b2e1 100644 --- a/examples/12-ServiceLoops/DEV_Sensors.h +++ b/examples/12-ServiceLoops/DEV_Sensors.h @@ -70,6 +70,8 @@ struct DEV_AirQualitySensor : Service::AirQualitySensor { // A standalone Ai airQuality=new Characteristic::AirQuality(1); // instantiate the Air Quality Characteristic and set initial value to 1 o3Density=new Characteristic::OzoneDensity(300.0); // instantiate the Ozone Density Characteristic and set initial value to 300.0 no2Density=new Characteristic::NitrogenDioxideDensity(700.0); // instantiate the Nitrogen Dioxide Density Characteristic and set initial value to 700.0 + new SpanRange(300,500,2); + Serial.print("Configuring Air Quality Sensor"); // initialization message Serial.print("\n"); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 50801b4..d2d1fb7 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -342,7 +342,12 @@ struct SpanCharacteristic{ template SpanCharacteristic *setRange(A min, B max, S step=0){ char c[256]; - homeSpan.configLog+=String("------>Set Range for ") + String(hapName) + "-" + String(iid); + homeSpan.configLog+=String("------>Set Range for ") + String(hapName) + "-" + String(iid); + + if(customRange){ + sprintf(c," *** ERROR! Range already set for this Characteristic! ***\n"); + homeSpan.nFatalErrors++; + } else if(staticRange){ sprintf(c," *** ERROR! Can't change range for this Characteristic! ***\n");