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.
This commit is contained in:
parent
b2790386d6
commit
3edc30222f
|
|
@ -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
|
// 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.
|
// 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("Configuring Temperature Sensor"); // initialization message
|
||||||
Serial.print("\n");
|
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
|
if(temp->timeVal()>5000){ // check time elapsed since last update and proceed only if greater than 5 seconds
|
||||||
float temperature=temp->getVal<float>()+0.5; // "simulate" a half-degree temperature change...
|
float temperature=temp->getVal<float>()+0.5; // "simulate" a half-degree temperature change...
|
||||||
if(temperature>35.0) // ...but cap the maximum at 35C before starting over at 10C
|
if(temperature>35.0) // ...but cap the maximum at 35C before starting over at -30C
|
||||||
temperature=10.0;
|
temperature=-30.0;
|
||||||
|
|
||||||
temp->setVal(temperature); // set the new temperature; this generates an Event Notification and also resets the elapsed time
|
temp->setVal(temperature); // set the new temperature; this generates an Event Notification and also resets the elapsed time
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,8 @@ struct HapCharType {
|
||||||
|
|
||||||
#define HAPCHAR(name,id,perms) HapCharType name {#id,#name,perms}
|
#define HAPCHAR(name,id,perms) HapCharType name {#id,#name,perms}
|
||||||
|
|
||||||
|
struct HapCharList {
|
||||||
|
|
||||||
enum { // create bitflags based on HAP Table 6-4
|
enum { // create bitflags based on HAP Table 6-4
|
||||||
PR=1,
|
PR=1,
|
||||||
PW=2,
|
PW=2,
|
||||||
|
|
@ -109,8 +111,6 @@ struct HapCharType {
|
||||||
WR=64,
|
WR=64,
|
||||||
NV=128
|
NV=128
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HapCharList {
|
|
||||||
|
|
||||||
HAPCHAR( Active, B0, PW+PR+EV );
|
HAPCHAR( Active, B0, PW+PR+EV );
|
||||||
HAPCHAR( AirQuality, 95, PR+EV );
|
HAPCHAR( AirQuality, 95, PR+EV );
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue