src/DetailFermenter.cpp

changeset 323
d053ffbbf3e9
parent 318
ff02aca2b63c
child 324
c1bb6b197763
equal deleted inserted replaced
322:e7ca120d93c7 323:d053ffbbf3e9
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 #include "DetailFermenter.h" 17 #include "DetailFermenter.h"
18 #include "../ui/ui_DetailFermenter.h" 18 #include "../ui/ui_DetailFermenter.h"
19 #include "global.h"
19 #include "MainWindow.h" 20 #include "MainWindow.h"
20 21
21 22
22 DetailFermenter::DetailFermenter(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailFermenter) 23 DetailFermenter::DetailFermenter(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailFermenter)
23 { 24 {
25 QSqlQuery query;
26
24 qDebug() << "DetailFermenter record:" << id; 27 qDebug() << "DetailFermenter record:" << id;
25 ui->setupUi(this); 28 ui->setupUi(this);
26 this->recno = id; 29 this->recno = id;
27 30 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
28 WindowTitle(); 31 setWindowTitle(tr("BMSapp - Details Fermenter"));
29 32
30 // srcMode = ['OFF', 'NONE', 'FRIDGE', 'BEER', 'PROFILE']; 33 ui->airThermo->setMaximum(45.0);
31 // srcStage = ['PRIMARY', 'SECONDARY', 'TERTIARY', 'CARBONATION']; 34 ui->airThermo->setNominal(15.0);
32 // 35 ui->airThermo->setCritical(20.0);
33 // connect(ui->nameEdit, &QLineEdit::textChanged, this, &DetailFermenter::is_changed); 36 ui->airThermo->setSuffix(QString("°C"));
34 // connect(ui->unlimitedEdit, &QCheckBox::stateChanged, this, &DetailFermenter::is_changed); 37
35 // connect(ui->caEdit, &QDoubleSpinBox::textChanged, this, &DetailFermenter::water_changed); 38 ui->beerThermo->setMaximum(45.0);
36 39 ui->beerThermo->setNominal(15.0);
40 ui->beerThermo->setCritical(20.0);
41 ui->beerThermo->setSuffix(QString("°C"));
42
43 ui->modeEdit->addItem("OFF");
44 ui->modeEdit->addItem("NONE");
45 ui->modeEdit->addItem("FRIDGE");
46 ui->modeEdit->addItem("BEER");
47 ui->modeEdit->addItem("PROFILE");
48
49 ui->stageEdit->addItem("PRIMARY");
50 ui->stageEdit->addItem("SECONDARY");
51 ui->stageEdit->addItem("TERTIARY");
52 ui->stageEdit->addItem("CARBONATION");
53
54 ui->codePick->addItem("Free - Dummy"); // Will be replaced later
55 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");
56 while (query.next()) {
57 ui->codePick->addItem(query.value("code").toString()+" - "+query.value("name").toString());
58 }
59
60 connect(ui->loEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &DetailFermenter::lo_changed);
61 connect(ui->hiEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &DetailFermenter::hi_changed);
62 connect(ui->heatSwitch, SIGNAL(clicked()), this, SLOT(heat_switched()));
63 connect(ui->coolSwitch, SIGNAL(clicked()), this, SLOT(cool_switched()));
64 connect(ui->fanSwitch, SIGNAL(clicked()), this, SLOT(fan_switched()));
65 connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::mode_changed);
66 connect(parent, SIGNAL(updateFermenter(QString)), this, SLOT(refreshFermenter(QString)));
37 emit refreshTable(); 67 emit refreshTable();
38 } 68 }
39 69
40 70
41 void DetailFermenter::refreshTable() 71 void DetailFermenter::refreshTable()
47 query.prepare("SELECT * FROM mon_fermenters WHERE record = :recno"); 77 query.prepare("SELECT * FROM mon_fermenters WHERE record = :recno");
48 query.bindValue(":recno", this->recno); 78 query.bindValue(":recno", this->recno);
49 query.exec(); 79 query.exec();
50 if (query.next()) { 80 if (query.next()) {
51 81
82 const QSignalBlocker blocker1(ui->codePick);
83 const QSignalBlocker blocker2(ui->modeEdit);
84
85 _node = query.value("node").toString();
86 _alias = query.value("alias").toString();
87
52 ui->uuidEdit->setText(query.value("uuid").toString()); 88 ui->uuidEdit->setText(query.value("uuid").toString());
53 ui->systemEdit->setText(query.value("node").toString()+"/"+query.value("alias").toString()); 89 ui->systemEdit->setText(_node+"/"+_alias);
90 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias);
54 91
55 if (query.value("online").toInt()) { 92 if (query.value("online").toInt()) {
56 ui->statusEdit->setText(tr("Online")); 93 ui->statusEdit->setText(tr("Online"));
57 ui->codeEdit->setText(query.value("beercode").toString()+" - "+query.value("beername").toString()); 94 ui->codeEdit->setText(query.value("beercode").toString()+" - "+query.value("beername").toString());
95 ui->airThermo->setNominal(query.value("yeast_lo").toDouble());
96 ui->airThermo->setCritical(query.value("yeast_hi").toDouble());
97 ui->beerThermo->setNominal(query.value("yeast_lo").toDouble());
98 ui->beerThermo->setCritical(query.value("yeast_hi").toDouble());
99
100 if (query.value("mode").toString() == "OFF")
101 ui->modeEdit->setCurrentIndex(0);
102 else if (query.value("mode").toString() == "NONE")
103 ui->modeEdit->setCurrentIndex(1);
104 else if (query.value("mode").toString() == "FRIDGE")
105 ui->modeEdit->setCurrentIndex(2);
106 else if (query.value("mode").toString() == "BEER")
107 ui->modeEdit->setCurrentIndex(3);
108 else if (query.value("mode").toString() == "PROFILE")
109 ui->modeEdit->setCurrentIndex(4);
110
111 if (query.value("stage").toString() == "PRIMARY")
112 ui->stageEdit->setCurrentIndex(0);
113 else if (query.value("stage").toString() == "SECONDARY")
114 ui->stageEdit->setCurrentIndex(1);
115 else if (query.value("stage").toString() == "TERTIARY")
116 ui->stageEdit->setCurrentIndex(2);
117 else if (query.value("stage").toString() == "CARBONATION")
118 ui->stageEdit->setCurrentIndex(3);
119
120 if (query.value("door_address").toString() != "") {
121 ui->doorLED->show();
122 ui->doorLabel->show();
123 ui->doorLED->setChecked((query.value("door_state").toInt() != 0) ? true:false);
124 } else {
125 ui->doorLED->hide();
126 ui->doorLabel->hide();
127 }
128
129 if (query.value("light_address").toString() != "") {
130 ui->lightLED->show();
131 ui->lightLabel->show();
132 ui->lightLED->setChecked((query.value("light_state").toInt() != 0) ? true:false);
133 } else {
134 ui->lightLED->hide();
135 ui->lightLabel->hide();
136 }
58 137
59 if (query.value("mode").toString() == "OFF") { 138 if (query.value("mode").toString() == "OFF") {
60 ui->powerLED->setChecked(false); 139 ui->powerLED->setChecked(false);
61 // disable dropdowns select beer. 140 ui->codePick->show();
62 } else { 141 } else {
63 ui->powerLED->setChecked(true); 142 ui->powerLED->setChecked(true);
64 // enable beerslect 143 ui->codePick->hide();
65 } 144 }
66 ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false); 145 ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false);
67 146
147 ui->tempsetBox->show();
148 if ((query.value("mode").toString() == "FRIDGE") || (query.value("mode").toString() == "BEER")) {
149 ui->loEdit->setReadOnly(false);
150 ui->loEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows);
151 ui->hiEdit->setReadOnly(false);
152 ui->hiEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows);
153 } else {
154 ui->loEdit->setReadOnly(true);
155 ui->loEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
156 ui->hiEdit->setReadOnly(true);
157 ui->hiEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
158 }
159 ui->loEdit->setValue(query.value("setpoint_low").toDouble());
160 ui->hiEdit->setValue(query.value("setpoint_high").toDouble());
161
162 ui->switchBox->show();
163 ui->heatLED->setChecked((query.value("heater_state").toInt() != 0) ? true:false);
164 ui->coolLED->setChecked((query.value("cooler_state").toInt() != 0) ? true:false);
165 ui->fanLED->setChecked((query.value("fan_state").toInt() != 0) ? true:false);
166
167 if (query.value("mode").toString() == "NONE") {
168 ui->heatSwitch->show();
169 ui->coolSwitch->show();
170 ui->fanSwitch->show();
171 } else {
172 ui->heatSwitch->hide();
173 ui->coolSwitch->hide();
174 ui->fanSwitch->hide();
175 }
176
177 //webSocket->sendTextMessage(QString("dd"));
178
179 ui->thermoBox->show();
68 if (query.value("air_state").toString() == "OK") { 180 if (query.value("air_state").toString() == "OK") {
69 ui->airThermo->setValue(query.value("air_temperature").toDouble()); 181 ui->airThermo->setValue(query.value("air_temperature").toDouble());
70 } 182 }
71 if (query.value("beer_state").toString() == "OK") { 183 if (query.value("beer_state").toString() == "OK") {
72 ui->beerThermo->setValue(query.value("beer_temperature").toDouble()); 184 ui->beerThermo->setValue(query.value("beer_temperature").toDouble());
73 } 185 }
74 186
75 } else { 187 } else {
76 /* Offline */ 188 /* Offline */
189 ui->statusEdit->setText(tr("Offline"));
77 ui->powerLED->setChecked(false); 190 ui->powerLED->setChecked(false);
78 ui->alarmLED->setChecked(true); 191 ui->alarmLED->setChecked(true);
79 192 ui->codePick->hide();
193 ui->modeEdit->hide();
194 ui->stageEdit->hide();
195 ui->thermoBox->hide();
196 ui->tempsetBox->hide();
197 ui->switchBox->hide();
80 } 198 }
81 } 199 }
82 200
83 } 201 }
84 202
90 emit entry_changed(); 208 emit entry_changed();
91 } 209 }
92 210
93 211
94 /* 212 /*
95 * Window header, mark any change with '**' 213 * Receive signals destined for all fermenters.
214 * Check if the signal is for us.
96 */ 215 */
97 void DetailFermenter::WindowTitle() 216 void DetailFermenter::refreshFermenter(QString data)
98 { 217 {
99 QString txt; 218 if (_node+"/"+_alias == data) {
100 219 qDebug() << "for us";
101 txt = QString(tr("BMSapp - Edit brewing water %1").arg(this->recno)); 220 emit refreshTable();
102 setWindowTitle(txt); 221 }
103 } 222 }
104 223
105 224
106 void DetailFermenter::on_quitButton_clicked() 225 void DetailFermenter::on_quitButton_clicked()
107 { 226 {
108 this->close(); 227 this->close();
109 this->setResult(1); 228 this->setResult(1);
110 } 229 }
230
231
232 void DetailFermenter::lo_changed(double val)
233 {
234 qDebug() << "lo_changed" << val;
235 }
236
237
238 void DetailFermenter::hi_changed(double val)
239 {
240 qDebug() << "hi_changed" << val;
241 }
242
243
244 void DetailFermenter::heat_switched()
245 {
246 qDebug() << "heat_switched" << heat_state;
247 }
248
249
250 void DetailFermenter::cool_switched()
251 {
252 qDebug() << "cool_switched" << cool_state;
253 }
254
255
256 void DetailFermenter::fan_switched()
257 {
258 qDebug() << "fan_switched" << fan_state;
259 }
260
261
262 void DetailFermenter::mode_changed(int val)
263 {
264 qDebug() << "mode_changed" << val;
265 QStringList mode ({ "OFF", "NONE", "FRIDGE", "BEER", "PROFiLE" });
266 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"mode\":\"" + mode[val] + "\"}");
267 qDebug() << msg;
268 webSocket->sendTextMessage(msg);
269 }
270

mercurial