limit config keys to 15 characters, show sources and units

This commit is contained in:
andreas 2021-11-10 16:13:49 +01:00
parent dc39832483
commit 4c8d17ef40
5 changed files with 143 additions and 73 deletions

View File

@ -52,31 +52,44 @@ def generateCfg():
if isCurrent(infile,outfile):
return
print("creating %s"%CFG_INCLUDE)
oh=None
with open(CFG_FILE,'rb') as ch:
config=json.load(ch)
with open(outfile,'w') as oh:
oh.write("//generated from %s\n"%CFG_FILE)
oh.write('#include "GwConfigItem.h"\n')
l=len(config)
oh.write('class GwConfigDefinitions{\n')
oh.write(' public:\n')
oh.write(' int getNumConfig() const{return %d;}\n'%(l))
for item in config:
n=item.get('name')
if n is None:
continue
oh.write(' const String %s=F("%s");\n'%(n,n))
oh.write(' protected:\n')
oh.write(' GwConfigItem *configs[%d]={\n'%(l))
first=True
for item in config:
if not first:
oh.write(',\n')
first=False
oh.write(" new GwConfigItem(%s,\"%s\")"%(item.get('name'),item.get('default')))
oh.write('};\n')
oh.write('};\n')
oh.close()
try:
with open(outfile,'w') as oh:
oh.write("//generated from %s\n"%CFG_FILE)
oh.write('#include "GwConfigItem.h"\n')
l=len(config)
oh.write('class GwConfigDefinitions{\n')
oh.write(' public:\n')
oh.write(' int getNumConfig() const{return %d;}\n'%(l))
for item in config:
n=item.get('name')
if n is None:
continue
if len(n) > 15:
raise Exception("%s: config names must be max 15 caracters"%n)
oh.write(' const String %s=F("%s");\n'%(n,n))
oh.write(' protected:\n')
oh.write(' GwConfigItem *configs[%d]={\n'%(l))
first=True
for item in config:
if not first:
oh.write(',\n')
first=False
oh.write(" new GwConfigItem(%s,\"%s\")"%(item.get('name'),item.get('default')))
oh.write('};\n')
oh.write('};\n')
oh.close()
except Exception as e:
if oh is not None:
try:
oh.close()
except:
pass
os.unlink(outfile)
raise
if not checkDir():
sys.exit(1)
for f in FILES:

View File

@ -147,8 +147,8 @@ GwConfigInterface *sendSerial=config.getConfigItem(config.sendSerial,true);
GwConfigInterface *n2kFromSerial=config.getConfigItem(config.serialToN2k,true);
GwNmeaFilter usbReadFilter(config.getConfigItem(config.usbReadFilter,true));
GwNmeaFilter usbWriteFilter(config.getConfigItem(config.usbWriteFilter,true));
GwNmeaFilter serialReadFilter(config.getConfigItem(config.serialReadFilter,true));
GwNmeaFilter serialWriteFilter(config.getConfigItem(config.serialWriteFilter,true));
GwNmeaFilter serialReadFilter(config.getConfigItem(config.serialReadF,true));
GwNmeaFilter serialWriteFilter(config.getConfigItem(config.serialWriteF,true));
GwNmeaFilter tcpReadFilter(config.getConfigItem(config.tcpReadFilter,true));
GwNmeaFilter tcpWriteFilter(config.getConfigItem(config.tcpWriteFilter,true));
@ -358,6 +358,7 @@ protected:
result = JSON_OK;
logger.logString("update config and restart");
config.saveConfig();
delay(500);
delayedRestart();
}
else

View File

