Renamed Services.h to Span.h
Also, made it possible to use UVAL.set() for STRING Characteristic (upon initialization) but setVal() is NOT allowed.
This commit is contained in:
parent
7930e3a0d9
commit
c8a2770253
|
|
@ -65,6 +65,10 @@ union UVal {
|
||||||
double FLOAT;
|
double FLOAT;
|
||||||
const char *STRING;
|
const char *STRING;
|
||||||
|
|
||||||
|
void set(FORMAT fmt, const char *val){
|
||||||
|
STRING=val;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T> void set(FORMAT fmt, T val){
|
template <typename T> void set(FORMAT fmt, T val){
|
||||||
|
|
||||||
switch(fmt){
|
switch(fmt){
|
||||||
|
|
@ -98,7 +102,7 @@ union UVal {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // set()
|
} // set()
|
||||||
|
|
||||||
template <class T> T get(FORMAT fmt){
|
template <class T> T get(FORMAT fmt){
|
||||||
|
|
||||||
switch(fmt){
|
switch(fmt){
|
||||||
|
|
@ -125,7 +129,7 @@ union UVal {
|
||||||
return((T) FLOAT);
|
return((T) FLOAT);
|
||||||
|
|
||||||
case FORMAT::STRING:
|
case FORMAT::STRING:
|
||||||
Serial.print("*** ERROR: Can't use getVal() or getNewVal() for string Characteristics.\n\n");
|
Serial.print("\n*** WARNING: Can't use getVal() or getNewVal() with string Characteristics.\n\n");
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -331,6 +335,11 @@ struct SpanCharacteristic{
|
||||||
template <class T=int> T getNewVal(){return(newValue.get<T>(format));} // returns UVal newValue
|
template <class T=int> T getNewVal(){return(newValue.get<T>(format));} // returns UVal newValue
|
||||||
|
|
||||||
template <typename T> void setVal(T val){
|
template <typename T> void setVal(T val){
|
||||||
|
|
||||||
|
if(format==STRING){
|
||||||
|
Serial.printf("\n*** WARNING: Attempt to update Characteristic::%s(\"%s\") with setVal() ignored. Can't update string characteristics once they are initialized!\n\n",hapName,value.STRING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
value.set(format, val);
|
value.set(format, val);
|
||||||
newValue.set(format, val);
|
newValue.set(format, val);
|
||||||
|
|
@ -382,4 +391,4 @@ struct SpanButton{
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
#include "Services.h"
|
#include "Span.h"
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,7 @@ namespace Service {
|
||||||
#define CREATE_CHAR_UINT32(HAPCHAR,DEFVAL) struct HAPCHAR : SpanCharacteristic { HAPCHAR(uint32_t val=DEFVAL) : SpanCharacteristic {&hapChars.HAPCHAR} { init(val); } };
|
#define CREATE_CHAR_UINT32(HAPCHAR,DEFVAL) struct HAPCHAR : SpanCharacteristic { HAPCHAR(uint32_t val=DEFVAL) : SpanCharacteristic {&hapChars.HAPCHAR} { init(val); } };
|
||||||
#define CREATE_CHAR_UINT64(HAPCHAR,DEFVAL) struct HAPCHAR : SpanCharacteristic { HAPCHAR(uint64_t val=DEFVAL) : SpanCharacteristic {&hapChars.HAPCHAR} { init(val); } };
|
#define CREATE_CHAR_UINT64(HAPCHAR,DEFVAL) struct HAPCHAR : SpanCharacteristic { HAPCHAR(uint64_t val=DEFVAL) : SpanCharacteristic {&hapChars.HAPCHAR} { init(val); } };
|
||||||
#define CREATE_CHAR_BOOL(HAPCHAR,DEFVAL) struct HAPCHAR : SpanCharacteristic { HAPCHAR(boolean val=DEFVAL) : SpanCharacteristic {&hapChars.HAPCHAR} { init(val); } };
|
#define CREATE_CHAR_BOOL(HAPCHAR,DEFVAL) struct HAPCHAR : SpanCharacteristic { HAPCHAR(boolean val=DEFVAL) : SpanCharacteristic {&hapChars.HAPCHAR} { init(val); } };
|
||||||
#define CREATE_CHAR_STRING(HAPCHAR,DEFVAL) struct HAPCHAR : SpanCharacteristic { HAPCHAR(const char *val=DEFVAL) : SpanCharacteristic {&hapChars.HAPCHAR} { value.STRING=val; } };
|
#define CREATE_CHAR_STRING(HAPCHAR,DEFVAL) struct HAPCHAR : SpanCharacteristic { HAPCHAR(const char *val=DEFVAL) : SpanCharacteristic {&hapChars.HAPCHAR} { init(val); } };
|
||||||
|
|
||||||
namespace Characteristic {
|
namespace Characteristic {
|
||||||
|
|
||||||
Loading…
Reference in New Issue