Skip to content

Commit 5c161db

Browse files
committed
Add dropdowns for pins (part 1 of 2)
Set for Audioreactive and 4linedisplay usermods Prepare for globals (part2): Rename SDA to SDApin etc
1 parent e6bd66d commit 5c161db

File tree

6 files changed

+296
-232
lines changed

6 files changed

+296
-232
lines changed

usermods/audioreactive/audio_reactive.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,28 +2059,29 @@ class AudioReactive : public Usermod {
20592059
oappend(SET_F("addOption(dd,'Send',1);"));
20602060
oappend(SET_F("addOption(dd,'Receive',2);"));
20612061
oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'<i>requires reboot!</i>');")); // 0 is field type, 1 is actual field
2062-
#ifdef I2S_SDPIN
2063-
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'<i>sd/data/dout, &#9100; ")); oappendi(I2S_SDPIN); oappend("</i>','I2S SD');");
2064-
#else
20652062
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'<i>sd/data/dout</i>','I2S SD');"));
2063+
#ifdef I2S_SDPIN
2064+
oappend(SET_F("replaceOption('AudioReactive:digitalmic:pin[]',0,'")); oappendi(I2S_SDPIN); oappend(" ⎌',"); oappendi(I2S_SDPIN); oappend(");");
20662065
#endif
2066+
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'<i>ws/clk/lrck</i>','I2S WS');"));
20672067
#ifdef I2S_WSPIN
2068-
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'<i>ws/clk/lrck, &#9100; ")); oappendi(I2S_WSPIN); oappend("</i>','I2S WS');");
2068+
oappend(SET_F("replaceOption('AudioReactive:digitalmic:pin[]',1,'")); oappendi(I2S_WSPIN); oappend(" ⎌',"); oappendi(I2S_WSPIN); oappend(");");
20692069
#else
2070-
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'<i>ws/clk/lrck</i>','I2S WS');"));
20712070
#endif
2071+
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'<i>sck/bclk</i>','I2S SCK');"));
20722072
#ifdef I2S_CKPIN
2073-
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'<i>sck/bclk, &#9100; ")); oappendi(I2S_CKPIN); oappend("</i>','I2S SCK');");
2073+
oappend(SET_F("replaceOption('AudioReactive:digitalmic:pin[]',2,'")); oappendi(I2S_CKPIN); oappend(" ⎌',"); oappendi(I2S_CKPIN); oappend(");");
20742074
#else
2075-
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'<i>sck/bclk</i>','I2S SCK');"));
20762075
#endif
20772076
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
20782077
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'<i>only use -1, 0, 1 or 3</i>','I2S MCLK');"));
20792078
#else
20802079
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'<i>master clock</i>','I2S MCLK');"));
20812080
#endif
20822081
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'','I2C SDA');"));
2082+
oappend(SET_F("replaceOption('AudioReactive:digitalmic:pin[]',4,'use global (")); oappendi(i2c_sda); oappend(")',-1);");
20832083
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'','I2C SCL');"));
2084+
oappend(SET_F("replaceOption('AudioReactive:digitalmic:pin[]',5,'use global (")); oappendi(i2c_sda); oappend(")',-1);");
20842085
}
20852086

20862087

usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,16 +1048,16 @@ class FourLineDisplayUsermod : public Usermod {
10481048
oappend(SET_F("addOption(dd,'SSD1306 SPI',6);"));
10491049
oappend(SET_F("addOption(dd,'SSD1306 SPI 128x64',7);"));
10501050
// WLEDMM add defaults
1051+
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'','I2C/SPI CLK');"));
10511052
#ifdef FLD_PIN_SCL
1052-
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'<i>-1 use global, &#9100; ")); oappendi(FLD_PIN_SCL); oappend("</i>','I2C/SPI CLK');");
1053-
#else
1054-
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'<i>-1 use global</i>','I2C/SPI CLK');"));
1053+
oappend(SET_F("replaceOption('4LineDisplay:pin[]',0,'")); oappendi(FLD_PIN_SCL); oappend(" ⎌',"); oappendi(FLD_PIN_SCL); oappend(");");
10551054
#endif
1055+
oappend(SET_F("replaceOption('4LineDisplay:pin[]',0,'use global (")); oappendi(i2c_scl); oappend(")',-1);");
1056+
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'','I2C/SPI DTA');"));
10561057
#ifdef FLD_PIN_SDA
1057-
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'<i>-1 use global, &#9100; ")); oappendi(FLD_PIN_SDA); oappend("</i>','I2C/SPI DTA');");
1058-
#else
1059-
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'<i>-1 use global</i>','I2C/SPI DTA');"));
1058+
oappend(SET_F("replaceOption('4LineDisplay:pin[]',1,'")); oappendi(FLD_PIN_SDA); oappend(" ⎌',"); oappendi(FLD_PIN_SDA); oappend(");");
10601059
#endif
1060+
oappend(SET_F("replaceOption('4LineDisplay:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);");
10611061
oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'','SPI CS');"));
10621062
oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'','SPI DC');"));
10631063
oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'','SPI RST');"));

