|
136 | 136 | getLoc(); |
137 | 137 | loadJS(getURL('/settings/s.js?p=1'), false); // If we set async false, file is loaded and executed, then next statement is processed |
138 | 138 | if (loc) d.Sf.action = getURL('/settings/wifi'); |
| 139 | + setTimeout(tE, 500); // wait for DOM to load before calling tE() |
139 | 140 | } |
| 141 | + |
| 142 | + var rC = 0; // remote count |
| 143 | + // toggle visibility of ESP-NOW remote list based on checkbox state |
| 144 | + function tE() { |
| 145 | + // keep the hidden input with MAC addresses, only toggle visibility of the list UI |
| 146 | + gId('rlc').style.display = d.Sf.RE.checked ? 'block' : 'none'; |
| 147 | + } |
| 148 | + // reset remotes: initialize empty list (called from xml.cpp) |
| 149 | + function rstR() { |
| 150 | + gId('rml').innerHTML = ''; // clear remote list |
| 151 | + } |
| 152 | + // add remote MAC to the list |
| 153 | + function aR(id, mac) { |
| 154 | + if (!/^[0-9A-F]{12}$/i.test(mac)) return; // check for valid hex string |
| 155 | + let inputs = d.querySelectorAll("#rml input"); |
| 156 | + for (let i of (inputs || [])) { |
| 157 | + if (i.value === mac) return; |
| 158 | + } |
| 159 | + let l = gId('rml'), r = cE('div'), i = cE('input'); |
| 160 | + i.type = 'text'; |
| 161 | + i.name = id; |
| 162 | + i.value = mac; |
| 163 | + i.maxLength = 12; |
| 164 | + i.minLength = 12; |
| 165 | + //i.onchange = uR; |
| 166 | + r.appendChild(i); |
| 167 | + let b = cE('button'); |
| 168 | + b.type = 'button'; |
| 169 | + b.className = 'sml'; |
| 170 | + b.innerText = '-'; |
| 171 | + b.onclick = (e) => { |
| 172 | + r.remove(); |
| 173 | + }; |
| 174 | + r.appendChild(b); |
| 175 | + l.appendChild(r); |
| 176 | + rC++; |
| 177 | + gId('+').style.display = gId("rml").childElementCount < 10 ? 'inline' : 'none'; // can't append to list anymore, hide button |
| 178 | + } |
| 179 | + |
140 | 180 | </script> |
141 | 181 | <style>@import url("style.css");</style> |
142 | 182 | </head> |
143 | 183 | <body onload="S()"> |
144 | | - <form id="form_s" name="Sf" method="post"> |
| 184 | + <form id="form_s" name="Sf" method="post"> |
145 | 185 | <div class="toprow"> |
146 | 186 | <div class="helpB"><button type="button" onclick="H('features/settings/#wifi-settings')">?</button></div> |
147 | 187 | <button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button><hr> |
@@ -202,11 +242,16 @@ <h3>ESP-NOW Wireless</h3> |
202 | 242 | <i class="warn">This firmware build does not include ESP-NOW support.<br></i> |
203 | 243 | </div> |
204 | 244 | <div id="ESPNOW"> |
205 | | - Enable ESP-NOW: <input type="checkbox" name="RE"><br> |
| 245 | + Enable ESP-NOW: <input type="checkbox" name="RE" onchange="tE()"><br> |
206 | 246 | <i>Listen for events over ESP-NOW<br> |
207 | | - Keep disabled if not using a remote or wireless sync, increases power consumption.<br></i> |
208 | | - Paired Remote MAC: <input type="text" name="RMAC" minlength="12" maxlength="12"><br> |
209 | | - Last device seen: <span class="rlid" onclick="d.Sf.RMAC.value=this.textContent;" style="cursor:pointer;">None</span> <br> |
| 247 | + Keep disabled if not using a remote or ESP-NOW sync, increases power consumption.<br></i> |
| 248 | + <div id="rlc"> |
| 249 | + Last device seen: <span class="rlid" id="ld">None</span> |
| 250 | + <button type="button" class="sml" id="+" onclick="aR('RM'+rC,gId('ld').textContent)">+</button><br> |
| 251 | + Linked MACs (10 max):<br> |
| 252 | + <div id="rml"> |
| 253 | + </div> |
| 254 | + </div> |
210 | 255 | </div> |
211 | 256 |
|
212 | 257 | <div id="ethd"> |
|
0 commit comments