diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-12-05 17:11:10 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-12-05 17:11:10 +0100 |
commit | 67e263e63994c908d34ec3344cb4dff830b356d1 (patch) | |
tree | eb3d81e2a1cd347d10ba90a1de2b4ab2c257ce47 /confui | |
parent | 8c3eaff565c9af6b12f59569982a42be1e66c69a (diff) |
automations tab layout done
Diffstat (limited to 'confui')
-rw-r--r-- | confui/mainwindow.cpp | 5 | ||||
-rw-r--r-- | confui/mesh_connector.cpp | 26 | ||||
-rw-r--r-- | confui/mesh_connector.h | 17 | ||||
-rw-r--r-- | confui/ui_automation.cpp | 24 | ||||
-rw-r--r-- | confui/ui_node.cpp | 2 | ||||
-rw-r--r-- | confui/ui_tab_automations.cpp | 10 | ||||
-rw-r--r-- | confui/ui_tab_automations.h | 3 | ||||
-rw-r--r-- | confui/ui_tab_node_overview.cpp | 18 |
8 files changed, 82 insertions, 23 deletions
diff --git a/confui/mainwindow.cpp b/confui/mainwindow.cpp index ca78603..2d06268 100644 --- a/confui/mainwindow.cpp +++ b/confui/mainwindow.cpp @@ -6,8 +6,11 @@ #include "ui_tab_automations.h" #include "ui_tab_node_overview.h" +CDMeshConnector* g_cd_mesh_connector = nullptr; + CDMainWindow::CDMainWindow(QWidget *parent) : QMainWindow(parent) { - this->mesh_connector = new CDMeshConnector(); + g_cd_mesh_connector = new CDMeshConnector(); + this->mesh_connector = g_cd_mesh_connector; QMenuBar* menu_bar = new QMenuBar(this); menu_bar->addMenu("ayo"); diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp index 3864c3b..c6c3988 100644 --- a/confui/mesh_connector.cpp +++ b/confui/mesh_connector.cpp @@ -2,6 +2,7 @@ #include <cstdio> #include <cstring> #include <algorithm> +#include <array> #include "mesh_connector.h" @@ -25,7 +26,7 @@ CDMeshConnector::CDMeshConnector() { cd_mac_addr_t temp_node_berta_address = { 0x00, 0xff, 0x21, 0x69, 0xf2, 0x31 }; memcpy(temp_node_berta->address, temp_node_berta_address, 6); - printf("adding dummy node berta...\n"); + printf("adding dummy node gerrit...\n"); char* temp_node_gerrit_name = (char*) malloc(6); memcpy(temp_node_gerrit_name, "gerrit", 6); @@ -34,7 +35,7 @@ CDMeshConnector::CDMeshConnector() { 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 }; + cd_mac_addr_t temp_node_gerrit_address = { 0x0e, 0xf9, 0x46, 0x4d, 0xe8, 0x02 }; memcpy(temp_node_gerrit->address, temp_node_gerrit_address, 6); _nodes.push_back(temp_node_berta); @@ -48,7 +49,7 @@ CDMeshConnector::CDMeshConnector() { CDMeshConnector::~CDMeshConnector() { map<cd_link_t, cd_s_automation*> links = get_links(); - vector<cd_s_node*> nodes = get_nodes(); + vector<cd_s_node*> nodes = get_raw_nodes(); // free all automation structs for (pair<cd_link_t, cd_s_automation*> link : links) @@ -69,10 +70,20 @@ void CDMeshConnector::refresh_nodes_sync() { return; } -vector<cd_s_node*> CDMeshConnector::get_nodes() { +vector<cd_s_node*> CDMeshConnector::get_raw_nodes() { return _nodes; } +map<cd_mac_addr_cpp_t, cd_s_node*> CDMeshConnector::get_nodes(bool provisioned) { + map<cd_mac_addr_cpp_t, cd_s_node*> nodes; + vector<cd_s_node*> raw_nodes = get_raw_nodes(); + for (cd_s_node* node : raw_nodes) { + if (provisioned && (node->provisioned == false)) continue; + nodes[cd_mac_to_cpp_arr(node->address)] = node; + } + return nodes; +} + map<cd_link_t, cd_s_automation*> CDMeshConnector::get_links() { return _links; } @@ -131,10 +142,15 @@ void CDMeshConnector::node_remove_network(cd_s_node* node_ptr) { return; } -string cd_node_mac_string(cd_mac_addr_t mac) { +string cd_mac_to_string(cd_mac_addr_t mac) { char* addr = nullptr; asprintf(&addr, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); string ret = addr; free(addr); return ret; } + +cd_mac_addr_cpp_t cd_mac_to_cpp_arr(cd_mac_addr_t mac) { + return { mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] }; +} + diff --git a/confui/mesh_connector.h b/confui/mesh_connector.h index b6aa94e..3b13b3c 100644 --- a/confui/mesh_connector.h +++ b/confui/mesh_connector.h @@ -5,13 +5,15 @@ #include <map> #include <string> -typedef uint32_t cd_link_t; -typedef uint8_t cd_mac_addr_t[6]; - using std::size_t; using std::vector; using std::map; using std::string; +using std::array; + +typedef uint32_t cd_link_t; +typedef uint8_t cd_mac_addr_t[6]; +typedef array<uint8_t, 6> cd_mac_addr_cpp_t; enum cd_e_automation_type { CD_AUTOMATION_TYPE_TOGGLE, @@ -44,8 +46,9 @@ public: virtual ~CDMeshConnector(); virtual void refresh_nodes_sync(); virtual void refresh_config_sync(); - virtual vector<cd_s_node*> get_nodes(); virtual map<cd_link_t, cd_s_automation*> get_links(); + virtual map<cd_mac_addr_cpp_t, cd_s_node*> get_nodes(bool provisioned); + virtual vector<cd_s_node*> get_raw_nodes(); virtual vector<cd_s_automation*> get_config(); virtual cd_link_t set_link(cd_s_node* button, cd_s_node* light, enum cd_e_automation_type action); virtual void remove_link(cd_link_t link_handle); @@ -55,4 +58,8 @@ public: virtual void node_remove_network(cd_s_node* node_ptr); }; -string cd_node_mac_string(cd_mac_addr_t mac); +extern CDMeshConnector* g_cd_mesh_connector; + +string cd_mac_to_string(cd_mac_addr_t mac); +cd_mac_addr_cpp_t cd_mac_to_cpp_arr(cd_mac_addr_t mac); + diff --git a/confui/ui_automation.cpp b/confui/ui_automation.cpp index f427930..2a04edb 100644 --- a/confui/ui_automation.cpp +++ b/confui/ui_automation.cpp @@ -1,7 +1,10 @@ #include "ui_automation.h" +#include "mesh_connector.h" + +using std::pair; CDAutomationWidget::~CDAutomationWidget() { } -CDAutomationWidget::CDAutomationWidget(cd_s_automation* automation, QWidget *parent) : QWidget(parent) { +CDAutomationWidget::CDAutomationWidget(cd_s_automation* automation, QWidget* parent) : QWidget(parent) { set_automation(automation); main_layout = new QHBoxLayout; @@ -28,8 +31,27 @@ void CDAutomationWidget::set_automation(cd_s_automation* automation) { void CDAutomationWidget::update() { button_remove->setText("Delete"); + map<cd_mac_addr_cpp_t, cd_s_node*> nodes = g_cd_mesh_connector->get_nodes(false); + + for (pair<cd_mac_addr_cpp_t, cd_s_node*> node : nodes) { + QString label = ""; + label.append(QString::fromLocal8Bit(node.second->name, node.second->name_len)); + label.append(" ("); + label.append(QString::fromStdString(cd_mac_to_string(node.second->address))); + label.append(")"); + + QString userData = QString::fromLocal8Bit((char*) node.second->address, 6); + dropdown_button->addItem(label, userData); + dropdown_light->addItem(label, userData); + } + + dropdown_button->setCurrentIndex(dropdown_button->findData(QString::fromLocal8Bit((char*) _automation->button->address, 6))); + dropdown_action->clear(); dropdown_action->addItem("Toggles", CD_AUTOMATION_TYPE_TOGGLE); dropdown_action->addItem("Switches on", CD_AUTOMATION_TYPE_TURN_ON); dropdown_action->addItem("Switches off", CD_AUTOMATION_TYPE_TURN_OFF); + dropdown_action->setCurrentIndex(dropdown_action->findData(_automation->type)); + + dropdown_light->setCurrentIndex(dropdown_light->findData(QString::fromLocal8Bit((char*) _automation->light->address, 6))); } diff --git a/confui/ui_node.cpp b/confui/ui_node.cpp index 3f1b43b..94768f9 100644 --- a/confui/ui_node.cpp +++ b/confui/ui_node.cpp @@ -28,7 +28,7 @@ void CDNodeWidget::update() { QString node_name = QString::fromLocal8Bit(_node->name, _node->name_len); label_node_name->setText(node_name); - QString node_address = QString::fromStdString(cd_node_mac_string(_node->address)); + QString node_address = QString::fromStdString(cd_mac_to_string(_node->address)); node_address.prepend("("); node_address.append(")"); label_node_address->setText(node_address); diff --git a/confui/ui_tab_automations.cpp b/confui/ui_tab_automations.cpp index 698b813..18b3073 100644 --- a/confui/ui_tab_automations.cpp +++ b/confui/ui_tab_automations.cpp @@ -29,6 +29,14 @@ CDAutomationsTabWidget::~CDAutomationsTabWidget() { } CDAutomationsTabWidget::CDAutomationsTabWidget(CDMainWindow* main_window) : QWidget(main_window) { this->mainwindow = main_window; main_layout = new CDScrollContainerLayout(this); + automations = new QVBoxLayout; + new_automation_button = new CDAddAutomationWidget(this); + + QWidget* automations_widget = new QWidget(this); + automations_widget->setLayout(automations); + + main_layout->addWidget(automations_widget); + main_layout->addWidget(new_automation_button); update(); setLayout(main_layout); @@ -44,7 +52,7 @@ void CDAutomationsTabWidget::update() { } else { widgets[link.first] = new CDAutomationWidget(link.second, this); } - main_layout->addWidget(widgets[link.first]); + automations->addWidget(widgets[link.first]); } } diff --git a/confui/ui_tab_automations.h b/confui/ui_tab_automations.h index 96c2387..3fd433a 100644 --- a/confui/ui_tab_automations.h +++ b/confui/ui_tab_automations.h @@ -5,11 +5,14 @@ #include "ui_scroll_container.h" #include "mainwindow.h" +class CDAddAutomationWidget; class CDAutomationsTabWidget : public QWidget { Q_OBJECT private: CDScrollContainerLayout* main_layout; + QVBoxLayout* automations; + CDAddAutomationWidget* new_automation_button; public: CDMainWindow *mainwindow = nullptr; diff --git a/confui/ui_tab_node_overview.cpp b/confui/ui_tab_node_overview.cpp index b3a79ee..3625249 100644 --- a/confui/ui_tab_node_overview.cpp +++ b/confui/ui_tab_node_overview.cpp @@ -6,6 +6,8 @@ #include "ui_tab_node_overview.h" #include "ui_node.h" +using std::pair; + CDNodeOverviewTabWidget::~CDNodeOverviewTabWidget() { } CDNodeOverviewTabWidget::CDNodeOverviewTabWidget(CDMainWindow* main_window) : QWidget(main_window) { this->mainwindow = main_window; @@ -16,17 +18,15 @@ CDNodeOverviewTabWidget::CDNodeOverviewTabWidget(CDMainWindow* main_window) : QW } void CDNodeOverviewTabWidget::update() { - vector<cd_s_node*> nodes = this->mainwindow->mesh_connector->get_nodes(); - map<uint8_t(*)[6], CDNodeWidget*> node_widgets; + map<cd_mac_addr_cpp_t, cd_s_node*> nodes = g_cd_mesh_connector->get_nodes(false); + map<cd_mac_addr_cpp_t, 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(); + for (pair<cd_mac_addr_cpp_t, cd_s_node*> node : nodes) { + if (node_widgets.count(node.first)) { // node is already in list + node_widgets[node.first]->update(); } else { - node_widgets[addr] = new CDNodeWidget(node, this); + node_widgets[node.first] = new CDNodeWidget(node.second, this); } - main_layout->addWidget(node_widgets[addr]); + main_layout->addWidget(node_widgets[node.first]); } } |