Compare commits

...

2 commits

2 changed files with 92 additions and 19 deletions

View file

@ -9,8 +9,11 @@
#include "config.h"
//********* Config block *********//
// blue, warmwhite, purple, white&red&green
// blau, schwarz, rot, weiß
// 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 gateway_ip(192, 168, 0, 1); // Router IP
@ -38,8 +41,8 @@ IPAddress dns(192, 168, 0, 1);
// 10 bit PWM
#define PWM_OFF 0 // 0V
#define PWM_MIN 0 // 0V - minimum light amount (~1%)
#define PWM_MAX 1023 // 24V - maximum light amount (100%)
#define BRI_TO_PWM_FACTOR 4.012 // 24V-15V = 24V range
#define PWM_MAX 255 // 24V - maximum light amount (100%)
#define BRI_TO_PWM_FACTOR 1.0 // 24V-0V = 24V range
//********************************//
@ -570,6 +573,11 @@ void init_webserver()
}
EEPROM.commit();
if (tc_enabled == TIMING_CONTROL_DISABLED)
{
process_lightdata(light, default_transitiontime);
}
} else {
// light is off
if (tc_enabled == TIMING_CONTROL_DISABLED)
@ -655,15 +663,13 @@ void init_webserver()
http_content += "<h4>Light " + (String)(light_num + 1) + "</h4>";
http_content += "<div class=\"pure-control-group\">";
http_content += "<label for=\"power\"><strong>Power</strong></label>";
http_content += "<a id=\"on" + (String)light_num + "_on\" class=\"pure-button";
http_content += "\" href=\"/?on" + (String)light_num + "=true\">ON</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 += "<a id=\"on" + (String)light_num + "_on\" class=\"pure-button\" href=\"#\">ON</a>";
http_content += "<a id=\"on" + (String)light_num + "_off\" class=\"pure-button\" href=\"#\">OFF</a>";
http_content += "</div>";
// slider for brightness
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 += "&nbsp;<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>";
@ -681,6 +687,73 @@ void init_webserver()
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
http_content += "</td><td>";
@ -724,12 +797,12 @@ void init_webserver()
http_content += "<div class=\"pure-control-group\">";
http_content += "<label for=\"tc\"><strong>Timing control</strong></label>";
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";
http_content += "\" href=\"/?tc=true\">ON</a>";
http_content += "<a class=\"pure-button";
http_content += "\" href=\"#\">ON</a>";
http_content += "<a id=\"tc_off\" class=\"pure-button";
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 += "<br>";
@ -961,7 +1034,7 @@ void init_webserver()
"fetch(url)"
".then(response => response.json())"
".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);"
"pwmElement.innerText = pwmValue.toString();"
"pwmElement.value = pwmValue;"

View file

@ -214,19 +214,19 @@ void tc_update_main()
bri[3] = tc_data[target_data_block].ch4;
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])
{
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])
{
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])
{
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++)