Fri, 08 Jul 2022 13:24:45 +0200
Removed old experiment to calculate flameout and whirlpool ibu's. Changed Tinseth calculation to use a time window so you can select the ibu contribution during a specified time. Added ibu_method Tinset++. Added calculation extensions for Tinseth++, this calculates the flameout and whirlpool effects on all hops. During cooling is to be done.
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 | ||
35 | qDebug() << "DetailiSpindel record:" << id; | |
36 | ui->setupUi(this); | |
37 | this->recno = id; | |
38 | setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); | |
39 | setWindowTitle(tr("BMSapp - Details iSpindel")); | |
40 | ||
41 | ui->thermoMeter->setMaximum(40.0); | |
42 | ui->thermoMeter->setNominal(20.0); | |
43 | ui->thermoMeter->setCritical(25.0); | |
44 | ui->thermoMeter->setSuffix(QString("°C")); | |
45 | ||
46 | ui->modeEdit->addItem("OFF"); | |
47 | ui->modeEdit->addItem("ON"); | |
48 | ||
49 | ui->codePick->addItem("Free - Dummy"); // Will be replaced later | |
50 | query.exec("SELECT code,name FROM products WHERE stage='1' OR stage='2' OR stage='3' OR stage='4' OR stage='5' OR stage='6' OR stage='7' ORDER BY code"); | |
51 | while (query.next()) { | |
52 | ui->codePick->addItem(query.value("code").toString()+" - "+query.value("name").toString()); | |
53 | } | |
54 | ||
55 | connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::code_changed); | |
56 | connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::mode_changed); | |
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
|
57 | connect(ui->logButton, SIGNAL(clicked()), this, SLOT(on_ChartButton_clicked())); |
329 | 58 | connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString))); |
59 | emit refreshTable(); | |
60 | } | |
61 | ||
62 | ||
63 | void DetailiSpindel::refreshTable() | |
64 | { | |
65 | QSqlQuery query; | |
66 | ||
67 | qDebug() << "refreshTable ispindel rec:" << this->recno; | |
68 | ||
69 | query.prepare("SELECT * FROM mon_ispindels WHERE record = :recno"); | |
70 | query.bindValue(":recno", this->recno); | |
71 | query.exec(); | |
72 | if (query.next()) { | |
73 | ||
74 | const QSignalBlocker blocker1(ui->codePick); | |
75 | const QSignalBlocker blocker2(ui->modeEdit); | |
76 | ||
77 | _node = query.value("node").toString(); | |
78 | _alias = query.value("alias").toString(); | |
79 | _uuid = query.value("uuid").toString(); | |
80 | _beercode = query.value("beercode").toString(); | |
81 | _beername = query.value("beername").toString(); | |
82 | ||
83 | ui->uuidEdit->setText(_uuid); | |
84 | ui->systemEdit->setText(_node+"/"+_alias); | |
85 | ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); | |
86 | ||
87 | if (query.value("online").toInt()) { | |
88 | ui->statusEdit->setText(tr("Online")); | |
89 | ui->codeEdit->setText(_beercode+" - "+_beername); | |
90 | ui->modeEdit->show(); | |
91 | if (query.value("mode").toString() == "OFF") { | |
92 | ui->powerLED->setChecked(false); | |
93 | ui->modeEdit->setCurrentIndex(0); | |
94 | ui->codePick->show(); | |
95 | } else { | |
96 | ui->powerLED->setChecked(true); | |
97 | ui->modeEdit->setCurrentIndex(1); | |
98 | ui->codePick->hide(); | |
99 | } | |
100 | ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false); | |
101 | ||
102 | ui->voltEdit->setText(QString("%1").arg(query.value("battery").toDouble(), 4, 'f', 3, '0')); | |
103 | ui->tiltEdit->setText(QString("%1").arg(query.value("angle").toDouble(), 6, 'f', 5, '0')); | |
104 | ui->platoEdit->setText(QString("%1").arg(query.value("gravity").toDouble(), 4, 'f', 3, '0')); | |
105 | double sg = Utils::plato_to_sg(query.value("gravity").toDouble()); | |
106 | ui->sgEdit->setText(QString("%1").arg(sg, 5, 'f', 4, '0')); | |
107 | ||
108 | if (query.value("gravity").toDouble()) { | |
109 | double og = Utils::plato_to_sg(query.value("og_gravity").toDouble()); | |
110 | double svg = Utils::calc_svg(og, sg); | |
111 | ||
112 | ui->ogVal->setText(QString("%1").arg(og, 5, 'f', 4, '0')); | |
113 | ui->ogVal2->setText(QString("%1°P").arg(query.value("og_gravity").toDouble(), 4, 'f', 3, '0')); | |
114 | ui->sgVal->setText(QString("%1").arg(sg, 5, 'f', 4, '0')); | |
115 | ui->sgVal2->setText(QString("%1°P").arg(query.value("gravity").toDouble(), 4, 'f', 3, '0')); | |
116 | ui->svgVal->setText(QString("%1%").arg(svg, 2, 'f', 1, '0')); | |
117 | ui->svgBar->setValue(svg); | |
118 | ui->abvVal->setText(QString("%1%").arg(Utils::abvol(og, sg), 3, 'f', 2, '0')); | |
119 | } else { | |
120 | ui->ogVal->setText(""); | |
121 | ui->ogVal2->setText(""); | |
122 | ui->sgVal->setText(""); | |
123 | ui->sgVal2->setText(""); | |
124 | ui->svgVal->setText(""); | |
125 | ui->abvVal->setText(""); | |
126 | ui->batVal->setText(""); | |
127 | } | |
128 | ||
129 | double batt = query.value("battery").toDouble() - 3.064; // 0% voltage | |
130 | if (batt < 0) | |
131 | batt = 0; | |
132 | batt = round(batt / 1.17875 * 100.0); // 100% range | |
133 | if (batt > 100) | |
134 | batt = 100; | |
135 | ui->batVal->setText(QString("%1%").arg(batt, 2, 'f', 1, '0')); | |
136 | ||
137 | ui->thermoBox->show(); | |
138 | ui->thermoMeter->setValue(query.value("temperature").toDouble()); | |
139 | ||
140 | } else { | |
141 | /* Offline */ | |
142 | ui->statusEdit->setText(tr("Offline")); | |
143 | ui->powerLED->setChecked(false); | |
144 | ui->alarmLED->setChecked(true); | |
145 | ui->codePick->hide(); | |
146 | ui->modeEdit->hide(); | |
147 | ui->thermoBox->hide(); | |
148 | ui->logButton->hide(); | |
149 | } | |
150 | } | |
151 | ||
152 | } | |
153 | ||
154 | ||
155 | DetailiSpindel::~DetailiSpindel() | |
156 | { | |
157 | qDebug() << "DetailiSpindel done"; | |
158 | delete ui; | |
159 | emit entry_changed(); | |
160 | } | |
161 | ||
162 | ||
163 | /* | |
164 | * Receive signals destined for all co2meters. | |
165 | * Check if the signal is for us. | |
166 | */ | |
167 | void DetailiSpindel::refreshiSpindel(QString data) | |
168 | { | |
169 | if (_node+"/"+_alias == data) { | |
170 | emit refreshTable(); | |
171 | } | |
172 | } | |
173 | ||
174 | ||
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
|
175 | void DetailiSpindel::on_ChartButton_clicked() |
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
|
176 | { |
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
|
177 | 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
|
178 | } |
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
|
179 | |
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
|
180 | |
329 | 181 | void DetailiSpindel::on_quitButton_clicked() |
182 | { | |
183 | this->close(); | |
184 | this->setResult(1); | |
185 | } | |
186 | ||
187 | ||
188 | void DetailiSpindel::mode_changed(int val) | |
189 | { | |
190 | QStringList mode ({ "OFF", "ON" }); | |
191 | QString msg = QString("{\"device\":\"ispindels\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"mode\":\"" + mode[val] + "\"}"); | |
192 | qDebug() << "mode_changed" << val << msg; | |
193 | webSocket->sendTextMessage(msg); | |
194 | } | |
195 | ||
196 | ||
197 | void DetailiSpindel::code_changed(int val) | |
198 | { | |
199 | QJsonParseError parseError; | |
200 | QSqlQuery query; | |
201 | ||
202 | QString msg = QString("{\"device\":\"ispindels\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\","); | |
203 | if (val == 0) { | |
204 | msg.append(QString("\"beeruuid\":\"") + _uuid + "\","); | |
205 | msg.append(QString("\"beercode\":\"") + _alias.toUpper() + "\","); | |
206 | msg.append(QString("\"beername\":\"") + _alias + "\"}"); | |
207 | } else { | |
208 | 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"); | |
209 | for (int i = 0; i < val; i++) { | |
210 | query.next(); | |
211 | } | |
212 | msg.append(QString("\"beeruuid\":\"") + query.value("uuid").toString() + "\","); | |
213 | msg.append(QString("\"beercode\":\"") + query.value("code").toString() + "\","); | |
214 | msg.append(QString("\"beername\":\"") + query.value("name").toString() + "\"}"); | |
215 | } | |
216 | ||
217 | qDebug() << "code_changed" << val << msg; | |
218 | webSocket->sendTextMessage(msg); | |
219 | } | |
220 |