add boatData config item type to select a value from the boatDataItems
This commit is contained in:
parent
4f2c9ed1c2
commit
24cd250d86
|
@ -45,6 +45,7 @@ void exampleTask(GwApi *api){
|
||||||
bool exampleSwitch=api->getConfig()->getConfigItem(
|
bool exampleSwitch=api->getConfig()->getConfigItem(
|
||||||
api->getConfig()->exampleConfig,
|
api->getConfig()->exampleConfig,
|
||||||
true)->asBoolean();
|
true)->asBoolean();
|
||||||
|
String boatItemName=api->getConfig()->getString(api->getConfig()->exampleBDSel);
|
||||||
//------
|
//------
|
||||||
//initialization goes here
|
//initialization goes here
|
||||||
//------
|
//------
|
||||||
|
@ -53,7 +54,10 @@ void exampleTask(GwApi *api){
|
||||||
LOG_DEBUG(GwLog::DEBUG,"example switch ist %s",exampleSwitch?"true":"false");
|
LOG_DEBUG(GwLog::DEBUG,"example switch ist %s",exampleSwitch?"true":"false");
|
||||||
GwApi::BoatValue *longitude=new GwApi::BoatValue(F("Longitude"));
|
GwApi::BoatValue *longitude=new GwApi::BoatValue(F("Longitude"));
|
||||||
GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude"));
|
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){
|
while(true){
|
||||||
delay(1000);
|
delay(1000);
|
||||||
/*
|
/*
|
||||||
|
@ -101,7 +105,7 @@ void exampleTask(GwApi *api){
|
||||||
or with the ValueMap approach.
|
or with the ValueMap approach.
|
||||||
**/
|
**/
|
||||||
//fetch the current values of the items that we have in itemNames
|
//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)
|
//check if the values are valid (i.e. the values we requested have been found in boatData)
|
||||||
if (longitude->valid && latitude->valid){
|
if (longitude->valid && latitude->valid){
|
||||||
//both values are there - so we have a valid position
|
//both values are there - so we have a valid position
|
||||||
|
@ -118,6 +122,19 @@ void exampleTask(GwApi *api){
|
||||||
hasPosition2=false;
|
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);
|
vTaskDelete(NULL);
|
||||||
|
|
|
@ -9,5 +9,16 @@
|
||||||
"capabilities": {
|
"capabilities": {
|
||||||
"testboard":"true"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
32
web/index.js
32
web/index.js
|
@ -339,7 +339,7 @@ function checkCondition(element){
|
||||||
}
|
}
|
||||||
function createInput(configItem, frame,clazz) {
|
function createInput(configItem, frame,clazz) {
|
||||||
let el;
|
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=addEl('select',clazz,frame);
|
||||||
el.setAttribute('name', configItem.name)
|
el.setAttribute('name', configItem.name)
|
||||||
let slist = [];
|
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: 'on', v: 'true' })
|
||||||
slist.push({ l: 'off', v: 'false' })
|
slist.push({ l: 'off', v: 'false' })
|
||||||
}
|
}
|
||||||
|
@ -361,6 +361,9 @@ function createInput(configItem, frame,clazz) {
|
||||||
let sitemEl = addEl('option','',el,sitem.l);
|
let sitemEl = addEl('option','',el,sitem.l);
|
||||||
sitemEl.setAttribute('value', sitem.v);
|
sitemEl.setAttribute('value', sitem.v);
|
||||||
})
|
})
|
||||||
|
if (configItem.type == 'boatData'){
|
||||||
|
el.classList.add('boatDataSelect');
|
||||||
|
}
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
if (configItem.type === 'filter') {
|
if (configItem.type === 'filter') {
|
||||||
|
@ -961,6 +964,9 @@ function loadConfigDefinitions() {
|
||||||
if (normalConfig) createConfigDefinitions(normalConfig,capabilities,defs,false);
|
if (normalConfig) createConfigDefinitions(normalConfig,capabilities,defs,false);
|
||||||
if (xdrParent) createConfigDefinitions(xdrParent,capabilities,defs,true);
|
if (xdrParent) createConfigDefinitions(xdrParent,capabilities,defs,true);
|
||||||
resetForm();
|
resetForm();
|
||||||
|
getText('api/boatDataString').then(function (data) {
|
||||||
|
updateDashboard(data.split('\n'));
|
||||||
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1182,6 +1188,7 @@ function sourceName(v){
|
||||||
if (v >= 3) return "TCP";
|
if (v >= 3) return "TCP";
|
||||||
return "---";
|
return "---";
|
||||||
}
|
}
|
||||||
|
let lastSelectList=[];
|
||||||
function updateDashboard(data) {
|
function updateDashboard(data) {
|
||||||
let frame = document.getElementById('dashboardPage');
|
let frame = document.getElementById('dashboardPage');
|
||||||
let names={};
|
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);
|
window.setInterval(update, 1000);
|
||||||
|
|
Loading…
Reference in New Issue