@ -131,7 +131,7 @@
"category":"serial port"
},
{
"name": "serialReadFilter",
"name": "serialReadF",
"label": "serial read Filter",
"type": "filter",
"default": "",
@ -140,7 +140,7 @@
"category":"serial port"
},
{
"name": "serialWriteFilter",
"name": "serialWriteF",
"label": "serial write Filter",
"type": "filter",
"default": "",

View File

@ -197,5 +197,18 @@ body{
.dashValue{
font-size: 1.6em;
text-align: center;
flex: 1;
}
.footer {
display: flex;
flex-direction: row;
padding: 0.1em;
background-color: lightgray;
font-size: 0.7em;
}
.footer .unit{
}
.footer .source{
flex: 1;
}

View File

@ -428,11 +428,89 @@ function handleTab(el) {
el.classList.add('active');
activeTab.classList.remove('hidden');
}
let valueFormatters = {
formatCourse: {
f: function (v) {
let x = parseFloat(v);
let rt = x * 180.0 / Math.PI;
if (rt > 360) rt -= 360;
if (rt < 0) rt += 360;
return rt.toFixed(0);
},
u: '°'
},
formatKnots: {
f: function (v) {
let x = parseFloat(v);
x = x * 3600.0 / 1852.0;
return x.toFixed(2);
},
u: 'kn'
},
formatWind: {
f: function (v) {
let x = parseFloat(v);
x = x * 180.0 / Math.PI;
if (x > 180) x = 180 - x;
return x.toFixed(0);
},
u: '°'
},
mtr2nm: {
f: function (v) {
let x = parseFloat(v);
x = x / 1852.0;
return x.toFixed(2);
},
u: 'nm'
},
kelvinToC: {
f: function (v) {
let x = parseFloat(v);
x = x - 273.15;
return x.toFixed(0);
},
u: '°'
},
formatFixed0: {
f: function (v) {
let x = parseFloat(v);
return x.toFixed(0);
},
u: ''
},
formatDepth: {
f: function (v) {
let x = parseFloat(v);
return x.toFixed(1);
},
u: 'm'
},
formatLatitude: {
f: function (v) {
let x = parseFloat(v);
return x.toFixed(4);
},
u: '°'
},
formatLongitude: {
f: function (v) {
let x = parseFloat(v);
return x.toFixed(4);
},
u: ''
},
}
function createDashboardItem(name, def, parent) {
let frame = addEl('div', 'dash', parent);
let title = addEl('span', 'dashTitle', frame, name);
let value = addEl('span', 'dashValue', frame);
value.setAttribute('id', 'data_' + name);
let fmt=valueFormatters[def.format];
let footer = addEl('div','footer',frame);
let src= addEl('span','source',footer);
src.setAttribute('id','source_'+name);
addEl('span','unit',footer,fmt?fmt.u:'');
return value;
}
function createDashboard() {
@ -446,51 +524,12 @@ function createDashboard() {
updateDashboard(json);
});
}
let valueFormatters = {
formatCourse: function (v) {
let x = parseFloat(v);
let rt=x*180.0 / Math.PI;
if (rt > 360) rt -= 360;
if (rt < 0) rt += 360;
return rt.toFixed(0);
},
formatKnots: function (v) {
let x = parseFloat(v);
x=x *3600.0/1852.0;
return x.toFixed(2);
},
formatWind: function (v) {
let x = parseFloat(v);
x=x*180.0 / Math.PI;
if (x > 180) x=180-x;
return x.toFixed(0);
},
mtr2nm: function (v) {
let x = parseFloat(v);
x=x/1852.0;
return x.toFixed(2);
},
kelvinToC: function (v) {
let x = parseFloat(v);
x=x-273.15;
return x.toFixed(0);
},
formatFixed0: function (v) {
let x = parseFloat(v);
return x.toFixed(0);
},
formatDepth: function (v) {
let x = parseFloat(v);
return x.toFixed(1);
},
formatLatitude: function(v){
let x = parseFloat(v);
return x.toFixed(4);
},
formatLongitued: function(v){
let x = parseFloat(v);
return x.toFixed(4);
},
function sourceName(v){
if (v == 0) return "N2K";
if (v == 1) return "USB";
if (v == 2) return "SER";
if (v >= 3) return "TCP";
return "---";
}
function updateDashboard(data) {
for (let n in data) {
@ -503,7 +542,7 @@ function updateDashboard(data) {
formatter = valueFormatters[key];
}
if (formatter) {
de.textContent = formatter(data[n].value);
de.textContent = formatter.f(data[n].value);
}
else {
let v = parseFloat(data[n].value);
@ -518,6 +557,10 @@ function updateDashboard(data) {
}
else de.textContent = "---";
}
let src=document.getElementById('source_'+n);
if (src){
src.textContent=sourceName(data[n].source);
}
}
}