diff --git a/soft/thermostat/inc/mainwindow.h b/soft/thermostat/inc/mainwindow.h index 9fd4d26..93dc2bb 100644 --- a/soft/thermostat/inc/mainwindow.h +++ b/soft/thermostat/inc/mainwindow.h @@ -13,8 +13,12 @@ #include #include +#include "mqttclient.h" +#include "zoneitem.h" #include "backgroundloop.h" +#define NB_ZONES 4 + class MainWindow : public QMainWindow { Q_OBJECT @@ -23,8 +27,15 @@ public: explicit MainWindow(QWidget *parent = NULL); ~MainWindow(); + MQTTSubcriber *mqttclient; private: + BackgroundLoop m_backLoop; + ZoneItem *m_zones[NB_ZONES]; + +private slots: + void temperature_slot(unsigned idx, double val); + void hygro_slot(unsigned idx, double val); }; #endif // MAINWINDOW_H diff --git a/soft/thermostat/src/main.cpp b/soft/thermostat/src/main.cpp index 7e30b71..2ba8918 100644 --- a/soft/thermostat/src/main.cpp +++ b/soft/thermostat/src/main.cpp @@ -18,7 +18,6 @@ int main(int argc, char *argv[]) { QTranslator qtTranslator; QTranslator translator; - MQTTSubcriber mqttclient(QHostAddress("192.168.1.2"), 1883); Q_INIT_RESOURCE(thermostat); @@ -38,8 +37,6 @@ int main(int argc, char *argv[]) MainWindow w; w.show(); - mqttclient.connectToHost(); - return a.exec(); } diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index 4647286..32470e7 100644 --- a/soft/thermostat/src/mainwindow.cpp +++ b/soft/thermostat/src/mainwindow.cpp @@ -11,6 +11,7 @@ #include #include +#include "mqttclient.h" #include "zoneitem.h" #include "settings.h" #include "mainwindow.h" @@ -20,16 +21,27 @@ MainWindow::MainWindow(QWidget *parent) : { Settings *s = Settings::getInstance(); + mqttclient = new MQTTSubcriber(QHostAddress("192.168.1.2"), 1883); + + for (int i = 0; i < NB_ZONES; i++) { + m_zones[i] = new ZoneItem(s->m_rooms_names[i], this); + } + + connect(mqttclient, SIGNAL(new_temperature(unsigned, double)), + this, SLOT(temperature_slot(unsigned, double))); + connect(mqttclient, SIGNAL(new_hygro(unsigned, double)), + this, SLOT(hygro_slot(unsigned, double))); + /* * Sensors-related layout */ QGridLayout *mainLayout = new QGridLayout; - mainLayout->addWidget(new ZoneItem(s->m_rooms_names[0], this), 0, 0); - mainLayout->addWidget(new ZoneItem(s->m_rooms_names[1], this), 0, 1); + mainLayout->addWidget(m_zones[0], 0, 0); + mainLayout->addWidget(m_zones[1], 0, 1); mainLayout->addWidget(new QPushButton(tr("Menu")), 0, 2); - mainLayout->addWidget(new ZoneItem(s->m_rooms_names[2], this), 1, 0); - mainLayout->addWidget(new ZoneItem(s->m_rooms_names[3], this), 1, 1); + mainLayout->addWidget(m_zones[2], 1, 0); + mainLayout->addWidget(m_zones[3], 1, 1); mainLayout->addWidget(new QPushButton(tr("Auto")), 1, 2); QWidget *mainWidget = new QWidget; @@ -42,10 +54,28 @@ MainWindow::MainWindow(QWidget *parent) : setWindowTitle(tr("Sorico's thermostat")); m_backLoop.start(); + + mqttclient->connectToHost(); } MainWindow::~MainWindow() { } +void MainWindow::temperature_slot(unsigned idx, double val) +{ + qDebug() << "temperature idx:" << idx << " val: " << val << endl; + if (idx < NB_ZONES) { + m_zones[idx]->set_temperature_value(val); + } +} + +void MainWindow::hygro_slot(unsigned idx, double val) +{ + qDebug() << "hygro idx:" << idx << " val: " << val << endl; + if (idx < NB_ZONES) { + m_zones[idx]->set_hygro_value(val); + } +} + /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */