Merge pull request #336 from MoonModules/um_pins

show HUB75 and DMX pins in usermods pin dropdown, and fix a bug related to busses without pins.

Previously the pins allocated to HUB75 and DMX were wrongly listed as available 🟢.
This commit is contained in:
Frank Möhle
2026-02-05 00:24:04 +01:00
committed by GitHub
2 changed files with 35 additions and 1 deletions

View File

@@ -10,6 +10,8 @@
d.um_p = []; d.um_p = [];
d.rsvd = []; d.rsvd = [];
d.ro_gpio = []; d.ro_gpio = [];
d.h_pins = [];
d.x_pins = [];
var umCfg = {}; var umCfg = {};
var pins = [], pinO = [], owner; var pins = [], pinO = [], owner;
var loc = false, locip; var loc = false, locip;
@@ -56,6 +58,8 @@
// function check(o,k) {} //WLEDMM not needed as we use dropdowns // function check(o,k) {} //WLEDMM not needed as we use dropdowns
function getPins(o) { function getPins(o) {
if (isO(o)) { if (isO(o)) {
// If this object is a bus instance, extract the "type" field
let busType = o.type !== undefined ? o.type : -1;
for (const [k,v] of Object.entries(o)) { for (const [k,v] of Object.entries(o)) {
if (isO(v)) { if (isO(v)) {
owner = k; owner = k;
@@ -63,6 +67,10 @@
continue; continue;
} }
if (k.replace("[]","").substr(-3)=="pin") { if (k.replace("[]","").substr(-3)=="pin") {
// Skip pin arrays for special bus types where pin array doesn't contain GPIO numbers, but allow all other entries
if (busType >= 80 && busType < 96) continue; // Network buses - pin array stores IP address
if (busType >= 100 && busType <= 110) continue; // HUB75 buses - pin array stores chain length
if (Array.isArray(v)) { if (Array.isArray(v)) {
for (var i=0; i<v.length; i++) if (v[i]>=0) { pins.push(v[i]); pinO.push(owner); } for (var i=0; i<v.length; i++) if (v[i]>=0) { pins.push(v[i]); pinO.push(owner); }
} else { } else {
@@ -269,6 +277,8 @@
// console.log("pinPost option", c, c.value, d.ro_gpio.includes(c.value)); // console.log("pinPost option", c, c.value, d.ro_gpio.includes(c.value));
for (let j=0; j<d.ro_gpio.length; j++) if (d.ro_gpio[j] == c.value) c.text += " read only 🟠"; //if (d.ro_gpio.includes(c.value)) not working ??? for (let j=0; j<d.ro_gpio.length; j++) if (d.ro_gpio[j] == c.value) c.text += " read only 🟠"; //if (d.ro_gpio.includes(c.value)) not working ???
for (let j=0; j<d.rsvd.length; j++) if (d.rsvd[j] == c.value) {c.text += " reserved 🟣"; c.disabled=true;} //now always disabled as post is done last if (d.rsvd.includes(c.value)) for (let j=0; j<d.rsvd.length; j++) if (d.rsvd[j] == c.value) {c.text += " reserved 🟣"; c.disabled=true;} //now always disabled as post is done last if (d.rsvd.includes(c.value))
for (let j=0; j<d.h_pins.length; j++) if (d.h_pins[j] == c.value && c.text.length <= 4) {c.text += " HUB75 🔴"; c.disabled=true;} // HUB75 pins
for (let j=0; j<d.x_pins.length; j++) if (d.x_pins[j] == c.value && c.text.length <= 4) {c.text += " DMX 🔴"; c.disabled=true;} // DMX pins
//remove pins > max_gpio //remove pins > max_gpio
if (c.value > d.max_gpio) { if (c.value > d.max_gpio) {
select.removeChild(c); select.removeChild(c);
@@ -278,7 +288,7 @@
//https://www.javascripttutorial.net/javascript-dom/javascript-remove-items-from-a-select-conditionally/ //https://www.javascripttutorial.net/javascript-dom/javascript-remove-items-from-a-select-conditionally/
if (c.text.length <= 4) c.text += " 🟢"; //2 digit number space and ⍼/⎌. If no reserved/read only/other um, then pin can be freely used (green) if (c.text.length <= 4) c.text += " 🟢"; //2 digit number space and ⍼/⎌. If no reserved/read only/other um, then pin can be freely used (green)
for (let jj=0; jj<d.dt_pins.length; jj++) if (d.dt_pins[jj] == c.value) c.text += ((jj<9)?` D${jj}`:((jj==9)?` RX`:` TX`)); //WLEDMM: Add D0-D8, RX/TX to name for (let jj=0; jj<d.dt_pins.length; jj++) if (d.dt_pins[jj] == c.value) c.text += ((jj<9)?` D${jj}`:((jj==9)?` RX`:` TX`)); //WLEDMM: Add D0-D8, RX/TX to name
for (let jj=0; jj<d.a_pins.length; jj++) if (d.a_pins[jj] == c.value) c.text += ` A${jj}`; //WLEDMM: Add A0-A10 for (let jj=0; jj<d.a_pins.length; jj++) if (d.a_pins[jj] == c.value) c.text += `   A${jj}`; //WLEDMM: Add A0-A10
} }
} }
} }

View File

@@ -287,6 +287,30 @@ void appendGPIOinfo() {
char a_pins[64] = { '\0' }; // fix warning: output 45 bytes into a destination of size 30 char a_pins[64] = { '\0' }; // fix warning: output 45 bytes into a destination of size 30
snprintf(a_pins, 64, "d.a_pins=[%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d];", pinManager.getADCPin(PM_ADC1, 0), pinManager.getADCPin(PM_ADC1, 1), pinManager.getADCPin(PM_ADC1, 2), pinManager.getADCPin(PM_ADC1, 3), pinManager.getADCPin(PM_ADC1, 4), pinManager.getADCPin(PM_ADC1, 5), pinManager.getADCPin(PM_ADC1, 6), pinManager.getADCPin(PM_ADC1, 7), pinManager.getADCPin(PM_ADC1, 8), pinManager.getADCPin(PM_ADC1, 9), pinManager.getADCPin(PM_ADC1, 10)); snprintf(a_pins, 64, "d.a_pins=[%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d];", pinManager.getADCPin(PM_ADC1, 0), pinManager.getADCPin(PM_ADC1, 1), pinManager.getADCPin(PM_ADC1, 2), pinManager.getADCPin(PM_ADC1, 3), pinManager.getADCPin(PM_ADC1, 4), pinManager.getADCPin(PM_ADC1, 5), pinManager.getADCPin(PM_ADC1, 6), pinManager.getADCPin(PM_ADC1, 7), pinManager.getADCPin(PM_ADC1, 8), pinManager.getADCPin(PM_ADC1, 9), pinManager.getADCPin(PM_ADC1, 10));
oappend(a_pins); oappend(a_pins);
// WLEDMM add HUB75 pins, as they are not stored directly in cfg.json
strcpy(ro_gpio, "d.h_pins=["); // WLEDMM we re-use this array, instead of creating an addition one; 140 bytes is more than enough for 14 pins.
bool isFirstPin = true;
for(int pinNr = 0; pinNr < WLED_NUM_PINS; pinNr++) {
if ((pinManager.isPinOk(pinNr)) && (pinManager.getPinOwner(pinNr) == PinOwner::HUB75)) {
sprintf(pinString, "%s%d", isFirstPin ? "" : ",", pinNr);
strcat(ro_gpio, pinString); isFirstPin = false;
}
}
oappend(ro_gpio);
oappend(SET_F("];"));
// WLEDMM same procedure for DMX pins
strcpy(ro_gpio, "d.x_pins=["); // WLEDMM we re-use this array, instead of creating an addition one; 140 bytes is more than enough for max 4 pins.
isFirstPin = true;
for(int pinNr = 0; pinNr < WLED_NUM_PINS; pinNr++) {
if ((pinManager.isPinOk(pinNr)) && (pinManager.getPinOwner(pinNr) == PinOwner::DMX || pinManager.getPinOwner(pinNr) == PinOwner::DMX_INPUT)) {
sprintf(pinString, "%s%d", isFirstPin ? "" : ",", pinNr);
strcat(ro_gpio, pinString); isFirstPin = false;
}
}
oappend(ro_gpio);
oappend(SET_F("];"));
} }
//get values for settings form in javascript //get values for settings form in javascript