add boatData config item type to select a value from the boatDataItems

This commit is contained in:
wellenvogel 2021-12-05 22:01:17 +01:00
parent 4f2c9ed1c2
commit 24cd250d86
3 changed files with 60 additions and 4 deletions

View File

@ -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);

View File

@ -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"
}
}
]

View File

@ -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<lastSelectList.length;i++){
if (selectList[i] != lastSelectList[i]){
selectChanged=true;
break;
}
}
}
else{
selectChanged=true;
}
if (selectChanged){
forEl('.boatDataSelect',function(el){
updateSelectList(el,selectList);
});
}
}
window.setInterval(update, 1000);