wled00/data/settings_um.htm

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
GetV();
3434
for (let k=0; k<d.rsvd.length; k++) { pins.push(d.rsvd[k]); pinO.push("rsvd"); }
3535
if (d.um_p[0]==-1) d.um_p.shift();
36-
d.Sf.SDA.max = d.max_gpio;
37-
d.Sf.SCL.max = d.max_gpio;
38-
d.Sf.MOSI.max = d.max_gpio;
39-
d.Sf.SCLK.max = d.max_gpio;
40-
d.Sf.MISO.max = d.max_gpio;
36+
d.Sf.SDApin.max = d.max_gpio;
37+
d.Sf.SCLpin.max = d.max_gpio;
38+
d.Sf.MOSIpin.max = d.max_gpio;
39+
d.Sf.SCLKpin.max = d.max_gpio;
40+
d.Sf.MISOpin.max = d.max_gpio;
4141
});
4242
// error event
4343
scE.addEventListener("error", (ev) => {
@@ -62,6 +62,7 @@
6262
function isI(n) { return n === +n && n === (n|0); }
6363
function check(o,k) { // input object, pin owner key
6464
var n = o.name.replace("[]","").substr(-3);
65+
// console.log("check", o, k, n, pins, pinO);
6566
if (o.type=="number" && n.substr(0,3)=="pin") {
6667
for (var i=0; i<pins.length; i++) {
6768
if (k==pinO[i]) continue;
@@ -70,11 +71,11 @@
7071
}
7172
} else {
7273
switch (o.name) {
73-
case "SDA": break;
74-
case "SCL": break;
75-
case "MOSI": break;
76-
case "SCLK": break;
77-
case "MISO": break;
74+
case "SDApin": break;
75+
case "SCLpin": break;
76+
case "MOSIpin": break;
77+
case "SCLKpin": break;
78+
case "MISOpin": break;
7879
default: return;
7980
}
8081
for (var i=0; i<pins.length; i++) {
@@ -111,6 +112,7 @@
111112
return s.replace(/[\W_]/g,' ').replace(/(^\w{1})|(\s+\w{1})/g, l=>l.toUpperCase()); // replace - and _ with space, capitalize every 1st letter
112113
}
113114
function addField(k,f,o,a=false) { //key, field, (sub)object, isArray
115+
// console.log("addField", k, f, o, a);
114116
if (isO(o)) {
115117
urows += '<hr class="sml">';
116118
if (f!=='unknown' && !k.includes(":")) urows += `<p><u>${initCap(f)}</u></p>`; //WLEDMM show group title
@@ -131,8 +133,10 @@
131133
break;
132134
case "number":
133135
c = `value="${o}"`;
136+
// console.log("addField nr", c);
134137
if (f.substr(-3)==="pin") {
135138
c += ` max="${d.max_gpio}" min="-1" class="s"`;
139+
// console.log("addField nr pin should not happen", c);
136140
t = "int";
137141
} else {
138142
c += ' step="any" class="xxl"';
@@ -146,7 +150,37 @@
146150
// https://stackoverflow.com/questions/11657123/posting-both-checked-and-unchecked-checkboxes
147151
if (t=="checkbox") urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="false">`;
148152
else if (!a) urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="${t}">`;
149-
urows += `<input type="${t==="int"?"number":t}" name="${k}:${f}${a?"[]":""}" ${c} oninput="check(this,'${k.substr(k.indexOf(":")+1)}')"><br>`;
153+
// make a dropdown for pin variables
154+
if (f.includes("pin")) { //} || f == "SDApin" || f == "SCLpin" || f == "MOSIpin" || f == "SCLKpin" || f == "MISOpin") {
155+
var n = this.name.replace("[]","").substr(-3);
156+
// console.log("addPin", k, f, o, a, n, pins, pinO);
157+
urows += `<select name="${k}:${f}${a?"[]":""}">`;
158+
// urows += `<option value="-1">Use global</option>`;
159+
// urows += `<option value="-2">Use ⎌</option>`;
160+
for (var j=-1; j<=39; j++) { // all possible pins (d.max_gpio not working)
161+
let foundPin = -1;
162+
for (var i=0; i<pins.length; i++) { // check if pin is reserved
163+
if (pins[i] == j) foundPin = i;
164+
}
165+
urows += `<option value="${j}"`;
166+
if (j==o) urows += ` selected`; //add selected value
167+
if (foundPin >=0) {// already reserved pin
168+
if (!k.includes(pinO[foundPin]) && pinO[foundPin] != "if") urows += ` disabled`;
169+
}
170+
if (j==-1) urows += `>undefined`; else urows += `>${j}`; // don't show -1
171+
if (foundPin >=0) {// already reserved pin
172+
urows += ` ${pinO[foundPin]}`;
173+
if (k.includes(pinO[foundPin]) || pinO[foundPin] == "if") urows += ` 😀`; else urows += ` ⛔`; //add pins assigned here
174+
}
175+
urows += `</option>`;
176+
// if (j==5) //exclude pin 6 to 11
177+
// j=11
178+
}
179+
urows += `</select>`;
180+
}
181+
else
182+
urows += `<input type="${t==="int"?"number":t}" name="${k}:${f}${a?"[]":""}" ${c} oninput="check(this,'${k.substr(k.indexOf(":")+1)}')">`;
183+
urows += `<br>`;
150184
}
151185
}
152186
// https://stackoverflow.com/questions/39729741/javascript-change-input-text-to-select-option
@@ -184,6 +218,17 @@
184218
if (c.value == sel.dataset.val) sel.selectedIndex = i;
185219
}
186220
}
221+
//WLEDMM: replaceOption to set build flag defaults and globals
222+
function replaceOption(name,el,txt,val) {
223+
let obj = d.getElementsByName(name);
224+
if (obj[el]) {
225+
let sel = obj[el];
226+
for (let i=0; i<sel.childNodes.length; i++) {
227+
let c = sel.childNodes[i];
228+
if (c.value == val) c.text = txt;
229+
}
230+
}
231+
}
187232
// https://stackoverflow.com/questions/26440494/insert-text-after-this-input-element-with-javascript
188233
function addInfo(name,el,txt, txt2="") {
189234
let obj = d.getElementsByName(name);
@@ -208,11 +253,15 @@
208253
umCfg = json.um;
209254
getPins(json);
210255
urows="";
256+
// addField("SCL", "pin", -1, true);
257+
// addField("SCL", "pin", -1, true);
258+
// addInfo('SCL:pin[]',0,'','SCL');
259+
// addInfo('SCL:pin[]',1,'','SCLK');
260+
const queryString = window.location.search;
261+
const urlParams = new URLSearchParams(queryString);
262+
const userMod = urlParams.get('um')
211263
if (isO(umCfg)) {
212264
//WLEDMM: read url parameter. e.g. um=AudioReactive and if set only add the usermod with the same name
213-
const queryString = window.location.search;
214-
const urlParams = new URLSearchParams(queryString);
215-
const userMod = urlParams.get('um')
216265
for (const [k,o] of Object.entries(umCfg)) {
217266
if (userMod == k) {
218267
urows += `<hr><h3>${k}</h3><div name="${k}:help"></div>`;
@@ -222,7 +271,7 @@
222271
if (userMod != null && urows==="") urows = "Usermods configuration not found.<br>Press <i>Save</i> to initialize defaults.";
223272
}
224273
//WLEDMM: only show globalGPIOs if no usermod info is shown (url without um parameter)
225-
gId("globalGPIOs").style.display = urows===""?"block":"none";
274+
gId("globalGPIOs").style.display = (userMod == null)?"block":"none";
226275

227276
gId("um").innerHTML = urows;
228277
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=8';
@@ -254,14 +303,14 @@
254303
<h2>Usermod Setup</h2>
255304
Global I<sup>2</sup>C GPIOs (HW)<br>
256305
<i style="color: orange;">(only changable on ESP32, change requires reboot!)</i><br>
257-
SDA:<input type="number" min="-1" max="48" name="SDA" onchange="check(this,'if')" class="s" placeholder="SDA"><br>
258-
SCL:<input type="number" min="-1" max="48" name="SCL" onchange="check(this,'if')" class="s" placeholder="SCL">
306+
SDA:<input type="number" min="-1" max="48" name="SDApin" onchange="check(this,'if')" class="s" placeholder="SDApin"><br>
307+
SCL:<input type="number" min="-1" max="48" name="SCLpin" onchange="check(this,'if')" class="s" placeholder="SCLpin">
259308
<hr class="sml">
260309
Global SPI GPIOs (HW)<br>
261310
<i style="color: orange;">(only changable on ESP32, change requires reboot!)</i><br>
262-
MOSI:<input type="number" min="-1" max="48" name="MOSI" onchange="check(this,'if')" class="s" placeholder="MOSI"><br>
263-
MISO:<input type="number" min="-1" max="48" name="MISO" onchange="check(this,'if')" class="s" placeholder="MISO"><br>
264-
SCLK:<input type="number" min="-1" max="48" name="SCLK" onchange="check(this,'if')" class="s" placeholder="SCLK">
311+
MOSI:<input type="number" min="-1" max="48" name="MOSIpin" onchange="check(this,'if')" class="s" placeholder="MOSIpin"><br>
312+
MISO:<input type="number" min="-1" max="48" name="MISOpin" onchange="check(this,'if')" class="s" placeholder="MISOpin"><br>
313+
SCLK:<input type="number" min="-1" max="48" name="SCLKpin" onchange="check(this,'if')" class="s" placeholder="SCLKpin">
265314
</div>
266315
<div id="um">Loading settings...</div>
267316
<hr><button type="button" onclick="B()">Back</button><button type="submit">Save</button>

0 commit comments

Comments
 (0)