From 3edc30222f5882652340318fcd9d87717fabab43 Mon Sep 17 00:00:00 2001 From: Gregg Date: Mon, 22 Feb 2021 20:27:42 -0600 Subject: [PATCH] Updated Example 12 to demonstrate negative temperatures Use SpanRange() to change HAP default range of 0-100 to -50 to 100. Change starting temp +30 and have it reset to -30 after hitting +35. --- examples/12-ServiceLoops/DEV_Sensors.h | 7 ++++--- src/HAPConstants.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/12-ServiceLoops/DEV_Sensors.h b/examples/12-ServiceLoops/DEV_Sensors.h index f32520d..a47acb6 100644 --- a/examples/12-ServiceLoops/DEV_Sensors.h +++ b/examples/12-ServiceLoops/DEV_Sensors.h @@ -15,7 +15,8 @@ struct DEV_TempSensor : Service::TemperatureSensor { // A standalone Tempera // Though the HAP documentation includes a Characteristic that appears to allow the device to over-ride this setting by specifying a display // of Celsius or Fahrenheit for each Service, it does not appear to work as advertised. - temp=new Characteristic::CurrentTemperature(20.0); // instantiate the Current Temperature Characteristic + temp=new Characteristic::CurrentTemperature(30.0); // instantiate the Current Temperature Characteristic + new SpanRange(-50,100,1); // expand the range from the HAP default of 0-100 to -50 to 100 to allow for negative temperatures Serial.print("Configuring Temperature Sensor"); // initialization message Serial.print("\n"); @@ -39,8 +40,8 @@ struct DEV_TempSensor : Service::TemperatureSensor { // A standalone Tempera if(temp->timeVal()>5000){ // check time elapsed since last update and proceed only if greater than 5 seconds float temperature=temp->getVal()+0.5; // "simulate" a half-degree temperature change... - if(temperature>35.0) // ...but cap the maximum at 35C before starting over at 10C - temperature=10.0; + if(temperature>35.0) // ...but cap the maximum at 35C before starting over at -30C + temperature=-30.0; temp->setVal(temperature); // set the new temperature; this generates an Event Notification and also resets the elapsed time diff --git a/src/HAPConstants.h b/src/HAPConstants.h index fdef845..3e23ffc 100644 --- a/src/HAPConstants.h +++ b/src/HAPConstants.h @@ -99,6 +99,8 @@ struct HapCharType { #define HAPCHAR(name,id,perms) HapCharType name {#id,#name,perms} +struct HapCharList { + enum { // create bitflags based on HAP Table 6-4 PR=1, PW=2, @@ -109,8 +111,6 @@ struct HapCharType { WR=64, NV=128 }; - -struct HapCharList { HAPCHAR( Active, B0, PW+PR+EV ); HAPCHAR( AirQuality, 95, PR+EV );