From 4309be8f91a3af119647cd251ffe49b80c0b7506 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 24 Oct 2021 21:19:38 -0500 Subject: [PATCH] Finalized CUSTOM_CHAR() macro to add a custom Characteristic --- src/HomeSpan.h | 2 +- src/Span.h | 8 ++++++++ src/src.ino | 7 +------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 865dd22..7494647 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -441,7 +441,7 @@ struct SpanCharacteristic{ uvSet(stepValue,0); } - homeSpan.configLog+="(" + uvPrint(value) + ")" + ": IID=" + String(iid) + ", UUID=0x" + String(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)) + "]"; diff --git a/src/Span.h b/src/Span.h index 29bdac9..6cecf8b 100644 --- a/src/Span.h +++ b/src/Span.h @@ -522,3 +522,11 @@ namespace Characteristic { CREATE_CHAR(double,WaterLevel,0,0,100); } + +////////////////////////////////////////// +// MACROS TO ADD CUSTOM CHARACTERISTICS // +////////////////////////////////////////// + +#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); } }; } diff --git a/src/src.ino b/src/src.ino index 76b1973..8ab482e 100644 --- a/src/src.ino +++ b/src/src.ino @@ -4,12 +4,7 @@ #include "HomeSpan.h" -#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); } }; } - -CUSTOM_CHAR(CustomActive, 123-B0, PW+PR+EV, UINT8, uint8_t, 0, 0, 1, true); - +CUSTOM_CHAR(CustomActive, AB-123-B0, PW+PR+EV, UINT8, uint8_t, 0, 0, 1, true); void setup() {