Added CUSTOM_CHAR_DATA() macro

Similar to CUSTOM_CHAR_STRING() macro, but does not include a parameter to set the default value (since the user can type an invalid string).  Instead, user setData after creating the Characteristic as needed.
This commit is contained in:
Gregg 2023-01-01 15:08:34 -06:00
parent 72b4ece64d
commit 3cb8d27342
3 changed files with 19 additions and 7 deletions

View File

@ -196,8 +196,6 @@ struct HapCharacteristics {
HAPCHAR( VolumeSelector, EA, PW, UINT8, true ); HAPCHAR( VolumeSelector, EA, PW, UINT8, true );
HAPCHAR( WaterLevel, B5, PR+EV, FLOAT, false ); HAPCHAR( WaterLevel, B5, PR+EV, FLOAT, false );
HAPCHAR( EveTest, 12345678-079E-48FF-8F27-9C2605A29F52, PW+PR+EV, DATA, false );
}; };
extern HapCharacteristics hapChars; extern HapCharacteristics hapChars;

View File

@ -526,8 +526,6 @@ namespace Characteristic {
CREATE_CHAR(uint8_t,VolumeSelector,0,0,1); CREATE_CHAR(uint8_t,VolumeSelector,0,0,1);
CREATE_CHAR(double,WaterLevel,0,0,100); CREATE_CHAR(double,WaterLevel,0,0,100);
CREATE_CHAR(const char *,EveTest,"AAAA",0,1);
} }
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
@ -542,6 +540,10 @@ namespace Characteristic {
HapChar _CUSTOM_##NAME {#UUID,#NAME,(PERMS)(PERMISISONS),STRING,true}; \ HapChar _CUSTOM_##NAME {#UUID,#NAME,(PERMS)(PERMISISONS),STRING,true}; \
namespace Characteristic { struct NAME : SpanCharacteristic { NAME(const char * val=DEFVAL, boolean nvsStore=false) : SpanCharacteristic {&_CUSTOM_##NAME,true} { init(val,nvsStore); } }; } namespace Characteristic { struct NAME : SpanCharacteristic { NAME(const char * val=DEFVAL, boolean nvsStore=false) : SpanCharacteristic {&_CUSTOM_##NAME,true} { init(val,nvsStore); } }; }
#define CUSTOM_CHAR_DATA(NAME,UUID,PERMISISONS) \
HapChar _CUSTOM_##NAME {#UUID,#NAME,(PERMS)(PERMISISONS),DATA,true}; \
namespace Characteristic { struct NAME : SpanCharacteristic { NAME(const char * val="AA==", boolean nvsStore=false) : SpanCharacteristic {&_CUSTOM_##NAME,true} { init(val,nvsStore); } }; }
#define CUSTOM_SERV(NAME,UUID) \ #define CUSTOM_SERV(NAME,UUID) \
namespace Service { struct NAME : SpanService { NAME() : SpanService{#UUID,#NAME,true}{} }; } namespace Service { struct NAME : SpanService { NAME() : SpanService{#UUID,#NAME,true}{} }; }

View File

@ -4,7 +4,9 @@
#include "HomeSpan.h" #include "HomeSpan.h"
Characteristic::EveTest *eveTest; CUSTOM_CHAR_DATA(DataTest, 87654321-079E-48FF-8F27-9C2605A29F52, PW+PR+EV);
Characteristic::DataTest *eveTest;
void setup() { void setup() {
@ -21,16 +23,26 @@ void setup() {
new Service::LightBulb(); new Service::LightBulb();
new Characteristic::On(); new Characteristic::On();
new Characteristic::ConfiguredName(); new Characteristic::ConfiguredName();
eveTest=new Characteristic::EveTest(); eveTest=new Characteristic::DataTest();
uint8_t x[]={0x01,0x26,0xFF,0x01,0x26,0xFF}; uint8_t x[]={0x01,0x26,0xFF,0x01,0x26,0xFF};
eveTest->setData(x,6); eveTest->setData(x,6);
uint8_t y[6]={0}; uint8_t y[6]={0};
int n=eveTest->getData(y,10); int n=eveTest->getData(y,10);
Serial.printf("%d:",n); Serial.printf("%d:",n);
for(int i=0;i<n;i++) for(int i=0;i<n;i++){
Serial.printf(" %02X",y[i]); Serial.printf(" %02X",y[i]);
y[i]++;
}
Serial.printf("\n\n"); Serial.printf("\n\n");
eveTest->setData(y,6);
n=eveTest->getData(x,10);
Serial.printf("%d:",n);
for(int i=0;i<n;i++){
Serial.printf(" %02X",x[i]);
}
Serial.printf("\n\n");
} }