Fixed pwm start in case that the timing control mechanism is activated in a part of the data blocks. Updated tc link buttons to prevent reload of the web interface.
This commit is contained in:
parent
c176603240
commit
75e5541e5e
2 changed files with 83 additions and 15 deletions
|
@ -9,8 +9,11 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
//********* Config block *********//
|
//********* Config block *********//
|
||||||
|
// blue, warmwhite, purple, white&red&green
|
||||||
|
// blau, schwarz, rot, weiß
|
||||||
// ch1, ch2, ch3, ch4
|
// ch1, ch2, ch3, ch4
|
||||||
uint8_t pins[LIGHTS_COUNT] = { 14, 12, 15, 13 };
|
// D1, D2, D7, D5
|
||||||
|
uint8_t pins[LIGHTS_COUNT] = { 5, 4, 13, 14 };
|
||||||
|
|
||||||
IPAddress strip_ip(192, 168, 0, 26); // choose an unique IP Adress
|
IPAddress strip_ip(192, 168, 0, 26); // choose an unique IP Adress
|
||||||
IPAddress gateway_ip(192, 168, 0, 1); // Router IP
|
IPAddress gateway_ip(192, 168, 0, 1); // Router IP
|
||||||
|
@ -660,15 +663,13 @@ void init_webserver()
|
||||||
http_content += "<h4>Light " + (String)(light_num + 1) + "</h4>";
|
http_content += "<h4>Light " + (String)(light_num + 1) + "</h4>";
|
||||||
http_content += "<div class=\"pure-control-group\">";
|
http_content += "<div class=\"pure-control-group\">";
|
||||||
http_content += "<label for=\"power\"><strong>Power</strong></label>";
|
http_content += "<label for=\"power\"><strong>Power</strong></label>";
|
||||||
http_content += "<a id=\"on" + (String)light_num + "_on\" class=\"pure-button";
|
http_content += "<a id=\"on" + (String)light_num + "_on\" class=\"pure-button\" href=\"#\">ON</a>";
|
||||||
http_content += "\" href=\"/?on" + (String)light_num + "=true\">ON</a>";
|
http_content += "<a id=\"on" + (String)light_num + "_off\" class=\"pure-button\" href=\"#\">OFF</a>";
|
||||||
http_content += "<a id=\"on" + (String)light_num + "_off\" class=\"pure-button";
|
|
||||||
http_content += "\" href=\"/?on" + (String)light_num + "=false\">OFF</a>";
|
|
||||||
http_content += "</div>";
|
http_content += "</div>";
|
||||||
|
|
||||||
// slider for brightness
|
// slider for brightness
|
||||||
http_content += "<div class=\"pure-control-group\">";
|
http_content += "<div class=\"pure-control-group\">";
|
||||||
http_content += "<label for=\"bri\"" + (String)light_num + ">Bri</label>";
|
http_content += "<label for=\"bri" + (String)light_num + "\">Bri</label>";
|
||||||
http_content += "<input id=\"bri" + (String)light_num + "\" onchange=\"sendSliderValue(" + (String)(light_num+1) + ")\" name=\"bri" + (String)light_num + "\" type=\"range\" min=\"0\" max=\"255\" value=\"" + (String)bri[light_num] + "\">";
|
http_content += "<input id=\"bri" + (String)light_num + "\" onchange=\"sendSliderValue(" + (String)(light_num+1) + ")\" name=\"bri" + (String)light_num + "\" type=\"range\" min=\"0\" max=\"255\" value=\"" + (String)bri[light_num] + "\">";
|
||||||
http_content += " <span id=\"bri" + (String)light_num + "_val\" name=\"bri" + (String)light_num + "\">" + (String)(int)(bri[light_num] * 100.0 / 255.0) + "</span>%";
|
http_content += " <span id=\"bri" + (String)light_num + "_val\" name=\"bri" + (String)light_num + "\">" + (String)(int)(bri[light_num] * 100.0 / 255.0) + "</span>%";
|
||||||
http_content += "<br><label for=\"light" + (String)light_num + "_pwm\">PWM-Wert</label>";
|
http_content += "<br><label for=\"light" + (String)light_num + "_pwm\">PWM-Wert</label>";
|
||||||
|
@ -686,6 +687,73 @@ void init_webserver()
|
||||||
http_content += "</div>";
|
http_content += "</div>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
http_content += "<script>"
|
||||||
|
// 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 = this.id.replace('on', '').replace('_off', '');"
|
||||||
|
// Erstelle eine neue Anfrage an die entsprechende URL
|
||||||
|
"var xhr = new XMLHttpRequest();"
|
||||||
|
"xhr.open('GET', 'http://192.168.0.26/?on' + id + '=false', true);"
|
||||||
|
// Sende die Anfrage im Hintergrund
|
||||||
|
"xhr.send();"
|
||||||
|
"updateLightState();"
|
||||||
|
"});"
|
||||||
|
"});"
|
||||||
|
// 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 = this.id.replace('on', '').replace('_on', '');"
|
||||||
|
// Erstelle eine neue Anfrage an die entsprechende URL
|
||||||
|
"var xhr = new XMLHttpRequest();"
|
||||||
|
"xhr.open('GET', 'http://192.168.0.26/?on' + id + '=true', true);"
|
||||||
|
// Sende die Anfrage im Hintergrund
|
||||||
|
"xhr.send();"
|
||||||
|
"updateLightState();"
|
||||||
|
"});"
|
||||||
|
"});"
|
||||||
|
|
||||||
|
// Suche nach allen tc Links auf der Seite mit IDs tc_on
|
||||||
|
"var links = document.querySelectorAll('[id^=\"tc_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();"
|
||||||
|
// Erstelle eine neue Anfrage an die entsprechende URL
|
||||||
|
"var xhr = new XMLHttpRequest();"
|
||||||
|
"xhr.open('GET', 'http://192.168.0.26/?tc=true', true);"
|
||||||
|
// Sende die Anfrage im Hintergrund
|
||||||
|
"xhr.send();"
|
||||||
|
"updateLightState();"
|
||||||
|
"});"
|
||||||
|
"});"
|
||||||
|
// Suche nach allen tc Links auf der Seite mit IDs tc_off
|
||||||
|
"var links = document.querySelectorAll('[id^=\"tc_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();"
|
||||||
|
// Erstelle eine neue Anfrage an die entsprechende URL
|
||||||
|
"var xhr = new XMLHttpRequest();"
|
||||||
|
"xhr.open('GET', 'http://192.168.0.26/?tc=false', true);"
|
||||||
|
// Sende die Anfrage im Hintergrund
|
||||||
|
"xhr.send();"
|
||||||
|
"updateLightState();"
|
||||||
|
"});"
|
||||||
|
"});"
|
||||||
|
"</script>";
|
||||||
|
|
||||||
// startup state and scene for all of the lights
|
// startup state and scene for all of the lights
|
||||||
http_content += "</td><td>";
|
http_content += "</td><td>";
|
||||||
|
@ -729,12 +797,12 @@ void init_webserver()
|
||||||
http_content += "<div class=\"pure-control-group\">";
|
http_content += "<div class=\"pure-control-group\">";
|
||||||
http_content += "<label for=\"tc\"><strong>Timing control</strong></label>";
|
http_content += "<label for=\"tc\"><strong>Timing control</strong></label>";
|
||||||
int tc_val = EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS);
|
int tc_val = EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS);
|
||||||
http_content += "<a class=\"pure-button";
|
http_content += "<a id=\"tc_on\" class=\"pure-button";
|
||||||
if (tc_val == TIMING_CONTROL_ENABLED) http_content += " pure-button-primary";
|
if (tc_val == TIMING_CONTROL_ENABLED) http_content += " pure-button-primary";
|
||||||
http_content += "\" href=\"/?tc=true\">ON</a>";
|
http_content += "\" href=\"#\">ON</a>";
|
||||||
http_content += "<a class=\"pure-button";
|
http_content += "<a id=\"tc_off\" class=\"pure-button";
|
||||||
if (tc_val == TIMING_CONTROL_DISABLED) http_content += " pure-button-primary";
|
if (tc_val == TIMING_CONTROL_DISABLED) http_content += " pure-button-primary";
|
||||||
http_content += "\" href=\"/?tc=false\">OFF</a>";
|
http_content += "\" href=\"#\">OFF</a>";
|
||||||
http_content += "</div>";
|
http_content += "</div>";
|
||||||
http_content += "<br>";
|
http_content += "<br>";
|
||||||
|
|
||||||
|
@ -966,7 +1034,7 @@ void init_webserver()
|
||||||
"fetch(url)"
|
"fetch(url)"
|
||||||
".then(response => response.json())"
|
".then(response => response.json())"
|
||||||
".then(data => {"
|
".then(data => {"
|
||||||
"const pwmValue = ((Math.round((data.curpwm - ((data.curpwm >= " + (String)PWM_MIN+ ") ? " + (String)PWM_MIN + " : 0)) / " + (String)PWM_MAX + " * 100.0) * 100.0) / 100.0).toFixed(2);" // pwm as % PWM_MIN to PWM_MAX
|
"const pwmValue = ((Math.round((data.curpwm - ((data.curpwm >= " + (String)PWM_MIN+ ") ? " + (String)PWM_MIN + " : 0)) / " + (String)PWM_MAX + " * 10000) / 100).toFixed(2));"// pwm as % PWM_MIN to PWM_MAX
|
||||||
"console.log('curpwm[' + i + '] = ' + data.curpwm + ' = ' + pwmValue);"
|
"console.log('curpwm[' + i + '] = ' + data.curpwm + ' = ' + pwmValue);"
|
||||||
"pwmElement.innerText = pwmValue.toString();"
|
"pwmElement.innerText = pwmValue.toString();"
|
||||||
"pwmElement.value = pwmValue;"
|
"pwmElement.value = pwmValue;"
|
||||||
|
|
|
@ -214,19 +214,19 @@ void tc_update_main()
|
||||||
bri[3] = tc_data[target_data_block].ch4;
|
bri[3] = tc_data[target_data_block].ch4;
|
||||||
if (tc_data[target_data_block-1].ch1 != current_bri[0])
|
if (tc_data[target_data_block-1].ch1 != current_bri[0])
|
||||||
{
|
{
|
||||||
current_bri[0] = tc_data[target_data_block-1].ch1;
|
current_bri[0] = tc_data[target_data_block-1].ch1 + ((tc_data[target_data_block].ch1 == 0) ? 1 : -1);
|
||||||
}
|
}
|
||||||
if (tc_data[target_data_block-1].ch2 != current_bri[1])
|
if (tc_data[target_data_block-1].ch2 != current_bri[1])
|
||||||
{
|
{
|
||||||
current_bri[1] = tc_data[target_data_block-1].ch2;
|
current_bri[1] = tc_data[target_data_block-1].ch2 + ((tc_data[target_data_block].ch2 == 0) ? 1 : -1);
|
||||||
}
|
}
|
||||||
if (tc_data[target_data_block-1].ch3 != current_bri[2])
|
if (tc_data[target_data_block-1].ch3 != current_bri[2])
|
||||||
{
|
{
|
||||||
current_bri[2] = tc_data[target_data_block-1].ch3;
|
current_bri[2] = tc_data[target_data_block-1].ch3 + ((tc_data[target_data_block].ch3 == 0) ? 1 : -1);
|
||||||
}
|
}
|
||||||
if (tc_data[target_data_block-1].ch4 != current_bri[3])
|
if (tc_data[target_data_block-1].ch4 != current_bri[3])
|
||||||
{
|
{
|
||||||
current_bri[3] = tc_data[target_data_block-1].ch4;
|
current_bri[3] = tc_data[target_data_block-1].ch4 + ((tc_data[target_data_block].ch4 == 0) ? 1 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < LIGHTS_COUNT; i++)
|
for (uint8_t i = 0; i < LIGHTS_COUNT; i++)
|
||||||
|
|
Loading…
Reference in a new issue