diff --git a/soft/thermostat/inc/mainwindow.h b/soft/thermostat/inc/mainwindow.h index e524007..461115a 100644 --- a/soft/thermostat/inc/mainwindow.h +++ b/soft/thermostat/inc/mainwindow.h @@ -19,6 +19,13 @@ #include "backgroundloop.h" #include "settings.h" +enum power_states { + OFF, + ON, + AUTO, + MAX_POWER_STATES +}; + class MainWindow : public QMainWindow { Q_OBJECT @@ -28,15 +35,19 @@ public: ~MainWindow(); MQTTSubcriber *mqttclient; -private: +private: + QPushButton m_state_btn; BackgroundLoop m_backLoop; QVector m_zones; + enum power_states m_pwr_state; + void update_state_btn(enum power_states st); private slots: void temperature_slot(int idx, double val); void hygro_slot(int idx, double val); void availability_slot(int idx, bool ok); + void change_state(void); }; #endif // MAINWINDOW_H diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index d314d55..a9a88dd 100644 --- a/soft/thermostat/src/mainwindow.cpp +++ b/soft/thermostat/src/mainwindow.cpp @@ -43,6 +43,8 @@ MainWindow::MainWindow(QWidget *parent) : */ QGridLayout *mainLayout = new QGridLayout; + m_state_btn.setText(tr("Auto")); + if (s->nbZones() < 4) { // TODO qDebug() << "bad configuration" ; @@ -52,11 +54,13 @@ MainWindow::MainWindow(QWidget *parent) : mainLayout->addWidget(new QPushButton(tr("Menu")), 0, 2); mainLayout->addWidget(m_zones.at(2), 1, 0); 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; mainWidget->setLayout(mainLayout); - /* * Top widget */ @@ -66,12 +70,50 @@ MainWindow::MainWindow(QWidget *parent) : m_backLoop.start(); mqttclient->connectToHost(); + + connect(&m_state_btn, SIGNAL(clicked()), this, SLOT(change_state())); } 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) { Settings *s = Settings::getInstance();