add changed flag to BoatDataValue in API
This commit is contained in:
parent
c3482dbb3a
commit
20187fcb1d
|
@ -15,6 +15,7 @@ class GwApi{
|
|||
public:
|
||||
double value=0;
|
||||
bool valid=false;
|
||||
bool changed=false; //will be set by getBoatDataValues
|
||||
BoatValue(){}
|
||||
BoatValue(const String &n):name(n){
|
||||
}
|
||||
|
|
|
@ -88,8 +88,6 @@ void exampleTask(GwApi *api){
|
|||
GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude"));
|
||||
GwApi::BoatValue *testValue=new GwApi::BoatValue(boatItemName);
|
||||
GwApi::BoatValue *valueList[]={longitude,latitude,testValue};
|
||||
double lastTestValue=0;
|
||||
bool lastTestValueValid=false;
|
||||
while(true){
|
||||
delay(1000);
|
||||
/*
|
||||
|
@ -155,16 +153,13 @@ void exampleTask(GwApi *api){
|
|||
}
|
||||
}
|
||||
if (testValue->valid){
|
||||
if (! lastTestValueValid || lastTestValue != testValue->value){
|
||||
if (testValue->changed){
|
||||
LOG_DEBUG(GwLog::LOG,"%s new value %s",testValue->getName().c_str(),formatValue(testValue).c_str());
|
||||
lastTestValueValid=true;
|
||||
lastTestValue=testValue->value;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (lastTestValueValid){
|
||||
if (testValue->changed){
|
||||
LOG_DEBUG(GwLog::LOG,"%s now invalid",testValue->getName().c_str());
|
||||
lastTestValueValid=false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -412,12 +412,20 @@ public:
|
|||
virtual void getBoatDataValues(int numValues,BoatValue **list){
|
||||
for (int i=0;i<numValues;i++){
|
||||
GwBoatItemBase *item=boatData.getBase(list[i]->getName());
|
||||
list[i]->changed=false;
|
||||
if (item){
|
||||
list[i]->valid=item->isValid();
|
||||
if (list[i]->valid) list[i]->value=item->getDoubleValue();
|
||||
bool newValid=item->isValid();
|
||||
if (newValid != list[i]->valid) list[i]->changed=true;
|
||||
list[i]->valid=newValid;
|
||||
if (newValid){
|
||||
double newValue=item->getDoubleValue();
|
||||
if (newValue != list[i]->value) list[i]->changed=true;
|
||||
list[i]->value=newValue;
|
||||
}
|
||||
list[i]->setFormat(item->getFormat());
|
||||
}
|
||||
else{
|
||||
if (list[i]->valid) list[i]->changed=true;
|
||||
list[i]->valid=false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue