Fixed pwm value output - as % now.

This commit is contained in:
Kai Lauterbach 2023-04-28 19:49:52 +02:00
parent 26d43a6070
commit e3454e7e10

View file

@ -594,9 +594,9 @@ void init_webserver()
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 += "<label for=\"light" + (String)light_num + "_pwm\">PWM-Wert</label>";
http_content += "<input type=\"range\" min=\"0\" max=\"383\" value=\"0\" id=\"light" + (String)light_num + "_pwm\" disabled>";
http_content += "&nbsp;<span id=\"light" + (String)light_num + "_pwm_txt\"></span>";
http_content += "<br><label for=\"light" + (String)light_num + "_pwm\">PWM-Wert</label>";
http_content += "<input type=\"range\" min=\"0\" max=\"100\" value=\"0\" id=\"light" + (String)light_num + "_pwm\" disabled>";
http_content += "&nbsp;<span id=\"light" + (String)light_num + "_pwm_txt\"></span>%";
http_content += "<script>";
http_content += "var slider" + (String)light_num + " = document.getElementById(\"bri" + (String)light_num + "\");";
http_content += "var output" + (String)light_num + " = document.getElementById(\"bri" + (String)light_num + "\_val\");";
@ -875,8 +875,8 @@ void init_webserver()
"fetch(url)"
".then(response => response.json())"
".then(data => {"
"const pwmValue = data.curpwm - 640;"
//"console.log('curpwm[' + i + '] = ' + data.curpwm);"
"const pwmValue = ((Math.round((data.curpwm - ((data.curpwm >= 640.0) ? 640.0 : 0)) / 383.0 * 100.0) * 100.0) / 100.0).toFixed(2);" // pwm as % 640 to 1023
"console.log('curpwm[' + i + '] = ' + data.curpwm + ' = ' + pwmValue);"
"pwmElement.innerText = pwmValue.toString();"
"pwmElement.value = pwmValue;"
"pwmElementTxt.innerText = pwmValue.toString();"