mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
first attempt with easy config reading
This commit is contained in:
parent
cd6ab4f62f
commit
19a58a8a6c
25
gui/main.js
25
gui/main.js
|
@ -43,8 +43,7 @@ if (!fs.existsSync(configFolder)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create config file if not exists with defaults
|
// create config file if not exists with defaults
|
||||||
const configDefaultSettings =
|
const configDefaultSettings = '{\
|
||||||
'{\
|
|
||||||
"tnc_host": "127.0.0.1",\
|
"tnc_host": "127.0.0.1",\
|
||||||
"tnc_port": "3000",\
|
"tnc_port": "3000",\
|
||||||
"daemon_host": "127.0.0.1",\
|
"daemon_host": "127.0.0.1",\
|
||||||
|
@ -53,15 +52,19 @@ const configDefaultSettings =
|
||||||
"mygrid": "JN40aa",\
|
"mygrid": "JN40aa",\
|
||||||
"radiocontrol" : "disabled",\
|
"radiocontrol" : "disabled",\
|
||||||
"hamlib_deviceid": "RIG_MODEL_DUMMY_NOVFO",\
|
"hamlib_deviceid": "RIG_MODEL_DUMMY_NOVFO",\
|
||||||
"hamlib_deviceport": "/dev/ttyACM1",\
|
"hamlib_deviceport": "ignore",\
|
||||||
"hamlib_stop_bits" : "1",\
|
"hamlib_stop_bits": "ignore",\
|
||||||
"hamlib_data_bits" : "8",\
|
"hamlib_data_bits": "ignore",\
|
||||||
"hamlib_handshake" : "None",\
|
"hamlib_handshake": "ignore",\
|
||||||
"hamlib_serialspeed" : "9600",\
|
"hamlib_serialspeed": "ignore",\
|
||||||
"hamlib_dtrstate" : "OFF",\
|
"hamlib_dtrstate": "ignore",\
|
||||||
"hamlib_pttprotocol" : "USB",\
|
"hamlib_pttprotocol": "ignore",\
|
||||||
"hamlib_pttport": "/dev/ttyACM1",\
|
"hamlib_ptt_port": "ignore",\
|
||||||
"hamlib_dcd": "None",\
|
"hamlib_dcd": "ignore",\
|
||||||
|
"hamlib_rigctld_port": "ignore",\
|
||||||
|
"hamlib_rigctld_ip": "ignore",\
|
||||||
|
"hamlib_rigctld_path": "ignore",\
|
||||||
|
"hamlib_rigctld_server_port": "ignore",\
|
||||||
"hamlbib_serialspeed_ptt": "9600",\
|
"hamlbib_serialspeed_ptt": "9600",\
|
||||||
"hamlib_rigctld_port" : "4532",\
|
"hamlib_rigctld_port" : "4532",\
|
||||||
"hamlib_rigctld_ip" : "127.0.0.1",\
|
"hamlib_rigctld_ip" : "127.0.0.1",\
|
||||||
|
|
|
@ -41,6 +41,26 @@ const contrib = [
|
||||||
"N1QM",
|
"N1QM",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//let elements = document.querySelectorAll('[id^="hamlib_"]'); // get all elements starting with...
|
||||||
|
const hamlib_elements = ["hamlib_deviceid",
|
||||||
|
"hamlib_deviceport",
|
||||||
|
"hamlib_stop_bits",
|
||||||
|
"hamlib_data_bits",
|
||||||
|
"hamlib_handshake",
|
||||||
|
"hamlib_serialspeed",
|
||||||
|
"hamlib_dtrstate",
|
||||||
|
"hamlib_pttprotocol",
|
||||||
|
"hamlib_ptt_port",
|
||||||
|
"hamlib_dcd",
|
||||||
|
"hamlib_rigctld_port",
|
||||||
|
"hamlib_rigctld_ip",
|
||||||
|
"hamlib_rigctld_path",
|
||||||
|
"hamlib_rigctld_server_port"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// SET dbfs LEVEL GLOBAL
|
// SET dbfs LEVEL GLOBAL
|
||||||
// this is an attempt of reducing CPU LOAD
|
// this is an attempt of reducing CPU LOAD
|
||||||
// we are going to check if we have unequal values before we start calculating again
|
// we are going to check if we have unequal values before we start calculating again
|
||||||
|
@ -179,6 +199,12 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// LOAD SETTINGS
|
// LOAD SETTINGS
|
||||||
|
|
||||||
|
// load settings by function
|
||||||
|
loadSettings(hamlib_elements);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
document.getElementById("tnc_adress").value = config.tnc_host;
|
document.getElementById("tnc_adress").value = config.tnc_host;
|
||||||
document.getElementById("tnc_port").value = config.tnc_port;
|
document.getElementById("tnc_port").value = config.tnc_port;
|
||||||
|
|
||||||
|
@ -193,6 +219,10 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
document.getElementById("myCallSSID").value = ssid;
|
document.getElementById("myCallSSID").value = ssid;
|
||||||
document.getElementById("myGrid").value = config.mygrid;
|
document.getElementById("myGrid").value = config.mygrid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// hamlib settings
|
// hamlib settings
|
||||||
document.getElementById("hamlib_deviceid").value = config.hamlib_deviceid;
|
document.getElementById("hamlib_deviceid").value = config.hamlib_deviceid;
|
||||||
|
|
||||||
|
@ -541,6 +571,26 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// hamlib event listener for saving settings
|
||||||
|
hamlib_elements.forEach(function(elem) {
|
||||||
|
try{
|
||||||
|
document.getElementById(elem).addEventListener("change", function() {
|
||||||
|
config.elem = document.getElementById(elem).value;
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
console.log(config.elem)
|
||||||
|
});
|
||||||
|
} catch(e){
|
||||||
|
console.log(e)
|
||||||
|
console.log(elem)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
document
|
document
|
||||||
.getElementById("hamlib_rigctld_start")
|
.getElementById("hamlib_rigctld_start")
|
||||||
.addEventListener("click", () => {
|
.addEventListener("click", () => {
|
||||||
|
@ -566,15 +616,15 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// hamlib databits setting
|
// hamlib databits setting
|
||||||
if (document.getElementById("hamlib_databits").value !== 'ignore') {
|
if (document.getElementById("hamlib_data_bits").value !== 'ignore') {
|
||||||
var hamlib_databits = document.getElementById("hamlib_databits").value;
|
var hamlib_data_bits = document.getElementById("hamlib_data_bits").value;
|
||||||
paramList = paramList.concat("--set-conf=data_bits=" + hamlib_databits);
|
paramList = paramList.concat("--set-conf=data_bits=" + hamlib_data_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hamlib stopbits setting
|
// hamlib stopbits setting
|
||||||
if (document.getElementById("hamlib_stopbits").value !== 'ignore') {
|
if (document.getElementById("hamlib_stop_bits").value !== 'ignore') {
|
||||||
var hamlib_stopbits = document.getElementById("hamlib_stopbits").value;
|
var hamlib_stop_bits = document.getElementById("hamlib_stop_bits").value;
|
||||||
paramList = paramList.concat("--set-conf=stop_bits=" + hamlib_stopbits);
|
paramList = paramList.concat("--set-conf=stop_bits=" + hamlib_stop_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hamlib handshake setting
|
// hamlib handshake setting
|
||||||
|
@ -1083,8 +1133,8 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
var tx_audio = document.getElementById("audio_output_selectbox").value;
|
var tx_audio = document.getElementById("audio_output_selectbox").value;
|
||||||
|
|
||||||
var pttport = document.getElementById("hamlib_ptt_port").value;
|
var pttport = document.getElementById("hamlib_ptt_port").value;
|
||||||
var data_bits = document.getElementById("hamlib_databits").value;
|
var data_bits = document.getElementById("hamlib_data_bits").value;
|
||||||
var stop_bits = document.getElementById("hamlib_stopbits").value;
|
var stop_bits = document.getElementById("hamlib_stop_bits").value;
|
||||||
var handshake = document.getElementById("hamlib_handshake").value;
|
var handshake = document.getElementById("hamlib_handshake").value;
|
||||||
|
|
||||||
if (document.getElementById("scatterSwitch").checked == true) {
|
if (document.getElementById("scatterSwitch").checked == true) {
|
||||||
|
@ -1178,7 +1228,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
config.hamlib_deviceport = deviceport;
|
config.hamlib_deviceport = deviceport;
|
||||||
config.hamlib_serialspeed = serialspeed;
|
config.hamlib_serialspeed = serialspeed;
|
||||||
config.hamlib_pttprotocol = pttprotocol;
|
config.hamlib_pttprotocol = pttprotocol;
|
||||||
config.hamlib_pttport = pttport;
|
config.hamlib_ptt_port = pttport;
|
||||||
config.hamlib_data_bits = data_bits;
|
config.hamlib_data_bits = data_bits;
|
||||||
config.hamlib_stop_bits = stop_bits;
|
config.hamlib_stop_bits = stop_bits;
|
||||||
config.hamlib_handshake = handshake;
|
config.hamlib_handshake = handshake;
|
||||||
|
@ -1244,8 +1294,8 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
|
|
||||||
// TEST HAMLIB
|
// TEST HAMLIB
|
||||||
document.getElementById("testHamlib").addEventListener("click", () => {
|
document.getElementById("testHamlib").addEventListener("click", () => {
|
||||||
var data_bits = document.getElementById("hamlib_databits").value;
|
var data_bits = document.getElementById("hamlib_data_bits").value;
|
||||||
var stop_bits = document.getElementById("hamlib_stopbits").value;
|
var stop_bits = document.getElementById("hamlib_stop_bits").value;
|
||||||
var handshake = document.getElementById("hamlib_handshake").value;
|
var handshake = document.getElementById("hamlib_handshake").value;
|
||||||
var pttport = document.getElementById("hamlib_ptt_port").value;
|
var pttport = document.getElementById("hamlib_ptt_port").value;
|
||||||
|
|
||||||
|
@ -2152,7 +2202,7 @@ ipcRenderer.on("action-update-daemon-state", (event, arg) => {
|
||||||
option.text = arg.serial_devices[i]["description"];
|
option.text = arg.serial_devices[i]["description"];
|
||||||
option.value = arg.serial_devices[i]["port"];
|
option.value = arg.serial_devices[i]["port"];
|
||||||
// set device from config if available
|
// set device from config if available
|
||||||
if (config.hamlib_pttport == option.value) {
|
if (config.hamlib_ptt_port == option.value) {
|
||||||
option.setAttribute("selected", true);
|
option.setAttribute("selected", true);
|
||||||
}
|
}
|
||||||
document.getElementById("hamlib_ptt_port").add(option);
|
document.getElementById("hamlib_ptt_port").add(option);
|
||||||
|
@ -3032,3 +3082,36 @@ function displayToast(
|
||||||
toastHTMLElement.remove();
|
toastHTMLElement.remove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadSettings(elements){
|
||||||
|
elements.forEach(function(id) {
|
||||||
|
let element = document.getElementById(id);
|
||||||
|
|
||||||
|
if(element.tagName === 'SELECT') {
|
||||||
|
element.value = config.elem;
|
||||||
|
|
||||||
|
// add selected value
|
||||||
|
for(var i = 0, j = element.options.length; i < j; ++i) {
|
||||||
|
if(element.options[i].innerHTML === config.elem) {
|
||||||
|
element.selectedIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (element.tagName === 'INPUT' && element.type === 'text') {
|
||||||
|
element.value = config.elem;
|
||||||
|
|
||||||
|
} else if (element.tagName === 'INPUT' && element.type === 'radio') {
|
||||||
|
element.value = config.elem;
|
||||||
|
|
||||||
|
if(config.elem === "True"){
|
||||||
|
element.checked = true;
|
||||||
|
} else {
|
||||||
|
element.checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
|
@ -2080,7 +2080,7 @@
|
||||||
<select
|
<select
|
||||||
class="form-select form-select-sm"
|
class="form-select form-select-sm"
|
||||||
aria-label=".form-select-sm"
|
aria-label=".form-select-sm"
|
||||||
id="hamlib_databits"
|
id="hamlib_data_bits"
|
||||||
>
|
>
|
||||||
<option selected value="ignore">-- ignore --</option>
|
<option selected value="ignore">-- ignore --</option>
|
||||||
<option value="7">7</option>
|
<option value="7">7</option>
|
||||||
|
@ -2096,7 +2096,7 @@
|
||||||
<select
|
<select
|
||||||
class="form-select form-select-sm"
|
class="form-select form-select-sm"
|
||||||
aria-label=".form-select-sm"
|
aria-label=".form-select-sm"
|
||||||
id="hamlib_stopbits"
|
id="hamlib_stop_bits"
|
||||||
>
|
>
|
||||||
<option selected value="ignore">-- ignore --</option>
|
<option selected value="ignore">-- ignore --</option>
|
||||||
<option value="1">1</option>
|
<option value="1">1</option>
|
||||||
|
|
Loading…
Reference in a new issue