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:
@@ -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;
|
||||
}
|
||||
}
|
||||
})
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user