limit config keys to 15 characters, show sources and units
This commit is contained in:
parent
dc39832483
commit
4c8d17ef40
|
@ -52,31 +52,44 @@ def generateCfg():
|
||||||
if isCurrent(infile,outfile):
|
if isCurrent(infile,outfile):
|
||||||
return
|
return
|
||||||
print("creating %s"%CFG_INCLUDE)
|
print("creating %s"%CFG_INCLUDE)
|
||||||
|
oh=None
|
||||||
with open(CFG_FILE,'rb') as ch:
|
with open(CFG_FILE,'rb') as ch:
|
||||||
config=json.load(ch)
|
config=json.load(ch)
|
||||||
with open(outfile,'w') as oh:
|
try:
|
||||||
oh.write("//generated from %s\n"%CFG_FILE)
|
with open(outfile,'w') as oh:
|
||||||
oh.write('#include "GwConfigItem.h"\n')
|
oh.write("//generated from %s\n"%CFG_FILE)
|
||||||
l=len(config)
|
oh.write('#include "GwConfigItem.h"\n')
|
||||||
oh.write('class GwConfigDefinitions{\n')
|
l=len(config)
|
||||||
oh.write(' public:\n')
|
oh.write('class GwConfigDefinitions{\n')
|
||||||
oh.write(' int getNumConfig() const{return %d;}\n'%(l))
|
oh.write(' public:\n')
|
||||||
for item in config:
|
oh.write(' int getNumConfig() const{return %d;}\n'%(l))
|
||||||
n=item.get('name')
|
for item in config:
|
||||||
if n is None:
|
n=item.get('name')
|
||||||
continue
|
if n is None:
|
||||||
oh.write(' const String %s=F("%s");\n'%(n,n))
|
continue
|
||||||
oh.write(' protected:\n')
|
if len(n) > 15:
|
||||||
oh.write(' GwConfigItem *configs[%d]={\n'%(l))
|
raise Exception("%s: config names must be max 15 caracters"%n)
|
||||||
first=True
|
oh.write(' const String %s=F("%s");\n'%(n,n))
|
||||||
for item in config:
|
oh.write(' protected:\n')
|
||||||
if not first:
|
oh.write(' GwConfigItem *configs[%d]={\n'%(l))
|
||||||
oh.write(',\n')
|
first=True
|
||||||
first=False
|
for item in config:
|
||||||
oh.write(" new GwConfigItem(%s,\"%s\")"%(item.get('name'),item.get('default')))
|
if not first:
|
||||||
oh.write('};\n')
|
oh.write(',\n')
|
||||||
oh.write('};\n')
|
first=False
|
||||||
oh.close()
|
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():
|
if not checkDir():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
for f in FILES:
|
for f in FILES:
|
||||||
|
|
|
@ -147,8 +147,8 @@ GwConfigInterface *sendSerial=config.getConfigItem(config.sendSerial,true);
|
||||||
GwConfigInterface *n2kFromSerial=config.getConfigItem(config.serialToN2k,true);
|
GwConfigInterface *n2kFromSerial=config.getConfigItem(config.serialToN2k,true);
|
||||||
GwNmeaFilter usbReadFilter(config.getConfigItem(config.usbReadFilter,true));
|
GwNmeaFilter usbReadFilter(config.getConfigItem(config.usbReadFilter,true));
|
||||||
GwNmeaFilter usbWriteFilter(config.getConfigItem(config.usbWriteFilter,true));
|
GwNmeaFilter usbWriteFilter(config.getConfigItem(config.usbWriteFilter,true));
|
||||||
GwNmeaFilter serialReadFilter(config.getConfigItem(config.serialReadFilter,true));
|
GwNmeaFilter serialReadFilter(config.getConfigItem(config.serialReadF,true));
|
||||||
GwNmeaFilter serialWriteFilter(config.getConfigItem(config.serialWriteFilter,true));
|
GwNmeaFilter serialWriteFilter(config.getConfigItem(config.serialWriteF,true));
|
||||||
GwNmeaFilter tcpReadFilter(config.getConfigItem(config.tcpReadFilter,true));
|
GwNmeaFilter tcpReadFilter(config.getConfigItem(config.tcpReadFilter,true));
|
||||||
GwNmeaFilter tcpWriteFilter(config.getConfigItem(config.tcpWriteFilter,true));
|
GwNmeaFilter tcpWriteFilter(config.getConfigItem(config.tcpWriteFilter,true));
|
||||||
|
|
||||||
|
@ -358,6 +358,7 @@ protected:
|
||||||
result = JSON_OK;
|
result = JSON_OK;
|
||||||
logger.logString("update config and restart");
|
logger.logString("update config and restart");
|
||||||
config.saveConfig();
|
config.saveConfig();
|
||||||
|
delay(500);
|
||||||
delayedRestart();
|
delayedRestart();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -131,7 +131,7 @@
|
||||||
"category":"serial port"
|
"category":"serial port"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "serialReadFilter",
|
"name": "serialReadF",
|
||||||
"label": "serial read Filter",
|
"label": "serial read Filter",
|
||||||
"type": "filter",
|
"type": "filter",
|
||||||
"default": "",
|
"default": "",
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
"category":"serial port"
|
"category":"serial port"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "serialWriteFilter",
|
"name": "serialWriteF",
|
||||||
"label": "serial write Filter",
|
"label": "serial write Filter",
|
||||||
"type": "filter",
|
"type": "filter",
|
||||||
"default": "",
|
"default": "",
|
||||||
|
|
|
@ -197,5 +197,18 @@ body{
|
||||||
.dashValue{
|
.dashValue{
|
||||||
font-size: 1.6em;
|
font-size: 1.6em;
|
||||||
text-align: center;
|
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;
|
||||||
}
|
}
|
||||||
|
|
135
web/index.js
135
web/index.js
|
@ -428,11 +428,89 @@ function handleTab(el) {
|
||||||
el.classList.add('active');
|
el.classList.add('active');
|
||||||
activeTab.classList.remove('hidden');
|
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) {
|
function createDashboardItem(name, def, parent) {
|
||||||
let frame = addEl('div', 'dash', parent);
|
let frame = addEl('div', 'dash', parent);
|
||||||
let title = addEl('span', 'dashTitle', frame, name);
|
let title = addEl('span', 'dashTitle', frame, name);
|
||||||
let value = addEl('span', 'dashValue', frame);
|
let value = addEl('span', 'dashValue', frame);
|
||||||
value.setAttribute('id', 'data_' + name);
|
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;
|
return value;
|
||||||
}
|
}
|
||||||
function createDashboard() {
|
function createDashboard() {
|
||||||
|
@ -446,51 +524,12 @@ function createDashboard() {
|
||||||
updateDashboard(json);
|
updateDashboard(json);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let valueFormatters = {
|
function sourceName(v){
|
||||||
formatCourse: function (v) {
|
if (v == 0) return "N2K";
|
||||||
let x = parseFloat(v);
|
if (v == 1) return "USB";
|
||||||
let rt=x*180.0 / Math.PI;
|
if (v == 2) return "SER";
|
||||||
if (rt > 360) rt -= 360;
|
if (v >= 3) return "TCP";
|
||||||
if (rt < 0) rt += 360;
|
return "---";
|
||||||
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 updateDashboard(data) {
|
function updateDashboard(data) {
|
||||||
for (let n in data) {
|
for (let n in data) {
|
||||||
|
@ -503,7 +542,7 @@ function updateDashboard(data) {
|
||||||
formatter = valueFormatters[key];
|
formatter = valueFormatters[key];
|
||||||
}
|
}
|
||||||
if (formatter) {
|
if (formatter) {
|
||||||
de.textContent = formatter(data[n].value);
|
de.textContent = formatter.f(data[n].value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let v = parseFloat(data[n].value);
|
let v = parseFloat(data[n].value);
|
||||||
|
@ -518,6 +557,10 @@ function updateDashboard(data) {
|
||||||
}
|
}
|
||||||
else de.textContent = "---";
|
else de.textContent = "---";
|
||||||
}
|
}
|
||||||
|
let src=document.getElementById('source_'+n);
|
||||||
|
if (src){
|
||||||
|
src.textContent=sourceName(data[n].source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue