From 09063fb7dc3478849f0f19d114ea86bd81039b43 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 25 Feb 2023 15:07:02 -0600 Subject: [PATCH] Extended functionality of setValidValues() to allow INT, UINT8, UINT16, and UINT32 Characteristics --- examples/08-Bridges/08-Bridges.ino | 2 +- src/HomeSpan.cpp | 23 ++++++++--- src/HomeSpan.h | 2 +- src/src.ino | 65 +++++++----------------------- 4 files changed, 33 insertions(+), 59 deletions(-) diff --git a/examples/08-Bridges/08-Bridges.ino b/examples/08-Bridges/08-Bridges.ino index 072daa6..0331f3c 100644 --- a/examples/08-Bridges/08-Bridges.ino +++ b/examples/08-Bridges/08-Bridges.ino @@ -39,7 +39,7 @@ void setup() { - // If the only Service defined in the FIRST Accessory of a mult-Accessory device is the required Accessory Information Service, + // If the only Service defined in the FIRST Accessory of a multi-Accessory device is the required Accessory Information Service, // the device is said to be configured as a "Bridge". Historically there may have been a number of functional differences between bridge // devices and non-bridge devices, but since iOS 15, it's not obvious there are any differences in functionality, with two exceptions: diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 16915bc..2a709e8 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -1977,17 +1977,28 @@ unsigned long SpanCharacteristic::timeVal(){ /////////////////////////////// SpanCharacteristic *SpanCharacteristic::setValidValues(int n, ...){ - - if(format!=UINT8){ - setValidValuesError=true; - return(this); - } String s="["; va_list vl; va_start(vl,n); for(int i=0;i SpanCharacteristic *setRange(A min, B max, S step=0){ diff --git a/src/src.ino b/src/src.ino index 3585673..1760ce2 100644 --- a/src/src.ino +++ b/src/src.ino @@ -30,70 +30,33 @@ #include "HomeSpan.h" -struct RemoteTempSensor : Service::TemperatureSensor { - - SpanCharacteristic *temp; - SpanCharacteristic *fault; - SpanPoint *remoteTemp; - const char *name; - float temperature; - - RemoteTempSensor(const char *name, const char*macAddress, boolean is8266=false) : Service::TemperatureSensor(){ - - this->name=name; - - temp=new Characteristic::CurrentTemperature(-10.0); // set initial temperature - temp->setRange(-50,100); // expand temperature range to allow negative values - - fault=new Characteristic::StatusFault(1); // set initial state = fault - - remoteTemp=new SpanPoint(macAddress,0,sizeof(float),1,is8266); // create a SpanPoint with send size=0 and receive size=sizeof(float) - - } // end constructor - - void loop(){ - - if(remoteTemp->get(&temperature)){ // if there is data from the remote sensor - temp->setVal(temperature); // update temperature - fault->setVal(0); // clear fault - - LOG1("Sensor %s update: Temperature=%0.2f\n",name,temperature*9/5+32); - - } else if(remoteTemp->time()>60000 && !fault->getVal()){ // else if it has been a while since last update (60 seconds), and there is no current fault - fault->setVal(1); // set fault state - LOG1("Sensor %s update: FAULT\n",name); - } - - } // loop - -}; +CUSTOM_CHAR(CharFloat, 00000001-0001-0001-0001-46637266EA00, PR+PW+EV, FLOAT, 0, 0, 100, false); +CUSTOM_CHAR(CharUInt8, 00000009-0001-0001-0001-46637266EA00, PR+PW+EV, UINT8, 0, 0, 100, false); +CUSTOM_CHAR(CharUInt16, 00000016-0001-0001-0001-46637266EA00, PR+PW+EV, UINT16, 0, 0, 100, false); +CUSTOM_CHAR(CharUInt32, 00000032-0001-0001-0001-46637266EA00, PR+PW+EV, UINT32, 0, 0, 100, false); +CUSTOM_CHAR(CharInt, 00000002-0001-0001-0001-46637266EA00, PR+PW+EV, INT, 0, 0, 100, false); ////////////////////////////////////// - + void setup() { Serial.begin(115200); homeSpan.setLogLevel(1); - homeSpan.begin(Category::Bridges,"Sensor Hub"); + homeSpan.begin(Category::Other,"HomeSpan Test"); new SpanAccessory(); new Service::AccessoryInformation(); new Characteristic::Identify(); - - new SpanAccessory(); - new Service::AccessoryInformation(); - new Characteristic::Identify(); - new Characteristic::Name("Indoor Temp"); - new RemoteTempSensor("Device 1","AC:67:B2:77:42:20"); // pass MAC Address of Remote Device - - new SpanAccessory(); - new Service::AccessoryInformation(); - new Characteristic::Identify(); - new Characteristic::Name("Outdoor Temp"); - new RemoteTempSensor("Device 2","BC:FF:4D:40:8E:71",true); // pass MAC Address of Remote Device with 8266 flag set (will use AP MAC Address) + new Service::LightBulb(); + new Characteristic::On(); + (new Characteristic::CharFloat())->setValidValues(5,0,1,2,6,7,8); + (new Characteristic::CharUInt8())->setValidValues(5,0,1,2,6,7,8); + (new Characteristic::CharUInt16())->setValidValues(5,0,1<<8,1<<16,0xFFFFFFFF,-1); + (new Characteristic::CharUInt32())->setValidValues(5,0,1<<8,1<<16,0xFFFFFFFF,-1); + (new Characteristic::CharInt())->setValidValues(5,0,255,2000000000,-2000000000,-1); } // end of setup()