diff --git a/lib/api/GwApi.h b/lib/api/GwApi.h index ae18bd0..8d83a63 100644 --- a/lib/api/GwApi.h +++ b/lib/api/GwApi.h @@ -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){ } diff --git a/lib/exampletask/GwExampleTask.cpp b/lib/exampletask/GwExampleTask.cpp index f91125c..57fb613 100644 --- a/lib/exampletask/GwExampleTask.cpp +++ b/lib/exampletask/GwExampleTask.cpp @@ -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; } } diff --git a/src/main.cpp b/src/main.cpp index fb9c30f..ff74de7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -412,12 +412,20 @@ public: virtual void getBoatDataValues(int numValues,BoatValue **list){ for (int i=0;igetName()); + 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; } }