Created typedef for HAP types - used to simplify CUSTOM_CHAR
No need to specify both FORMAT and TYPE. For example, specifying UINT16 automatically sets type to be uint16_t. To do: Explore if this can be used for standard Characteristics - revisit standard Characteristics definitions and structure to see if it can be simplified.
This commit is contained in:
parent
eeb3c334ac
commit
eb9530800e
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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. ***";
|
||||
|
|
|
|||
|
|
@ -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 && i<homeSpan.Accessories.back()->Services.back()->req.size(); i++)
|
||||
valid=!strcmp(type,homeSpan.Accessories.back()->Services.back()->req[i]->type);
|
||||
|
|
|
|||
13
src/Span.h
13
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); } }; }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue