diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-12-09 17:12:21 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-12-09 17:12:21 +0100 |
commit | 23a526da7143e2464aa1416d46d2d94b04e89b11 (patch) | |
tree | c5bffa58a68bea8bdec14092c29f2c69a21f5d5a | |
parent | 9c3224b0474675195b53b4d58b27a854f405c3f4 (diff) |
add empty automations working
-rw-r--r-- | confui/mesh_connector.cpp | 42 | ||||
-rw-r--r-- | confui/mesh_connector.h | 3 | ||||
-rw-r--r-- | confui/ui_automation.cpp | 2 | ||||
-rw-r--r-- | confui/ui_tab_automations.cpp | 12 |
4 files changed, 43 insertions, 16 deletions
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp index 2994363..233f860 100644 --- a/confui/mesh_connector.cpp +++ b/confui/mesh_connector.cpp @@ -36,20 +36,10 @@ CDMeshConnector::CDMeshConnector() { .provisioned = false, }); - // garbage code below (only for dummy links) - cd_link_t temp; - temp = create_link(berta, berta, CD_AUTOMATION_TYPE_TOGGLE); - _links[temp]->valid = true; - update_link(temp, _links[temp]); - temp = create_link(berta, berta, CD_AUTOMATION_TYPE_TOGGLE); - _links[temp]->valid = true; - update_link(temp, _links[temp]); - temp = create_link(gerrit, berta, CD_AUTOMATION_TYPE_TURN_OFF); - _links[temp]->valid = true; - update_link(temp, _links[temp]); - temp = create_link(gerrit, gerrit, CD_AUTOMATION_TYPE_TURN_ON); - _links[temp]->valid = true; - update_link(temp, _links[temp]); + create_link(berta, berta, CD_AUTOMATION_TYPE_TOGGLE); + create_link(berta, berta, CD_AUTOMATION_TYPE_TOGGLE); + create_link(gerrit, berta, CD_AUTOMATION_TYPE_TURN_OFF); + create_link(gerrit, gerrit, CD_AUTOMATION_TYPE_TURN_ON); return; } @@ -110,7 +100,13 @@ map<cd_link_t, cd_s_automation*> CDMeshConnector::get_links(bool valid) { void CDMeshConnector::update_link(cd_link_t link, cd_s_automation* automation) { _links[link] = automation; - printf("link[%d] = %.*s %s %.*s\n", link, (int) automation->button->name_len, automation->button->name, automation->type == CD_AUTOMATION_TYPE_TOGGLE ? "toggles" : automation->type == CD_AUTOMATION_TYPE_TURN_OFF ? "turns off" : "turns on", (int) automation->light->name_len, automation->light->name); + printf("link[%d]", link); + if (automation->valid) { + printf(" = %.*s %s %.*s", (int) automation->button->name_len, automation->button->name, automation->type == CD_AUTOMATION_TYPE_TOGGLE ? "toggles" : automation->type == CD_AUTOMATION_TYPE_TURN_OFF ? "turns off" : "turns on", (int) automation->light->name_len, automation->light->name); + } else { + printf(" (invalid)"); + } + printf("\n"); } cd_link_t CDMeshConnector::create_link(cd_uid_t button, cd_uid_t light, enum cd_e_automation_type type) { @@ -121,6 +117,22 @@ cd_link_t CDMeshConnector::create_link(cd_uid_t button, cd_uid_t light, enum cd_ automation->type = type; automation->button = _nodes[button]; automation->light = _nodes[light]; + automation->valid = true; + + printf("(new) "); + update_link(id, automation); + + return id; +} + +cd_link_t CDMeshConnector::create_link() { + cd_link_t id = get_new_link_id(); + + cd_s_automation* automation = (cd_s_automation*) malloc(sizeof(cd_s_automation)); + automation->id = id; + automation->type = CD_AUTOMATION_TYPE_TOGGLE; + automation->button = nullptr; + automation->light = nullptr; automation->valid = false; printf("(new) "); diff --git a/confui/mesh_connector.h b/confui/mesh_connector.h index 659b9fc..2e810d4 100644 --- a/confui/mesh_connector.h +++ b/confui/mesh_connector.h @@ -67,6 +67,9 @@ public: virtual cd_s_node* get_node(cd_uid_t id); // network modification functions + /** @brief create empty automation */ + virtual cd_link_t create_link(); + /** @brief create valid automation */ virtual cd_link_t create_link(cd_uid_t button, cd_uid_t light, enum cd_e_automation_type action); virtual void update_link(cd_link_t link, cd_s_automation* automation); virtual void remove_link(cd_link_t link_handle); diff --git a/confui/ui_automation.cpp b/confui/ui_automation.cpp index cecb88e..663d032 100644 --- a/confui/ui_automation.cpp +++ b/confui/ui_automation.cpp @@ -76,8 +76,8 @@ void CDAutomationWidget::apply() { _automation->button = g_cd_mesh_connector->get_node(dropdown_button->findData(dropdown_button->currentIndex())); _automation->type = (enum cd_e_automation_type) dropdown_action->findData(dropdown_action->currentIndex()); _automation->light = g_cd_mesh_connector->get_node(dropdown_light->findData(dropdown_light->currentIndex())); - _automation->valid = true; + g_cd_mesh_connector->update_link(_id, _automation); } diff --git a/confui/ui_tab_automations.cpp b/confui/ui_tab_automations.cpp index 53349dd..89ad5d4 100644 --- a/confui/ui_tab_automations.cpp +++ b/confui/ui_tab_automations.cpp @@ -8,8 +8,18 @@ using std::pair; class CDAddAutomationWidget : public QWidget { +private: + CDAutomationsTabWidget* _parent; + public: + void new_automation() { + g_cd_mesh_connector->create_link(); + _parent->update(); + } + CDAddAutomationWidget(QWidget* parent) : QWidget(parent) { + _parent = (CDAutomationsTabWidget*) parent; + QHBoxLayout* main_layout = new QHBoxLayout; QPushButton* button_add = new QPushButton("Add automation"); @@ -17,6 +27,8 @@ public: main_layout->addWidget(button_add); main_layout->addStretch(); + connect(button_add, &QPushButton::clicked, this, &CDAddAutomationWidget::new_automation); + setLayout(main_layout); } |