diff --git a/src/HomeSpan.h b/src/HomeSpan.h index fefbfb9..00c559e 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -65,6 +65,10 @@ union UVal { double FLOAT; const char *STRING; + void set(FORMAT fmt, const char *val){ + STRING=val; + }; + template void set(FORMAT fmt, T val){ switch(fmt){ @@ -98,7 +102,7 @@ union UVal { break; } } // set() - + template T get(FORMAT fmt){ switch(fmt){ @@ -125,7 +129,7 @@ union UVal { return((T) FLOAT); 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); } @@ -331,6 +335,11 @@ struct SpanCharacteristic{ template T getNewVal(){return(newValue.get(format));} // returns UVal newValue template 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); newValue.set(format, val); @@ -382,4 +391,4 @@ struct SpanButton{ ///////////////////////////////////////////////// -#include "Services.h" +#include "Span.h" diff --git a/src/Services.h b/src/Span.h similarity index 99% rename from src/Services.h rename to src/Span.h index f28516e..563babd 100644 --- a/src/Services.h +++ b/src/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_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_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 {