Sun, 15 Oct 2023 13:30:24 +0200
Added MySQL query example in the source.
329 | 1 | /** |
2 | * DetailiSpindel.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 "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 | 19 | #include "../ui/ui_DetailiSpindel.h" |
20 | #include "global.h" | |
21 | #include "Utils.h" | |
22 | #include "MainWindow.h" | |
23 | ||
24 | ||
25 | /* | |
26 | * Results are available via MySQL and websockets. Because we initialize using | |
27 | * MySQL we only use that for the results and up to date status. | |
28 | * Commands are send via websockets only. | |
29 | */ | |
30 | ||
31 | DetailiSpindel::DetailiSpindel(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailiSpindel) | |
32 | { | |
33 | QSqlQuery query; | |
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 | 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 | 38 | ui->setupUi(this); |
39 | this->recno = id; | |
40 | setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); | |
41 | setWindowTitle(tr("BMSapp - Details iSpindel")); | |
42 | ||
43 | ui->thermoMeter->setMaximum(40.0); | |
44 | ui->thermoMeter->setNominal(20.0); | |
45 | ui->thermoMeter->setCritical(25.0); | |
46 | ui->thermoMeter->setSuffix(QString("°C")); | |
47 | ||
48 | ui->modeEdit->addItem("OFF"); | |
49 | ui->modeEdit->addItem("ON"); | |
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 | 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"); |
53 | while (query.next()) { | |
54 | ui->codePick->addItem(query.value("code").toString()+" - "+query.value("name").toString()); | |
55 | } | |
56 | ||
57 | connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::code_changed); | |
58 | connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::mode_changed); | |
59 | connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString))); | |
60 | emit refreshTable(); | |
61 | } | |
62 | ||
63 | ||
64 | void DetailiSpindel::refreshTable() | |
65 | { | |
66 | QSqlQuery query; | |
67 | ||
68 | query.prepare("SELECT * FROM mon_ispindels WHERE record = :recno"); | |
69 | query.bindValue(":recno", this->recno); | |
70 | query.exec(); | |
71 | if (query.next()) { | |
72 | ||
73 | const QSignalBlocker blocker1(ui->codePick); | |
74 | const QSignalBlocker blocker2(ui->modeEdit); | |
75 | ||
76 | _node = query.value("node").toString(); | |
77 | _alias = query.value("alias").toString(); | |
78 | _uuid = query.value("uuid").toString(); | |
79 | _beercode = query.value("beercode").toString(); | |
80 | _beername = query.value("beername").toString(); | |
81 | ||
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
|
82 | 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
|
83 | 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
|
84 | 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
|
85 | |
329 | 86 | ui->uuidEdit->setText(_uuid); |
87 | ui->systemEdit->setText(_node+"/"+_alias); | |
88 | 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
|
89 | ui->alarmLED->setChecked(alarm); |
329 | 90 | |
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
|
91 | if (online) { |
329 | 92 | 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
|
93 | ui->statusEdit->setStyleSheet(""); |
329 | 94 | ui->codeEdit->setText(_beercode+" - "+_beername); |
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
|
95 | 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
|
96 | ui->thermoMeter->setCritical(query.value("yeast_hi").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
|
97 | |
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
|
98 | ui->powerLED->setChecked(mode); |
329 | 99 | ui->modeEdit->show(); |
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
|
100 | 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
|
101 | ui->modeEdit->setCurrentIndex(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
|
102 | 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
|
103 | } else { |
329 | 104 | ui->modeEdit->setCurrentIndex(0); |
105 | ui->codePick->show(); | |
106 | } | |
107 | ||
108 | ui->voltEdit->setText(QString("%1").arg(query.value("battery").toDouble(), 4, 'f', 3, '0')); | |
109 | ui->tiltEdit->setText(QString("%1").arg(query.value("angle").toDouble(), 6, 'f', 5, '0')); | |
110 | ui->platoEdit->setText(QString("%1").arg(query.value("gravity").toDouble(), 4, 'f', 3, '0')); | |
111 | double sg = Utils::plato_to_sg(query.value("gravity").toDouble()); | |
112 | ui->sgEdit->setText(QString("%1").arg(sg, 5, 'f', 4, '0')); | |
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
|
113 | ui->lastEdit->setText(query.value("lastseen").toDateTime().toString("dd MMM HH:mm:ss")); |
329 | 114 | |
115 | 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
|
116 | 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
|
117 | double og = Utils::plato_to_sg(o_plato); |
329 | 118 | double svg = Utils::calc_svg(og, sg); |
119 | ||
120 | 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
|
121 | ui->ogVal2->setText(QString("%1°P").arg(o_plato, 4, 'f', 3, '0')); |
329 | 122 | ui->sgVal->setText(QString("%1").arg(sg, 5, 'f', 4, '0')); |
123 | 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
|
124 | 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
|
125 | 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
|
126 | 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
|
127 | 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
|
128 | } 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
|
129 | /* 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
|
130 | 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
|
131 | 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
|
132 | 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
|
133 | } |
329 | 134 | } else { |
135 | ui->ogVal->setText(""); | |
136 | ui->ogVal2->setText(""); | |
137 | ui->sgVal->setText(""); | |
138 | ui->sgVal2->setText(""); | |
139 | ui->svgVal->setText(""); | |
140 | ui->abvVal->setText(""); | |
141 | ui->batVal->setText(""); | |
142 | } | |
143 | ||
500
cf75e6fadcb1
New battery percentage formula for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
499
diff
changeset
|
144 | const float battery_max = 4.13; |
cf75e6fadcb1
New battery percentage formula for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
499
diff
changeset
|
145 | const float battery_min = 3.43; |
cf75e6fadcb1
New battery percentage formula for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
499
diff
changeset
|
146 | |
cf75e6fadcb1
New battery percentage formula for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents:
499
diff
changeset
|
147 | double batt = ((query.value("battery").toDouble() - battery_min) / (battery_max - battery_min)) * 100; |
329 | 148 | if (batt < 0) |
149 | batt = 0; | |
150 | if (batt > 100) | |
151 | batt = 100; | |
152 | ui->batVal->setText(QString("%1%").arg(batt, 2, 'f', 1, '0')); | |
153 | ||
154 | ui->thermoBox->show(); | |
155 | ui->thermoMeter->setValue(query.value("temperature").toDouble()); | |
156 | ||
157 | } else { | |
158 | /* Offline */ | |
159 | 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
|
160 | ui->statusEdit->setStyleSheet("background-color: red"); |
329 | 161 | ui->powerLED->setChecked(false); |
162 | ui->alarmLED->setChecked(true); | |
163 | ui->codePick->hide(); | |
164 | ui->modeEdit->hide(); | |
165 | ui->thermoBox->hide(); | |
166 | ui->logButton->hide(); | |
167 | } | |
168 | } | |
169 | ||
170 | } | |
171 | ||
172 | ||
173 | DetailiSpindel::~DetailiSpindel() | |
174 | { | |
175 | delete ui; | |
176 | emit entry_changed(); | |
177 | } | |
178 | ||
179 | ||
180 | /* | |
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
|
181 | * Receive signals destined for all iSpindels. |
329 | 182 | * Check if the signal is for us. |
183 | */ | |
184 | void DetailiSpindel::refreshiSpindel(QString data) | |
185 | { | |
186 | if (_node+"/"+_alias == data) { | |
187 | emit refreshTable(); | |
188 | } | |
189 | } | |
190 | ||
191 | ||
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
|
192 | 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
|
193 | { |
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
|
194 | 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
|
195 | } |
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
|
196 | |
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
|
197 | |
329 | 198 | void DetailiSpindel::on_quitButton_clicked() |
199 | { | |
200 | this->close(); | |
201 | this->setResult(1); | |
202 | } | |
203 | ||
204 | ||
205 | void DetailiSpindel::mode_changed(int val) | |
206 | { | |
207 | QStringList mode ({ "OFF", "ON" }); | |
208 | 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
|
209 | #ifdef DEBUG_MONITOR |
329 | 210 | 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
|
211 | #endif |
329 | 212 | webSocket->sendTextMessage(msg); |
213 | } | |
214 | ||
215 | ||
216 | void DetailiSpindel::code_changed(int val) | |
217 | { | |
218 | QJsonParseError parseError; | |
219 | QSqlQuery query; | |
220 | ||
221 | QString msg = QString("{\"device\":\"ispindels\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\","); | |
222 | if (val == 0) { | |
223 | msg.append(QString("\"beeruuid\":\"") + _uuid + "\","); | |
224 | 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
|
225 | 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
|
226 | 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
|
227 | msg.append(QString("\"yeast_hi\":25.0}")); |
329 | 228 | } else { |
229 | 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"); | |
230 | for (int i = 0; i < val; i++) { | |
231 | query.next(); | |
232 | } | |
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
|
233 | 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
|
234 | 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
|
235 | 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
|
236 | 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
|
237 | 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
|
238 | 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
|
239 | 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
|
240 | 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
|
241 | } 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
|
242 | 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
|
243 | 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
|
244 | 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
|
245 | 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
|
246 | 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
|
247 | 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
|
248 | 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
|
249 | } |
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
|
250 | } |
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
|
251 | } |
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
|
252 | } |
329 | 253 | msg.append(QString("\"beeruuid\":\"") + query.value("uuid").toString() + "\","); |
254 | 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
|
255 | 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
|
256 | 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
|
257 | msg.append(QString("\"yeast_hi\":%1}").arg(yh)); |
329 | 258 | } |
259 | ||
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
|
260 | #ifdef DEBUG_MONITOR |
329 | 261 | 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
|
262 | #endif |
329 | 263 | webSocket->sendTextMessage(msg); |
264 | } | |
265 |