Skip to content

Commit

Permalink
Add ability to toggle devices from nodes view.
Browse files Browse the repository at this point in the history
  • Loading branch information
blazoncek committed Jul 13, 2023
1 parent 42b2477 commit 6302056
Show file tree
Hide file tree
Showing 6 changed files with 2,042 additions and 1,997 deletions.
14 changes: 10 additions & 4 deletions wled00/NodeStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <IPAddress.h>

#define NODE_TYPE_ID_UNDEFINED 0
#define NODE_TYPE_ID_ESP8266 82
#define NODE_TYPE_ID_ESP32 32
#define NODE_TYPE_ID_ESP32S2 33
#define NODE_TYPE_ID_ESP8266 82 // should be 1
#define NODE_TYPE_ID_ESP32 32 // should be 2
#define NODE_TYPE_ID_ESP32S2 33 // etc
#define NODE_TYPE_ID_ESP32S3 34
#define NODE_TYPE_ID_ESP32C3 35

Expand All @@ -23,7 +23,13 @@ struct NodeStruct
String nodeName;
IPAddress ip;
uint8_t age;
uint8_t nodeType;
union {
uint8_t nodeType; // a waste of space as we only have 5 types
struct {
uint8_t type : 7; // still a waste of space (4 bits would be enough and future-proof)
bool on : 1;
};
};
uint32_t build;

NodeStruct() : age(0), nodeType(0), build(0)
Expand Down
7 changes: 5 additions & 2 deletions wled00/data/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ button {

.off {
color: var(--c-6) !important;
cursor: default !important;
/* cursor: default !important; */
}

.top .icons, .bot .icons {
Expand Down Expand Up @@ -1010,7 +1010,7 @@ textarea {
width: 50px !important;
}

.segname, .pname {
.segname, .pname, .bname {
white-space: nowrap;
text-align: center;
overflow: hidden;
Expand All @@ -1020,6 +1020,9 @@ textarea {
max-width: 170px;
position: relative;
}
.bname {
padding: 0 24px;
}

.segname .flr, .pname .flr {
transform: rotate(0deg);
Expand Down
28 changes: 26 additions & 2 deletions wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,15 @@ function generateListItemHtml(listName, id, name, clickAction, extraHtml = '', e
function btype(b)
{
switch (b) {
case 2:
case 32: return "ESP32";
case 3:
case 33: return "ESP32-S2";
case 4:
case 34: return "ESP32-S3";
case 5:
case 35: return "ESP32-C3";
case 1:
case 82: return "ESP8266";
}
return "?";
Expand All @@ -1028,8 +1033,9 @@ function populateNodes(i,n)
n.nodes.sort((a,b) => (a.name).localeCompare(b.name));
for (var o of n.nodes) {
if (o.name) {
var url = `<button class="btn" title="${o.ip}" onclick="location.assign('http://${o.ip}');">${bname(o)}</button>`;
urows += inforow(url,`${btype(o.type)}<br><i>${o.vid==0?"N/A":o.vid}</i>`);
let onoff = `<i class="icons e-icon flr ${o.type&0x80?'':'off'}" onclick="rmtTgl('${o.ip}',this);"">&#xe08f;</i>`;
var url = `<button class="btn" title="${o.ip}" onclick="location.assign('http://${o.ip}');"><div class="bname">${bname(o)}</div>${o.vid<2307130?'':onoff}</button>`;
urows += inforow(url,`${btype(o.type&0x7F)}<br><i>${o.vid==0?"N/A":o.vid}</i>`);
nnodes++;
}
}
Expand Down Expand Up @@ -2571,6 +2577,24 @@ function setBalance(b)
requestJson(obj);
}

function rmtTgl(ip,i) {
event.preventDefault();
event.stopPropagation();
fetch(`http://${ip}/win&T=2`, {method: 'get'})
.then((r)=>{
return r.text();
})
.then((t)=>{
let c = (new window.DOMParser()).parseFromString(t, "text/xml");
// perhaps just i.classList.toggle("off"); would be enough
if (c.getElementsByTagName('ac')[0].textContent === "0") {
i.classList.add("off");
} else {
i.classList.remove("off");
}
});
}

var hc = 0;
setInterval(()=>{
if (!isInfo) return;
Expand Down
Loading

0 comments on commit 6302056

Please sign in to comment.