52 ui->codePick->addItem(query.value("code").toString()+" - "+query.value("name").toString()); |
54 ui->codePick->addItem(query.value("code").toString()+" - "+query.value("name").toString()); |
53 } |
55 } |
54 |
56 |
55 connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::code_changed); |
57 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); |
58 connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::mode_changed); |
57 connect(ui->logButton, SIGNAL(clicked()), this, SLOT(on_ChartButton_clicked())); |
|
58 connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString))); |
59 connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString))); |
59 emit refreshTable(); |
60 emit refreshTable(); |
60 } |
61 } |
61 |
62 |
62 |
63 |
63 void DetailiSpindel::refreshTable() |
64 void DetailiSpindel::refreshTable() |
64 { |
65 { |
65 QSqlQuery query; |
66 QSqlQuery query; |
66 |
67 |
67 qDebug() << "refreshTable ispindel rec:" << this->recno; |
68 qDebug() << "DetailiSpindel::refreshTable()"; |
68 |
69 |
69 query.prepare("SELECT * FROM mon_ispindels WHERE record = :recno"); |
70 query.prepare("SELECT * FROM mon_ispindels WHERE record = :recno"); |
70 query.bindValue(":recno", this->recno); |
71 query.bindValue(":recno", this->recno); |
71 query.exec(); |
72 query.exec(); |
72 if (query.next()) { |
73 if (query.next()) { |
78 _alias = query.value("alias").toString(); |
79 _alias = query.value("alias").toString(); |
79 _uuid = query.value("uuid").toString(); |
80 _uuid = query.value("uuid").toString(); |
80 _beercode = query.value("beercode").toString(); |
81 _beercode = query.value("beercode").toString(); |
81 _beername = query.value("beername").toString(); |
82 _beername = query.value("beername").toString(); |
82 |
83 |
|
84 bool alarm = (query.value("alarm").toInt() != 0) ? true:false; |
|
85 bool online = (query.value("online").toInt() != 0) ? true:false; |
|
86 bool mode = (query.value("mode").toString() == "ON") ? true:false; |
|
87 |
83 ui->uuidEdit->setText(_uuid); |
88 ui->uuidEdit->setText(_uuid); |
84 ui->systemEdit->setText(_node+"/"+_alias); |
89 ui->systemEdit->setText(_node+"/"+_alias); |
85 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); |
90 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); |
86 |
91 ui->alarmLED->setChecked(alarm); |
87 if (query.value("online").toInt()) { |
92 |
|
93 if (online) { |
88 ui->statusEdit->setText(tr("Online")); |
94 ui->statusEdit->setText(tr("Online")); |
|
95 ui->statusEdit->setStyleSheet(""); |
89 ui->codeEdit->setText(_beercode+" - "+_beername); |
96 ui->codeEdit->setText(_beercode+" - "+_beername); |
|
97 ui->thermoMeter->setNominal(query.value("yeast_lo").toDouble()); |
|
98 ui->thermoMeter->setCritical(query.value("yeast_hi").toDouble()); |
|
99 |
|
100 ui->powerLED->setChecked(mode); |
90 ui->modeEdit->show(); |
101 ui->modeEdit->show(); |
91 if (query.value("mode").toString() == "OFF") { |
102 if (mode) { |
92 ui->powerLED->setChecked(false); |
103 ui->modeEdit->setCurrentIndex(1); |
|
104 ui->codePick->hide(); |
|
105 } else { |
93 ui->modeEdit->setCurrentIndex(0); |
106 ui->modeEdit->setCurrentIndex(0); |
94 ui->codePick->show(); |
107 ui->codePick->show(); |
95 } else { |
|
96 ui->powerLED->setChecked(true); |
|
97 ui->modeEdit->setCurrentIndex(1); |
|
98 ui->codePick->hide(); |
|
99 } |
108 } |
100 ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false); |
|
101 |
109 |
102 ui->voltEdit->setText(QString("%1").arg(query.value("battery").toDouble(), 4, 'f', 3, '0')); |
110 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')); |
111 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')); |
112 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()); |
113 double sg = Utils::plato_to_sg(query.value("gravity").toDouble()); |
106 ui->sgEdit->setText(QString("%1").arg(sg, 5, 'f', 4, '0')); |
114 ui->sgEdit->setText(QString("%1").arg(sg, 5, 'f', 4, '0')); |
107 |
115 |
108 if (query.value("gravity").toDouble()) { |
116 if (query.value("gravity").toDouble()) { |
109 double og = Utils::plato_to_sg(query.value("og_gravity").toDouble()); |
117 double o_plato = query.value("og_gravity").toDouble(); |
|
118 double og = Utils::plato_to_sg(o_plato); |
110 double svg = Utils::calc_svg(og, sg); |
119 double svg = Utils::calc_svg(og, sg); |
111 |
120 |
112 ui->ogVal->setText(QString("%1").arg(og, 5, 'f', 4, '0')); |
121 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')); |
122 ui->ogVal2->setText(QString("%1°P").arg(o_plato, 4, 'f', 3, '0')); |
114 ui->sgVal->setText(QString("%1").arg(sg, 5, 'f', 4, '0')); |
123 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')); |
124 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')); |
125 if (o_plato > 0.1) { |
117 ui->svgBar->setValue(svg); |
126 ui->svgVal->setText(QString("%1%").arg(svg, 2, 'f', 1, '0')); |
118 ui->abvVal->setText(QString("%1%").arg(Utils::abvol(og, sg), 3, 'f', 2, '0')); |
127 ui->svgBar->setValue(svg); |
|
128 ui->abvVal->setText(QString("%1%").arg(Utils::abvol(og, sg), 3, 'f', 2, '0')); |
|
129 } else { |
|
130 /* o_plato is 0 if a new beer is selected. */ |
|
131 ui->svgVal->setText(""); |
|
132 ui->svgBar->setValue(0); |
|
133 ui->abvVal->setText(""); |
|
134 } |
119 } else { |
135 } else { |
120 ui->ogVal->setText(""); |
136 ui->ogVal->setText(""); |
121 ui->ogVal2->setText(""); |
137 ui->ogVal2->setText(""); |
122 ui->sgVal->setText(""); |
138 ui->sgVal->setText(""); |
123 ui->sgVal2->setText(""); |
139 ui->sgVal2->setText(""); |
201 |
219 |
202 QString msg = QString("{\"device\":\"ispindels\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\","); |
220 QString msg = QString("{\"device\":\"ispindels\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\","); |
203 if (val == 0) { |
221 if (val == 0) { |
204 msg.append(QString("\"beeruuid\":\"") + _uuid + "\","); |
222 msg.append(QString("\"beeruuid\":\"") + _uuid + "\","); |
205 msg.append(QString("\"beercode\":\"") + _alias.toUpper() + "\","); |
223 msg.append(QString("\"beercode\":\"") + _alias.toUpper() + "\","); |
206 msg.append(QString("\"beername\":\"") + _alias + "\"}"); |
224 msg.append(QString("\"beername\":\"") + _alias + "\","); |
|
225 msg.append(QString("\"yeast_lo\":20.0,")); |
|
226 msg.append(QString("\"yeast_hi\":25.0}")); |
207 } else { |
227 } 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"); |
228 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++) { |
229 for (int i = 0; i < val; i++) { |
210 query.next(); |
230 query.next(); |
211 } |
231 } |
|
232 double yl = 0; |
|
233 double yh = 40; |
|
234 const auto& y_json = query.value("json_yeasts").toString(); |
|
235 if (! y_json.trimmed().isEmpty()) { |
|
236 const auto& formattedJson = QString("%1").arg(y_json); |
|
237 QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
238 if (parseError.error != QJsonParseError::NoError) { |
|
239 qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
|
240 } else if (yeasts.isArray()) { |
|
241 for (int i = 0; i < yeasts.array().size(); i++) { |
|
242 QJsonObject obj = yeasts.array().at(i).toObject(); |
|
243 if (obj["y_use"].toInt() == 0) { // Primary yeast |
|
244 if (obj["y_min_temperature"].toDouble() > yl) |
|
245 yl = obj["y_min_temperature"].toDouble(); |
|
246 if (obj["y_max_temperature"].toDouble() < yh) |
|
247 yh = obj["y_max_temperature"].toDouble(); |
|
248 } |
|
249 } |
|
250 } |
|
251 } |
212 msg.append(QString("\"beeruuid\":\"") + query.value("uuid").toString() + "\","); |
252 msg.append(QString("\"beeruuid\":\"") + query.value("uuid").toString() + "\","); |
213 msg.append(QString("\"beercode\":\"") + query.value("code").toString() + "\","); |
253 msg.append(QString("\"beercode\":\"") + query.value("code").toString() + "\","); |
214 msg.append(QString("\"beername\":\"") + query.value("name").toString() + "\"}"); |
254 msg.append(QString("\"beername\":\"") + query.value("name").toString() + "\","); |
215 } |
255 msg.append(QString("\"yeast_lo\":%1,").arg(yl)); |
216 |
256 msg.append(QString("\"yeast_hi\":%1}").arg(yh)); |
|
257 } |
|
258 |
|
259 #ifdef DEBUG_MONITOR |
217 qDebug() << "code_changed" << val << msg; |
260 qDebug() << "code_changed" << val << msg; |
|
261 #endif |
218 webSocket->sendTextMessage(msg); |
262 webSocket->sendTextMessage(msg); |
219 } |
263 } |
220 |
264 |