Browse Source

zones are now showing reality

master
Richard Genoud 5 years ago
parent
commit
c861902918
3 changed files with 45 additions and 7 deletions
  1. +11
    -0
      soft/thermostat/inc/mainwindow.h
  2. +0
    -3
      soft/thermostat/src/main.cpp
  3. +34
    -4
      soft/thermostat/src/mainwindow.cpp

+ 11
- 0
soft/thermostat/inc/mainwindow.h View File

@ -13,8 +13,12 @@
#include <QPushButton> #include <QPushButton>
#include <QtWidgets> #include <QtWidgets>
#include "mqttclient.h"
#include "zoneitem.h"
#include "backgroundloop.h" #include "backgroundloop.h"
#define NB_ZONES 4
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -23,8 +27,15 @@ public:
explicit MainWindow(QWidget *parent = NULL); explicit MainWindow(QWidget *parent = NULL);
~MainWindow(); ~MainWindow();
MQTTSubcriber *mqttclient;
private: private:
BackgroundLoop m_backLoop; 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 #endif // MAINWINDOW_H


+ 0
- 3
soft/thermostat/src/main.cpp View File

@ -18,7 +18,6 @@ int main(int argc, char *argv[])
{ {
QTranslator qtTranslator; QTranslator qtTranslator;
QTranslator translator; QTranslator translator;
MQTTSubcriber mqttclient(QHostAddress("192.168.1.2"), 1883);
Q_INIT_RESOURCE(thermostat); Q_INIT_RESOURCE(thermostat);
@ -38,8 +37,6 @@ int main(int argc, char *argv[])
MainWindow w; MainWindow w;
w.show(); w.show();
mqttclient.connectToHost();
return a.exec(); return a.exec();
} }


+ 34
- 4
soft/thermostat/src/mainwindow.cpp View File

@ -11,6 +11,7 @@
#include <QTime> #include <QTime>
#include <QLocale> #include <QLocale>
#include "mqttclient.h"
#include "zoneitem.h" #include "zoneitem.h"
#include "settings.h" #include "settings.h"
#include "mainwindow.h" #include "mainwindow.h"
@ -20,16 +21,27 @@ MainWindow::MainWindow(QWidget *parent) :
{ {
Settings *s = Settings::getInstance(); 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 * Sensors-related layout
*/ */
QGridLayout *mainLayout = new QGridLayout; 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 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); mainLayout->addWidget(new QPushButton(tr("Auto")), 1, 2);
QWidget *mainWidget = new QWidget; QWidget *mainWidget = new QWidget;
@ -42,10 +54,28 @@ MainWindow::MainWindow(QWidget *parent) :
setWindowTitle(tr("Sorico's thermostat")); setWindowTitle(tr("Sorico's thermostat"));
m_backLoop.start(); m_backLoop.start();
mqttclient->connectToHost();
} }
MainWindow::~MainWindow() 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: */ /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

Loading…
Cancel
Save