From 24cd250d86515e307be0eb1344e44ee8521f52ea Mon Sep 17 00:00:00 2001 From: wellenvogel Date: Sun, 5 Dec 2021 22:01:17 +0100 Subject: [PATCH] add boatData config item type to select a value from the boatDataItems --- lib/exampletask/GwExampleTask.cpp | 21 ++++++++++++++++++-- lib/exampletask/config.json | 11 +++++++++++ web/index.js | 32 +++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/lib/exampletask/GwExampleTask.cpp b/lib/exampletask/GwExampleTask.cpp index f82fd9d..c5e1858 100644 --- a/lib/exampletask/GwExampleTask.cpp +++ b/lib/exampletask/GwExampleTask.cpp @@ -45,6 +45,7 @@ void exampleTask(GwApi *api){ bool exampleSwitch=api->getConfig()->getConfigItem( api->getConfig()->exampleConfig, true)->asBoolean(); + String boatItemName=api->getConfig()->getString(api->getConfig()->exampleBDSel); //------ //initialization goes here //------ @@ -53,7 +54,10 @@ void exampleTask(GwApi *api){ LOG_DEBUG(GwLog::DEBUG,"example switch ist %s",exampleSwitch?"true":"false"); GwApi::BoatValue *longitude=new GwApi::BoatValue(F("Longitude")); GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude")); - GwApi::BoatValue *valueList[]={longitude,latitude}; + GwApi::BoatValue *testValue=new GwApi::BoatValue(boatItemName); + GwApi::BoatValue *valueList[]={longitude,latitude,testValue}; + double lastTestValue=0; + bool lastTestValueValid=false; while(true){ delay(1000); /* @@ -101,7 +105,7 @@ void exampleTask(GwApi *api){ or with the ValueMap approach. **/ //fetch the current values of the items that we have in itemNames - api->getBoatDataValues(2,valueList); + api->getBoatDataValues(3,valueList); //check if the values are valid (i.e. the values we requested have been found in boatData) if (longitude->valid && latitude->valid){ //both values are there - so we have a valid position @@ -118,6 +122,19 @@ void exampleTask(GwApi *api){ hasPosition2=false; } } + if (testValue->valid){ + if (! lastTestValueValid || lastTestValue != testValue->value){ + LOG_DEBUG(GwLog::LOG,"%s new value %f",testValue->getName().c_str(),testValue->value); + lastTestValueValid=true; + lastTestValue=testValue->value; + } + } + else{ + if (lastTestValueValid){ + LOG_DEBUG(GwLog::LOG,"%s now invalid",testValue->getName().c_str()); + lastTestValueValid=false; + } + } } vTaskDelete(NULL); diff --git a/lib/exampletask/config.json b/lib/exampletask/config.json index ff556d4..9074b25 100644 --- a/lib/exampletask/config.json +++ b/lib/exampletask/config.json @@ -9,5 +9,16 @@ "capabilities": { "testboard":"true" } + }, + { + "name": "exampleBDSel", + "label": "value to check", + "type": "boatData", + "default": "", + "description": "select a value to monitor for value change", + "category": "example", + "capabilities": { + "testboard":"true" + } } ] \ No newline at end of file diff --git a/web/index.js b/web/index.js index 9928fa1..3e3ac8a 100644 --- a/web/index.js +++ b/web/index.js @@ -339,7 +339,7 @@ function checkCondition(element){ } function createInput(configItem, frame,clazz) { let el; - if (configItem.type === 'boolean' || configItem.type === 'list') { + if (configItem.type === 'boolean' || configItem.type === 'list' || configItem.type == 'boatData') { el=addEl('select',clazz,frame); el.setAttribute('name', configItem.name) let slist = []; @@ -353,7 +353,7 @@ function createInput(configItem, frame,clazz) { } }) } - else { + else if (configItem.type != 'boatData') { slist.push({ l: 'on', v: 'true' }) slist.push({ l: 'off', v: 'false' }) } @@ -361,6 +361,9 @@ function createInput(configItem, frame,clazz) { let sitemEl = addEl('option','',el,sitem.l); sitemEl.setAttribute('value', sitem.v); }) + if (configItem.type == 'boatData'){ + el.classList.add('boatDataSelect'); + } return el; } if (configItem.type === 'filter') { @@ -961,6 +964,9 @@ function loadConfigDefinitions() { if (normalConfig) createConfigDefinitions(normalConfig,capabilities,defs,false); if (xdrParent) createConfigDefinitions(xdrParent,capabilities,defs,true); resetForm(); + getText('api/boatDataString').then(function (data) { + updateDashboard(data.split('\n')); + }); }) }) }) @@ -1182,6 +1188,7 @@ function sourceName(v){ if (v >= 3) return "TCP"; return "---"; } +let lastSelectList=[]; function updateDashboard(data) { let frame = document.getElementById('dashboardPage'); let names={}; @@ -1235,6 +1242,27 @@ function updateDashboard(data) { } } }); + let selectList=[]; + for (let n in names){ + selectList.push({l:n,v:n}); + } + let selectChanged=false; + if (lastSelectList.length == selectList.length){ + for (let i=0;i