aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-07 16:17:37 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-07 16:17:37 +0100
commit170f1d1dc4291aaac001e69002f5c80d03798e52 (patch)
tree21de0e1329adfb89b425b478d3972224eadee499
parent67e263e63994c908d34ec3344cb4dff830b356d1 (diff)
add CDMeshConnector routines to CDNodeWidget
-rw-r--r--confui/mesh_connector.cpp3
-rw-r--r--confui/mesh_connector.h2
-rw-r--r--confui/ui_node.cpp18
-rw-r--r--confui/ui_node.h2
4 files changed, 22 insertions, 3 deletions
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp
index c6c3988..19f899e 100644
--- a/confui/mesh_connector.cpp
+++ b/confui/mesh_connector.cpp
@@ -124,8 +124,7 @@ cd_s_node* CDMeshConnector::get_node_by_id(cd_mac_addr_t address) {
return node;
}
-void CDMeshConnector::set_node(cd_s_node* node_ptr, bool light_status) {
- node_ptr->light_on = light_status;
+void CDMeshConnector::update_node(cd_s_node* node_ptr) {
printf("turning %.*s %s\n", (int) node_ptr->name_len, node_ptr->name, node_ptr->light_on ? "on" : "off");
return;
}
diff --git a/confui/mesh_connector.h b/confui/mesh_connector.h
index 3b13b3c..2d9931e 100644
--- a/confui/mesh_connector.h
+++ b/confui/mesh_connector.h
@@ -53,7 +53,7 @@ public:
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);
virtual cd_s_node* get_node_by_id(cd_mac_addr_t address);
- virtual void set_node(cd_s_node* node_ptr, bool light_status);
+ virtual void update_node(cd_s_node* node_ptr);
virtual void node_join_network(cd_s_node* node_ptr);
virtual void node_remove_network(cd_s_node* node_ptr);
};
diff --git a/confui/ui_node.cpp b/confui/ui_node.cpp
index 94768f9..c810c29 100644
--- a/confui/ui_node.cpp
+++ b/confui/ui_node.cpp
@@ -16,6 +16,9 @@ CDNodeWidget::CDNodeWidget(cd_s_node* node, QWidget *parent) : QWidget(parent) {
main_layout->addWidget(switch_on_off);
main_layout->addWidget(button_add_remove);
+ connect(button_add_remove, &QPushButton::clicked, this, &CDNodeWidget::toggle_provision);
+ connect(switch_on_off, &QCheckBox::toggled, this, &CDNodeWidget::update_led);
+
update();
setLayout(main_layout);
}
@@ -40,3 +43,18 @@ void CDNodeWidget::update() {
button_add_remove->setText(_node->provisioned ? "Remove from network" : "Join network");
}
+
+void CDNodeWidget::toggle_provision() {
+ if (_node->provisioned) g_cd_mesh_connector->node_remove_network(_node);
+ else g_cd_mesh_connector->node_join_network(_node);
+
+ update();
+}
+
+void CDNodeWidget::update_led(bool on) {
+ _node->light_on = on;
+ g_cd_mesh_connector->update_node(_node);
+
+ update();
+}
+
diff --git a/confui/ui_node.h b/confui/ui_node.h
index 0b7049c..93fc296 100644
--- a/confui/ui_node.h
+++ b/confui/ui_node.h
@@ -26,4 +26,6 @@ public:
virtual ~CDNodeWidget();
virtual void update();
virtual void set_node(cd_s_node* node);
+ virtual void toggle_provision();
+ virtual void update_led(bool on);
};