mirror of
https://github.com/wled/WLED.git
synced 2025-07-23 02:36:39 +00:00
Code size reduction
This commit is contained in:
parent
8de2301c6b
commit
8e0809ceba
@ -52,51 +52,55 @@
|
|||||||
maxB = b; maxV = v; maxM = m; maxPB = p; maxL = l;
|
maxB = b; maxV = v; maxM = m; maxPB = p; maxL = l;
|
||||||
}
|
}
|
||||||
function pinsOK() {
|
function pinsOK() {
|
||||||
var LCs = d.Sf.querySelectorAll("#mLC input[name^=L]"); // input fields
|
var ok = true;
|
||||||
for (i=0; i<LCs.length; i++) {
|
var nList = d.Sf.querySelectorAll("#mLC input[name^=L]");
|
||||||
var nm = LCs[i].name.substring(0,2);
|
nList.forEach((LC,i)=>{
|
||||||
|
if (!ok) return; // prevent iteration after conflict
|
||||||
|
let nm = LC.name.substring(0,2);
|
||||||
|
let n = LC.name.substring(2);
|
||||||
|
let t = parseInt(d.Sf["LT"+n].value, 10); // LED type SELECT
|
||||||
// ignore IP address
|
// ignore IP address
|
||||||
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
|
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
|
||||||
var n = LCs[i].name.substring(2);
|
if (t>=80) return;
|
||||||
var t = parseInt(d.getElementsByName("LT"+n)[0].value, 10); // LED type SELECT
|
|
||||||
if (t>=80) continue;
|
|
||||||
}
|
}
|
||||||
//check for pin conflicts
|
//check for pin conflicts
|
||||||
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4"/* || nm=="RL" || nm=="BT" || nm=="IR"*/)
|
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4")
|
||||||
if (LCs[i].value!="" && LCs[i].value!="-1") {
|
if (LC.value!="" && LC.value!="-1") {
|
||||||
var p = d.rsvd.concat(d.um_p); // used pin array
|
let p = d.rsvd.concat(d.um_p); // used pin array
|
||||||
d.Sf.querySelectorAll("select.pin").forEach((e)=>{if(e.value>-1)p.push(parseInt(e.value));}) // buttons, IR & relay
|
d.Sf.querySelectorAll("select.pin").forEach((e)=>{if(e.value>-1)p.push(parseInt(e.value));}) // buttons, IR & relay
|
||||||
if (p.some((e)=>e==parseInt(LCs[i].value))) {
|
if (p.some((e)=>e==parseInt(LC.value))) {
|
||||||
alert(`Sorry, pins ${JSON.stringify(p)} can't be used.`);
|
alert(`Sorry, pins ${JSON.stringify(p)} can't be used.`);
|
||||||
LCs[i].value="";
|
LC.value="";
|
||||||
LCs[i].focus();
|
LC.focus();
|
||||||
return false;
|
ok = false;
|
||||||
}
|
return;
|
||||||
else if (/*!(nm == "IR" || nm=="BT") &&*/ d.ro_gpio.some((e)=>e==parseInt(LCs[i].value))) {
|
} else if (d.ro_gpio.some((e)=>e==parseInt(LC.value))) {
|
||||||
alert(`Sorry, pins ${JSON.stringify(d.ro_gpio)} are input only.`);
|
alert(`Sorry, pins ${JSON.stringify(d.ro_gpio)} are input only.`);
|
||||||
LCs[i].value="";
|
LC.value="";
|
||||||
LCs[i].focus();
|
LC.focus();
|
||||||
return false;
|
ok = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (j=i+1; j<LCs.length; j++) {
|
for (j=i+1; j<nList.length; j++) {
|
||||||
var n2 = LCs[j].name.substring(0,2);
|
let n2 = nList[j].name.substring(0,2);
|
||||||
if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4"/* || n2=="RL" || n2=="BT" || n2=="IR"*/) {
|
if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4") {
|
||||||
if (n2.substring(0,1)==="L") {
|
if (n2.substring(0,1)==="L") {
|
||||||
var m = LCs[j].name.substring(2);
|
var m = nList[j].name.substring(2);
|
||||||
var t2 = parseInt(d.getElementsByName("LT"+m)[0].value, 10);
|
var t2 = parseInt(d.Sf["LT"+m].value, 10);
|
||||||
if (t2>=80) continue;
|
if (t2>=80) continue;
|
||||||
}
|
}
|
||||||
if (LCs[j].value!="" && LCs[i].value==LCs[j].value) {
|
if (nList[j].value!="" && nList[i].value==nList[j].value) {
|
||||||
alert(`Pin conflict between ${LCs[i].name}/${LCs[j].name}!`);
|
alert(`Pin conflict between ${LC.name}/${nList[j].name}!`);
|
||||||
LCs[j].value="";
|
nList[j].value="";
|
||||||
LCs[j].focus();
|
nList[j].focus();
|
||||||
return false;
|
ok = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
return true;
|
return ok;
|
||||||
}
|
}
|
||||||
function trySubmit(e) {
|
function trySubmit(e) {
|
||||||
d.Sf.data.value = '';
|
d.Sf.data.value = '';
|
||||||
@ -206,7 +210,7 @@
|
|||||||
|
|
||||||
// enumerate pins
|
// enumerate pins
|
||||||
for (p=1; p<5; p++) {
|
for (p=1; p<5; p++) {
|
||||||
var LK = d.getElementsByName("L"+p+n)[0]; // secondary pins
|
var LK = d.Sf["L"+p+n]; // secondary pins
|
||||||
if (!LK) continue;
|
if (!LK) continue;
|
||||||
if (((t>=80 && t<96) && p<4) || (t>49 && p==1) || (t>41 && t < 50 && (p+40 < t))) // TYPE_xxxx values from const.h
|
if (((t>=80 && t<96) && p<4) || (t>49 && p==1) || (t>41 && t < 50 && (p+40 < t))) // TYPE_xxxx values from const.h
|
||||||
{
|
{
|
||||||
@ -222,7 +226,7 @@
|
|||||||
}
|
}
|
||||||
if (change) {
|
if (change) {
|
||||||
gId("rf"+n).checked = (gId("rf"+n).checked || t == 31); // LEDs require data in off state
|
gId("rf"+n).checked = (gId("rf"+n).checked || t == 31); // LEDs require data in off state
|
||||||
if (t > 31 && t < 48) d.getElementsByName("LC"+n)[0].value = 1; // for sanity change analog count just to 1 LED
|
if (t > 31 && t < 48) d.Sf["LC"+n].value = 1; // for sanity change analog count just to 1 LED
|
||||||
d.Sf["LA"+n].min = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? 0 : 1;
|
d.Sf["LA"+n].min = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? 0 : 1;
|
||||||
d.Sf["MA"+n].min = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? 0 : 250;
|
d.Sf["MA"+n].min = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? 0 : 250;
|
||||||
}
|
}
|
||||||
@ -230,7 +234,7 @@
|
|||||||
gRGBW |= isRGBW = ((t > 17 && t < 22) || (t > 28 && t < 32) || (t > 40 && t < 46 && t != 43) || t == 88); // RGBW checkbox, TYPE_xxxx values from const.h
|
gRGBW |= isRGBW = ((t > 17 && t < 22) || (t > 28 && t < 32) || (t > 40 && t < 46 && t != 43) || t == 88); // RGBW checkbox, TYPE_xxxx values from const.h
|
||||||
gId("co"+n).style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? "none":"inline"; // hide color order for PWM
|
gId("co"+n).style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? "none":"inline"; // hide color order for PWM
|
||||||
gId("dig"+n+"w").style.display = (t > 28 && t < 32) ? "inline":"none"; // show swap channels dropdown
|
gId("dig"+n+"w").style.display = (t > 28 && t < 32) ? "inline":"none"; // show swap channels dropdown
|
||||||
if (!(t > 28 && t < 32)) d.getElementsByName("WO"+n)[0].value = 0; // reset swapping
|
if (!(t > 28 && t < 32)) d.Sf["WO"+n].value = 0; // reset swapping
|
||||||
gId("dig"+n+"c").style.display = (t >= 40 && t < 48) ? "none":"inline"; // hide count for analog
|
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+"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+"s").style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? "none":"inline"; // hide skip 1st for virtual & analog
|
||||||
@ -249,21 +253,21 @@
|
|||||||
d.Sf.AW.selectedIndex = 0;
|
d.Sf.AW.selectedIndex = 0;
|
||||||
d.Sf.CR.checked = false;
|
d.Sf.CR.checked = false;
|
||||||
}
|
}
|
||||||
// check for pin conflicts
|
// update start indexes, max values, calculate current, etc
|
||||||
var LCs = d.Sf.querySelectorAll("#mLC input[name^=L]"); // input fields
|
var nList = d.Sf.querySelectorAll("#mLC input[name^=L]");
|
||||||
for (i=0; i<LCs.length; i++) {
|
nList.forEach((LC,i)=>{
|
||||||
var nm = LCs[i].name.substring(0,2); // field name
|
let nm = LC.name.substring(0,2); // field name
|
||||||
var n = LCs[i].name.substring(2); // bus number
|
let n = LC.name.substring(2); // bus number
|
||||||
|
let t = parseInt(d.Sf["LT"+n].value); // LED type SELECT
|
||||||
// do we have a led count field
|
// do we have a led count field
|
||||||
if (nm=="LC") {
|
if (nm=="LC") {
|
||||||
var c=parseInt(LCs[i].value,10); //get LED count
|
let c = parseInt(LC.value,10); //get LED count
|
||||||
if (!customStarts || !startsDirty[n]) gId("ls"+n).value=sLC; //update start value
|
if (!customStarts || !startsDirty[n]) gId("ls"+n).value=sLC; //update start value
|
||||||
gId("ls"+n).disabled = !customStarts; //enable/disable field editing
|
gId("ls"+n).disabled = !customStarts; //enable/disable field editing
|
||||||
if (c) {
|
if (c) {
|
||||||
var s = parseInt(gId("ls"+n).value); //start value
|
let s = parseInt(gId("ls"+n).value); //start value
|
||||||
if (s+c > sLC) sLC = s+c; //update total count
|
if (s+c > sLC) sLC = s+c; //update total count
|
||||||
if (c > maxLC) maxLC = c; //max per output
|
if (c > maxLC) maxLC = c; //max per output
|
||||||
var t = parseInt(d.Sf["LT"+n].value); // LED type SELECT
|
|
||||||
if (t < 80) sPC += c; //virtual out busses do not count towards physical LEDs
|
if (t < 80) sPC += c; //virtual out busses do not count towards physical LEDs
|
||||||
if (!((t >= 80 && t < 96) || (t >= 40 && t < 48))) sDI += c;
|
if (!((t >= 80 && t < 96) || (t >= 40 && t < 48))) sDI += c;
|
||||||
if (!((t >= 80 && t < 96) || (t >= 40 && t < 48))) {
|
if (!((t >= 80 && t < 96) || (t >= 40 && t < 48))) {
|
||||||
@ -272,52 +276,46 @@
|
|||||||
busMA += maPL*c;
|
busMA += maPL*c;
|
||||||
}
|
}
|
||||||
} // increase led count
|
} // increase led count
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
// do we have led pins for digital leds
|
// do we have led pins for digital leds
|
||||||
if (nm=="L0" || nm=="L1") {
|
if (nm=="L0" || nm=="L1") {
|
||||||
var lc=d.Sf["LC"+n];
|
d.Sf["LC"+n].max = maxPB; // update max led count value
|
||||||
lc.max=maxPB; // update max led count value
|
|
||||||
}
|
}
|
||||||
// ignore IP address (stored in pins for virtual busses)
|
// ignore IP address (stored in pins for virtual busses)
|
||||||
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
|
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
|
||||||
var t = parseInt(d.Sf["LT"+n].value); // LED type SELECT
|
|
||||||
if (t>=80) {
|
if (t>=80) {
|
||||||
LCs[i].max = 255;
|
LC.max = 255;
|
||||||
LCs[i].min = 0;
|
LC.min = 0;
|
||||||
LCs[i].style.color="#fff";
|
LC.style.color="#fff";
|
||||||
continue; // do not check conflicts
|
return; // do not check conflicts
|
||||||
} else {
|
} else {
|
||||||
LCs[i].max = d.max_gpio;
|
LC.max = d.max_gpio;
|
||||||
LCs[i].min = -1;
|
LC.min = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check for pin conflicts
|
// check for pin conflicts & color fields
|
||||||
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4"/* || nm=="RL" || nm=="BT" || nm=="IR"*/)
|
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4")
|
||||||
if (LCs[i].value!="" && LCs[i].value!="-1") {
|
if (LC.value!="" && LC.value!="-1") {
|
||||||
var p = d.rsvd.concat(d.um_p); // used pin array
|
let p = d.rsvd.concat(d.um_p); // used pin array
|
||||||
d.Sf.querySelectorAll("select.pin").forEach((e)=>{if(e.value>-1)p.push(parseInt(e.value));}) // buttons, IR & relay
|
d.Sf.querySelectorAll("select.pin").forEach((e)=>{if(e.value>-1)p.push(parseInt(e.value));}) // buttons, IR & relay
|
||||||
for (j=0; j<LCs.length; j++) {
|
for (j=0; j<nList.length; j++) {
|
||||||
if (i==j) continue;
|
if (i==j) continue;
|
||||||
var n2 = LCs[j].name.substring(0,2);
|
let n2 = nList[j].name.substring(0,2);
|
||||||
if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4"/* || n2=="RL" || n2=="BT" || n2=="IR"*/) {
|
if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4") {
|
||||||
if (n2.substring(0,1)==="L") {
|
if (n2.substring(0,1)==="L") {
|
||||||
var m = LCs[j].name.substring(2);
|
let m = nList[j].name.substring(2);
|
||||||
var t2 = parseInt(d.Sf["LT"+m].value, 10);
|
let t2 = parseInt(d.Sf["LT"+m].value, 10);
|
||||||
if (t2 >= 80) continue;
|
if (t2 >= 80) continue;
|
||||||
}
|
}
|
||||||
if (LCs[j].value!="" && LCs[j].value!="-1") p.push(parseInt(LCs[j].value,10)); // add current pin
|
if (nList[j].value!="" && nList[j].value!="-1") p.push(parseInt(nList[j].value,10)); // add current pin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// now check for conflicts
|
// now check for conflicts
|
||||||
if (p.some((e)=>e==parseInt(LCs[i].value))) LCs[i].style.color="red"; else LCs[i].style.color=d.ro_gpio.some((e)=>e==parseInt(LCs[i].value))?"orange":"#fff";
|
if (p.some((e)=>e==parseInt(LC.value))) LC.style.color = "red";
|
||||||
}
|
else LC.style.color = d.ro_gpio.some((e)=>e==parseInt(LC.value)) ? "orange" : "#fff";
|
||||||
// check buttons, IR & relay
|
|
||||||
//if (nm=="IR" || nm=="BT" || nm=="RL") {
|
|
||||||
// LCs[i].max = d.max_gpio;
|
|
||||||
// LCs[i].min = -1;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
d.Sf.querySelectorAll("#mLC input[name^=LC]").forEach((s,n)=>{
|
d.Sf.querySelectorAll("#mLC input[name^=LC]").forEach((s,n)=>{
|
||||||
let c = parseInt(s.value,10); //get LED count
|
let c = parseInt(s.value,10); //get LED count
|
||||||
let t = parseInt(d.Sf["LT"+n].value);
|
let t = parseInt(d.Sf["LT"+n].value);
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user