mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 22:13:07 +01:00
add changed flag to BoatDataValue in API
This commit is contained in:
@@ -15,6 +15,7 @@ class GwApi{
|
|||||||
public:
|
public:
|
||||||
double value=0;
|
double value=0;
|
||||||
bool valid=false;
|
bool valid=false;
|
||||||
|
bool changed=false; //will be set by getBoatDataValues
|
||||||
BoatValue(){}
|
BoatValue(){}
|
||||||
BoatValue(const String &n):name(n){
|
BoatValue(const String &n):name(n){
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,8 +88,6 @@ void exampleTask(GwApi *api){
|
|||||||
GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude"));
|
GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude"));
|
||||||
GwApi::BoatValue *testValue=new GwApi::BoatValue(boatItemName);
|
GwApi::BoatValue *testValue=new GwApi::BoatValue(boatItemName);
|
||||||
GwApi::BoatValue *valueList[]={longitude,latitude,testValue};
|
GwApi::BoatValue *valueList[]={longitude,latitude,testValue};
|
||||||
double lastTestValue=0;
|
|
||||||
bool lastTestValueValid=false;
|
|
||||||
while(true){
|
while(true){
|
||||||
delay(1000);
|
delay(1000);
|
||||||
/*
|
/*
|
||||||
@@ -155,16 +153,13 @@ void exampleTask(GwApi *api){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (testValue->valid){
|
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());
|
LOG_DEBUG(GwLog::LOG,"%s new value %s",testValue->getName().c_str(),formatValue(testValue).c_str());
|
||||||
lastTestValueValid=true;
|
|
||||||
lastTestValue=testValue->value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (lastTestValueValid){
|
if (testValue->changed){
|
||||||
LOG_DEBUG(GwLog::LOG,"%s now invalid",testValue->getName().c_str());
|
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){
|
virtual void getBoatDataValues(int numValues,BoatValue **list){
|
||||||
for (int i=0;i<numValues;i++){
|
for (int i=0;i<numValues;i++){
|
||||||
GwBoatItemBase *item=boatData.getBase(list[i]->getName());
|
GwBoatItemBase *item=boatData.getBase(list[i]->getName());
|
||||||
|
list[i]->changed=false;
|
||||||
if (item){
|
if (item){
|
||||||
list[i]->valid=item->isValid();
|
bool newValid=item->isValid();
|
||||||
if (list[i]->valid) list[i]->value=item->getDoubleValue();
|
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());
|
list[i]->setFormat(item->getFormat());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
if (list[i]->valid) list[i]->changed=true;
|
||||||
list[i]->valid=false;
|
list[i]->valid=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user