Browse Source

prepare zoneitem to show real values

master
Richard Genoud 5 years ago
parent
commit
6ca19d2990
4 changed files with 77 additions and 4 deletions
  1. +6
    -0
      soft/thermostat/inc/mqttclient.h
  2. +11
    -0
      soft/thermostat/inc/zoneitem.h
  3. +22
    -2
      soft/thermostat/src/mqttclient.cpp
  4. +38
    -2
      soft/thermostat/src/zoneitem.cpp

+ 6
- 0
soft/thermostat/inc/mqttclient.h View File

@ -26,6 +26,12 @@ public slots:
void onConnected();
void onSubscribed(const QString& topic);
void onReceived(const QMQTT::Message& message);
signals:
void new_temperature(unsigned idx, double val);
void new_hygro(unsigned idx, double val);
void new_battery(unsigned idx, double val);
void new_availability(unsigned idx, bool ok);
};
#endif


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

@ -21,10 +21,21 @@ class ZoneItem : public QWidget
public:
explicit ZoneItem(const QString &zoneName, QWidget *parent = Q_NULLPTR);
~ZoneItem();
void set_temperature_value(double val);
void set_target_temperature(double val);
void set_hygro_value(double val);
private:
QPushButton m_zoneNameBtn;
QPushButton m_temperatureBtn;
QPushButton m_hygroBtn;
void refresh(void);
double m_temperature_value;
double m_hygro_value;
double m_target_temperature;
};
#endif // ZONEITEM_H


+ 22
- 2
soft/thermostat/src/mqttclient.cpp View File

@ -43,6 +43,7 @@ void MQTTSubcriber::onSubscribed(const QString& topic)
void MQTTSubcriber::onReceived(const QMQTT::Message& message)
{
QJsonDocument sensorData;
QJsonValue val;
qDebug() << "publish received: \"" << QString::fromUtf8(message.payload())
<< "\"" << " from: " << message.topic() << endl;
@ -56,12 +57,31 @@ void MQTTSubcriber::onReceived(const QMQTT::Message& message)
goto out;
}
QJsonObject obj(sensorData.object());
QJsonValue val = obj["temperature"];
val = obj["temperature"];
if (val.isDouble()) {
emit new_temperature(i, val.toDouble());
qDebug() << val.toDouble() << endl;
}
val = obj["humidity"];
if (val.isDouble()) {
emit new_hygro(i, val.toDouble());
qDebug() << val.toDouble() << endl;
}
qDebug() << val.toDouble() << endl;
val = obj["battery"];
if (val.isDouble()) {
emit new_battery(i, val.toDouble());
qDebug() << val.toDouble() << endl;
}
break;
}
if (Settings::getInstance()->m_availability_topics.at(i) == message.topic()) {
emit new_availability(i, message.payload() == QString("online").toUtf8());
}
}
out:
return;


+ 38
- 2
soft/thermostat/src/zoneitem.cpp View File

@ -19,11 +19,13 @@ ZoneItem::ZoneItem(const QString &zoneName, QWidget *parent) :
{
m_zoneNameBtn.setText(zoneName);
m_zoneNameBtn.setFlat(true);
m_temperatureBtn.setText("20.3°C / 20°C");
m_temperatureBtn.setFlat(true);
m_hygroBtn.setText("45%h");
m_hygroBtn.setFlat(true);
m_temperature_value = 0;
m_hygro_value = 0;
m_target_temperature = 0;
/*
* Layout for the left part of the window
*/
@ -39,4 +41,38 @@ ZoneItem::~ZoneItem()
{
}
void ZoneItem::refresh(void)
{
QString text;
text += QString::number(m_temperature_value);
text += QString("°C / ");
text += QString::number(m_target_temperature);
text += QString("°C");
m_temperatureBtn.setText(text);
text = QString::number(m_hygro_value);
text += QString("%h");
m_hygroBtn.setText(text);
}
void ZoneItem::set_temperature_value(double val)
{
m_temperature_value = val;
refresh();
}
void ZoneItem::set_target_temperature(double val)
{
m_target_temperature = val;
refresh();
}
void ZoneItem::set_hygro_value(double val)
{
m_hygro_value = val;
refresh();
}
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

Loading…
Cancel
Save