34 ui->setupUi(this); |
34 ui->setupUi(this); |
35 this->recno = id; |
35 this->recno = id; |
36 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); |
36 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); |
37 setWindowTitle(tr("BMSapp - Details Fermenter")); |
37 setWindowTitle(tr("BMSapp - Details Fermenter")); |
38 |
38 |
39 ui->airThermo->setMaximum(45.0); |
39 ui->airThermo->setMaximum(40.0); |
40 ui->airThermo->setNominal(15.0); |
40 ui->airThermo->setNominal(15.0); |
41 ui->airThermo->setCritical(20.0); |
41 ui->airThermo->setCritical(20.0); |
42 ui->airThermo->setSuffix(QString("°C")); |
42 ui->airThermo->setSuffix(QString("°C")); |
43 |
43 |
44 ui->beerThermo->setMaximum(45.0); |
44 ui->beerThermo->setMaximum(40.0); |
45 ui->beerThermo->setNominal(15.0); |
45 ui->beerThermo->setNominal(15.0); |
46 ui->beerThermo->setCritical(20.0); |
46 ui->beerThermo->setCritical(20.0); |
47 ui->beerThermo->setSuffix(QString("°C")); |
47 ui->beerThermo->setSuffix(QString("°C")); |
|
48 |
|
49 ui->chillerThermo->setMinimum(-15.0); |
|
50 ui->chillerThermo->setMaximum(25.0); |
|
51 ui->chillerThermo->setNominal(0.0); |
|
52 ui->chillerThermo->setCritical(15.0); |
|
53 ui->chillerThermo->setSuffix(QString("°C")); |
48 |
54 |
49 ui->modeEdit->addItem("OFF"); |
55 ui->modeEdit->addItem("OFF"); |
50 ui->modeEdit->addItem("NONE"); |
56 ui->modeEdit->addItem("NONE"); |
51 ui->modeEdit->addItem("FRIDGE"); |
57 ui->modeEdit->addItem("FRIDGE"); |
52 ui->modeEdit->addItem("BEER"); |
58 ui->modeEdit->addItem("BEER"); |
109 const QSignalBlocker blocker4(ui->hiEdit); |
115 const QSignalBlocker blocker4(ui->hiEdit); |
110 const QSignalBlocker blocker5(ui->stageEdit); |
116 const QSignalBlocker blocker5(ui->stageEdit); |
111 |
117 |
112 _node = query.value("node").toString(); |
118 _node = query.value("node").toString(); |
113 _alias = query.value("alias").toString(); |
119 _alias = query.value("alias").toString(); |
|
120 _beercode = query.value("beercode").toString(); |
|
121 _beername = query.value("beername").toString(); |
114 |
122 |
115 ui->uuidEdit->setText(query.value("uuid").toString()); |
123 ui->uuidEdit->setText(query.value("uuid").toString()); |
116 ui->systemEdit->setText(_node+"/"+_alias); |
124 ui->systemEdit->setText(_node+"/"+_alias); |
117 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); |
125 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); |
118 |
126 |
119 if (query.value("online").toInt()) { |
127 if (query.value("online").toInt()) { |
120 ui->statusEdit->setText(tr("Online")); |
128 ui->statusEdit->setText(tr("Online")); |
121 ui->codeEdit->setText(query.value("beercode").toString()+" - "+query.value("beername").toString()); |
129 ui->codeEdit->setText(_beercode+" - "+_beername); |
122 ui->airThermo->setNominal(query.value("yeast_lo").toDouble()); |
130 ui->airThermo->setNominal(query.value("yeast_lo").toDouble()); |
123 ui->airThermo->setCritical(query.value("yeast_hi").toDouble()); |
131 ui->airThermo->setCritical(query.value("yeast_hi").toDouble()); |
124 ui->beerThermo->setNominal(query.value("yeast_lo").toDouble()); |
132 ui->beerThermo->setNominal(query.value("yeast_lo").toDouble()); |
125 ui->beerThermo->setCritical(query.value("yeast_hi").toDouble()); |
133 ui->beerThermo->setCritical(query.value("yeast_hi").toDouble()); |
126 |
134 |
|
135 ui->modeEdit->show(); |
127 if (query.value("mode").toString() == "OFF") |
136 if (query.value("mode").toString() == "OFF") |
128 ui->modeEdit->setCurrentIndex(0); |
137 ui->modeEdit->setCurrentIndex(0); |
129 else if (query.value("mode").toString() == "NONE") |
138 else if (query.value("mode").toString() == "NONE") |
130 ui->modeEdit->setCurrentIndex(1); |
139 ui->modeEdit->setCurrentIndex(1); |
131 else if (query.value("mode").toString() == "FRIDGE") |
140 else if (query.value("mode").toString() == "FRIDGE") |
133 else if (query.value("mode").toString() == "BEER") |
142 else if (query.value("mode").toString() == "BEER") |
134 ui->modeEdit->setCurrentIndex(3); |
143 ui->modeEdit->setCurrentIndex(3); |
135 else if (query.value("mode").toString() == "PROFILE") |
144 else if (query.value("mode").toString() == "PROFILE") |
136 ui->modeEdit->setCurrentIndex(4); |
145 ui->modeEdit->setCurrentIndex(4); |
137 |
146 |
|
147 ui->stageEdit->show(); |
138 if (query.value("stage").toString() == "PRIMARY") |
148 if (query.value("stage").toString() == "PRIMARY") |
139 ui->stageEdit->setCurrentIndex(0); |
149 ui->stageEdit->setCurrentIndex(0); |
140 else if (query.value("stage").toString() == "SECONDARY") |
150 else if (query.value("stage").toString() == "SECONDARY") |
141 ui->stageEdit->setCurrentIndex(1); |
151 ui->stageEdit->setCurrentIndex(1); |
142 else if (query.value("stage").toString() == "TERTIARY") |
152 else if (query.value("stage").toString() == "TERTIARY") |
263 ui->modeButton1->hide(); |
273 ui->modeButton1->hide(); |
264 ui->modeButton2->hide(); |
274 ui->modeButton2->hide(); |
265 _profile = QString(""); |
275 _profile = QString(""); |
266 } |
276 } |
267 |
277 |
|
278 if (query.value("webcam_url").toString() == "") { |
|
279 ui->camButton->hide(); |
|
280 } else { |
|
281 ui->camButton->show(); |
|
282 } |
|
283 |
268 ui->thermoBox->show(); |
284 ui->thermoBox->show(); |
269 if (query.value("air_state").toString() == "OK") { |
285 if (query.value("air_state").toString() == "OK") { |
270 ui->airThermo->setValue(query.value("air_temperature").toDouble()); |
286 ui->airThermo->setValue(query.value("air_temperature").toDouble()); |
271 } |
287 } |
272 if (query.value("beer_state").toString() == "OK") { |
288 if (query.value("beer_state").toString() == "OK") { |
273 ui->beerThermo->setValue(query.value("beer_temperature").toDouble()); |
289 ui->beerThermo->setValue(query.value("beer_temperature").toDouble()); |
274 } |
290 } |
|
291 if (query.value("chiller_state").toString() == "OK") { |
|
292 ui->chillerThermo->setValue(query.value("chiller_temperature").toDouble()); |
|
293 } |
275 |
294 |
276 } else { |
295 } else { |
277 /* Offline */ |
296 /* Offline */ |
278 ui->statusEdit->setText(tr("Offline")); |
297 ui->statusEdit->setText(tr("Offline")); |
279 ui->powerLED->setChecked(false); |
298 ui->powerLED->setChecked(false); |
385 webSocket->sendTextMessage(msg); |
405 webSocket->sendTextMessage(msg); |
386 return; |
406 return; |
387 } |
407 } |
388 |
408 |
389 if ((_profile == "RUN") || (_profile == "PAUSE")) { |
409 if ((_profile == "RUN") || (_profile == "PAUSE")) { |
390 // use popup |
|
391 int rc = QMessageBox::warning(this, tr("Profile running"), tr("Profile is active, really abort?"), |
410 int rc = QMessageBox::warning(this, tr("Profile running"), tr("Profile is active, really abort?"), |
392 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
411 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
393 if (rc == QMessageBox::Yes) { |
412 if (rc == QMessageBox::Yes) { |
394 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"abort\"}}"); |
413 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"abort\"}}"); |
395 qDebug() << msg; |
414 qDebug() << msg; |
420 |
439 |
421 void DetailFermenter::mode_changed(int val) |
440 void DetailFermenter::mode_changed(int val) |
422 { |
441 { |
423 QStringList mode ({ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }); |
442 QStringList mode ({ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }); |
424 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"mode\":\"" + mode[val] + "\"}"); |
443 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"mode\":\"" + mode[val] + "\"}"); |
425 qDebug() << "mode_changed" << val << msg; |
444 //qDebug() << "mode_changed" << val << msg; |
426 webSocket->sendTextMessage(msg); |
445 webSocket->sendTextMessage(msg); |
427 } |
446 } |
428 |
447 |
429 |
448 |
430 void DetailFermenter::stage_changed(int val) |
449 void DetailFermenter::stage_changed(int val) |
431 { |
450 { |
432 QStringList stage ({ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" }); |
451 QStringList stage ({ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" }); |
433 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"stage\":\"" + stage[val] + "\"}"); |
452 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"stage\":\"" + stage[val] + "\"}"); |
434 qDebug() << "stage_changed" << val << msg; |
453 //qDebug() << "stage_changed" << val << msg; |
435 webSocket->sendTextMessage(msg); |
454 webSocket->sendTextMessage(msg); |
436 } |
455 } |
437 |
456 |
438 |
457 |
439 void DetailFermenter::code_changed(int val) |
458 void DetailFermenter::code_changed(int val) |
440 { |
459 { |
441 QString msg = QString(""); |
460 QJsonParseError parseError; |
|
461 QSqlQuery query; |
|
462 |
|
463 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\","); |
|
464 if (val == 0) { |
|
465 msg.append(QString("\"beeruuid\":\"66ecccbf-e942-4a35-af49-8b02314561a5\",")); |
|
466 msg.append(QString("\"beercode\":\"") + _alias.toUpper() + "\","); |
|
467 msg.append(QString("\"beername\":\"") + _alias + "\","); |
|
468 msg.append(QString("\"yeast_lo\":12.0,")); |
|
469 msg.append(QString("\"yeast_hi\":24.0}")); |
|
470 |
|
471 } else { |
|
472 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"); |
|
473 for (int i = 0; i < val; i++) { |
|
474 query.next(); |
|
475 } |
|
476 double yl = 0; |
|
477 double yh = 40; |
|
478 const auto& y_json = query.value("json_yeasts").toString(); |
|
479 if (! y_json.trimmed().isEmpty()) { |
|
480 const auto& formattedJson = QString("%1").arg(y_json); |
|
481 QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
482 if (parseError.error != QJsonParseError::NoError) { |
|
483 qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
|
484 } else if (yeasts.isArray()) { |
|
485 for (int i = 0; i < yeasts.array().size(); i++) { |
|
486 QJsonObject obj = yeasts.array().at(i).toObject(); |
|
487 if (obj["y_use"].toInt() == 0) { // Primary yeast |
|
488 if (obj["y_min_temperature"].toDouble() > yl) |
|
489 yl = obj["y_min_temperature"].toDouble(); |
|
490 if (obj["y_max_temperature"].toDouble() < yh) |
|
491 yh = obj["y_max_temperature"].toDouble(); |
|
492 } |
|
493 } |
|
494 } |
|
495 } |
|
496 msg.append(QString("\"beeruuid\":\"") + query.value("uuid").toString() + "\","); |
|
497 msg.append(QString("\"beercode\":\"") + query.value("code").toString() + "\","); |
|
498 msg.append(QString("\"beername\":\"") + query.value("name").toString() + "\","); |
|
499 msg.append(QString("\"yeast_lo\":%1,").arg(yl)); |
|
500 msg.append(QString("\"yeast_hi\":%1}").arg(yh)); |
|
501 } |
|
502 |
442 qDebug() << "code_changed" << val << msg; |
503 qDebug() << "code_changed" << val << msg; |
|
504 webSocket->sendTextMessage(msg); |
443 } |
505 } |
444 |
506 |
445 |
507 |
446 void DetailFermenter::profile_changed(int val) |
508 void DetailFermenter::profile_changed(int val) |
447 { |
509 { |