Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
53 changes: 51 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,originalBusCount=0,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 configuration changed. A reboot is required for changes to take effect.\n\nDo you want to continue and reboot after saving?";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorten the string but keep the meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shortened the confirmation message to "LED hardware changed. Reboot required to apply changes.\n\nContinue and reboot after saving?" while keeping the meaning clear. Fixed in commit 7dba246.

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,35 @@
gId("si").checked = cs;
tglSi(cs);
}
function captureInitialBusState() {
// capture initial number of buses and their types
let buses = d.Sf.querySelectorAll("#mLC select[name^=LT]");
originalBusCount = buses.length;
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]");
let currentBusCount = buses.length;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is redundant, if bus count increases, the below check for value will catch it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant bus count check. The bus type comparison now catches both type changes and additions/removals. Fixed in commit 7dba246.


// check if bus count changed
if (currentBusCount != originalBusCount) {
busChanged = true;
return;
}

// check if any bus type changed
for (let i = 0; i < buses.length; i++) {
if (parseInt(buses[i].value) != originalBusTypes[i]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exempt virtual and network buses

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added exemption for virtual and network buses using isVir() and isNet() functions. These buses are hardware-independent and don't require reboot. Fixed in commit 7dba246.

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