2021-09-23 21:44:24 +02:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=500" >
2021-12-08 14:38:21 +01:00
< meta content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name = "viewport" / >
2021-09-23 21:44:24 +02:00
< title > LED Settings< / title >
< script >
2021-10-03 12:23:24 +02:00
var d=document,laprev=55,maxB=1,maxM=4000,maxPB=4096,maxL=1333,maxLbquot=0; //maximum bytes for LED allocation: 4kB for 8266, 32kB for 32
2022-01-13 16:06:01 +01:00
var customStarts=false,startsDirty=[],maxCOOverrides=5;
2021-12-08 22:05:51 +01:00
function H(){window.open("https://kno.wled.ge/features/settings/#led-settings");}
function B(){window.open("/settings","_self");}
2021-09-23 21:44:24 +02:00
function gId(n){return d.getElementById(n);}
2021-12-08 22:05:51 +01:00
function off(n){d.getElementsByName(n)[0].value = -1;}
2021-09-23 21:44:24 +02:00
var timeout;
function showToast(text, error = false)
{
var x = gId("toast");
x.innerHTML = text;
x.className = error ? "error":"show";
clearTimeout(timeout);
x.style.animation = 'none';
timeout = setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2900);
}
2021-10-03 12:23:24 +02:00
function bLimits(b,p,m,l) {
maxB = b; maxM = m; maxPB = p; maxL = l;
2021-09-23 21:44:24 +02:00
}
function pinsOK() {
var LCs = d.getElementsByTagName("input");
for (i=0; i< LCs.length ; i + + ) {
var nm = LCs[i].name.substring(0,2);
// ignore IP address
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
var n = LCs[i].name.substring(2);
var t = parseInt(d.getElementsByName("LT"+n)[0].value, 10); // LED type SELECT
2021-10-06 14:30:41 +02:00
if (t>=80) continue;
2021-09-23 21:44:24 +02:00
}
//check for pin conflicts
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR")
if (LCs[i].value!="" & & LCs[i].value!="-1") {
if (d.um_p & & d.um_p.some((e)=>e==parseInt(LCs[i].value,10))) {alert(`Sorry, pins ${JSON.stringify(d.um_p)} can't be used.`);LCs[i].value="";LCs[i].focus();return false;}
else if (LCs[i].value > 5 & & LCs[i].value < 12 ) { alert ( " Sorry , pins 6-11 can not be used . " ) ; LCs [ i ] . value = "" ; LCs [ i ] . focus ( ) ; return false ; }
else if (!(nm == "IR" || nm=="BT") & & LCs[i].value > 33) {alert("Sorry, pins >33 are input only.");LCs[i].value="";LCs[i].focus();return false;}
for (j=i+1; j< LCs.length ; j + + )
{
var n2 = LCs[j].name.substring(0,2);
if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4" || n2=="RL" || n2=="BT" || n2=="IR") {
if (n2.substring(0,1)==="L") {
var m = LCs[j].name.substring(2);
var t2 = parseInt(d.getElementsByName("LT"+m)[0].value, 10);
2021-11-09 17:49:05 +01:00
if (t2>=80) continue;
2021-09-23 21:44:24 +02:00
}
if (LCs[j].value!="" & & LCs[i].value==LCs[j].value) {alert(`Pin conflict between ${LCs[i].name}/${LCs[j].name}!`);LCs[j].value="";LCs[j].focus();return false;}
}
}
}
}
return true;
}
function trySubmit(e) {
d.Sf.data.value = '';
e.preventDefault();
if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server
if (bquot > 100) {var msg = "Too many LEDs for me to handle!"; if (maxM < 10000 ) msg + = " \ n \ rConsider using an ESP32 . " ; alert ( msg ) ; }
if (d.Sf.checkValidity()) d.Sf.submit(); //https://stackoverflow.com/q/37323914
}
function enABL()
{
var en = gId('able').checked;
d.Sf.LA.value = (en) ? laprev:0;
gId('abl').style.display = (en) ? 'inline':'none';
gId('psu2').style.display = (en) ? 'inline':'none';
if (d.Sf.LA.value > 0) setABL();
}
function enLA()
{
var val = d.Sf.LAsel.value;
d.Sf.LA.value = val;
gId('LAdis').style.display = (val == 50) ? 'inline':'none';
UI();
}
function setABL()
{
gId('able').checked = true;
d.Sf.LAsel.value = 50;
switch (parseInt(d.Sf.LA.value)) {
case 0: gId('able').checked = false; enABL(); break;
case 30: d.Sf.LAsel.value = 30; break;
case 35: d.Sf.LAsel.value = 35; break;
case 55: d.Sf.LAsel.value = 55; break;
case 255: d.Sf.LAsel.value = 255; break;
default: gId('LAdis').style.display = 'inline';
}
gId('m1').innerHTML = maxM;
d.getElementsByName("Sf")[0].addEventListener("submit", trySubmit);
UI();
}
//returns mem usage
2022-03-16 01:45:07 +01:00
function getMem(t, n) {
let len = parseInt(d.getElementsByName("LC"+n)[0].value);
len += parseInt(d.getElementsByName("SL"+n)[0].value); // skipped LEDs are allocated too
2021-10-06 14:30:41 +02:00
if (t < 32 ) {
2022-03-16 01:45:07 +01:00
if (maxM < 10000 & & d . getElementsByName ( " L0 " + n ) [ 0 ] . value = = 3 ) { / / 8266 DMA uses 5x the mem
2021-09-23 21:44:24 +02:00
if (t > 29) return len*20; //RGBW
return len*15;
} else if (maxM >= 10000) //ESP32 RMT uses double buffer?
{
if (t > 29) return len*8; //RGBW
return len*6;
}
if (t > 29) return len*4; //RGBW
return len*3;
}
if (t > 31 & & t < 48 ) return 5 ;
if (t == 44 || t == 45) return len*4; //RGBW
return len*3;
}
function UI(change=false)
{
var isRGBW = false, memu = 0;
gId('ampwarning').style.display = (d.Sf.MA.value > 7200) ? 'inline':'none';
if (d.Sf.LA.value == 255) laprev = 12;
else if (d.Sf.LA.value > 0) laprev = d.Sf.LA.value;
// enable/disable LED fields
var s = d.getElementsByTagName("select");
for (i=0; i< s.length ; i + + ) {
// is the field a LED type?
if (s[i].name.substring(0,2)=="LT") {
var n = s[i].name.substring(2);
var t = parseInt(s[i].value,10);
2022-06-20 22:17:01 +02:00
gId("p0d"+n).innerHTML = (t>=80 & & t< 96 ) ? " IP address: " : ( t > 49) ? "Data GPIO:" : (t > 41) ? "GPIOs:" : "GPIO:";
2021-10-06 14:30:41 +02:00
gId("p1d"+n).innerHTML = (t> 49 & & t< 64 ) ? " Clk GPIO: " : " " ;
2021-09-23 21:44:24 +02:00
var LK = d.getElementsByName("L1"+n)[0]; // clock pin
2022-03-16 01:45:07 +01:00
memu += getMem(t, n); // calc memory
2021-09-23 21:44:24 +02:00
// enumerate pins
for (p=1; p< 5 ; p + + ) {
var LK = d.getElementsByName("L"+p+n)[0]; // secondary pins
if (!LK) continue;
2021-10-06 14:30:41 +02:00
if (((t>=80 & & t< 96 ) & & p < 4 ) | | ( t > 49 & & p==1) || (t>41 & & t < 50 & & ( p + 40 < t ) ) ) / / TYPE_xxxx values from const . h
2021-09-23 21:44:24 +02:00
{
// display pin field
LK.style.display = "inline";
LK.required = true;
} else {
// hide pin field
LK.style.display = "none";
LK.required = false;
LK.value="";
}
}
if (change) {
2021-10-07 22:57:07 +02:00
gId("rf"+n).checked = (gId("rf"+n).checked || t == 31); // LEDs require data in off state
2021-09-23 21:44:24 +02:00
if (t > 31 & & t < 48 ) d . getElementsByName ( " LC " + n ) [ 0 ] . value = 1; / / for sanity change analog count just to 1 LED
}
2021-10-07 22:57:07 +02:00
gId("rf"+n).onclick = (t == 31) ? (function(){return false}) : (function(){}); // prevent change for TM1814
2021-09-23 21:44:24 +02:00
isRGBW |= (t == 30 || t == 31 || (t > 40 & & t < 46 & & t ! = 43 ) ) ; / / RGBW checkbox , TYPE_xxxx values from const . h
2022-06-20 22:17:01 +02:00
gId("co"+n).style.display = ((t >= 80 & & t < 96 ) | | ( t > = 40 & & t < 48 ) ) ? " none " : " inline " ; / / hide color order for PWM
2022-04-30 12:45:38 +02:00
gId("dig"+n+"w").style.display = (t == 30 || t == 31) ? "inline":"none"; // show swap channels dropdown
if (!(t == 30 || t == 31)) d.getElementsByName("WO"+n)[0].value = 0; // reset swapping
2022-06-20 22:17:01 +02:00
gId("dig"+n+"c").style.display = (t >= 40 & & t < 48 ) ? " none " : " inline " ; / / hide count for analog
gId("dig"+n+"r").style.display = (t >= 80 & & t < 96 ) ? " none " : " inline " ; / / hide reversed for virtual
gId("dig"+n+"s").style.display = ((t >= 80 & & t < 96 ) | | ( t > = 40 & & t < 48 ) ) ? " none " : " inline " ; / / hide skip 1st for virtual & analog
gId("dig"+n+"f").style.display = ((t >= 16 & & t < 32 ) | | ( t > = 50 & & t < 64 ) ) ? " inline " : " none " ; / / hide refresh
gId("dig"+n+"a").style.display = (isRGBW & & t != 40) ? "inline":"none"; // auto calculate white
gId("rev"+n).innerHTML = (t >= 40 & & t < 48 ) ? " Inverted output " : " Reversed ( rotated 180 ° ) " ; / / change reverse text for analog
gId("psd"+n).innerHTML = (t >= 40 & & t < 48 ) ? " Index: " : " Start: " ; / / change analog start description
2021-09-23 21:44:24 +02:00
}
}
// display white channel calculation method
var myC = d.querySelectorAll('.wc'),
l = myC.length;
for (i = 0; i < l ; i + + ) {
myC[i].style.display = (isRGBW) ? 'inline':'none';
}
// check for pin conflicts
var LCs = d.getElementsByTagName("input");
2021-10-03 12:23:24 +02:00
var sLC = 0, sPC = 0, maxLC = 0;
2021-09-23 21:44:24 +02:00
for (i=0; i< LCs.length ; i + + ) {
var nm = LCs[i].name.substring(0,2); // field name
var n = LCs[i].name.substring(2); // bus number
2021-10-03 12:23:24 +02:00
// do we have a led count field
if (nm=="LC") {
2022-02-26 01:37:09 +01:00
var c=parseInt(LCs[i].value,10); //get LED count
2021-10-16 15:13:30 +02:00
if (!customStarts || !startsDirty[n]) gId("ls"+n).value=sLC; //update start value
gId("ls"+n).disabled = !customStarts; //enable/disable field editing
2021-10-03 12:23:24 +02:00
if(c){
2021-10-16 15:13:30 +02:00
var s = parseInt(gId("ls"+n).value); //start value
if (s+c > sLC) sLC = s+c; //update total count
if(c>maxLC)maxLC=c; //max per output
2021-10-03 20:48:08 +02:00
var t = parseInt(d.getElementsByName("LT"+n)[0].value); // LED type SELECT
2021-10-06 14:30:41 +02:00
if (t< 80 ) sPC + = c ; / / virtual out busses do not count towards physical LEDs
2021-10-03 12:23:24 +02:00
} // increase led count
2021-09-23 21:44:24 +02:00
continue;
}
// do we have led pins for digital leds
if (nm=="L0" || nm=="L1") {
var lc=d.getElementsByName("LC"+n)[0];
lc.max=maxPB; // update max led count value
}
2021-10-03 12:23:24 +02:00
// ignore IP address (stored in pins for virtual busses)
2021-09-23 21:44:24 +02:00
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
2021-10-03 20:48:08 +02:00
var t = parseInt(d.getElementsByName("LT"+n)[0].value); // LED type SELECT
2021-10-06 14:30:41 +02:00
if (t>=80) {
2021-09-23 21:44:24 +02:00
LCs[i].max = 255;
LCs[i].min = 0;
2021-10-07 13:47:36 +02:00
LCs[i].style.color="#fff";
2021-09-23 21:44:24 +02:00
continue; // do not check conflicts
} else {
LCs[i].max = 33;
LCs[i].min = -1;
}
}
// check for pin conflicts
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR")
if (LCs[i].value!="" & & LCs[i].value!="-1") {
var p = []; // used pin array
if (d.um_p & & Array.isArray(d.um_p)) for (k=0;k< d.um_p.length ; k + + ) p . push ( d . um_p [ k ] ) ; / / fill with reservations
for (j=0; j< LCs.length ; j + + ) {
if (i==j) continue;
var n2 = LCs[j].name.substring(0,2);
if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4" || n2=="RL" || n2=="BT" || n2=="IR") {
if (n2.substring(0,1)==="L") {
var m = LCs[j].name.substring(2);
var t2 = parseInt(d.getElementsByName("LT"+m)[0].value, 10);
2021-10-06 14:30:41 +02:00
if (t2>=80) continue;
2021-09-23 21:44:24 +02:00
}
if (LCs[j].value!="" & & LCs[j].value!="-1") p.push(parseInt(LCs[j].value,10)); // add current pin
}
}
// now check for conflicts
if (p.some((e)=>e==parseInt(LCs[i].value,10))) LCs[i].style.color="red"; else LCs[i].style.color=parseInt(LCs[i].value,10)>33?"orange":"#fff";
}
}
// update total led count
2021-10-03 12:23:24 +02:00
gId("lc").textContent = sLC;
gId("pc").textContent = (sLC == sPC) ? "":"(" + sPC + " physical)";
2021-09-23 21:44:24 +02:00
// memory usage and warnings
gId('m0').innerHTML = memu;
bquot = memu / maxM * 100;
2021-12-08 10:00:31 +01:00
gId('dbar').style.background = `linear-gradient(90deg, ${bquot > 60 ? (bquot > 90 ? "red":"orange"):"#ccc"} 0 ${bquot}%, #444 ${bquot}% 100%)`;
2021-10-16 15:13:30 +02:00
gId('ledwarning').style.display = (maxLC > Math.min(maxPB,800) || bquot > 80) ? 'inline':'none';
gId('ledwarning').style.color = (maxLC > Math.max(maxPB,800) || bquot > 100) ? 'red':'orange';
2021-10-03 12:23:24 +02:00
gId('wreason').innerHTML = (bquot > 80) ? "80% of max. LED memory" +(bquot>100 ? ` (< b > ERROR: Using over ${maxM}B!< / b > )` : "") : "800 LEDs per output";
2021-09-23 21:44:24 +02:00
// calculate power
2021-10-03 12:23:24 +02:00
var val = Math.ceil((100 + sPC * laprev)/500)/2;
2021-09-23 21:44:24 +02:00
val = (val > 5) ? Math.ceil(val) : val;
var s = "";
var is12V = (d.Sf.LAsel.value == 30);
var isWS2815 = (d.Sf.LAsel.value == 255);
if (val < 1.02 & & ! is12V & & ! isWS2815 )
{
s = "ESP 5V pin with 1A USB supply";
} else
{
s += is12V ? "12V ": isWS2815 ? "WS2815 12V " : "5V ";
s += val;
s += "A supply connected to LEDs";
}
2021-10-03 12:23:24 +02:00
var val2 = Math.ceil((100 + sPC * laprev)/1500)/2;
2021-09-23 21:44:24 +02:00
val2 = (val2 > 5) ? Math.ceil(val2) : val2;
var s2 = "(for most effects, ~";
s2 += val2;
s2 += "A is enough)< br > ";
gId('psu').innerHTML = s;
gId('psu2').innerHTML = isWS2815 ? "" : s2;
gId("json").style.display = d.Sf.IT.value==8 ? "" : "none";
}
function lastEnd(i) {
if (i< 1 ) return 0 ;
v = parseInt(d.getElementsByName("LS"+(i-1))[0].value) + parseInt(d.getElementsByName("LC"+(i-1))[0].value);
var t = parseInt(d.getElementsByName("LT"+(i-1))[0].value);
if (t > 31 & & t < 48 ) v = 1; / / PWM busses
if (isNaN(v)) return 0;
return v;
}
2021-10-06 14:30:41 +02:00
function addLEDs(n,init=true)
2021-09-23 21:44:24 +02:00
{
var o = d.getElementsByClassName("iST");
var i = o.length;
if ((n==1 & & i>=maxB) || (n==-1 & & i==0)) return;
var f = gId("mLC");
if (n==1) {
// npm run build has trouble minimizing spaces inside string
var cn = `< div class = "iST" >
< hr style = "width:260px" >
${i+1}:
< select name = "LT${i}" onchange = "UI(true)" >
< option value = "22" selected > WS281x< / option >
< option value = "30" > SK6812 RGBW< / option >
< option value = "31" > TM1814< / option >
< option value = "24" > 400kHz< / option >
< option value = "50" > WS2801< / option >
< option value = "51" > APA102< / option >
< option value = "52" > LPD8806< / option >
< option value = "53" > P9813< / option >
2022-06-20 22:17:01 +02:00
< option value = "40" > On/Off< / option >
2021-09-23 21:44:24 +02:00
< option value = "41" > PWM White< / option >
2021-11-28 01:21:17 +01:00
< option value = "42" > PWM CCT< / option >
2021-09-23 21:44:24 +02:00
< option value = "43" > PWM RGB< / option >
< option value = "44" > PWM RGBW< / option >
2021-11-28 01:21:17 +01:00
< option value = "45" > PWM RGB+CCT< / option >
<!-- option value="46">PWM RGB+DCCT</option -->
2021-10-06 14:30:41 +02:00
< option value = "80" > DDP RGB (network)< / option >
<!-- option value="81">E1.31 RGB (network)</option -->
<!-- option value="82">ArtNet RGB (network)</option -->
2021-12-08 22:05:51 +01:00
< / select > < br >
2021-09-23 21:44:24 +02:00
< div id = "co${i}" style = "display:inline" > Color Order:
< select name = "CO${i}" >
< option value = "0" > GRB< / option >
< option value = "1" > RGB< / option >
< option value = "2" > BRG< / option >
< option value = "3" > RBG< / option >
< option value = "4" > BGR< / option >
< option value = "5" > GBR< / option >
2022-04-30 12:45:38 +02:00
< / select > < / div >
< div id = "dig${i}w" style = "display:none" > Swap: < select name = "WO${i}" > < option value = "0" > None< / option > < option value = "1" > W & B< / option > < option value = "2" > W & G< / option > < option value = "3" > W & R< / option > < / select > < / div >
< div >
2021-10-03 22:01:50 +02:00
< span id = "psd${i}" > Start:< / span > < input type = "number" name = "LS${i}" id = "ls${i}" class = "l starts" min = "0" max = "8191" value = "${lastEnd(i)}" oninput = "startsDirty[${i}]=true;UI();" required / >
2022-04-30 12:45:38 +02:00
< div id = "dig${i}c" style = "display:inline" > Length: < input type = "number" name = "LC${i}" class = "l" min = "1" max = "${maxPB}" value = "1" required oninput = "UI()" / > < / div > < br >
< / div >
2021-10-11 17:55:26 +02:00
< span id = "p0d${i}" > GPIO:< / span > < input type = "number" name = "L0${i}" min = "0" max = "33" required class = "s" onchange = "UI()" / >
< span id = "p1d${i}" > < / span > < input type = "number" name = "L1${i}" min = "0" max = "33" class = "s" onchange = "UI()" / >
< span id = "p2d${i}" > < / span > < input type = "number" name = "L2${i}" min = "0" max = "33" class = "s" onchange = "UI()" / >
< span id = "p3d${i}" > < / span > < input type = "number" name = "L3${i}" min = "0" max = "33" class = "s" onchange = "UI()" / >
< span id = "p4d${i}" > < / span > < input type = "number" name = "L4${i}" min = "0" max = "33" class = "s" onchange = "UI()" / >
2021-10-07 22:57:07 +02:00
< div id = "dig${i}r" style = "display:inline" > < br > < span id = "rev${i}" > Reversed< / span > : < input type = "checkbox" name = "CV${i}" > < / div >
2022-03-16 01:45:07 +01:00
< div id = "dig${i}s" style = "display:inline" > < br > Skip first LEDs: < input type = "number" name = "SL${i}" min = "0" max = "255" oninput = "UI()" > < / div >
2021-11-28 01:21:17 +01:00
< div id = "dig${i}f" style = "display:inline" > < br > Off Refresh: < input id = "rf${i}" type = "checkbox" name = "RF${i}" > < / div >
2022-03-09 13:39:51 +01:00
< div id = "dig${i}a" style = "display:inline" > < br > Auto-calculate white channel from RGB:< br > < select name = "AW${i}" > < option value = 0 > None< / option > < option value = 1 > Brighter< / option > < option value = 2 > Accurate< / option > < option value = 3 > Dual< / option > < / select > < / div >
2021-09-23 21:44:24 +02:00
< / div > `;
f.insertAdjacentHTML("beforeend", cn);
}
if (n==-1) {
o[--i].remove();--i;
}
gId("+").style.display = (i< maxB-1 ) ? " inline " : " none " ;
gId("-").style.display = (i>0) ? "inline":"none";
2021-10-06 14:30:41 +02:00
if (!init) UI();
2021-09-23 21:44:24 +02:00
}
2022-01-01 22:08:07 +01:00
function addCOM(start=0,len=1,co=0) {
var i = d.getElementsByClassName("com_entry").length;
if (i >= 10) return;
var b = `< div class = "com_entry" >
< hr style = "width:260px" >
${i+1}: Start: < input type = "number" name = "XS${i}" id = "xs${i}" class = "l starts" min = "0" max = "65535" value = "${start}" oninput = "UI();" required = "" >
Length: < input type = "number" name = "XC${i}" id = "xc${i}" class = "l" min = "1" max = "65535" value = "${len}" required = "" oninput = "UI()" >
< div style = "display:inline" > Color Order:
< select id = "xo${i}" name = "XO${i}" >
< option value = "0" > GRB< / option >
< option value = "1" > RGB< / option >
< option value = "2" > BRG< / option >
< option value = "3" > RBG< / option >
< option value = "4" > BGR< / option >
< option value = "5" > GBR< / option >
< / select >
< / div > < br > < / div > `;
gId("com_entries").insertAdjacentHTML("beforeend", b);
gId("xo"+i).value = co;
btnCOM(i+1);
2022-01-22 23:35:00 +01:00
UI();
2022-01-01 22:08:07 +01:00
}
function remCOM() {
var entries = d.getElementsByClassName("com_entry");
var i = entries.length;
if (i === 0) return;
entries[i-1].remove();
btnCOM(i-1);
2022-01-22 23:35:00 +01:00
UI();
2022-01-01 22:08:07 +01:00
}
2022-01-13 16:06:01 +01:00
function resetCOM(_newMaxCOOverrides=undefined) {
if (_newMaxCOOverrides) {
maxCOOverrides = _newMaxCOOverrides;
}
2022-01-01 22:08:07 +01:00
for (let e of d.getElementsByClassName("com_entry")) {
e.remove();
}
btnCOM(0);
}
function btnCOM(i) {
2022-01-13 16:06:01 +01:00
gId("com_add").style.display = (i< maxCOOverrides ) ? " inline " : " none " ;
2022-01-01 22:08:07 +01:00
gId("com_rem").style.display = (i>0) ? "inline":"none";
}
2021-09-23 21:44:24 +02:00
function addBtn(i,p,t) {
var c = gId("btns").innerHTML;
2021-11-28 11:24:58 +01:00
var bt = "BT" + String.fromCharCode((i< 10 ? 48:55 ) + i ) ;
var be = "BE" + String.fromCharCode((i< 10 ? 48:55 ) + i ) ;
2021-10-02 15:07:02 +02:00
c += `Button ${i} GPIO: < input type = "number" min = "-1" max = "40" name = "${bt}" onchange = "UI()" class = "xs" value = "${p}" > `;
2021-10-03 12:23:24 +02:00
c += ` < select name = "${be}" > `
2021-09-23 21:44:24 +02:00
c += `< option value = "0" $ { t = =0?"selected":""} > Disabled< / option > `;
c += `< option value = "2" $ { t = =2?"selected":""} > Pushbutton< / option > `;
c += `< option value = "3" $ { t = =3?"selected":""} > Push inverted< / option > `;
c += `< option value = "4" $ { t = =4?"selected":""} > Switch< / option > `;
c += `< option value = "5" $ { t = =5?"selected":""} > PIR sensor< / option > `;
c += `< option value = "6" $ { t = =6?"selected":""} > Touch< / option > `;
c += `< option value = "7" $ { t = =7?"selected":""} > Analog< / option > `;
c += `< option value = "8" $ { t = =8?"selected":""} > Analog inverted< / option > `;
c += `< / select > `;
2022-01-01 16:36:06 +01:00
c += `< span style = "cursor: pointer;" onclick = "off('${bt}')" > ✕ < / span > < br > `;
2021-09-23 21:44:24 +02:00
gId("btns").innerHTML = c;
}
2021-10-06 16:29:04 +02:00
function tglSi(cs) {
customStarts = cs;
2021-10-03 20:48:08 +02:00
if (!customStarts) startsDirty = []; //set all starts to clean
UI();
}
function checkSi() { //on load, checks whether there are custom start fields
var cs = false;
for (var i=1; i < d.getElementsByClassName ( " iST " ) . length ; i + + ) {
var v = parseInt(gId("ls"+(i-1)).value) + parseInt(d.getElementsByName("LC"+(i-1))[0].value);
if (v != parseInt(gId("ls"+i).value)) {cs = true; startsDirty[i] = true;}
}
2022-04-30 12:45:38 +02:00
if (gId("ls0") & & parseInt(gId("ls0").value) != 0) {cs = true; startsDirty[0] = true;}
2021-10-06 08:37:27 +02:00
gId("si").checked = cs;
2021-10-06 16:29:04 +02:00
tglSi(cs);
2021-10-03 20:48:08 +02:00
}
2021-09-23 21:44:24 +02:00
function uploadFile(name) {
var req = new XMLHttpRequest();
req.addEventListener('load', function(){showToast(this.responseText,this.status >= 400)});
req.addEventListener('error', function(e){showToast(e.stack,true);});
req.open("POST", "/upload");
var formData = new FormData();
formData.append("data", d.Sf.data.files[0], name);
req.send(formData);
d.Sf.data.value = '';
return false;
2021-10-16 21:44:53 +02:00
}
// https://stackoverflow.com/questions/7346563/loading-local-json-file
function loadCfg(o) {
var f, fr;
if (typeof window.FileReader !== 'function') {
alert("The file API isn't supported on this browser yet.");
return;
}
if (!o.files) {
2021-11-28 01:21:17 +01:00
alert("This browser doesn't support the `files` property of file inputs.");
2021-10-16 21:44:53 +02:00
} else if (!o.files[0]) {
2021-11-28 01:21:17 +01:00
alert("Please select a JSON file first!");
2021-10-16 21:44:53 +02:00
} else {
f = o.files[0];
fr = new FileReader();
fr.onload = receivedText;
fr.readAsText(f);
}
2021-10-17 14:38:19 +02:00
o.value = '';
2021-10-16 21:44:53 +02:00
function receivedText(e) {
let lines = e.target.result;
var c = JSON.parse(lines);
if (c.hw) {
2022-01-22 23:35:00 +01:00
if (c.hw.led) {
2021-10-16 21:44:53 +02:00
for (var i=0; i< 10 ; i + + ) addLEDs ( -1 ) ;
var l = c.hw.led;
l.ins.forEach((v,i,a)=>{
addLEDs(1);
2021-10-17 14:38:19 +02:00
for (var j=0; j< v.pin.length ; j + + ) d . getElementsByName ( ` L $ { j } $ { i } ` ) [ 0 ] . value = v.pin[j];
2021-10-16 21:44:53 +02:00
d.getElementsByName("LT"+i)[0].value = v.type;
d.getElementsByName("LS"+i)[0].value = v.start;
d.getElementsByName("LC"+i)[0].value = v.len;
d.getElementsByName("CO"+i)[0].value = v.order;
2022-03-16 01:45:07 +01:00
d.getElementsByName("SL"+i)[0].value = v.skip;
2021-10-16 21:44:53 +02:00
d.getElementsByName("RF"+i)[0].checked = v.ref;
d.getElementsByName("CV"+i)[0].checked = v.rev;
});
}
2022-01-01 22:08:07 +01:00
if(c.hw.com) {
resetCOM();
c.hw.com.forEach(e => {
addCOM(e.start, e.len, e.order);
});
}
2021-10-16 21:44:53 +02:00
if (c.hw.btn) {
var b = c.hw.btn;
2021-10-17 14:38:19 +02:00
if (Array.isArray(b.ins)) gId("btns").innerHTML = "";
2021-10-16 21:44:53 +02:00
b.ins.forEach((v,i,a)=>{
addBtn(i,v.pin[0],v.type);
});
d.getElementsByName("TT")[0].value = b.tt;
}
if (c.hw.ir) {
d.getElementsByName("IR")[0].value = c.hw.ir.pin;
d.getElementsByName("IT")[0].value = c.hw.ir.type;
}
if (c.hw.relay) {
d.getElementsByName("RL")[0].value = c.hw.relay.pin;
d.getElementsByName("RM")[0].checked = c.hw.relay.inv;
}
UI();
}
}
2021-09-23 21:44:24 +02:00
}
2021-12-06 20:53:09 +01:00
function S(){GetV();checkSi();setABL();}
2021-09-23 21:44:24 +02:00
function GetV()
{
//values injected by server while sending HTML
2021-10-06 14:30:41 +02:00
//d.um_p=[6,7,8,9,10,11,1];bLimits(3,4096,4000,1664);d.Sf.MS.checked=1;addLEDs(1);d.Sf.L00.value=2;d.Sf.LC0.value=30;d.Sf.LT0.value=22;d.Sf.CO0.value=0;d.Sf.LS0.value=15;d.Sf.CV0.checked=1;d.Sf.SL0.checked=0;addLEDs(1);d.Sf.L01.value=10;d.Sf.L11.value=10;d.Sf.L21.value=1;d.Sf.L31.value=10;d.Sf.LC1.value=60;d.Sf.LT1.value=80;d.Sf.CO1.value=1;d.Sf.LS1.value=0;d.Sf.CV1.checked=0;d.Sf.SL1.checked=0;d.Sf.MA.value=850;d.Sf.LA.value=0;d.Sf.CA.value=56;d.Sf.AW.value=3;d.Sf.BO.checked=1;d.Sf.BP.value=80;d.Sf.GB.checked=0;d.Sf.GC.checked=1;d.Sf.TF.checked=1;d.Sf.TD.value=700;d.Sf.PF.checked=0;d.Sf.BF.value=100;d.Sf.TB.value=0;d.Sf.TL.value=60;d.Sf.TW.value=0;d.Sf.PB.selectedIndex=0;d.Sf.RL.value=12;d.Sf.RM.checked=1;addBtn(0,0,0);addBtn(1,-1,0);d.Sf.TT.value=32;d.Sf.IR.value=-1;d.Sf.IT.value=0;
2021-10-17 14:38:19 +02:00
//d.um_p=[6,7,8,9,10,11,14,15,13,1,21,19,22,25,26,27,5,23,18,17];bLimits(10,2048,64000,8192);d.Sf.MS.checked=1;d.Sf.CCT.checked=0;addLEDs(1);d.Sf.L00.value=192;d.Sf.L10.value=168;d.Sf.L20.value=0;d.Sf.L30.value=61;d.Sf.LC0.value=421;d.Sf.LT0.value=80;d.Sf.CO0.value=1;d.Sf.LS0.value=0;d.Sf.CV0.checked=0;d.Sf.SL0.checked=0;d.Sf.RF0.checked=0;d.Sf.MA.value=850;d.Sf.LA.value=0;d.Sf.CA.value=127;d.Sf.AW.value=3;d.Sf.BO.checked=0;d.Sf.BP.value=0;d.Sf.GB.checked=0;d.Sf.GC.checked=1;d.Sf.TF.checked=1;d.Sf.TD.value=700;d.Sf.PF.checked=1;d.Sf.BF.value=100;d.Sf.TB.value=0;d.Sf.TL.value=60;d.Sf.TW.value=1;d.Sf.PB.selectedIndex=0;d.Sf.RL.value=-1;d.Sf.RM.checked=1;addBtn(0,-1,0);addBtn(1,-1,0);addBtn(2,-1,0);addBtn(3,-1,0);d.Sf.TT.value=32;d.Sf.IR.value=-1;d.Sf.IT.value=8;
2021-09-23 21:44:24 +02:00
}
< / script >
< style > @ import url ( "style.css" ) ; < / style >
< / head >
< body onload = "S()" >
< form id = "form_s" name = "Sf" method = "post" >
< div class = "toprow" >
< div class = "helpB" > < button type = "button" onclick = "H()" > ?< / button > < / div >
< button type = "button" onclick = "B()" > Back< / button > < button type = "submit" > Save< / button > < hr >
< / div >
< h2 > LED & Hardware setup< / h2 >
2021-10-03 12:23:24 +02:00
Total LEDs: < span id = "lc" > ?< / span > < span id = "pc" > < / span > < br >
2021-09-23 21:44:24 +02:00
< i > Recommended power supply for brightest white:< / i > < br >
< b > < span id = "psu" > ?< / span > < / b > < br >
< span id = "psu2" > < br > < / span >
< br >
Enable automatic brightness limiter: < input type = "checkbox" name = "ABen" onchange = "enABL()" id = "able" > < br >
< div id = "abl" >
Maximum Current: < input name = "MA" type = "number" class = "l" min = "250" max = "65000" oninput = "UI()" required > mA< br >
< div id = "ampwarning" style = "color: orange; display: none;" >
⚠ Your power supply provides high current.< br >
To improve the safety of your setup,< br >
please use thick cables,< br >
multiple power injection points and a fuse!< br >
< / div >
< i > Automatically limits brightness to stay close to the limit.< br >
Keep at < 1A if powering LEDs directly from the ESP 5V pin!< br >
If you are using an external power supply, enter its rating.< br >
(Current estimated usage: < span class = "pow" > unknown< / span > )< / i > < br > < br >
LED voltage (Max. current for a single LED):< br >
< select name = "LAsel" onchange = "enLA()" >
< option value = "55" selected > 5V default (55mA)< / option >
< option value = "35" > 5V efficient (35mA)< / option >
< option value = "30" > 12V (30mA)< / option >
< option value = "255" > WS2815 (12mA)< / option >
< option value = "50" > Custom< / option >
< / select > < br >
< span id = "LAdis" style = "display: none;" > Custom max. current per LED: < input name = "LA" type = "number" min = "0" max = "255" id = "la" oninput = "UI()" required > mA< br > < / span >
< i > Keep at default if you are unsure about your type of LEDs.< / i > < br >
< / div >
< h3 > Hardware setup< / h3 >
< div id = "mLC" > LED outputs:< / div >
< hr style = "width:260px" >
2021-10-07 13:47:36 +02:00
< button type = "button" id = "+" onclick = "addLEDs(1,false)" > +< / button >
< button type = "button" id = "-" onclick = "addLEDs(-1,false)" > -< / button > < br >
2021-09-23 21:44:24 +02:00
LED Memory Usage: < span id = "m0" > 0< / span > / < span id = "m1" > ?< / span > B< br >
< div id = "dbar" style = "display:inline-block; width: 100px; height: 10px; border-radius: 20px;" > < / div > < br >
< div id = "ledwarning" style = "color: orange; display: none;" >
⚠ You might run into stability or lag issues.< br >
2021-10-03 12:23:24 +02:00
Use less than < span id = "wreason" > 800 LEDs per output< / span > for the best experience!< br >
2021-09-23 21:44:24 +02:00
< / div >
< hr style = "width:260px" >
2021-09-11 01:17:42 +02:00
Make a segment for each output: < input type = "checkbox" name = "MS" > < br >
2021-10-06 16:29:04 +02:00
Custom bus start indices: < input type = "checkbox" onchange = "tglSi(this.checked)" id = "si" > < br >
2021-09-23 21:44:24 +02:00
< hr style = "width:260px" >
2022-01-01 22:08:07 +01:00
< div id = "color_order_mapping" >
Color Order Override:
< div id = "com_entries" > < / div >
< hr style = "width:260px" >
2022-01-22 23:35:00 +01:00
< button type = "button" id = "com_add" onclick = "addCOM()" > +< / button >
< button type = "button" id = "com_rem" onclick = "remCOM()" > -< / button > < br >
2022-01-01 22:08:07 +01:00
< / div >
< hr style = "width:260px" >
2021-09-23 21:44:24 +02:00
< div id = "btns" > < / div >
2021-07-01 00:01:27 +02:00
Touch threshold: < input type = "number" class = "s" min = "0" max = "100" name = "TT" required > < br >
2021-10-02 15:07:02 +02:00
IR GPIO: < input type = "number" min = "-1" max = "40" name = "IR" onchange = "UI()" class = "xs" > < select name = "IT" onchange = "UI()" >
2021-09-23 21:44:24 +02:00
< option value = 0 > Remote disabled< / option >
< option value = 1 > 24-key RGB< / option >
< option value = 2 > 24-key with CT< / option >
< option value = 3 > 40-key blue< / option >
< option value = 4 > 44-key RGB< / option >
< option value = 5 > 21-key RGB< / option >
< option value = 6 > 6-key black< / option >
< option value = 7 > 9-key red< / option >
< option value = 8 > JSON remote< / option >
2022-01-01 16:36:06 +01:00
< / select > < span style = "cursor: pointer;" onclick = "off('IR')" > ✕ < / span > < br >
2022-02-25 10:24:00 +01:00
Apply IR change to main segment only: < input type = "checkbox" name = "MSO" > < br >
2021-12-25 18:46:43 +01:00
< div id = "json" style = "display:none;" > JSON file: < input type = "file" name = "data" accept = ".json" > < button type = "button" class = "sml" onclick = "uploadFile('/ir.json')" > Upload< / button > < br > < / div >
2021-10-06 16:29:04 +02:00
< a href = "https://kno.wled.ge/interfaces/infrared/" target = "_blank" > IR info< / a > < br >
2022-01-01 16:36:06 +01:00
Relay GPIO: < input type = "number" min = "-1" max = "33" name = "RL" onchange = "UI()" class = "xs" > Invert < input type = "checkbox" name = "RM" > < span style = "cursor: pointer;" onclick = "off('RL')" > ✕ < / span > < br >
2021-09-23 21:44:24 +02:00
< hr style = "width:260px" >
< h3 > Defaults< / h3 >
Turn LEDs on after power up/reset: < input type = "checkbox" name = "BO" > < br >
Default brightness: < input name = "CA" type = "number" class = "m" min = "0" max = "255" required > (0-255)< br > < br >
Apply preset < input name = "BP" type = "number" class = "m" min = "0" max = "250" required > at boot (0 uses defaults)
< br > < br >
Use Gamma correction for color: < input type = "checkbox" name = "GC" > (strongly recommended)< br >
Use Gamma correction for brightness: < input type = "checkbox" name = "GB" > (not recommended)< br > < br >
2021-12-08 10:00:31 +01:00
Brightness factor: < input name = "BF" type = "number" class = "m" min = "1" max = "255" required > %
2021-09-23 21:44:24 +02:00
< h3 > Transitions< / h3 >
Crossfade: < input type = "checkbox" name = "TF" > < br >
Transition Time: < input name = "TD" type = "number" class = "xl" min = "0" max = "65500" > ms< br >
Enable Palette transitions: < input type = "checkbox" name = "PF" >
< h3 > Timed light< / h3 >
Default Duration: < input name = "TL" type = "number" class = "m" min = "1" max = "255" required > min< br >
Default Target brightness: < input name = "TB" type = "number" class = "m" min = "0" max = "255" required > < br >
Mode:
< select name = "TW" >
< option value = "0" > Wait and set< / option >
< option value = "1" > Fade< / option >
< option value = "2" > Fade Color< / option >
< option value = "3" > Sunrise< / option >
< / select >
2021-11-28 01:21:17 +01:00
< h3 > White management< / h3 >
White Balance correction: < input type = "checkbox" name = "CCT" > < br >
< span class = "wc" >
2022-03-26 23:20:14 +01:00
Global override for Auto-calculate white:< br >
2021-11-28 01:21:17 +01:00
< select name = "AW" >
2022-03-26 23:20:14 +01:00
< option value = 255 > Disabled< / option >
2021-11-28 01:21:17 +01:00
< option value = 0 > None< / option >
< option value = 1 > Brighter< / option >
< option value = 2 > Accurate< / option >
< option value = 3 > Dual< / option >
< / select >
< br >
Calculate CCT from RGB: < input type = "checkbox" name = "CR" > < br >
2021-12-08 10:00:31 +01:00
CCT additive blending: < input type = "number" class = "s" min = "0" max = "100" name = "CB" required > %< / span >
2021-09-23 21:44:24 +02:00
< h3 > Advanced< / h3 >
Palette blending:
< select name = "PB" >
< option value = "0" > Linear (wrap if moving)< / option >
< option value = "1" > Linear (always wrap)< / option >
< option value = "2" > Linear (never wrap)< / option >
< option value = "3" > None (not recommended)< / option >
< / select > < br >
2021-12-25 01:30:27 +01:00
Target refresh rate: < input type = "number" class = "s" min = "1" max = "120" name = "FR" required > FPS
2021-10-16 21:44:53 +02:00
< hr style = "width:260px" >
2021-12-25 18:46:43 +01:00
< div id = "cfg" > Config template: < input type = "file" name = "data2" accept = ".json" > < button type = "button" class = "sml" onclick = "loadCfg(d.Sf.data2)" > Apply< / button > < br > < / div >
2021-10-16 21:44:53 +02:00
< hr >
2021-09-23 21:44:24 +02:00
< button type = "button" onclick = "B()" > Back< / button > < button type = "submit" > Save< / button >
< / form >
2021-12-08 10:00:31 +01:00
< div id = "toast" > < / div >
2021-09-23 21:44:24 +02:00
< / body >
< / html >