|
|
|
|
|
|
|
|
let rangeValues = {}; |
|
|
let rangeValues = {}; |
|
|
let xhrUpd = new XMLHttpRequest(); |
|
|
let xhrUpd = new XMLHttpRequest(); |
|
|
|
|
|
|
|
|
xhrUpd.onreadystatechange = function(){ |
|
|
|
|
|
if(xhrUpd.readyState == 4) { |
|
|
|
|
|
if (xhrUpd.status == 200){ |
|
|
|
|
|
|
|
|
xhrUpd.onreadystatechange = function () { |
|
|
|
|
|
if (xhrUpd.readyState == 4) { |
|
|
|
|
|
if (xhrUpd.status == 200) { |
|
|
console.log(xhrUpd.responseText); |
|
|
console.log(xhrUpd.responseText); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
|
|
|
function reloadRangeValues() { |
|
|
function reloadRangeValues() { |
|
|
let url = "/update"; |
|
|
let url = "/update"; |
|
|
// if there are scheduled updates, send them |
|
|
// if there are scheduled updates, send them |
|
|
if(Object.keys(rangeValues).length > 0) { |
|
|
|
|
|
|
|
|
if (Object.keys(rangeValues).length > 0) { |
|
|
let params = []; |
|
|
let params = []; |
|
|
for(let p in rangeValues) |
|
|
|
|
|
|
|
|
for (let p in rangeValues) |
|
|
params.push(encodeURIComponent(p) + "=" + encodeURIComponent(rangeValues[p])); |
|
|
params.push(encodeURIComponent(p) + "=" + encodeURIComponent(rangeValues[p])); |
|
|
params = params.join("&"); |
|
|
params = params.join("&"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rangeValues = {}; |
|
|
rangeValues = {}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
setTimeout(reloadRangeValues, 1000); |
|
|
|
|
|
}; |
|
|
|
|
|
reloadRangeValues(); |
|
|
|
|
|
|
|
|
|
|
|
function sendRangeValue(range, val) { |
|
|
|
|
|
rangeValues[range] = val; |
|
|
|
|
|
console.log(rangeValues); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// connect actions to range inputs |
|
|
// connect actions to range inputs |
|
|
function rangeToOutput(range, output) { |
|
|
function rangeToOutput(range, output) { |
|
|
document.getElementById(range).oninput = function() { |
|
|
|
|
|
|
|
|
document.getElementById(range).oninput = function () { |
|
|
document.getElementById(output).innerHTML = this.value; |
|
|
document.getElementById(output).innerHTML = this.value; |
|
|
sendRangeValue(this.id, this.value); |
|
|
|
|
|
|
|
|
// add to pending range changes |
|
|
|
|
|
rangeValues[range] = val; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rangeToOutput("range_ldr_shw", "out_ldr_shw"); |
|
|
rangeToOutput("range_ldr_shw", "out_ldr_shw"); |
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest(); |
|
|
let xhr = new XMLHttpRequest(); |
|
|
|
|
|
|
|
|
xhr.onreadystatechange = function(){ |
|
|
|
|
|
if(xhr.readyState == 4) { |
|
|
|
|
|
if (xhr.status == 200){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xhr.onreadystatechange = function () { |
|
|
|
|
|
if (xhr.readyState == 4) { |
|
|
|
|
|
if (xhr.status == 200) { |
|
|
console.log(xhr.responseText); |
|
|
console.log(xhr.responseText); |
|
|
terminal = document.getElementById("term"); |
|
|
terminal = document.getElementById("term"); |
|
|
autoscroll = document.getElementById("scroll"); |
|
|
autoscroll = document.getElementById("scroll"); |
|
|
terminal.innerHTML += xhr.responseText; |
|
|
terminal.innerHTML += xhr.responseText; |
|
|
if(autoscroll.checked) |
|
|
|
|
|
|
|
|
if (autoscroll.checked) |
|
|
terminal.scrollTop = terminal.scrollHeight; |
|
|
terminal.scrollTop = terminal.scrollHeight; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
|
|
|
function reloadTerminal() { |
|
|
function reloadTerminal() { |
|
|
xhr.open("POST", "/terminal", true); |
|
|
xhr.open("POST", "/terminal", true); |
|
|
xhr.send(); |
|
|
xhr.send(); |
|
|
setTimeout(reloadTerminal, 1000); |
|
|
|
|
|
}; |
|
|
}; |
|
|
reloadTerminal(); |
|
|
|
|
|
function clearTerminal() { |
|
|
|
|
|
document.getElementById("term").innerHTML = ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => { |
|
|
|
|
|
setInterval(reloadTerminal, 1000); |
|
|
|
|
|
setInterval(reloadRangeValues, 1000); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// use data- attributes for action |
|
|
|
|
|
document.querySelectorAll('.control').forEach((button) => { |
|
|
|
|
|
button.onclick = () => { |
|
|
|
|
|
fetch(`/action=${button.dataset.action}`) |
|
|
|
|
|
.then(response => console.log(response)) |
|
|
|
|
|
.catch(error => console.log('Error:', error)); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.querySelector('#clear_term').onclick = () => { |
|
|
|
|
|
document.querySelector("#term").innerHTML = ''; |
|
|
|
|
|
}; |