2022-12-23 03:19:24 +00:00
|
|
|
function sleep(ms) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
resolve();
|
|
|
|
}, ms);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function readJSON(path) {
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open("GET", path, false);
|
|
|
|
request.send(null)
|
|
|
|
var JSONObj = JSON.parse(request.responseText);
|
|
|
|
return JSONObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseStatus(data) {
|
|
|
|
switch (data) {
|
|
|
|
case 0:
|
|
|
|
return "Off";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return "On";
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return "Error";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshData() {
|
|
|
|
const log = document.getElementById('log-area');
|
|
|
|
log.contentWindow.location.reload();
|
|
|
|
sleep(100).then(() => {
|
2023-01-06 22:04:46 +00:00
|
|
|
document.getElementById('log-area').contentWindow.scrollTo(0, 9999999999);
|
2022-12-23 03:19:24 +00:00
|
|
|
});
|
|
|
|
|
2023-01-06 22:04:46 +00:00
|
|
|
// Get the elements we need to update
|
2022-12-23 03:19:24 +00:00
|
|
|
const augerStatus = document.getElementById('auger-status');
|
2023-01-06 22:04:46 +00:00
|
|
|
const augerOn = document.getElementById('auger-on');
|
|
|
|
const augerOff = document.getElementById('auger-off');
|
|
|
|
const pauseInt = document.getElementById('pause-int');
|
|
|
|
|
|
|
|
// Get the config file
|
2022-12-23 03:19:24 +00:00
|
|
|
const config = readJSON('./config.json');
|
2023-01-06 22:04:46 +00:00
|
|
|
// console.log(config);
|
2022-12-23 03:19:24 +00:00
|
|
|
|
|
|
|
augerStatus.innerHTML = parseStatus(config.status.auger);
|
2023-01-06 22:04:46 +00:00
|
|
|
augerOn.value = config.intervals.augerOn;
|
|
|
|
augerOff.value = config.intervals.augerOff;
|
|
|
|
pauseInt.value = config.intervals.pause;
|
|
|
|
|
|
|
|
// Run this again after 2 seconds
|
|
|
|
sleep(5000).then(() => {
|
2022-12-23 03:19:24 +00:00
|
|
|
refreshData();
|
|
|
|
});
|
|
|
|
};
|