diff --git a/firmware/data/bottom.js b/firmware/data/bottom.js index e577721..40a1950 100644 --- a/firmware/data/bottom.js +++ b/firmware/data/bottom.js @@ -272,15 +272,23 @@ if (document.getElementById('tab-tde').classList.contains('visible')) { loadTCGraphData(); } }, 2000); -function updateLightState() { -console.log('----> setting bri and power switch <----'); +function updateLightStateAndPWMValues() { +console.log('----> setting bri, power switch, and pwm data <----'); +const promises = []; for (let i = 1; i <= {{LIGHT_COUNT}}; i++) { const lightURL = `http://{{IP_ADDRESS}}/state?light=${i}`; -fetch(lightURL).then(response => response.json()).then(data => { +promises.push(fetch(lightURL).then(response => response.json())); +} +Promise.all(promises) +.then(dataArray => { +for (let i = 1; i <= {{LIGHT_COUNT}}; i++) { +const data = dataArray[i - 1]; const briSlider = document.getElementById(`bri${i - 1}`); const briSliderVal = document.getElementById(`bri${i - 1}_val`); const onLinkOn = document.getElementById(`on${i - 1}_on`); const onLinkOff = document.getElementById(`on${i - 1}_off`); +const pwmElement = document.getElementById(`light${i - 1}_pwm`); +const pwmElementTxt = document.getElementById(`light${i - 1}_pwm_txt`); briSlider.value = data.bri; briSliderVal.innerHTML = (Math.round((data.bri * 100.0 / 255.0) * 100) / 100).toFixed(2); if (data.on == true) { @@ -290,30 +298,18 @@ onLinkOff.classList.remove('pure-button-primary'); onLinkOn.classList.remove('pure-button-primary'); onLinkOff.classList.add('pure-button-primary'); } -}).catch(error => console.error(error)); -} -} -setInterval(updateLightState, 10000); -updateLightState(); -function updatePWMValues() { -console.log('----> setting pwm data <----'); -for (let i = 0; i < {{LIGHT_COUNT}}; i++) { -const lightID = i + 1; -const pwmElement = document.getElementById(`light${i}_pwm`); -const pwmElementTxt = document.getElementById(`light${i}_pwm_txt`); if (pwmElement) { -const url = `http://{{IP_ADDRESS}}/state?light=${lightID}`; -fetch(url).then(response => response.json()).then(data => { const pwmValue = ((Math.round((data.curpwm - ((data.curpwm >= {{PWM_MIN}}) ? {{PWM_MIN}} : 0)) / {{PWM_MAX}} * 10000) / 100).toFixed(2)); pwmElement.innerText = pwmValue.toString(); pwmElement.value = pwmValue; pwmElementTxt.innerText = pwmValue.toString(); -}).catch(error => console.error(error)); } } +}) +.catch(error => console.error(error)); } -updatePWMValues(); -setInterval(updatePWMValues, 5000); +updateLightStateAndPWMValues(); +setInterval(updateLightStateAndPWMValues, 5000); var links = document.querySelectorAll('[id^="on"][id$="_off"]'); links.forEach(function(link) { link.addEventListener('click', function(event) { diff --git a/firmware/data/index_template_bottom.html b/firmware/data/index_template_bottom.html index f401ad3..98b621e 100644 --- a/firmware/data/index_template_bottom.html +++ b/firmware/data/index_template_bottom.html @@ -18,7 +18,6 @@ -
save diff --git a/firmware/html/bottom.js b/firmware/html/bottom.js index 776c4c8..1b69507 100644 --- a/firmware/html/bottom.js +++ b/firmware/html/bottom.js @@ -317,50 +317,49 @@ setInterval(function() { } }, 2000); -function updateLightState() { - console.log('----> setting bri and power switch <----'); +function updateLightStateAndPWMValues() { + console.log('----> setting bri, power switch, and pwm data <----'); + const promises = []; + for (let i = 1; i <= {{LIGHT_COUNT}}; i++) { const lightURL = `http://{{IP_ADDRESS}}/state?light=${i}`; - fetch(lightURL).then(response => response.json()).then(data => { - const briSlider = document.getElementById(`bri${i - 1}`); - const briSliderVal = document.getElementById(`bri${i - 1}_val`); - const onLinkOn = document.getElementById(`on${i - 1}_on`); - const onLinkOff = document.getElementById(`on${i - 1}_off`); - briSlider.value = data.bri; - briSliderVal.innerHTML = (Math.round((data.bri * 100.0 / 255.0) * 100) / 100).toFixed(2); - if (data.on == true) { - onLinkOn.classList.add('pure-button-primary'); - onLinkOff.classList.remove('pure-button-primary'); - } else { - onLinkOn.classList.remove('pure-button-primary'); - onLinkOff.classList.add('pure-button-primary'); - } - }).catch(error => console.error(error)); + promises.push(fetch(lightURL).then(response => response.json())); } -} -setInterval(updateLightState, 10000); -updateLightState(); -function updatePWMValues() { - console.log('----> setting pwm data <----'); - for (let i = 0; i < {{LIGHT_COUNT}}; i++) { - const lightID = i + 1; - const pwmElement = document.getElementById(`light${i}_pwm`); - const pwmElementTxt = document.getElementById(`light${i}_pwm_txt`); - if (pwmElement) { - const url = `http://{{IP_ADDRESS}}/state?light=${lightID}`; - fetch(url).then(response => response.json()).then(data => { - const pwmValue = ((Math.round((data.curpwm - ((data.curpwm >= {{PWM_MIN}}) ? {{PWM_MIN}} : 0)) / {{PWM_MAX}} * 10000) / 100).toFixed(2)); - //console.log('curpwm[' + i + '] = ' + data.curpwm + ' = ' + pwmValue); - pwmElement.innerText = pwmValue.toString(); - pwmElement.value = pwmValue; - pwmElementTxt.innerText = pwmValue.toString(); - }).catch(error => console.error(error)); - } - } + Promise.all(promises) + .then(dataArray => { + for (let i = 1; i <= {{LIGHT_COUNT}}; i++) { + const data = dataArray[i - 1]; + const briSlider = document.getElementById(`bri${i - 1}`); + const briSliderVal = document.getElementById(`bri${i - 1}_val`); + const onLinkOn = document.getElementById(`on${i - 1}_on`); + const onLinkOff = document.getElementById(`on${i - 1}_off`); + const pwmElement = document.getElementById(`light${i - 1}_pwm`); + const pwmElementTxt = document.getElementById(`light${i - 1}_pwm_txt`); + + briSlider.value = data.bri; + briSliderVal.innerHTML = (Math.round((data.bri * 100.0 / 255.0) * 100) / 100).toFixed(2); + if (data.on == true) { + onLinkOn.classList.add('pure-button-primary'); + onLinkOff.classList.remove('pure-button-primary'); + } else { + onLinkOn.classList.remove('pure-button-primary'); + onLinkOff.classList.add('pure-button-primary'); + } + + if (pwmElement) { + const pwmValue = ((Math.round((data.curpwm - ((data.curpwm >= {{PWM_MIN}}) ? {{PWM_MIN}} : 0)) / {{PWM_MAX}} * 10000) / 100).toFixed(2)); + pwmElement.innerText = pwmValue.toString(); + pwmElement.value = pwmValue; + pwmElementTxt.innerText = pwmValue.toString(); + } + } + }) + .catch(error => console.error(error)); } -updatePWMValues(); -setInterval(updatePWMValues, 5000); + +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"]'); diff --git a/firmware/html/index_template_bottom.html b/firmware/html/index_template_bottom.html index 37d78fd..ba771d0 100644 --- a/firmware/html/index_template_bottom.html +++ b/firmware/html/index_template_bottom.html @@ -19,7 +19,6 @@ -
save