|
33 | 33 | GetV(); |
34 | 34 | for (let k=0; k<d.rsvd.length; k++) { pins.push(d.rsvd[k]); pinO.push("rsvd"); } |
35 | 35 | 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; |
41 | 41 | }); |
42 | 42 | // error event |
43 | 43 | scE.addEventListener("error", (ev) => { |
|
62 | 62 | function isI(n) { return n === +n && n === (n|0); } |
63 | 63 | function check(o,k) { // input object, pin owner key |
64 | 64 | var n = o.name.replace("[]","").substr(-3); |
| 65 | + // console.log("check", o, k, n, pins, pinO); |
65 | 66 | if (o.type=="number" && n.substr(0,3)=="pin") { |
66 | 67 | for (var i=0; i<pins.length; i++) { |
67 | 68 | if (k==pinO[i]) continue; |
|
70 | 71 | } |
71 | 72 | } else { |
72 | 73 | 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; |
78 | 79 | default: return; |
79 | 80 | } |
80 | 81 | for (var i=0; i<pins.length; i++) { |
|
111 | 112 | return s.replace(/[\W_]/g,' ').replace(/(^\w{1})|(\s+\w{1})/g, l=>l.toUpperCase()); // replace - and _ with space, capitalize every 1st letter |
112 | 113 | } |
113 | 114 | function addField(k,f,o,a=false) { //key, field, (sub)object, isArray |
| 115 | + // console.log("addField", k, f, o, a); |
114 | 116 | if (isO(o)) { |
115 | 117 | urows += '<hr class="sml">'; |
116 | 118 | if (f!=='unknown' && !k.includes(":")) urows += `<p><u>${initCap(f)}</u></p>`; //WLEDMM show group title |
|
131 | 133 | break; |
132 | 134 | case "number": |
133 | 135 | c = `value="${o}"`; |
| 136 | + // console.log("addField nr", c); |
134 | 137 | if (f.substr(-3)==="pin") { |
135 | 138 | c += ` max="${d.max_gpio}" min="-1" class="s"`; |
| 139 | + // console.log("addField nr pin should not happen", c); |
136 | 140 | t = "int"; |
137 | 141 | } else { |
138 | 142 | c += ' step="any" class="xxl"'; |
|
146 | 150 | // https://stackoverflow.com/questions/11657123/posting-both-checked-and-unchecked-checkboxes |
147 | 151 | if (t=="checkbox") urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="false">`; |
148 | 152 | 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>`; |
150 | 184 | } |
151 | 185 | } |
152 | 186 | // https://stackoverflow.com/questions/39729741/javascript-change-input-text-to-select-option |
|
184 | 218 | if (c.value == sel.dataset.val) sel.selectedIndex = i; |
185 | 219 | } |
186 | 220 | } |
| 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 | + } |
187 | 232 | // https://stackoverflow.com/questions/26440494/insert-text-after-this-input-element-with-javascript |
188 | 233 | function addInfo(name,el,txt, txt2="") { |
189 | 234 | let obj = d.getElementsByName(name); |
|
208 | 253 | umCfg = json.um; |
209 | 254 | getPins(json); |
210 | 255 | 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') |
211 | 263 | if (isO(umCfg)) { |
212 | 264 | //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') |
216 | 265 | for (const [k,o] of Object.entries(umCfg)) { |
217 | 266 | if (userMod == k) { |
218 | 267 | urows += `<hr><h3>${k}</h3><div name="${k}:help"></div>`; |
|
222 | 271 | if (userMod != null && urows==="") urows = "Usermods configuration not found.<br>Press <i>Save</i> to initialize defaults."; |
223 | 272 | } |
224 | 273 | //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"; |
226 | 275 |
|
227 | 276 | gId("um").innerHTML = urows; |
228 | 277 | var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=8'; |
|
254 | 303 | <h2>Usermod Setup</h2> |
255 | 304 | Global I<sup>2</sup>C GPIOs (HW)<br> |
256 | 305 | <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"> |
259 | 308 | <hr class="sml"> |
260 | 309 | Global SPI GPIOs (HW)<br> |
261 | 310 | <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"> |
265 | 314 | </div> |
266 | 315 | <div id="um">Loading settings...</div> |
267 | 316 | <hr><button type="button" onclick="B()">Back</button><button type="submit">Save</button> |
|
0 commit comments