From 197eb6198439d90a709c298baa87843114fe115c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 5 Dec 2022 15:41:49 +0100 Subject: load nodes from mesh_connector --- confui/mesh_connector.cpp | 22 +++++++++++++++++++--- confui/mesh_connector.h | 2 +- confui/ui_scroll_container.cpp | 3 ++- confui/ui_tab_node_overview.cpp | 17 ++++++++++++----- 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 _nodes; map _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 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 nodes = this->mainwindow->mesh_connector->get_nodes(); + map 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]); + } } -- cgit v1.2.3