aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--confui/confui.pro7
-rw-r--r--confui/mainwindow.cpp2
-rw-r--r--confui/mesh_connector.cpp8
-rw-r--r--confui/mesh_connector.h6
-rw-r--r--confui/ui_node.cpp38
-rw-r--r--confui/ui_node.h16
-rw-r--r--confui/ui_node_overview.cpp19
7 files changed, 92 insertions, 4 deletions
diff --git a/confui/confui.pro b/confui/confui.pro
index 761cd31..2fef635 100644
--- a/confui/confui.pro
+++ b/confui/confui.pro
@@ -5,13 +5,16 @@ SOURCES += \
mainwindow.cpp \
mesh_connector.cpp \
ui_automations.cpp \
- ui_node_overview.cpp
+ ui_node_overview.cpp \
+ ui_node.cpp
HEADERS += \
mainwindow.h \
mesh_connector.h \
ui_automations.h \
- ui_node_overview.h
+ ui_node_overview.h \
+ ui_node.h
CONFIG += c++17
+CONFIG += force_debug_info
diff --git a/confui/mainwindow.cpp b/confui/mainwindow.cpp
index b6d952b..27bdb6c 100644
--- a/confui/mainwindow.cpp
+++ b/confui/mainwindow.cpp
@@ -16,8 +16,8 @@ CDMainWindow::CDMainWindow(QWidget *parent) : QMainWindow(parent) {
this->automations_widget = new CDAutomationsWidget(this);
this->node_overview_widget = new CDNodeOverviewWidget(this);
- tab_bar_widget->addTab(this->automations_widget, "automations");
tab_bar_widget->addTab(this->node_overview_widget, "node overview");
+ tab_bar_widget->addTab(this->automations_widget, "automations");
setMenuBar(menu_bar);
setCentralWidget(tab_bar_widget);
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp
index 004ee6c..ffddde1 100644
--- a/confui/mesh_connector.cpp
+++ b/confui/mesh_connector.cpp
@@ -1,3 +1,4 @@
+#include <cstdio>
#include "mesh_connector.h"
CDMeshConnector::CDMeshConnector() {
@@ -56,3 +57,10 @@ void CDMeshConnector::node_remove_network(cd_s_node* node_ptr) {
return;
}
+string cd_node_mac_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;
+}
diff --git a/confui/mesh_connector.h b/confui/mesh_connector.h
index 070a83c..b248e27 100644
--- a/confui/mesh_connector.h
+++ b/confui/mesh_connector.h
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <vector>
#include <map>
+#include <string>
typedef uint32_t cd_link_t;
typedef uint8_t cd_mac_addr_t[6];
@@ -10,6 +11,7 @@ typedef uint8_t cd_mac_addr_t[6];
using std::size_t;
using std::vector;
using std::map;
+using std::string;
enum cd_e_automation_type {
CD_AUTOMATION_TYPE_TOGGLE,
@@ -20,7 +22,7 @@ enum cd_e_automation_type {
typedef struct {
cd_mac_addr_t address;
size_t name_len;
- char* name;
+ const char* name;
bool light_on;
bool provisioned;
} cd_s_node;
@@ -49,3 +51,5 @@ public:
virtual void node_join_network(cd_s_node* node_ptr);
virtual void node_remove_network(cd_s_node* node_ptr);
};
+
+string cd_node_mac_string(cd_mac_addr_t mac);
diff --git a/confui/ui_node.cpp b/confui/ui_node.cpp
new file mode 100644
index 0000000..38c189e
--- /dev/null
+++ b/confui/ui_node.cpp
@@ -0,0 +1,38 @@
+#include <QWidget>
+#include <QLabel>
+#include <QHBoxLayout>
+#include <QCheckBox>
+#include <QPushButton>
+#include <QString>
+
+#include "ui_node.h"
+
+CDNodeWidget::~CDNodeWidget() { }
+CDNodeWidget::CDNodeWidget(cd_s_node* node, QWidget *parent) : QWidget(parent) {
+ _node = node;
+ QHBoxLayout* main_layout = new QHBoxLayout;
+ QHBoxLayout* float_left = new QHBoxLayout;
+ QHBoxLayout* float_right = new QHBoxLayout;
+
+ QString node_name = QString::fromLocal8Bit(_node->name, _node->name_len);
+ QString node_address = QString::fromStdString(cd_node_mac_string(_node->address));
+ node_address.prepend("(");
+ node_address.append(")");
+ QLabel* label_node_name = new QLabel(node_name, this);
+ QLabel* label_node_address = new QLabel(node_address, this);
+ float_left->addWidget(label_node_name);
+ float_left->addWidget(label_node_address);
+
+ float_left->addStretch();
+ float_right->addStretch();
+
+ QCheckBox* switch_on_off = new QCheckBox("on", this);
+ switch_on_off->setCheckable(_node->provisioned);
+ QPushButton* button_add_remove = new QPushButton(_node->provisioned ? "Remove from network" : "Join network", this);
+ float_right->addWidget(switch_on_off);
+ float_right->addWidget(button_add_remove);
+
+ main_layout->addLayout(float_left);
+ main_layout->addLayout(float_right);
+ setLayout(main_layout);
+}
diff --git a/confui/ui_node.h b/confui/ui_node.h
new file mode 100644
index 0000000..c37f373
--- /dev/null
+++ b/confui/ui_node.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <QWidget>
+
+#include "mesh_connector.h"
+
+class CDNodeWidget : public QWidget {
+ Q_OBJECT
+
+private:
+ cd_s_node* _node;
+
+public:
+ CDNodeWidget(cd_s_node* node, QWidget *parent = nullptr);
+ virtual ~CDNodeWidget();
+};
diff --git a/confui/ui_node_overview.cpp b/confui/ui_node_overview.cpp
index eb6f976..3e63ddd 100644
--- a/confui/ui_node_overview.cpp
+++ b/confui/ui_node_overview.cpp
@@ -1,9 +1,28 @@
#include <QWidget>
#include <QLabel>
+#include <QVBoxLayout>
#include "ui_node_overview.h"
+#include "ui_node.h"
CDNodeOverviewWidget::~CDNodeOverviewWidget() { }
CDNodeOverviewWidget::CDNodeOverviewWidget(CDMainWindow* main_window) : QWidget(main_window) {
this->mainwindow = main_window;
+
+ QVBoxLayout* main_layout = new QVBoxLayout;
+
+ const char* n_name = "berta";
+ cd_s_node n = {
+ .address = { 0x00, 0xff, 0x21, 0x69, 0xf2, 0x31 },
+ .name_len = strlen(n_name),
+ .name = n_name,
+ .light_on = false,
+ .provisioned = false,
+ };
+
+ CDNodeWidget* nd_w = new CDNodeWidget(&n, this);
+
+ main_layout->addWidget(nd_w);
+
+ setLayout(main_layout);
}