diff --git a/firmware/data/bottom.js b/firmware/data/bottom.js index 8459e2f..3682501 100644 --- a/firmware/data/bottom.js +++ b/firmware/data/bottom.js @@ -190,7 +190,7 @@ break; } } if (lowerIndex === -1 || upperIndex === -1) { -console.log("Error: Current time not found in time array and not between two elements in time array. Fixing it..."); +console.log("Warning: Current time not found in time array and not between two elements in time array. Fixing it..."); lowerIndex = 0; upperIndex = 1; var tmp1 = time[0].split(':'); @@ -336,6 +336,7 @@ button.classList.remove("error"); button.classList.add("pure-button-primary"); button.innerHTML = "OFF"; }, 2000); +showToast('Error while sending data to server.', 'error'); console.log('Error while sending data to server.'); } } @@ -376,6 +377,7 @@ button.classList.remove("error"); button.classList.add("pure-button-primary"); button.innerHTML = "ON"; }, 2000); +showToast('Error while sending data to server.', 'error'); console.log('Error while sending data to server.'); } } @@ -405,18 +407,11 @@ tr.appendChild(tdHour); var tdMinute = createSelectCell(59, 0, 1); tdMinute.id = "minute" + i; tr.appendChild(tdMinute); -var tdCh1 = createSelectCell(100, 0, 1); -tdCh1.id = "ch1_" + i; -tr.appendChild(tdCh1); -var tdCh2 = createSelectCell(100, 0, 1); -tdCh2.id = "ch2_" + i; -tr.appendChild(tdCh2); -var tdCh3 = createSelectCell(100, 0, 1); -tdCh3.id = "ch3_" + i; -tr.appendChild(tdCh3); -var tdCh4 = createSelectCell(100, 0, 1); -tdCh4.id = "ch4_" + i; -tr.appendChild(tdCh4); +for (var j = 1; j <=4; j++) +{ +var tdCh = createSlider("ch" + j + "_" + i, 100, 0, 1); +tr.appendChild(tdCh); +} table.appendChild(tr); } var container = document.getElementById("table-container"); @@ -424,6 +419,36 @@ container.innerHTML = ""; container.classList.add("pure-form"); container.appendChild(table); } +function createSlider(id, max, value, step) { +var input = document.createElement("input"); +input.type = "range"; +input.min = 0; +input.max = max; +input.step = step; +input.value = value; +input.classList.add("pure-slider-range"); +if (id.startsWith("ch1_")) { +input.style.backgroundColor = "blue"; +} else if (id.startsWith("ch2_")) { +input.style.backgroundColor = "orange"; +} else if (id.startsWith("ch3_")) { +input.style.backgroundColor = "green"; +} else if (id.startsWith("ch4_")) { +input.style.backgroundColor = "red"; +} +div = document.createElement("div"); +div.appendChild(input); +var span = document.createElement("span"); +span.innerHTML = " " + value + " %"; +div.appendChild(span); +input.oninput = function() { +span.innerHTML = " " + this.value + " %"; +}; +var td = document.createElement("td"); +td.id = id; +td.appendChild(div); +return td; +} function createSelectCell(max, value, step) { var select = document.createElement("select"); for (var i = 0; i <= max; i += step) { @@ -446,10 +471,14 @@ for (var i = 0; i < tcdata.length; i++) { var row = document.getElementById("hour" + (i+1)).parentNode; row.cells[0].childNodes[0].value = tcdata[i].hour; row.cells[1].childNodes[0].value = tcdata[i].min; -row.cells[2].childNodes[0].value = parseInt(Math.round(tcdata[i].ch1 * 100 / 255)); -row.cells[3].childNodes[0].value = parseInt(Math.round(tcdata[i].ch2 * 100 / 255)); -row.cells[4].childNodes[0].value = parseInt(Math.round(tcdata[i].ch3 * 100 / 255)); -row.cells[5].childNodes[0].value = parseInt(Math.round(tcdata[i].ch4 * 100 / 255)); +row.cells[2].childNodes[0].childNodes[0].value = parseInt(Math.round(tcdata[i].ch1 * 100 / 255)); +row.cells[2].childNodes[0].childNodes[1].innerHTML = " " + row.cells[2].childNodes[0].childNodes[0].value + " %"; +row.cells[3].childNodes[0].childNodes[0].value = parseInt(Math.round(tcdata[i].ch2 * 100 / 255)); +row.cells[3].childNodes[0].childNodes[1].innerHTML = " " + row.cells[3].childNodes[0].childNodes[0].value + " %"; +row.cells[4].childNodes[0].childNodes[0].value = parseInt(Math.round(tcdata[i].ch3 * 100 / 255)); +row.cells[4].childNodes[0].childNodes[1].innerHTML = " " + row.cells[4].childNodes[0].childNodes[0].value + " %"; +row.cells[5].childNodes[0].childNodes[0].value = parseInt(Math.round(tcdata[i].ch4 * 100 / 255)); +row.cells[5].childNodes[0].childNodes[1].innerHTML = " " + row.cells[5].childNodes[0].childNodes[0].value + " %"; } loadTCGraphData(); }); @@ -457,22 +486,42 @@ loadTCGraphData(); function createJsonFromTable() { var tableRows = document.querySelectorAll("table tr"); var tcdata = []; +var timeArr = []; for (var i = 1; i <= 10; i++) { var row = document.getElementById("hour" + i).parentNode; var hour = parseInt(row.cells[0].childNodes[0].value); var min = parseInt(row.cells[1].childNodes[0].value); -var ch1 = Math.round(parseInt(row.cells[2].childNodes[0].value) * 2.55); -var ch2 = Math.round(parseInt(row.cells[3].childNodes[0].value) * 2.55); -var ch3 = Math.round(parseInt(row.cells[4].childNodes[0].value) * 2.55); -var ch4 = Math.round(parseInt(row.cells[5].childNodes[0].value) * 2.55); +timeArr.push(hour * 60 + min); +var ch1 = Math.round(parseInt(row.cells[2].childNodes[0].childNodes[0].value) * 2.55); +var ch2 = Math.round(parseInt(row.cells[3].childNodes[0].childNodes[0].value) * 2.55); +var ch3 = Math.round(parseInt(row.cells[4].childNodes[0].childNodes[0].value) * 2.55); +var ch4 = Math.round(parseInt(row.cells[5].childNodes[0].childNodes[0].value) * 2.55); tcdata.push({hour: hour, min: min, ch1: ch1, ch2: ch2, ch3: ch3, ch4: ch4}); } +for (var i = 0; i < timeArr.length - 1; i++) { +if (timeArr[i] >= timeArr[i + 1]) { +showToast('Error while verifying timing control data. The timestamps are not incrementing.', 'error'); +return null; +} +} var currentTime = {hour: new Date().getHours(), min: new Date().getMinutes()}; var jsonData = {tcdata: tcdata, currenttime: currentTime}; return JSON.stringify(jsonData); } function sendDataToServer() { var jsonData = createJsonFromTable(); +if (!jsonData) { +button.classList.remove("pure-button-primary"); +button.classList.add("error"); +button.innerHTML = "Error!"; +setTimeout(function () { +button.classList.remove("error"); +button.classList.add("pure-button-primary"); +button.innerHTML = "save"; +}, 2000); +console.log('Error while generating timing control data.'); +return; +} var urlEncodedData = encodeURIComponent(jsonData); var url = 'http://{{IP_ADDRESS}}/tc_data_blocks_store?data=' + urlEncodedData; var xhr = new XMLHttpRequest(); @@ -499,6 +548,7 @@ button.classList.remove("error"); button.classList.add("pure-button-primary"); button.innerHTML = "save"; }, 2000); +showToast('Error while sending timing control data to server.', 'error'); console.log('Error while sending data to server.'); } } @@ -506,3 +556,19 @@ console.log('Error while sending data to server.'); xhr.send(); loadTCGraphData(); } +function showToast(message, type) { +const toast = document.querySelector('.toast'); +if (toast) { +toast.textContent = message; +toast.classList.remove('success', 'error'); +if (type === 'success') { +toast.classList.add('success'); +} else if (type === 'error') { +toast.classList.add('error'); +} +toast.style.opacity = 1; +setTimeout(() => { +toast.style.opacity = 0; +}, 5000); +} +} diff --git a/firmware/data/index_template_top.html b/firmware/data/index_template_top.html index 66e10a9..7345687 100644 --- a/firmware/data/index_template_top.html +++ b/firmware/data/index_template_top.html @@ -15,6 +15,7 @@