1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-13 05:53:06 +01:00

restructure boat data display handling, allow for more flexible user formatters

This commit is contained in:
andreas
2024-10-13 16:10:03 +02:00
parent e982389c75
commit 9c979657bf
4 changed files with 290 additions and 131 deletions

View File

@@ -1,12 +1,39 @@
(function(){
const api=window.esp32nmea2k;
if (! api) return;
let isActive=false;
window.esp32nmea2k.registerListener((id,data)=>{
if (id === 0){
const tabName="example";
const configName="exampleBDSel";
let boatItemName;
api.registerListener((id,data)=>{
if (id === api.EVENTS.init){
//data is capabilities
if (data.testboard) isActive=true;
if (isActive){
let page=api.addTabPage(tabName,"Example");
api.addEl('div','',page,"this is a test tab");
}
}
if (isActive){
console.log("exampletask listener",id,data);
if (id === api.EVENTS.tab){
if (data === tabName){
console.log("example tab activated");
}
}
if (id == api.EVENTS.config){
let nextboatItemName=data[configName];
console.log("value of "+configName,nextboatItemName);
if (nextboatItemName){
api.addUserFormatter(nextboatItemName,"xxx",function(v){
return "X"+v+"X";
})
}
if (boatItemName !== undefined && boatItemName != nextboatItemName){
api.removeUserFormatter(boatItemName);
}
boatItemName=nextboatItemName;
}
}
})
})();