|
1 /** |
|
2 * DetailCO2meter.cpp is part of bmsapp. |
|
3 * |
|
4 * bmsapp is free software: you can redistribute it and/or modify |
|
5 * it under the terms of the GNU General Public License as published by |
|
6 * the Free Software Foundation, either version 3 of the License, or |
|
7 * (at your option) any later version. |
|
8 * |
|
9 * bmsapp is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 #include "DetailCO2meter.h" |
|
18 #include "../ui/ui_DetailCO2meter.h" |
|
19 #include "global.h" |
|
20 #include "MainWindow.h" |
|
21 |
|
22 |
|
23 /* |
|
24 * Results are available via MySQL and websockets. Because we initialize using |
|
25 * MySQL we only use that for the results and up to date status. |
|
26 * Commands are send via websockets only. |
|
27 */ |
|
28 |
|
29 DetailCO2meter::DetailCO2meter(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailCO2meter) |
|
30 { |
|
31 QSqlQuery query; |
|
32 |
|
33 qDebug() << "DetailCO2meter record:" << id; |
|
34 ui->setupUi(this); |
|
35 this->recno = id; |
|
36 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); |
|
37 setWindowTitle(tr("BMSapp - Details Carbonation")); |
|
38 |
|
39 ui->thermoMeter->setMaximum(40.0); |
|
40 ui->thermoMeter->setNominal(20.0); |
|
41 ui->thermoMeter->setCritical(25.0); |
|
42 ui->thermoMeter->setSuffix(QString("°C")); |
|
43 |
|
44 ui->barMeter->setMaximum(6.0); |
|
45 ui->barMeter->setNominal(1.0); |
|
46 ui->barMeter->setCritical(3.0); |
|
47 ui->barMeter->setSuffix(QString(" bar")); |
|
48 |
|
49 ui->codePick->addItem("Free - Dummy"); // Will be replaced later |
|
50 query.exec("SELECT code,name FROM products WHERE stage='1' OR stage='2' OR stage='3' OR stage='4' OR stage='5' OR stage='6' OR stage='7' ORDER BY code"); |
|
51 while (query.next()) { |
|
52 ui->codePick->addItem(query.value("code").toString()+" - "+query.value("name").toString()); |
|
53 } |
|
54 |
|
55 connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailCO2meter::code_changed); |
|
56 connect(parent, SIGNAL(updateCO2meter(QString)), this, SLOT(refreshCO2meter(QString))); |
|
57 emit refreshTable(); |
|
58 } |
|
59 |
|
60 |
|
61 void DetailCO2meter::refreshTable() |
|
62 { |
|
63 QSqlQuery query; |
|
64 |
|
65 qDebug() << "refreshTable co2meter rec:" << this->recno; |
|
66 |
|
67 query.prepare("SELECT * FROM mon_co2meters WHERE record = :recno"); |
|
68 query.bindValue(":recno", this->recno); |
|
69 query.exec(); |
|
70 if (query.next()) { |
|
71 |
|
72 const QSignalBlocker blocker1(ui->codePick); |
|
73 const QSignalBlocker blocker2(ui->modeEdit); |
|
74 |
|
75 _node = query.value("node").toString(); |
|
76 _alias = query.value("alias").toString(); |
|
77 _uuid = query.value("uuid").toString(); |
|
78 _beercode = query.value("beercode").toString(); |
|
79 _beername = query.value("beername").toString(); |
|
80 |
|
81 ui->uuidEdit->setText(_uuid); |
|
82 ui->systemEdit->setText(_node+"/"+_alias); |
|
83 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); |
|
84 |
|
85 if (query.value("online").toInt()) { |
|
86 ui->statusEdit->setText(tr("Online")); |
|
87 ui->codeEdit->setText(_beercode+" - "+_beername); |
|
88 ui->modeEdit->setText(query.value("mode").toString()); |
|
89 ui->modeEdit->show(); |
|
90 if (query.value("mode").toString() == "OFF") { |
|
91 ui->powerLED->setChecked(false); |
|
92 ui->codePick->show(); |
|
93 } else { |
|
94 ui->powerLED->setChecked(true); |
|
95 ui->codePick->hide(); |
|
96 } |
|
97 ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false); |
|
98 |
|
99 ui->thermoBox->show(); |
|
100 if (query.value("temperature_state").toString() == "OK") { |
|
101 ui->thermoMeter->setValue(query.value("temperature").toDouble()); |
|
102 } |
|
103 if (query.value("pressure_state").toString() == "OK") { |
|
104 ui->barMeter->setValue(query.value("pressure_bar").toDouble()); |
|
105 } |
|
106 |
|
107 } else { |
|
108 /* Offline */ |
|
109 ui->statusEdit->setText(tr("Offline")); |
|
110 ui->powerLED->setChecked(false); |
|
111 ui->alarmLED->setChecked(true); |
|
112 ui->codePick->hide(); |
|
113 ui->modeEdit->hide(); |
|
114 ui->thermoBox->hide(); |
|
115 ui->logButton->hide(); |
|
116 } |
|
117 } |
|
118 |
|
119 } |
|
120 |
|
121 |
|
122 DetailCO2meter::~DetailCO2meter() |
|
123 { |
|
124 qDebug() << "DetailCO2meter done"; |
|
125 delete ui; |
|
126 emit entry_changed(); |
|
127 } |
|
128 |
|
129 |
|
130 /* |
|
131 * Receive signals destined for all co2meters. |
|
132 * Check if the signal is for us. |
|
133 */ |
|
134 void DetailCO2meter::refreshCO2meter(QString data) |
|
135 { |
|
136 if (_node+"/"+_alias == data) { |
|
137 emit refreshTable(); |
|
138 } |
|
139 } |
|
140 |
|
141 |
|
142 void DetailCO2meter::on_quitButton_clicked() |
|
143 { |
|
144 this->close(); |
|
145 this->setResult(1); |
|
146 } |
|
147 |
|
148 |
|
149 void DetailCO2meter::code_changed(int val) |
|
150 { |
|
151 QJsonParseError parseError; |
|
152 QSqlQuery query; |
|
153 |
|
154 QString msg = QString("{\"device\":\"co2meters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\","); |
|
155 if (val == 0) { |
|
156 msg.append(QString("\"beeruuid\":\"") + _uuid + "\","); |
|
157 msg.append(QString("\"beercode\":\"") + _alias.toUpper() + "\","); |
|
158 msg.append(QString("\"beername\":\"") + _alias + "\"}"); |
|
159 } else { |
|
160 query.exec("SELECT code,name,uuid,stage,json_yeasts FROM products WHERE stage='1' OR stage='2' OR stage='3' OR stage='4' OR stage='5' OR stage='6' OR stage='7' ORDER BY code"); |
|
161 for (int i = 0; i < val; i++) { |
|
162 query.next(); |
|
163 } |
|
164 msg.append(QString("\"beeruuid\":\"") + query.value("uuid").toString() + "\","); |
|
165 msg.append(QString("\"beercode\":\"") + query.value("code").toString() + "\","); |
|
166 msg.append(QString("\"beername\":\"") + query.value("name").toString() + "\"}"); |
|
167 } |
|
168 |
|
169 qDebug() << "code_changed" << val << msg; |
|
170 webSocket->sendTextMessage(msg); |
|
171 } |
|
172 |