hestia/www/public/main.js

73 lines
1.9 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
2023-01-07 02:53:54 +00:00
const statusTable = document.getElementById('status-table');
const augerStatus = statusTable.rows[0].cells[1];
const augerOn = statusTable.rows[0].cells[3];
const augerOff = statusTable.rows[1].cells[3];
const feedRate = statusTable.rows[1].cells[1];
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) {
2023-01-07 01:26:51 +00:00
case '600':
feedRate.innerHTML = 'Low';
2023-01-06 23:47:38 +00:00
break;
2023-01-07 01:26:51 +00:00
case '800':
feedRate.innerHTML = 'Medium';
2023-01-06 23:47:38 +00:00
break;
2023-01-07 01:26:51 +00:00
case '1000':
feedRate.innerHTML = 'High';
2023-01-06 23:47:38 +00:00
break;
default:
feedRate.innerHTML = 'Unknown';
2023-01-06 23:47:38 +00:00
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
2023-01-07 02:29:28 +00:00
sleep(1000).then(() => {
2022-12-23 03:19:24 +00:00
refreshData();
});
};