aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-05 15:41:49 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-05 15:41:49 +0100
commit197eb6198439d90a709c298baa87843114fe115c (patch)
treea45a0330261eb0a65608bcaa04e2d7b1aa6580d7
parent052fde2c37b56ab4af4598878eb14ae3d4fe204e (diff)
load nodes from mesh_connector
-rw-r--r--confui/mesh_connector.cpp22
-rw-r--r--confui/mesh_connector.h2
-rw-r--r--confui/ui_scroll_container.cpp3
-rw-r--r--confui/ui_tab_node_overview.cpp17
4 files changed, 34 insertions, 10 deletions
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp
index f2d5ca2..3864c3b 100644
--- a/confui/mesh_connector.cpp
+++ b/confui/mesh_connector.cpp
@@ -12,10 +12,10 @@ cd_link_t CDMeshConnector::get_new_map_id() {
}
CDMeshConnector::CDMeshConnector() {
- printf("adding dummy node and automation...\n");
+ printf("adding dummy node berta...\n");
char* temp_node_berta_name = (char*) malloc(5);
- strncpy(temp_node_berta_name, "berta", 5);
+ memcpy(temp_node_berta_name, "berta", 5);
cd_s_node* temp_node_berta = (cd_s_node*) malloc(sizeof(cd_s_node));
temp_node_berta->name = temp_node_berta_name;
@@ -23,10 +23,26 @@ CDMeshConnector::CDMeshConnector() {
temp_node_berta->light_on = false;
temp_node_berta->provisioned = false;
cd_mac_addr_t temp_node_berta_address = { 0x00, 0xff, 0x21, 0x69, 0xf2, 0x31 };
- strncpy((char*)temp_node_berta->address, (char*)&temp_node_berta_address, 6);
+ memcpy(temp_node_berta->address, temp_node_berta_address, 6);
+
+ printf("adding dummy node berta...\n");
+ char* temp_node_gerrit_name = (char*) malloc(6);
+ memcpy(temp_node_gerrit_name, "gerrit", 6);
+
+ cd_s_node* temp_node_gerrit = (cd_s_node*) malloc(sizeof(cd_s_node));
+ temp_node_gerrit->name = temp_node_gerrit_name;
+ temp_node_gerrit->name_len = 6;
+ temp_node_gerrit->light_on = false;
+ temp_node_gerrit->provisioned = false;
+ cd_mac_addr_t temp_node_gerrit_address = { 0x00, 0xff, 0x21, 0x69, 0xf2, 0x31 };
+ memcpy(temp_node_gerrit->address, temp_node_gerrit_address, 6);
_nodes.push_back(temp_node_berta);
+ _nodes.push_back(temp_node_gerrit);
set_link(temp_node_berta, temp_node_berta, CD_AUTOMATION_TYPE_TOGGLE);
+ set_link(temp_node_berta, temp_node_gerrit, CD_AUTOMATION_TYPE_TOGGLE);
+ set_link(temp_node_gerrit, temp_node_berta, CD_AUTOMATION_TYPE_TURN_OFF);
+ set_link(temp_node_gerrit, temp_node_gerrit, CD_AUTOMATION_TYPE_TURN_ON);
return;
}
diff --git a/confui/mesh_connector.h b/confui/mesh_connector.h
index 3de6eca..b6aa94e 100644
--- a/confui/mesh_connector.h
+++ b/confui/mesh_connector.h
@@ -37,7 +37,7 @@ class CDMeshConnector {
private:
vector<cd_s_node*> _nodes;
map<cd_link_t, cd_s_automation*> _links;
- cd_link_t _fresh_map_id;
+ cd_link_t _fresh_map_id = 0;
virtual cd_link_t get_new_map_id();
public:
CDMeshConnector();
diff --git a/confui/ui_scroll_container.cpp b/confui/ui_scroll_container.cpp
index 5a412f8..6b15221 100644
--- a/confui/ui_scroll_container.cpp
+++ b/confui/ui_scroll_container.cpp
@@ -11,7 +11,8 @@ CDScrollContainerLayout::CDScrollContainerLayout(QWidget *parent) : QVBoxLayout(
scroll_area->setBackgroundRole(QPalette::Window);
scroll_area->setFrameShadow(QFrame::Plain);
scroll_area->setWidget(scroll_container);
- scroll_area->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+ scroll_area->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
+ scroll_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll_container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
scroll_container->setLayout(scroll_inner);
diff --git a/confui/ui_tab_node_overview.cpp b/confui/ui_tab_node_overview.cpp
index 44ef788..b3a79ee 100644
--- a/confui/ui_tab_node_overview.cpp
+++ b/confui/ui_tab_node_overview.cpp
@@ -11,15 +11,22 @@ CDNodeOverviewTabWidget::CDNodeOverviewTabWidget(CDMainWindow* main_window) : QW
this->mainwindow = main_window;
main_layout = new CDScrollContainerLayout(this);
- vector<cd_s_node*> nodes = this->mainwindow->mesh_connector->get_nodes();
- CDNodeWidget* nd_w = new CDNodeWidget(nodes[0], this);
-
- main_layout->addWidget(nd_w);
-
update();
setLayout(main_layout);
}
void CDNodeOverviewTabWidget::update() {
+ vector<cd_s_node*> nodes = this->mainwindow->mesh_connector->get_nodes();
+ map<uint8_t(*)[6], CDNodeWidget*> node_widgets;
+ for (cd_s_node* node : nodes) {
+ // c++ cast from uint8_t[6] to uint8_t* with length 6
+ uint8_t (*addr)[6] = (uint8_t (*)[6]) node->address;
+ if (node_widgets.count(addr)) { // node is already in list
+ node_widgets[addr]->update();
+ } else {
+ node_widgets[addr] = new CDNodeWidget(node, this);
+ }
+ main_layout->addWidget(node_widgets[addr]);
+ }
}