Browse Source

Thermostat: state button: WIP

master
Richard Genoud 5 years ago
parent
commit
1b52fdc3fd
2 changed files with 56 additions and 3 deletions
  1. +12
    -1
      soft/thermostat/inc/mainwindow.h
  2. +44
    -2
      soft/thermostat/src/mainwindow.cpp

+ 12
- 1
soft/thermostat/inc/mainwindow.h View File

@ -19,6 +19,13 @@
#include "backgroundloop.h" #include "backgroundloop.h"
#include "settings.h" #include "settings.h"
enum power_states {
OFF,
ON,
AUTO,
MAX_POWER_STATES
};
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -28,15 +35,19 @@ public:
~MainWindow(); ~MainWindow();
MQTTSubcriber *mqttclient; MQTTSubcriber *mqttclient;
private:
private:
QPushButton m_state_btn;
BackgroundLoop m_backLoop; BackgroundLoop m_backLoop;
QVector<ZoneItem *> m_zones; QVector<ZoneItem *> m_zones;
enum power_states m_pwr_state;
void update_state_btn(enum power_states st);
private slots: private slots:
void temperature_slot(int idx, double val); void temperature_slot(int idx, double val);
void hygro_slot(int idx, double val); void hygro_slot(int idx, double val);
void availability_slot(int idx, bool ok); void availability_slot(int idx, bool ok);
void change_state(void);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H


+ 44
- 2
soft/thermostat/src/mainwindow.cpp View File

@ -43,6 +43,8 @@ MainWindow::MainWindow(QWidget *parent) :
*/ */
QGridLayout *mainLayout = new QGridLayout; QGridLayout *mainLayout = new QGridLayout;
m_state_btn.setText(tr("Auto"));
if (s->nbZones() < 4) { if (s->nbZones() < 4) {
// TODO // TODO
qDebug() << "bad configuration" ; qDebug() << "bad configuration" ;
@ -52,11 +54,13 @@ MainWindow::MainWindow(QWidget *parent) :
mainLayout->addWidget(new QPushButton(tr("Menu")), 0, 2); mainLayout->addWidget(new QPushButton(tr("Menu")), 0, 2);
mainLayout->addWidget(m_zones.at(2), 1, 0); mainLayout->addWidget(m_zones.at(2), 1, 0);
mainLayout->addWidget(m_zones.at(3), 1, 1); mainLayout->addWidget(m_zones.at(3), 1, 1);
mainLayout->addWidget(new QPushButton(tr("Auto")), 1, 2);
mainLayout->addWidget(&m_state_btn, 1, 2);
} }
m_pwr_state = OFF;
update_state_btn(m_pwr_state);
QWidget *mainWidget = new QWidget; QWidget *mainWidget = new QWidget;
mainWidget->setLayout(mainLayout); mainWidget->setLayout(mainLayout);
/* /*
* Top widget * Top widget
*/ */
@ -66,12 +70,50 @@ MainWindow::MainWindow(QWidget *parent) :
m_backLoop.start(); m_backLoop.start();
mqttclient->connectToHost(); mqttclient->connectToHost();
connect(&m_state_btn, SIGNAL(clicked()), this, SLOT(change_state()));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
} }
void MainWindow::update_state_btn(enum power_states st)
{
switch (st) {
case OFF:
m_state_btn.setText(tr("Force off"));
break;
case ON:
m_state_btn.setText(tr("Force on"));
break;
case AUTO:
m_state_btn.setText(tr("Auto"));
break;
default:
m_state_btn.setText(tr("Error"));
break;
}
}
void MainWindow::change_state(void)
{
switch (m_pwr_state) {
case OFF:
m_pwr_state = ON;
break;
case ON:
m_pwr_state = AUTO;
break;
case AUTO:
/* fall through */
default:
m_pwr_state = OFF;
break;
}
update_state_btn(m_pwr_state);
}
void MainWindow::temperature_slot(int idx, double val) void MainWindow::temperature_slot(int idx, double val)
{ {
Settings *s = Settings::getInstance(); Settings *s = Settings::getInstance();


Loading…
Cancel
Save