diff --git a/src/Characteristics.h b/src/Characteristics.h index cf2b44d..8b85fa2 100644 --- a/src/Characteristics.h +++ b/src/Characteristics.h @@ -53,6 +53,17 @@ enum FORMAT { // HAP Table 6-5 /////////////////////////////// +typedef boolean BOOL_t; +typedef uint8_t UINT8_t; +typedef uint16_t UINT16_t; +typedef uint32_t UINT32_t; +typedef uint64_t UINT64_t; +typedef int32_t INT_t; +typedef double FLOAT_t; +typedef char * STRING_t; + +/////////////////////////////// + struct HapChar { const char *type; const char *hapName; diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index b6a77dc..f0b0b15 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -1479,7 +1479,7 @@ SpanService::SpanService(const char *type, const char *hapName){ homeSpan.Accessories.back()->Services.push_back(this); iid=++(homeSpan.Accessories.back()->iidCount); - homeSpan.configLog+=": IID=" + String(iid) + ", UUID=0x" + String(type); + homeSpan.configLog+=": IID=" + String(iid) + ", UUID=\"" + String(type) + "\""; if(!strcmp(this->type,"3E") && iid!=1){ homeSpan.configLog+=" *** ERROR! The AccessoryInformation Service must be defined before any other Services in an Accessory. ***"; diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 7494647..f06314d 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -239,14 +239,14 @@ struct SpanCharacteristic{ union UVal { - boolean BOOL; - uint8_t UINT8; - uint16_t UINT16; - uint32_t UINT32; - uint64_t UINT64; - int32_t INT; - double FLOAT; - char *STRING = NULL; + BOOL_t BOOL; + UINT8_t UINT8; + UINT16_t UINT16; + UINT32_t UINT32; + UINT64_t UINT64; + INT_t INT; + FLOAT_t FLOAT; + STRING_t STRING = NULL; }; int iid=0; // Instance ID (HAP Table 6-3) @@ -441,16 +441,18 @@ struct SpanCharacteristic{ uvSet(stepValue,0); } - homeSpan.configLog+="(" + uvPrint(value) + ")" + ": IID=" + String(iid) + ", UUID=" + String(type); + boolean isCustom=strchr(type,'-'); + + homeSpan.configLog+="(" + uvPrint(value) + ")" + ": IID=" + String(iid) + ", UUID=\"" + String(type) + "\""; if(format!=FORMAT::STRING && format!=FORMAT::BOOL) - homeSpan.configLog+= " Range=[" + String(uvPrint(minValue)) + "," + String(uvPrint(maxValue)) + "]"; + homeSpan.configLog+= ", Range=[" + String(uvPrint(minValue)) + "," + String(uvPrint(maxValue)) + "]"; if(nvsFlag==2) homeSpan.configLog+=" (restored)"; else if(nvsFlag==1) homeSpan.configLog+=" (storing)"; - - boolean valid=false; + + boolean valid=isCustom; for(int i=0; !valid && iServices.back()->req.size(); i++) valid=!strcmp(type,homeSpan.Accessories.back()->Services.back()->req[i]->type); diff --git a/src/Span.h b/src/Span.h index 6cecf8b..3a6ce2d 100644 --- a/src/Span.h +++ b/src/Span.h @@ -524,9 +524,16 @@ namespace Characteristic { } ////////////////////////////////////////// -// MACROS TO ADD CUSTOM CHARACTERISTICS // +// MACRO TO ADD CUSTOM CHARACTERISTICS // ////////////////////////////////////////// -#define CUSTOM_CHAR(NAME,UUID,PERMISISONS,FORMAT,TYPE,DEFVAL,MINVAL,MAXVAL,STATIC_RANGE) \ +//#define CUSTOM_CHAR(NAME,UUID,PERMISISONS,FORMAT,TYPE,DEFVAL,MINVAL,MAXVAL,STATIC_RANGE) \ +// HapChar _CUSTOM_##NAME {#UUID,#NAME,(PERMS)(PERMISISONS),FORMAT,STATIC_RANGE}; \ +// namespace Characteristic { struct NAME : SpanCharacteristic { NAME(TYPE val=DEFVAL, boolean nvsStore=false) : SpanCharacteristic {&_CUSTOM_##NAME} { init(val,nvsStore,(TYPE)MINVAL,(TYPE)MAXVAL); } }; } + + +#define CUSTOM_CHAR(NAME,UUID,PERMISISONS,FORMAT,DEFVAL,MINVAL,MAXVAL,STATIC_RANGE) \ HapChar _CUSTOM_##NAME {#UUID,#NAME,(PERMS)(PERMISISONS),FORMAT,STATIC_RANGE}; \ - namespace Characteristic { struct NAME : SpanCharacteristic { NAME(TYPE val=DEFVAL, boolean nvsStore=false) : SpanCharacteristic {&_CUSTOM_##NAME} { init(val,nvsStore,(TYPE)MINVAL,(TYPE)MAXVAL); } }; } + namespace Characteristic { struct NAME : SpanCharacteristic { NAME(FORMAT##_t val=DEFVAL, boolean nvsStore=false) : SpanCharacteristic {&_CUSTOM_##NAME} { init(val,nvsStore,(FORMAT##_t)MINVAL,(FORMAT##_t)MAXVAL); } }; } + + diff --git a/src/src.ino b/src/src.ino index f594660..9f1e5c6 100644 --- a/src/src.ino +++ b/src/src.ino @@ -4,7 +4,7 @@ #include "HomeSpan.h" -// CUSTOM_CHAR(CustomActive, AB-123-B0, PW+PR+EV, UINT8, uint8_t, 0, 0, 1, true); +CUSTOM_CHAR(CustomActive, AB-123-B0, PW+PR+EV, UINT8, 0, 0, 1, false); void setup() { @@ -45,9 +45,11 @@ void setup() { new Service::LightBulb(); new Characteristic::On(0); - new Characteristic::Brightness(); + (new Characteristic::CustomActive(2))->setRange(0,10,3); + new Characteristic::Brightness(500); new Characteristic::Name("Light 1"); new Characteristic::ColorTemperature(); + new Characteristic::Active(); new Service::LightBulb(); new Characteristic::On(0,true); (new Characteristic::Brightness(50,true))->setRange(10,100,5);