hestia/www/public/main.js

72 lines
1.8 KiB
JavaScript
Raw Normal View History

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');
2023-01-06 23:36:12 +00:00
const feedRate = document.getElementById('feed-rate');
2023-01-06 22:04:46 +00:00
// 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:09:58 +00:00
augerOn.innerHTML = config.intervals.augerOn;
augerOff.innerHTML = config.intervals.augerOff;
2023-01-06 23:47:38 +00:00
switch (config.intervals.augerOn) {
case 600:
feedRate.selectedIndex = 0;
break;
case 800:
feedRate.selectedIndex = 1;
break;
case 1000:
feedRate.selectedIndex = 2;
break;
default:
feedRate.selectedIndex = 0;
break;
}
2023-01-06 23:36:12 +00:00
feedRate.value = config.intervals.augerOn;
2023-01-06 22:04:46 +00:00
// Run this again after 2 seconds
sleep(5000).then(() => {
2022-12-23 03:19:24 +00:00
refreshData();
});
};