diff --git a/firmware/20230519_firmware.ino.bin b/firmware/20230520_firmware.ino.bin similarity index 79% rename from firmware/20230519_firmware.ino.bin rename to firmware/20230520_firmware.ino.bin index b399520..84010fe 100644 Binary files a/firmware/20230519_firmware.ino.bin and b/firmware/20230520_firmware.ino.bin differ diff --git a/firmware/20230519_firmware.spiffs.bin b/firmware/20230520_firmware.spiffs.bin similarity index 97% rename from firmware/20230519_firmware.spiffs.bin rename to firmware/20230520_firmware.spiffs.bin index ad0fb9f..7c92613 100644 Binary files a/firmware/20230519_firmware.spiffs.bin and b/firmware/20230520_firmware.spiffs.bin differ diff --git a/firmware/20230519_firmware_dev.ino.bin b/firmware/20230520_firmware_dev.ino.bin similarity index 79% rename from firmware/20230519_firmware_dev.ino.bin rename to firmware/20230520_firmware_dev.ino.bin index 42f3be6..d7d52b1 100644 Binary files a/firmware/20230519_firmware_dev.ino.bin and b/firmware/20230520_firmware_dev.ino.bin differ diff --git a/firmware/data/bottom.js b/firmware/data/bottom.js index fe5af92..11dcd6a 100644 --- a/firmware/data/bottom.js +++ b/firmware/data/bottom.js @@ -310,26 +310,21 @@ pwmElementTxt.innerText = pwmValue.toString(); } updateLightStateAndPWMValues(); setInterval(updateLightStateAndPWMValues, 5000); -var links = document.querySelectorAll('[id^="on"][id$="_off"]'); -links.forEach(function(link) { -link.addEventListener('click', function(event) { -event.preventDefault(); -var id_full = this.id; -var id = this.id.replace('on', '').replace('_off', ''); +function handleOnRequest(id_full, id, value) { +var button = document.getElementById(id_full); var xhr = new XMLHttpRequest(); -xhr.open('GET', 'http://{{IP_ADDRESS}}/?on' + id + '=false&transition=' + document.getElementById('transition').value, true); +xhr.open('GET', 'http://{{IP_ADDRESS}}/?on' + id + '=' + value + '&transition=' + document.getElementById('transition').value, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { -var button = document.getElementById(id_full); if (xhr.status === 200) { button.classList.remove("pure-button-primary"); button.classList.add("success"); -button.innerHTML = "Disabled!"; +button.innerHTML = value ? "Enabled!" : "Disabled!"; button.style.backgroundColor = "green"; setTimeout(function () { button.classList.remove("success"); button.classList.add("pure-button-primary"); -button.innerHTML = "OFF"; +button.innerHTML = value ? "ON" : "OFF"; button.style.backgroundColor = ""; }, 2000); console.log('Data successfully sent to server!'); @@ -341,7 +336,7 @@ button.style.backgroundColor = "red"; setTimeout(function () { button.classList.remove("error"); button.classList.add("pure-button-primary"); -button.innerHTML = "OFF"; +button.innerHTML = value ? "ON" : "OFF"; button.style.backgroundColor = ""; }, 2000); showToast('Error while sending data to server.', 'error'); @@ -351,54 +346,27 @@ console.log('Error while sending data to server.'); }; xhr.send(); updateLightStateAndPWMValues(); -this.classList.add('pure-button-primary'); -document.getElementById('on'+id+'_on').classList.remove('pure-button-primary'); -}); -}); -var links = document.querySelectorAll('[id^="on"][id$="_on"]'); -links.forEach(function(link) { -link.addEventListener('click', function(event) { +document.getElementById(id_full).classList.add('pure-button-primary'); +document.getElementById('on' + id + (value ? '_off' : '_on')).classList.remove('pure-button-primary'); +} +function addOnButtonClickListener(id_full, id, value) { +var link = document.getElementById(id_full); +link.addEventListener('click', function (event) { event.preventDefault(); -var id_full = this.id; -var id = this.id.replace('on', '').replace('_on', ''); -var xhr = new XMLHttpRequest(); -xhr.open('GET', 'http://{{IP_ADDRESS}}/?on' + id + '=true&transition=' + document.getElementById('transition').value, true); -xhr.onreadystatechange = function () { -if (xhr.readyState === 4) { -var button = document.getElementById(id_full); -if (xhr.status === 200) { -button.classList.remove("pure-button-primary"); -button.classList.add("success"); -button.innerHTML = "Enabled!"; -button.style.backgroundColor = "green"; -setTimeout(function () { -button.classList.remove("success"); -button.classList.add("pure-button-primary"); -button.innerHTML = "ON"; -button.style.backgroundColor = ""; -}, 2000); -console.log('Data successfully sent to server!'); -} else { -button.classList.remove("pure-button-primary"); -button.classList.add("error"); -button.innerHTML = "Error!"; -button.style.backgroundColor = "red"; -setTimeout(function () { -button.classList.remove("error"); -button.classList.add("pure-button-primary"); -button.innerHTML = "ON"; -button.style.backgroundColor = ""; -}, 2000); -showToast('Error while sending data to server.', 'error'); -console.log('Error while sending data to server.'); -} -} -}; -xhr.send(); -updateLightStateAndPWMValues(); -this.classList.add('pure-button-primary'); -document.getElementById('on'+id+'_off').classList.remove('pure-button-primary'); +handleOnRequest(id_full, id, value); }); +} +var offLinks = document.querySelectorAll('[id^="on"][id$="_off"]'); +offLinks.forEach(function (link) { +var id_full = link.id; +var id = link.id.replace('on', '').replace('_off', ''); +addOnButtonClickListener(id_full, id, false); +}); +var onLinks = document.querySelectorAll('[id^="on"][id$="_on"]'); +onLinks.forEach(function (link) { +var id_full = link.id; +var id = link.id.replace('on', '').replace('_on', ''); +addOnButtonClickListener(id_full, id, true); }); function createTable() { var table = document.createElement("table"); diff --git a/firmware/html/bottom.js b/firmware/html/bottom.js index 11f20f6..4d61172 100644 --- a/firmware/html/bottom.js +++ b/firmware/html/bottom.js @@ -361,111 +361,68 @@ function updateLightStateAndPWMValues() { updateLightStateAndPWMValues(); setInterval(updateLightStateAndPWMValues, 5000); -// Suche nach allen Links auf der Seite mit IDs von on0_off bis on3_off -var links = document.querySelectorAll('[id^="on"][id$="_off"]'); -// Füge einen Klick-Listener zu jedem Link hinzu -links.forEach(function(link) { - link.addEventListener('click', function(event) { - // Verhindere, dass der Link die Seite neu lädt - event.preventDefault(); - // Extrahiere die Zahl aus der ID des Links - var id_full = this.id; - var id = this.id.replace('on', '').replace('_off', ''); - // Erstelle eine neue Anfrage an die entsprechende URL - var xhr = new XMLHttpRequest(); - xhr.open('GET', 'http://{{IP_ADDRESS}}/?on' + id + '=false&transition=' + document.getElementById('transition').value, true); +function handleOnRequest(id_full, id, value) { + var button = document.getElementById(id_full); + var xhr = new XMLHttpRequest(); + xhr.open('GET', 'http://{{IP_ADDRESS}}/?on' + id + '=' + value + '&transition=' + document.getElementById('transition').value, true); - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - var button = document.getElementById(id_full); - if (xhr.status === 200) { - button.classList.remove("pure-button-primary"); - button.classList.add("success"); - button.innerHTML = "Disabled!"; - button.style.backgroundColor = "green"; - setTimeout(function () { - button.classList.remove("success"); - button.classList.add("pure-button-primary"); - button.innerHTML = "OFF"; - button.style.backgroundColor = ""; - }, 2000); - console.log('Data successfully sent to server!'); - } else { - button.classList.remove("pure-button-primary"); - button.classList.add("error"); - button.innerHTML = "Error!"; - button.style.backgroundColor = "red"; - setTimeout(function () { - button.classList.remove("error"); - button.classList.add("pure-button-primary"); - button.innerHTML = "OFF"; - button.style.backgroundColor = ""; - }, 2000); - showToast('Error while sending data to server.', 'error'); - console.log('Error while sending data to server.'); - } + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + button.classList.remove("pure-button-primary"); + button.classList.add("success"); + button.innerHTML = value ? "Enabled!" : "Disabled!"; + button.style.backgroundColor = "green"; + setTimeout(function () { + button.classList.remove("success"); + button.classList.add("pure-button-primary"); + button.innerHTML = value ? "ON" : "OFF"; + button.style.backgroundColor = ""; + }, 2000); + console.log('Data successfully sent to server!'); + } else { + button.classList.remove("pure-button-primary"); + button.classList.add("error"); + button.innerHTML = "Error!"; + button.style.backgroundColor = "red"; + setTimeout(function () { + button.classList.remove("error"); + button.classList.add("pure-button-primary"); + button.innerHTML = value ? "ON" : "OFF"; + button.style.backgroundColor = ""; + }, 2000); + showToast('Error while sending data to server.', 'error'); + console.log('Error while sending data to server.'); } - }; + } + }; - // Sende die Anfrage im Hintergrund - xhr.send(); - updateLightStateAndPWMValues(); - this.classList.add('pure-button-primary'); - document.getElementById('on'+id+'_on').classList.remove('pure-button-primary'); + xhr.send(); + updateLightStateAndPWMValues(); + document.getElementById(id_full).classList.add('pure-button-primary'); + document.getElementById('on' + id + (value ? '_off' : '_on')).classList.remove('pure-button-primary'); +} + +function addOnButtonClickListener(id_full, id, value) { + var link = document.getElementById(id_full); + link.addEventListener('click', function (event) { + event.preventDefault(); + handleOnRequest(id_full, id, value); }); +} + +var offLinks = document.querySelectorAll('[id^="on"][id$="_off"]'); +offLinks.forEach(function (link) { + var id_full = link.id; + var id = link.id.replace('on', '').replace('_off', ''); + addOnButtonClickListener(id_full, id, false); }); -// Suche nach allen Links auf der Seite mit IDs von on0_off bis on3_off -var links = document.querySelectorAll('[id^="on"][id$="_on"]'); -// Füge einen Klick-Listener zu jedem Link hinzu -links.forEach(function(link) { - link.addEventListener('click', function(event) { - // Verhindere, dass der Link die Seite neu lädt - event.preventDefault(); - // Extrahiere die Zahl aus der ID des Links - var id_full = this.id; - var id = this.id.replace('on', '').replace('_on', ''); - // Erstelle eine neue Anfrage an die entsprechende URL - var xhr = new XMLHttpRequest(); - xhr.open('GET', 'http://{{IP_ADDRESS}}/?on' + id + '=true&transition=' + document.getElementById('transition').value, true); - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - var button = document.getElementById(id_full); - if (xhr.status === 200) { - button.classList.remove("pure-button-primary"); - button.classList.add("success"); - button.innerHTML = "Enabled!"; - button.style.backgroundColor = "green"; - setTimeout(function () { - button.classList.remove("success"); - button.classList.add("pure-button-primary"); - button.innerHTML = "ON"; - button.style.backgroundColor = ""; - }, 2000); - console.log('Data successfully sent to server!'); - } else { - button.classList.remove("pure-button-primary"); - button.classList.add("error"); - button.innerHTML = "Error!"; - button.style.backgroundColor = "red"; - setTimeout(function () { - button.classList.remove("error"); - button.classList.add("pure-button-primary"); - button.innerHTML = "ON"; - button.style.backgroundColor = ""; - }, 2000); - showToast('Error while sending data to server.', 'error'); - console.log('Error while sending data to server.'); - } - } - }; - - // Sende die Anfrage im Hintergrund - xhr.send(); - updateLightStateAndPWMValues(); - this.classList.add('pure-button-primary'); - document.getElementById('on'+id+'_off').classList.remove('pure-button-primary'); - }); +var onLinks = document.querySelectorAll('[id^="on"][id$="_on"]'); +onLinks.forEach(function (link) { + var id_full = link.id; + var id = link.id.replace('on', '').replace('_on', ''); + addOnButtonClickListener(id_full, id, true); }); function createTable() { diff --git a/firmware/webserver.ino b/firmware/webserver.ino index 3970b8a..6cfd9c8 100644 --- a/firmware/webserver.ino +++ b/firmware/webserver.ino @@ -247,6 +247,7 @@ void init_webserver() EEPROM.commit(); Serial.print("Timing control = "); Serial.println(EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS)); + tc_reset(); tc_update_main(); // call the main update function to read data and set the light states } }