update setString() to use setValCheck() and setValFinish()

This commit is contained in:
Gregg 2024-03-31 08:51:06 -05:00
parent 11bd605a03
commit cbe26c7c41
2 changed files with 11 additions and 25 deletions

View File

@ -677,31 +677,10 @@ class SpanCharacteristic{
void setString(const char *val, boolean notify=true){
if(updateFlag==1)
LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setString() within update() while it is being updated by Home App. This may cause device to become non-responsive!\n\n",hapName);
setValCheck();
uvSet(value,val);
uvSet(newValue,value);
updateTime=homeSpan.snapTime;
if(notify){
if(updateFlag!=2){ // do not broadcast EV if update is being done in context of write-response
SpanBuf sb; // create SpanBuf object
sb.characteristic=this; // set characteristic
sb.status=StatusCode::OK; // set status
char dummy[]="";
sb.val=dummy; // set dummy "val" so that printfNotify knows to consider this "update"
homeSpan.Notifications.push_back(sb); // store SpanBuf in Notifications vector
}
if(nvsKey){
nvs_set_str(homeSpan.charNVS,nvsKey,value.STRING); // store data
nvs_commit(homeSpan.charNVS);
}
}
} // setString()
setValFinish(notify);
}
size_t getData(uint8_t *data, size_t len){
if(format<FORMAT::DATA)

View File

@ -38,9 +38,10 @@ struct HomeSpanTV : Service::Television {
SpanCharacteristic *settingsKey = new Characteristic::PowerModeSelection(); // Adds "View TV Setting" option to Selection Screen
SpanCharacteristic *displayOrder = new Characteristic::DisplayOrder();
SpanCharacteristic *testData = new Characteristic::TestData();
SpanCharacteristic *tvname;
HomeSpanTV(const char *name) : Service::Television() {
new Characteristic::ConfiguredName(name); // Name of TV
tvname = new Characteristic::ConfiguredName(name); // Name of TV
Serial.printf("Configured TV: %s\n",name);
TLV8 orderTLV;
@ -60,6 +61,7 @@ struct HomeSpanTV : Service::Television {
testData->setData(blob,1);
new SpanUserCommand('P', "- change order of inputs", changeOrder, this);
new SpanUserCommand('C', "- change name of TV", setTVName, this);
}
boolean update() override {
@ -111,6 +113,11 @@ struct HomeSpanTV : Service::Television {
return(true);
}
static void setTVName(const char *buf, void *arg){
HomeSpanTV *hsTV=(HomeSpanTV *)arg;
hsTV->tvname->setString("New Name");
}
static void changeOrder(const char *buf, void *arg){
HomeSpanTV *hsTV=(HomeSpanTV *)arg;