Finalized CUSTOM_CHAR() macro to add a custom Characteristic

This commit is contained in:
Gregg 2021-10-24 21:19:38 -05:00
parent d5fa8335fb
commit 4309be8f91
3 changed files with 10 additions and 7 deletions

View File

@ -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)) + "]";

View File

@ -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); } }; }

View File

@ -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() {