LED settings JS possibly complete (need to add saving logic to set.cpp)

This commit is contained in:
cschwinne 2021-01-26 01:58:34 +01:00
parent 89b76b514c
commit 9bdcfc8a45
5 changed files with 114 additions and 115 deletions

View File

@ -95,8 +95,8 @@
#define TYPE_WS2812_RGB 22
#define TYPE_GS8608 23 //same driver as WS2812, but will require signal 2x per second (else displays test pattern)
#define TYPE_WS2811_400KHZ 24 //half-speed WS2812 protocol, used by very old WS2811 units
#define TYPE_TM1814 25
#define TYPE_SK6812_RGBW 30
#define TYPE_TM1814 31
//"Analog" types (PWM) (32-47)
#define TYPE_ONOFF 40 //binary output (relays etc.)
#define TYPE_ANALOG_1CH 41 //single channel PWM. Uses value of brightest RGBW channel

View File

@ -5,7 +5,7 @@
<meta name="viewport" content="width=500">
<title>LED Settings</title>
<script>
var d=document,laprev=55;
var d=document,laprev=55,maxST=1;
function H()
{
window.open("https://github.com/Aircoookie/WLED/wiki/Settings#led-settings");
@ -46,12 +46,7 @@
}
function UI()
{
var isRGBW = false; //TODO check all strips for rgbw (old d.getElementById('rgbw').checked)
var myC = d.querySelectorAll('.wc'),
l = myC.length;
for (i = 0; i < l; i++) {
myC[i].style.display = (isRGBW) ? 'inline':'none';
}
var isRGBW = false;
d.getElementById('ampwarning').style.display = (d.Sf.MA.value > 7200) ? 'inline':'none';
@ -62,35 +57,54 @@
for (i=0; i<s.length; i++) {
if (s[i].name.substring(0,2)=="LT") {
n=s[i].name.substring(2);
var LK = d.getElementsByName("LK"+n)[0];
var o = d.getElementsByName("iLK");
n=(n==""?0:parseInt(n,10));
if (s[i].value>49 && s[i].value!=54) // TYPE_xxxx values from const.h
{
o[n].style.display = "inline";
var type = s[i].value;
d.getElementById("p0d"+n).innerHTML = (type > 49) ? "Data pin:" : (type >41) ? "Pins:" : "Pin:";
d.getElementById("p1d"+n).innerHTML = (type > 49) ? "Clk:" : "";
var LK = d.getElementsByName("L1"+n)[0];
//n=(n==""?0:parseInt(n,10));
for (p=1; p<5; p++) {
var LK = d.getElementsByName("L"+p+n)[0];
if (!LK) continue;
if ((type>49 && p==1) || (type>41 && type < 50 && (p+40 < type))) // TYPE_xxxx values from const.h
{
LK.style.display = "inline";
LK.required = true;
} else {
o[n].style.display = "none";
} else {
LK.style.display = "none";
LK.required = false;
LK.value="";
}
}
if (type == 30 || type == 31 || type == 44 || type == 45) isRGBW = true;
}
}
var myC = d.querySelectorAll('.wc'),
l = myC.length;
for (i = 0; i < l; i++) {
myC[i].style.display = (isRGBW) ? 'inline':'none';
}
if (d.activeElement == d.getElementsByName("LC")[0]) {
var o = d.getElementsByClassName("iST");
var i = o.length;
if (i == 1) d.getElementsByName("LC0")[0].value = d.getElementsByName("LC")[0].value;
}
var LCs = d.getElementsByTagName("input");
var sLC = 0;
for (i=0; i<LCs.length; i++) {
var nm = LCs[i].name.substring(0,2);
if (nm=="LC") {sLC+=parseInt(LCs[i].value,10);continue;}
if (nm=="LP") {var lc=d.getElementsByName("LC"+LCs[i].name.substring(2))[0]; if(LCs[i].value==3) lc.max=500; else lc.max=1500;}
if (nm=="LP" || nm=="LK" || nm=="RL" || nm=="BT" || nm=="IR" || nm=="AX")
if (nm=="LC" && LCs[i].name != "LC") {var c = parseInt(LCs[i].value,10); if (c) sLC+=c; continue;}
if (nm=="L0") {var lc=d.getElementsByName("LC"+LCs[i].name.substring(2))[0]; if(LCs[i].value==3) lc.max=500; else lc.max=1500;}
if (nm=="L0" || nm=="L1" || nm=="RL" || nm=="BT" || nm=="IR" || nm=="AX")
if (LCs[i].value!="" && LCs[i].value!="-1") {
if (d.um_p && d.um_p.some((e)=>e==parseInt(LCs[i].value,10))) {alert("Usermod pin clash!");LCs[i].value="";LCs[i].focus();continue;}
for (j=0; j<LCs.length; j++)
{
if (i==j) continue;
var n2 = LCs[j].name.substring(0,2);
if (n2=="LP" || n2=="LK" || n2=="RL" || n2=="BT" || n2=="IR" || n2=="AX")
if (n2=="L0" || n2=="L1" || n2=="RL" || n2=="BT" || n2=="IR" || n2=="AX")
if (LCs[j].value!="" && LCs[i].value==LCs[j].value) {alert("Pin clash!");LCs[i].value="";LCs[i].focus();break;}
}
}
@ -112,7 +126,7 @@
s += val;
s += "A supply connected to LEDs";
}
var val2 = Math.ceil((100 + d.Sf.LC.value * laprev)/1500)/2;
var val2 = Math.ceil((100 + sLC * laprev)/1500)/2;
val2 = (val2 > 5) ? Math.ceil(val2) : val2;
var s2 = "(for most effects, ~";
s2 += val2;
@ -122,72 +136,59 @@
}
function addLEDs(n)
{
if (n>1) {d.maxST=n; d.getElementById("+").style.display="inline"; return;}
if (n>1) {maxST=n; d.getElementById("+").style.display="inline"; return;}
var o = d.getElementsByName("iST");
var o = d.getElementsByClassName("iST");
var i = o.length;
if ((n==1 && i>=d.maxST) || (n==-1 && i==0)) return;
if ((n==1 && i>=maxST) || (n==-1 && i==0)) return;
var f = d.getElementById("mLC");
if (n==1) {
var s, t = d.createElement("div");
t.setAttribute("name","iST");
t.appendChild(d.createTextNode((i+1)+": "));
s = d.createElement("select");
s.setAttribute("name","LT"+i);
s.onchange = function(){UI()}
o = d.createElement("option"); o.text = "WS281x"; o.value = "22"; s.add(o);
o = d.createElement("option"); o.text = "SK6812 RGBW"; o.value = "30"; s.add(o);
o = d.createElement("option"); o.text = "WS2801"; o.value = "50"; s.add(o);
o = d.createElement("option"); o.text = "APA102"; o.value = "51"; s.add(o);
o = d.createElement("option"); o.text = "LPD8806"; o.value = "52"; s.add(o);
o = d.createElement("option"); o.text = "P9813"; o.value = "53"; s.add(o);
o = d.createElement("option"); o.text = "TM1814"; o.value = "54"; s.add(o);
t.appendChild(s);
t.appendChild(d.createTextNode(" CO: "));
s = d.createElement("select");
s.setAttribute("name","CO"+i);
o = d.createElement("option"); o.text = "GRB"; o.value = "0"; s.add(o);
o = d.createElement("option"); o.text = "RGB"; o.value = "1"; s.add(o);
o = d.createElement("option"); o.text = "BRG"; o.value = "2"; s.add(o);
o = d.createElement("option"); o.text = "RBG"; o.value = "3"; s.add(o);
o = d.createElement("option"); o.text = "BGR"; o.value = "4"; s.add(o);
o = d.createElement("option"); o.text = "GBR"; o.value = "5"; s.add(o);
t.appendChild(s);
t.appendChild(d.createElement("br"));
t.appendChild(d.createTextNode("Pin: "));
var e = d.createElement("input");
e.type = "number"; e.value = ""; e.name = "LP"+i; e.min=0; e.max=40; e.required=true; e.onchange=function(){UI()};
t.appendChild(e);
var b = d.createElement("div");
b.setAttribute("name","iLK");
b.appendChild(d.createTextNode(" Clk: "));
e = d.createElement("input");
e.type = "number"; e.value = ""; e.name = "LK"+i; e.min=0; e.max=40; e.onchange=function(){UI()};
//if (d.getElementsByName("LT"+i)[0].value>49) e.required = true;
b.appendChild(e);
t.appendChild(b);
t.appendChild(d.createTextNode(" Count: "));
e = d.createElement("input");
e.type = "number"; e.value = "0"; e.name = "LC"+i; e.min=0; e.max=1000; e.required=true; e.oninput = function(){UI()};
t.appendChild(e);
t.appendChild(d.createElement("br"));
f.appendChild(t);
var cn = `<div class="iST">
${i>0?'<hr style="width:260px">':''}
${i+1}:
<select name="LT${i}" onchange="UI()">
<option value="22">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>
<option value="41">PWM White</option>
<option value="42">PWM WWCW</option>
<option value="43">PWM RGB</option>
<option value="44">PWM RGBW</option>
<option value="45">PWM RGBWC</option>
</select>&nbsp;
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>
</select><br>
<span id="p0d${i}">Pin:</span> <input type="number" name="L0${i}" min="0" max="40" required style="width:35px"/>
<span id="p1d${i}">Clock:</span> <input type="number" name="L1${i}" min="0" max="40" style="width:35px"/>
<span id="p2d${i}"></span><input type="number" name="L2${i}" min="0" max="40" style="width:35px"/>
<span id="p3d${i}"></span><input type="number" name="L3${i}" min="0" max="40" style="width:35px"/>
<span id="p4d${i}"></span><input type="number" name="L4${i}" min="0" max="40" style="width:35px"/>
<br>
Start: <input type="number" name="LS${i}" min="0" max="1500" required oninput="UI()" />&nbsp;
Count: <input type="number" name="LC${i}" min="0" max="1500" required oninput="UI()" /><br>
Reverse: <input type="checkbox" name="CV${i}"><br>
</div>`;
f.insertAdjacentHTML("beforeend", cn);
}
if (n==-1) {
o[--i].remove();--i;
}
d.getElementById("+").style.display = (i<d.maxST-1) ? "inline":"none";
d.getElementById("+").style.display = (i<maxST-1) ? "inline":"none";
d.getElementById("-").style.display = (i>0) ? "inline":"none";
UI();
@ -195,9 +196,6 @@
function GetV()
{
//values injected by server while sending HTML
var d=document;
d.um_p=[];addLEDs(3);d.Sf.LC.max=1536;d.Sf.LC.value=120;addLEDs(1);d.Sf.LP0.value=2;d.Sf.LC0.value=120;d.Sf.LT0.value=22;d.Sf.CO0.value=0;d.Sf.MA.value=5400;d.Sf.LA.value=0;d.Sf.CA.value=40;d.Sf.AW.value=3;d.Sf.BO.checked=0;d.Sf.BP.value=3;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=64;d.Sf.TB.value=0;d.Sf.TL.value=60;d.Sf.TW.value=1;d.Sf.PB.selectedIndex=0;d.Sf.RV.checked=0;d.Sf.SL.checked=0;d.Sf.RL.value=12;d.Sf.RM.checked=0;d.Sf.BT.value=0;d.Sf.IR.value=-1;d.Sf.AX.value=-1;
}
</script>
<style>
@ -242,21 +240,11 @@
<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>
<span class="wc">
Auto-calculate white channel from RGB:<br>
<select name="AW">
<option value=0>None</option>
<option value=1>Brighter</option>
<option value=2>Accurate</option>
<option value=3>Dual</option>
<option value=4>Legacy</option>
</select>
<br></span>
<h3>Hardware setup</h3>
<div id="mLC">LED outputs:</div>
<button type="button" id="+" onclick="addLEDs(1)" style="display:none;border-radius:20px;height:36px;">+</button>
<button type="button" id="-" onclick="addLEDs(-1)" style="display:none;border-radius:20px;width:36px;height:36px;">-</button><br><br>
Relay pin: <input type="number" min="-1" max="40" name="RL" onchange="UI()"> Active high? <input type="checkbox" name="RM"><br>
Relay pin: <input type="number" min="-1" max="40" name="RL" onchange="UI()"> Active high <input type="checkbox" name="RM"><br>
Button pin: <input type="number" min="-1" max="40" name="BT" onchange="UI()"><br>
IR pin: <input type="number" min="-1" max="40" name="IR" onchange="UI()"><br>
AUX pin: <input type="number" min="-1" max="40" name="AX" onchange="UI()">
@ -283,7 +271,7 @@
<option value="2">Fade Color</option>
<option value="3">Sunrise</option>
</select>
<h3>Advanced</h3>
<h3>Advanced</h3>
Palette blending:
<select name="PB">
<option value="0">Linear (wrap if moving)</option>
@ -292,7 +280,17 @@
<option value="3">None (not recommended)</option>
</select><br>
Reverse LED order (rotate 180): <input type="checkbox" name="RV"><br>
Skip first LED: <input type="checkbox" name="SL"><hr>
Skip first LED: <input type="checkbox" name="SL"><br>
<span class="wc">
Auto-calculate white channel from RGB:<br>
<select name="AW">
<option value=0>None</option>
<option value=1>Brighter</option>
<option value=2>Accurate</option>
<option value=3>Dual</option>
<option value=4>Legacy</option>
</select>
<br></span><hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form>
</body>

File diff suppressed because one or more lines are too long

View File

@ -90,8 +90,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
uint8_t pins[2] = {255, 255};
for (uint8_t s = 0; s < WLED_MAX_BUSSES; s++) {
char lp[4] = "LP"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
char lk[4] = "LK"; lk[2] = 48+s; lk[3] = 0; //strip clock pin. 255 for none
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
char lk[4] = "L1"; lk[2] = 48+s; lk[3] = 0; //strip clock pin. 255 for none
char lc[4] = "LC"; lc[2] = 48+s; lc[3] = 0; //strip length
char co[4] = "CO"; co[2] = 48+s; co[3] = 0; //strip color order
char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type

View File

@ -290,8 +290,8 @@ void getSettingsJS(byte subPage, char* dest)
for (uint8_t s=0; s < busses.getNumBusses(); s++){
Bus* bus = busses.getBus(s);
char lp[4] = "LP"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
char lk[4] = "LK"; lk[2] = 48+s; lk[3] = 0; //strip clock pin. 255 for none
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
char lk[4] = "L1"; lk[2] = 48+s; lk[3] = 0; //strip clock pin. 255 for none
char lc[4] = "LC"; lc[2] = 48+s; lc[3] = 0; //strip length
char co[4] = "CO"; co[2] = 48+s; co[3] = 0; //strip color order
char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type