2021-07-05 18:15:57 +02:00
|
|
|
let rangeValues = {};
|
|
|
|
let xhrUpd = new XMLHttpRequest();
|
2021-06-23 02:13:48 +02:00
|
|
|
|
2021-07-05 18:15:57 +02:00
|
|
|
xhrUpd.onreadystatechange = function(){
|
|
|
|
if(xhrUpd.readyState == 4) {
|
|
|
|
if (xhrUpd.status == 200){
|
|
|
|
console.log(xhrUpd.responseText);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("status:", xhrUpd.status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-26 10:49:29 +02:00
|
|
|
|
2021-07-05 18:15:57 +02:00
|
|
|
function reloadRangeValues() {
|
|
|
|
let url = "/update";
|
|
|
|
// if there are scheduled updates, send them
|
|
|
|
if(Object.keys(rangeValues).length > 0) {
|
|
|
|
let params = [];
|
|
|
|
for(let p in rangeValues)
|
|
|
|
params.push(encodeURIComponent(p) + "=" + encodeURIComponent(rangeValues[p]));
|
2021-07-05 19:51:55 +02:00
|
|
|
params = params.join("&");
|
|
|
|
|
2021-07-05 18:15:57 +02:00
|
|
|
xhrUpd.open("POST", url, true);
|
|
|
|
xhrUpd.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
|
|
|
xhrUpd.send(params);
|
|
|
|
|
|
|
|
rangeValues = {};
|
|
|
|
}
|
|
|
|
|
2021-07-05 19:51:55 +02:00
|
|
|
setTimeout(reloadRangeValues, 1000);
|
2021-07-05 18:15:57 +02:00
|
|
|
};
|
|
|
|
reloadRangeValues();
|
|
|
|
|
|
|
|
function sendRangeValue(range, val) {
|
|
|
|
rangeValues[range] = val;
|
|
|
|
console.log(rangeValues);
|
|
|
|
};
|
|
|
|
|
|
|
|
// connect actions to range inputs
|
|
|
|
function rangeToOutput(range, output) {
|
|
|
|
document.getElementById(range).oninput = function() {
|
|
|
|
document.getElementById(output).innerHTML = this.value;
|
|
|
|
sendRangeValue(this.id, this.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rangeToOutput("range_act_pwm", "out_act_pwm");
|
|
|
|
rangeToOutput("range_idl_pwm", "out_idl_pwm");
|
|
|
|
rangeToOutput("range_tim_sta", "out_tim_sta");
|
2021-07-19 11:54:37 +02:00
|
|
|
rangeToOutput("range_tim_ldr", "out_tim_ldr");
|
|
|
|
rangeToOutput("range_ldr_shw", "out_ldr_shw");
|
2021-06-26 10:49:29 +02:00
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.onreadystatechange = function(){
|
|
|
|
if(xhr.readyState == 4) {
|
|
|
|
if (xhr.status == 200){
|
|
|
|
console.log(xhr.responseText);
|
|
|
|
terminal = document.getElementById("term");
|
|
|
|
autoscroll = document.getElementById("scroll");
|
2021-06-30 20:33:16 +02:00
|
|
|
terminal.innerHTML += xhr.responseText;
|
2021-06-26 10:49:29 +02:00
|
|
|
if(autoscroll.checked)
|
|
|
|
terminal.scrollTop = terminal.scrollHeight;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("status:", xhr.status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function reloadTerminal() {
|
2021-07-05 18:15:57 +02:00
|
|
|
xhr.open("POST", "/terminal", true);
|
2021-06-26 10:49:29 +02:00
|
|
|
xhr.send();
|
|
|
|
setTimeout(reloadTerminal, 1000);
|
|
|
|
};
|
|
|
|
reloadTerminal();
|
|
|
|
function clearTerminal() {
|
|
|
|
document.getElementById("term").innerHTML = '';
|
2021-07-05 18:15:57 +02:00
|
|
|
}
|