Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions wled00/data/settings_leds.htm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script>
var maxB=1,maxD=1,maxA=1,maxV=0,maxM=4000,maxPB=2048,maxL=1664,maxCO=5; //maximum bytes for LED allocation: 4kB for 8266, 32kB for 32
var customStarts=false,startsDirty=[];
var busChanged=false,originalBusTypes=[];
function off(n) { gN(n).value = -1;}
// these functions correspond to C macros found in const.h
function gT(t) { for (let type of d.ledTypes) if (t == type.i) return type; } // getType from available ledTypes
Expand Down Expand Up @@ -37,6 +38,7 @@
}, ()=>{
checkSi();
setABL();
captureInitialBusState(); // capture initial bus configuration
d.Sf.addEventListener("submit", trySubmit);
if (d.um_p[0]==-1) d.um_p.shift();
pinDropdowns();
Expand Down Expand Up @@ -112,6 +114,23 @@
d.Sf.data.value = '';
e.preventDefault();
if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server

// check for bus changes that require reboot
checkBusChanges();
if (busChanged) {
var msg = "LED hardware changed. Reboot required to apply changes.\n\nContinue and reboot after saving?";
if (!confirm(msg)) {
e.stopPropagation();
return false;
}
// set reboot flag
let rebootField = d.createElement('input');
rebootField.type = 'hidden';
rebootField.name = 'RBT';
rebootField.value = '1';
d.Sf.appendChild(rebootField);
}

if (bquot > 200) {var msg = "Too many LEDs! Can't handle that!"; alert(msg); e.stopPropagation(); return false;}
else {
if (bquot > 80) {var msg = "Memory usage is high, reboot recommended!\n\rSet transitions to 0 to save memory.";
Expand Down Expand Up @@ -270,7 +289,7 @@
let dC = 0; // count of digital buses (for parallel I2S)
let LTs = d.Sf.querySelectorAll("#mLC select[name^=LT]");
LTs.forEach((s,i)=>{
if (i < LTs.length-1) s.disabled = true; // prevent changing type (as we can't update options)
// no longer disable type changes - allow all bus type changes
// is the field a LED type?
var n = s.name.substring(2,3); // bus number (0-Z)
var t = parseInt(s.value);
Expand Down Expand Up @@ -467,7 +486,7 @@
var cn = `<div class="iST">
<hr class="sml">
${i+1}:
<select name="LT${s}" onchange="UI(true)"></select><br>
<select name="LT${s}" onchange="checkBusChanges();UI(true)"></select><br>
<div id="abl${s}">
mA/LED: <select name="LAsel${s}" onchange="enLA(this,'${s}');UI();">
<option value="55" selected>55mA (typ. 5V WS281x)</option>
Expand Down Expand Up @@ -540,6 +559,7 @@
gId("-").style.display = (i>0) ? "inline":"none";

if (!init) {
checkBusChanges(); // check if bus count changed
UI();
}
}
Expand Down Expand Up @@ -634,6 +654,32 @@
gId("si").checked = cs;
tglSi(cs);
}
function captureInitialBusState() {
// capture initial bus types
let buses = d.Sf.querySelectorAll("#mLC select[name^=LT]");
originalBusTypes = [];
buses.forEach((s) => {
originalBusTypes.push(parseInt(s.value));
});
busChanged = false;
}
function checkBusChanges() {
// check if bus configuration has changed
let buses = d.Sf.querySelectorAll("#mLC select[name^=LT]");

// check if any bus type changed (excluding virtual and network buses)
for (let i = 0; i < buses.length; i++) {
let oldType = originalBusTypes[i] || 0;
let newType = parseInt(buses[i].value) || 0;
if (oldType != newType) {
// only flag for reboot if neither old nor new type is virtual/network
if (!isVir(oldType) && !isNet(oldType) && !isVir(newType) && !isNet(newType)) {
busChanged = true;
return;
}
}
}
}
// https://stackoverflow.com/questions/7346563/loading-local-json-file
function loadCfg(o) {
var f, fr;
Expand Down
3 changes: 3 additions & 0 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
if (t > 0) briMultiplier = t;

doInitBusses = busesChanged;

// handle reboot request for bus changes
if (request->hasArg(F("RBT"))) doReboot = true;
}

//UI
Expand Down