src/DetailiSpindel.cpp

Sun, 23 Jun 2024 11:51:22 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 23 Jun 2024 11:51:22 +0200
changeset 539
e5972bf6e50c
parent 537
48de0f61e5ea
permissions
-rw-r--r--

Archive products on code and on date all use the packaging date.

329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * DetailiSpindel.cpp is part of bmsapp.
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "DetailiSpindel.h"
333
499c95108bbd Moved Fermenter and iSpindel charts to their own functions. Added these to DetailFermenter and DetailiSpindel too.
Michiel Broek <mbroek@mbse.eu>
parents: 329
diff changeset
18 #include "ChartiSpindel.h"
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include "../ui/ui_DetailiSpindel.h"
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include "global.h"
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 #include "Utils.h"
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 #include "MainWindow.h"
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 /*
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 * Results are available via MySQL and websockets. Because we initialize using
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 * MySQL we only use that for the results and up to date status.
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 * Commands are send via websockets only.
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 */
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 DetailiSpindel::DetailiSpindel(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailiSpindel)
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 QSqlQuery query;
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
35 #ifdef DEBUG_MONITOR
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 qDebug() << "DetailiSpindel record:" << id;
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
37 #endif
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 ui->setupUi(this);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 this->recno = id;
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 setWindowTitle(tr("BMSapp - Details iSpindel"));
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 ui->thermoMeter->setMaximum(40.0);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 ui->thermoMeter->setNominal(20.0);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 ui->thermoMeter->setCritical(25.0);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 ui->thermoMeter->setSuffix(QString("°C"));
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 ui->modeEdit->addItem("OFF");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 ui->modeEdit->addItem("ON");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50
416
3fac92cb1ee1 Handle choose beer if it needs to be cleared better in details iSpindels and CO2meters.
Michiel Broek <mbroek@mbse.eu>
parents: 333
diff changeset
51 ui->codePick->addItem("Erase beer");
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 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");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 while (query.next()) {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 ui->codePick->addItem(query.value("code").toString()+" - "+query.value("name").toString());
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::code_changed);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::mode_changed);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString)));
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 emit refreshTable();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 void DetailiSpindel::refreshTable()
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 QSqlQuery query;
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
67 double angle, plato, sg, poly[4];
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 query.prepare("SELECT * FROM mon_ispindels WHERE record = :recno");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 query.bindValue(":recno", this->recno);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 query.exec();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 if (query.next()) {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 const QSignalBlocker blocker1(ui->codePick);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 const QSignalBlocker blocker2(ui->modeEdit);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 _node = query.value("node").toString();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 _alias = query.value("alias").toString();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 _uuid = query.value("uuid").toString();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 _beercode = query.value("beercode").toString();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 _beername = query.value("beername").toString();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
83 bool alarm = (query.value("alarm").toInt() != 0) ? true:false;
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
84 bool online = (query.value("online").toInt() != 0) ? true:false;
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
85 bool mode = (query.value("mode").toString() == "ON") ? true:false;
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
86
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 ui->uuidEdit->setText(_uuid);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 ui->systemEdit->setText(_node+"/"+_alias);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias);
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
90 ui->alarmLED->setChecked(alarm);
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
91 ui->lastEdit->setText(query.value("lastseen").toDateTime().toString("dd MMM HH:mm:ss"));
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
92 ui->codeEdit->setText(_beercode+" - "+_beername);
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
93 ui->powerLED->setChecked(mode);
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
94 ui->modeEdit->show();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
95 ui->modeEdit->setCurrentIndex(mode ? 1:0);
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
97 if (online) {
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 ui->statusEdit->setText(tr("Online"));
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
99 ui->statusEdit->setStyleSheet("");
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
100 ui->thermoMeter->setNominal(query.value("yeast_lo").toDouble());
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
101 ui->thermoMeter->setCritical(query.value("yeast_hi").toDouble());
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
102 ui->modeEdit->setEnabled(true);
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
103 if (mode) {
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
104 ui->codePick->hide();
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
105 } else {
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 ui->codePick->show();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
109 plato = query.value("gravity").toDouble();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
110 angle = query.value("angle").toDouble();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
111 /*
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
112 * Try to use the calibrate poly to recalcultate the density.
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
113 */
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
114 QJsonParseError parseError;
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
115 const auto& json = query.value("calibrate").toString();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
116 if (!json.trimmed().isEmpty()) {
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
117 const auto& formattedJson = QString("%1").arg(json);
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
118 QJsonDocument jsonResponse = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
119 QJsonObject jsonObj = jsonResponse.object();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
120 QJsonArray polyData = jsonObj.value("polyData").toArray();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
121 if (polyData.size() == 4) {
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
122 for (int i = 0; i < polyData.size(); i++) {
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
123 poly[i] = polyData.at(i).toDouble();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
124 }
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
125 /* New plato from current polynomial */
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
126 plato = (poly[0] * pow(angle, 3)) + (poly[1] * pow(angle, 2)) + (poly[2] * angle) + poly[3];
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
127 }
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
128 }
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
129 sg = Utils::plato_to_sg(plato);
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
130
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 ui->voltEdit->setText(QString("%1").arg(query.value("battery").toDouble(), 4, 'f', 3, '0'));
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
132 ui->tiltEdit->setText(QString("%1").arg(angle, 6, 'f', 5, '0'));
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
133 ui->platoEdit->setText(QString("%1").arg(plato, 4, 'f', 3, '0'));
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 ui->sgEdit->setText(QString("%1").arg(sg, 5, 'f', 4, '0'));
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 if (query.value("gravity").toDouble()) {
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
137 double o_plato = query.value("og_gravity").toDouble();
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
138 double og = Utils::plato_to_sg(o_plato);
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 double svg = Utils::calc_svg(og, sg);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 ui->ogVal->setText(QString("%1").arg(og, 5, 'f', 4, '0'));
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
142 ui->ogVal2->setText(QString("%1°P").arg(o_plato, 4, 'f', 3, '0'));
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 ui->sgVal->setText(QString("%1").arg(sg, 5, 'f', 4, '0'));
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 ui->sgVal2->setText(QString("%1°P").arg(query.value("gravity").toDouble(), 4, 'f', 3, '0'));
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
145 if (o_plato > 0.1) {
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
146 ui->svgVal->setText(QString("%1%").arg(svg, 2, 'f', 1, '0'));
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
147 ui->svgBar->setValue(svg);
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
148 ui->abvVal->setText(QString("%1%").arg(Utils::abvol(og, sg), 3, 'f', 2, '0'));
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
149 } else {
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
150 /* o_plato is 0 if a new beer is selected. */
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
151 ui->svgVal->setText("");
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
152 ui->svgBar->setValue(0);
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
153 ui->abvVal->setText("");
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
154 }
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 } else {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 ui->ogVal->setText("");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 ui->ogVal2->setText("");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 ui->sgVal->setText("");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 ui->sgVal2->setText("");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 ui->svgVal->setText("");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 ui->abvVal->setText("");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 ui->batVal->setText("");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164
500
cf75e6fadcb1 New battery percentage formula for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 499
diff changeset
165 const float battery_max = 4.13;
cf75e6fadcb1 New battery percentage formula for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 499
diff changeset
166 const float battery_min = 3.43;
cf75e6fadcb1 New battery percentage formula for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 499
diff changeset
167
cf75e6fadcb1 New battery percentage formula for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 499
diff changeset
168 double batt = ((query.value("battery").toDouble() - battery_min) / (battery_max - battery_min)) * 100;
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 if (batt < 0)
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 batt = 0;
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 if (batt > 100)
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 batt = 100;
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 ui->batVal->setText(QString("%1%").arg(batt, 2, 'f', 1, '0'));
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 ui->thermoBox->show();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 ui->thermoMeter->setValue(query.value("temperature").toDouble());
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 } else {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 /* Offline */
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 ui->statusEdit->setText(tr("Offline"));
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
181 ui->statusEdit->setStyleSheet("background-color: red");
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 ui->alarmLED->setChecked(true);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 ui->codePick->hide();
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 502
diff changeset
184 ui->modeEdit->setEnabled(false);
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 ui->thermoBox->hide();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 ui->logButton->hide();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 DetailiSpindel::~DetailiSpindel()
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 delete ui;
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 emit entry_changed();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 /*
502
0f15edebc665 Changes in de iSpindel detail screen. Added a calibrate button and display the last update date and time.
Michiel Broek <mbroek@mbse.eu>
parents: 500
diff changeset
201 * Receive signals destined for all iSpindels.
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 * Check if the signal is for us.
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 */
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 void DetailiSpindel::refreshiSpindel(QString data)
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 if (_node+"/"+_alias == data) {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 emit refreshTable();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
212 void DetailiSpindel::on_logButton_clicked()
333
499c95108bbd Moved Fermenter and iSpindel charts to their own functions. Added these to DetailFermenter and DetailiSpindel too.
Michiel Broek <mbroek@mbse.eu>
parents: 329
diff changeset
213 {
499c95108bbd Moved Fermenter and iSpindel charts to their own functions. Added these to DetailFermenter and DetailiSpindel too.
Michiel Broek <mbroek@mbse.eu>
parents: 329
diff changeset
214 ChartiSpindel dialog(_beercode, _beername, this);
499c95108bbd Moved Fermenter and iSpindel charts to their own functions. Added these to DetailFermenter and DetailiSpindel too.
Michiel Broek <mbroek@mbse.eu>
parents: 329
diff changeset
215 }
499c95108bbd Moved Fermenter and iSpindel charts to their own functions. Added these to DetailFermenter and DetailiSpindel too.
Michiel Broek <mbroek@mbse.eu>
parents: 329
diff changeset
216
499c95108bbd Moved Fermenter and iSpindel charts to their own functions. Added these to DetailFermenter and DetailiSpindel too.
Michiel Broek <mbroek@mbse.eu>
parents: 329
diff changeset
217
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 void DetailiSpindel::on_quitButton_clicked()
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 this->close();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 this->setResult(1);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 void DetailiSpindel::mode_changed(int val)
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 QStringList mode ({ "OFF", "ON" });
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 QString msg = QString("{\"device\":\"ispindels\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"mode\":\"" + mode[val] + "\"}");
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
229 #ifdef DEBUG_MONITOR
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 qDebug() << "mode_changed" << val << msg;
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
231 #endif
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 webSocket->sendTextMessage(msg);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 void DetailiSpindel::code_changed(int val)
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 QJsonParseError parseError;
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 QSqlQuery query;
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 QString msg = QString("{\"device\":\"ispindels\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 if (val == 0) {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 msg.append(QString("\"beeruuid\":\"") + _uuid + "\",");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 msg.append(QString("\"beercode\":\"") + _alias.toUpper() + "\",");
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
245 msg.append(QString("\"beername\":\"") + _alias + "\",");
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
246 msg.append(QString("\"yeast_lo\":20.0,"));
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
247 msg.append(QString("\"yeast_hi\":25.0}"));
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 } else {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 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");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 for (int i = 0; i < val; i++) {
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 query.next();
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 }
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
253 double yl = 0;
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
254 double yh = 40;
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
255 const auto& y_json = query.value("json_yeasts").toString();
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
256 if (! y_json.trimmed().isEmpty()) {
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
257 const auto& formattedJson = QString("%1").arg(y_json);
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
258 QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
259 if (parseError.error != QJsonParseError::NoError) {
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
260 qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
261 } else if (yeasts.isArray()) {
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
262 for (int i = 0; i < yeasts.array().size(); i++) {
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
263 QJsonObject obj = yeasts.array().at(i).toObject();
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
264 if (obj["y_use"].toInt() == 0) { // Primary yeast
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
265 if (obj["y_min_temperature"].toDouble() > yl)
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
266 yl = obj["y_min_temperature"].toDouble();
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
267 if (obj["y_max_temperature"].toDouble() < yh)
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
268 yh = obj["y_max_temperature"].toDouble();
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
269 }
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
270 }
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
271 }
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
272 }
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 msg.append(QString("\"beeruuid\":\"") + query.value("uuid").toString() + "\",");
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 msg.append(QString("\"beercode\":\"") + query.value("code").toString() + "\",");
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
275 msg.append(QString("\"beername\":\"") + query.value("name").toString() + "\",");
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
276 msg.append(QString("\"yeast_lo\":%1,").arg(yl));
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
277 msg.append(QString("\"yeast_hi\":%1}").arg(yh));
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
280 #ifdef DEBUG_MONITOR
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 qDebug() << "code_changed" << val << msg;
493
520306773450 Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.
Michiel Broek <mbroek@mbse.eu>
parents: 416
diff changeset
282 #endif
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 webSocket->sendTextMessage(msg);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 }
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285

mercurial