94 |
94 |
95 void DetailFermenter::refreshTable() |
95 void DetailFermenter::refreshTable() |
96 { |
96 { |
97 QSqlQuery query; |
97 QSqlQuery query; |
98 |
98 |
|
99 #ifdef DEBUG_MONITOR |
99 qDebug() << "refreshTable fermenter rec:" << this->recno; |
100 qDebug() << "refreshTable fermenter rec:" << this->recno; |
|
101 #endif |
100 |
102 |
101 QIcon icon_done, icon_start, icon_abort, icon_pause, icon_cont; |
103 QIcon icon_done, icon_start, icon_abort, icon_pause, icon_cont; |
102 icon_done.addFile(QString::fromUtf8(":icons/silk/accept.png"), QSize(), QIcon::Normal, QIcon::Off); |
104 icon_done.addFile(QString::fromUtf8(":icons/silk/accept.png"), QSize(), QIcon::Normal, QIcon::Off); |
103 icon_start.addFile(QString::fromUtf8(":icons/silk/resultset_next.png"), QSize(), QIcon::Normal, QIcon::Off); |
105 icon_start.addFile(QString::fromUtf8(":icons/silk/resultset_next.png"), QSize(), QIcon::Normal, QIcon::Off); |
104 icon_abort.addFile(QString::fromUtf8(":icons/silk/bomb.png"), QSize(), QIcon::Normal, QIcon::Off); |
106 icon_abort.addFile(QString::fromUtf8(":icons/silk/bomb.png"), QSize(), QIcon::Normal, QIcon::Off); |
122 _beercode = query.value("beercode").toString(); |
124 _beercode = query.value("beercode").toString(); |
123 _beername = query.value("beername").toString(); |
125 _beername = query.value("beername").toString(); |
124 _webcam_url = query.value("webcam_url").toString(); |
126 _webcam_url = query.value("webcam_url").toString(); |
125 _webcam_light = query.value("webcam_light").toInt(); |
127 _webcam_light = query.value("webcam_light").toInt(); |
126 |
128 |
|
129 QString mode = query.value("mode").toString(); |
|
130 QString stage = query.value("stage").toString(); |
|
131 bool online = (query.value("online").toInt() != 0) ? true:false; |
|
132 bool alarm = (query.value("alarm").toInt() != 0) ? true:false; |
|
133 |
127 ui->uuidEdit->setText(_uuid); |
134 ui->uuidEdit->setText(_uuid); |
128 ui->systemEdit->setText(_node+"/"+_alias); |
135 ui->systemEdit->setText(_node+"/"+_alias); |
129 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); |
136 ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); |
130 |
137 |
131 if (query.value("online").toInt()) { |
138 if (online) { |
132 ui->statusEdit->setText(tr("Online")); |
139 ui->statusEdit->setText(tr("Online")); |
|
140 ui->statusEdit->setStyleSheet(""); |
133 ui->codeEdit->show(); |
141 ui->codeEdit->show(); |
134 ui->codeEdit->setText(_beercode+" - "+_beername); |
142 ui->codeEdit->setText(_beercode+" - "+_beername); |
135 ui->airThermo->setNominal(query.value("yeast_lo").toDouble()); |
143 ui->airThermo->setNominal(query.value("yeast_lo").toDouble()); |
136 ui->airThermo->setCritical(query.value("yeast_hi").toDouble()); |
144 ui->airThermo->setCritical(query.value("yeast_hi").toDouble()); |
137 ui->beerThermo->setNominal(query.value("yeast_lo").toDouble()); |
145 ui->beerThermo->setNominal(query.value("yeast_lo").toDouble()); |
138 ui->beerThermo->setCritical(query.value("yeast_hi").toDouble()); |
146 ui->beerThermo->setCritical(query.value("yeast_hi").toDouble()); |
139 |
147 |
140 ui->modeEdit->show(); |
148 ui->modeEdit->show(); |
141 if (query.value("mode").toString() == "OFF") |
149 if (mode == "OFF") |
142 ui->modeEdit->setCurrentIndex(0); |
150 ui->modeEdit->setCurrentIndex(0); |
143 else if (query.value("mode").toString() == "NONE") |
151 else if (mode == "NONE") |
144 ui->modeEdit->setCurrentIndex(1); |
152 ui->modeEdit->setCurrentIndex(1); |
145 else if (query.value("mode").toString() == "FRIDGE") |
153 else if (mode == "FRIDGE") |
146 ui->modeEdit->setCurrentIndex(2); |
154 ui->modeEdit->setCurrentIndex(2); |
147 else if (query.value("mode").toString() == "BEER") |
155 else if (mode == "BEER") |
148 ui->modeEdit->setCurrentIndex(3); |
156 ui->modeEdit->setCurrentIndex(3); |
149 else if (query.value("mode").toString() == "PROFILE") |
157 else if (mode == "PROFILE") |
150 ui->modeEdit->setCurrentIndex(4); |
158 ui->modeEdit->setCurrentIndex(4); |
151 |
159 |
152 ui->stageEdit->show(); |
160 ui->stageEdit->show(); |
153 if (query.value("stage").toString() == "PRIMARY") |
161 if (stage == "PRIMARY") |
154 ui->stageEdit->setCurrentIndex(0); |
162 ui->stageEdit->setCurrentIndex(0); |
155 else if (query.value("stage").toString() == "SECONDARY") |
163 else if (stage == "SECONDARY") |
156 ui->stageEdit->setCurrentIndex(1); |
164 ui->stageEdit->setCurrentIndex(1); |
157 else if (query.value("stage").toString() == "TERTIARY") |
165 else if (stage == "TERTIARY") |
158 ui->stageEdit->setCurrentIndex(2); |
166 ui->stageEdit->setCurrentIndex(2); |
159 else if (query.value("stage").toString() == "CARBONATION") |
167 else if (stage == "CARBONATION") |
160 ui->stageEdit->setCurrentIndex(3); |
168 ui->stageEdit->setCurrentIndex(3); |
161 |
169 |
162 if (query.value("door_address").toString() != "") { |
170 if (query.value("door_address").toString().length() == 36) { |
163 ui->doorLED->show(); |
171 ui->doorLED->show(); |
164 ui->doorLabel->show(); |
172 ui->doorLabel->show(); |
165 ui->doorLED->setChecked((query.value("door_state").toInt() != 0) ? true:false); |
173 ui->doorLED->setChecked((query.value("door_state").toInt() != 0) ? true:false); |
166 } else { |
174 } else { |
167 ui->doorLED->hide(); |
175 ui->doorLED->hide(); |
168 ui->doorLabel->hide(); |
176 ui->doorLabel->hide(); |
169 } |
177 } |
170 |
178 |
171 if (query.value("light_address").toString() != "") { |
179 if (query.value("light_address").toString().length() == 36) { |
172 ui->lightLED->show(); |
180 ui->lightLED->show(); |
173 ui->lightLabel->show(); |
181 ui->lightLabel->show(); |
174 ui->lightLED->setChecked((query.value("light_state").toInt() != 0) ? true:false); |
182 ui->lightLED->setChecked((query.value("light_state").toInt() != 0) ? true:false); |
175 } else { |
183 } else { |
176 ui->lightLED->hide(); |
184 ui->lightLED->hide(); |
177 ui->lightLabel->hide(); |
185 ui->lightLabel->hide(); |
178 } |
186 } |
179 |
187 |
180 if (query.value("mode").toString() == "OFF") { |
188 if (mode == "OFF") { |
181 ui->powerLED->setChecked(false); |
189 ui->powerLED->setChecked(false); |
182 ui->codePick->show(); |
190 ui->codePick->show(); |
183 } else { |
191 } else { |
184 ui->powerLED->setChecked(true); |
192 ui->powerLED->setChecked(true); |
185 ui->codePick->hide(); |
193 ui->codePick->hide(); |
186 } |
194 } |
187 ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false); |
195 ui->alarmLED->setChecked(alarm); |
188 |
196 |
189 ui->tempsetBox->show(); |
197 ui->tempsetBox->show(); |
190 if ((query.value("mode").toString() == "OFF") || (query.value("mode").toString() == "NONE")) { |
198 if ((mode == "OFF") || (mode == "NONE")) { |
191 ui->loEdit->hide(); |
199 ui->loEdit->hide(); |
192 ui->loLabel->hide(); |
200 ui->loLabel->hide(); |
193 ui->hiEdit->hide(); |
201 ui->hiEdit->hide(); |
194 ui->hiLabel->hide(); |
202 ui->hiLabel->hide(); |
195 } else { |
203 } else { |
196 ui->loEdit->show(); |
204 ui->loEdit->show(); |
197 ui->loLabel->show(); |
205 ui->loLabel->show(); |
198 ui->hiEdit->show(); |
206 ui->hiEdit->show(); |
199 ui->hiLabel->show(); |
207 ui->hiLabel->show(); |
200 if ((query.value("mode").toString() == "FRIDGE") || (query.value("mode").toString() == "BEER")) { |
208 if ((mode == "FRIDGE") || (mode == "BEER")) { |
201 ui->loEdit->setReadOnly(false); |
209 ui->loEdit->setReadOnly(false); |
202 ui->loEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows); |
210 ui->loEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows); |
203 ui->hiEdit->setReadOnly(false); |
211 ui->hiEdit->setReadOnly(false); |
204 ui->hiEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows); |
212 ui->hiEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows); |
205 } else { |
213 } else { |
273 qobject_cast<QStandardItemModel*>(ui->modeEdit->model())->item(4)->setEnabled(true); |
281 qobject_cast<QStandardItemModel*>(ui->modeEdit->model())->item(4)->setEnabled(true); |
274 } |
282 } |
275 ui->profileEdit->show(); |
283 ui->profileEdit->show(); |
276 ui->profileEdit->setText(query.value("profile_name").toString()); |
284 ui->profileEdit->setText(query.value("profile_name").toString()); |
277 |
285 |
278 if (query.value("mode").toString() == "PROFILE") { |
286 if (mode == "PROFILE") { |
279 _profile = query.value("profile_state").toString(); // So we know the profile state anywhere. |
287 _profile = query.value("profile_state").toString(); // So we know the profile state anywhere. |
280 qDebug() << "profile state" << query.value("profile_state").toString(); |
288 #ifdef DEBUG_MONITOR |
281 if (query.value("profile_state").toString() == "OFF") { |
289 qDebug() << "profile state" << _profile; |
|
290 #endif |
|
291 if (_profile == "OFF") { |
282 ui->profilePick->show(); |
292 ui->profilePick->show(); |
283 ui->profileShow->hide(); // Both on the same location. |
293 ui->profileShow->hide(); // Both on the same location. |
284 ui->modeButton1->show(); |
294 ui->modeButton1->show(); |
285 ui->modeButton1->setText(tr("Start")); |
295 ui->modeButton1->setText(tr("Start")); |
286 ui->modeButton1->setIcon(icon_start); |
296 ui->modeButton1->setIcon(icon_start); |
287 ui->modeButton2->hide(); |
297 ui->modeButton2->hide(); |
288 } else if (query.value("profile_state").toString() == "RUN") { |
298 } else if (_profile == "RUN") { |
289 ui->profilePick->hide(); |
299 ui->profilePick->hide(); |
290 ui->profileShow->show(); |
300 ui->profileShow->show(); |
291 ui->profileShow->setText(QString(tr("Profile active %1% done")).arg(query.value("profile_percent").toDouble())); |
301 ui->profileShow->setText(QString(tr("Profile active %1% done")).arg(query.value("profile_percent").toDouble())); |
292 ui->modeButton1->show(); |
302 ui->modeButton1->show(); |
293 ui->modeButton1->setText(tr("Abort")); |
303 ui->modeButton1->setText(tr("Abort")); |
294 ui->modeButton1->setIcon(icon_abort); |
304 ui->modeButton1->setIcon(icon_abort); |
295 ui->modeButton2->show(); |
305 ui->modeButton2->show(); |
296 ui->modeButton2->setText(tr("Pause")); |
306 ui->modeButton2->setText(tr("Pause")); |
297 ui->modeButton2->setIcon(icon_pause); |
307 ui->modeButton2->setIcon(icon_pause); |
298 } else if (query.value("profile_state").toString() == "PAUSE") { |
308 } else if (_profile == "PAUSE") { |
299 ui->profilePick->hide(); |
309 ui->profilePick->hide(); |
300 ui->profileShow->show(); |
310 ui->profileShow->show(); |
301 ui->profileShow->setText(QString(tr("Profile paused %1% done")).arg(query.value("profile_percent").toDouble())); |
311 ui->profileShow->setText(QString(tr("Profile paused %1% done")).arg(query.value("profile_percent").toDouble())); |
302 ui->modeButton1->show(); |
312 ui->modeButton1->show(); |
303 ui->modeButton1->setText(tr("Abort")); |
313 ui->modeButton1->setText(tr("Abort")); |
304 ui->modeButton1->setIcon(icon_abort); |
314 ui->modeButton1->setIcon(icon_abort); |
305 ui->modeButton2->show(); |
315 ui->modeButton2->show(); |
306 ui->modeButton2->setText(tr("Continue")); |
316 ui->modeButton2->setText(tr("Continue")); |
307 ui->modeButton2->setIcon(icon_cont); |
317 ui->modeButton2->setIcon(icon_cont); |
308 } else if (query.value("profile_state").toString() == "DONE") { |
318 } else if (_profile == "DONE") { |
309 ui->profilePick->hide(); |
319 ui->profilePick->hide(); |
310 ui->profileShow->show(); |
320 ui->profileShow->show(); |
311 ui->profileShow->setText(QString(tr("Profile ready"))); |
321 ui->profileShow->setText(QString(tr("Profile ready"))); |
312 ui->modeButton1->show(); |
322 ui->modeButton1->show(); |
313 ui->modeButton1->setText(tr("Profile Ok")); |
323 ui->modeButton1->setText(tr("Profile Ok")); |
332 if (query.value("air_address").toString().length() == 36) { |
342 if (query.value("air_address").toString().length() == 36) { |
333 ui->airThermo->show(); |
343 ui->airThermo->show(); |
334 ui->airLabel->show(); |
344 ui->airLabel->show(); |
335 if (query.value("air_state").toString() == "OK") { |
345 if (query.value("air_state").toString() == "OK") { |
336 ui->airThermo->setValue(query.value("air_temperature").toDouble()); |
346 ui->airThermo->setValue(query.value("air_temperature").toDouble()); |
337 } |
347 } else { |
|
348 ui->airThermo->setValue(NAN); |
|
349 } |
338 } else { |
350 } else { |
339 ui->airThermo->hide(); |
351 ui->airThermo->hide(); |
340 ui->airLabel->hide(); |
352 ui->airLabel->hide(); |
341 } |
353 } |
342 if (query.value("beer_address").toString().length() == 36) { |
354 if (query.value("beer_address").toString().length() == 36) { |
343 ui->beerThermo->show(); |
355 ui->beerThermo->show(); |
344 ui->beerLabel->show(); |
356 ui->beerLabel->show(); |
345 if (query.value("beer_state").toString() == "OK") { |
357 if (query.value("beer_state").toString() == "OK") { |
346 ui->beerThermo->setValue(query.value("beer_temperature").toDouble()); |
358 ui->beerThermo->setValue(query.value("beer_temperature").toDouble()); |
347 } |
359 } else { |
|
360 ui->beerThermo->setValue(NAN); |
|
361 } |
348 } else { |
362 } else { |
349 ui->beerThermo->hide(); |
363 ui->beerThermo->hide(); |
350 ui->beerLabel->hide(); |
364 ui->beerLabel->hide(); |
351 } |
365 } |
352 if (query.value("chiller_address").toString().length() == 36) { |
366 if (query.value("chiller_address").toString().length() == 36) { |
353 ui->chillerThermo->show(); |
367 ui->chillerThermo->show(); |
354 ui->chillerLabel->show(); |
368 ui->chillerLabel->show(); |
355 if (query.value("chiller_state").toString() == "OK") { |
369 if (query.value("chiller_state").toString() == "OK") { |
356 ui->chillerThermo->setValue(query.value("chiller_temperature").toDouble()); |
370 ui->chillerThermo->setValue(query.value("chiller_temperature").toDouble()); |
357 } |
371 } else { |
|
372 ui->chillerThermo->setValue(NAN); |
|
373 } |
358 } else { |
374 } else { |
359 ui->chillerThermo->hide(); |
375 ui->chillerThermo->hide(); |
360 ui->chillerLabel->hide(); |
376 ui->chillerLabel->hide(); |
361 } |
377 } |
362 |
378 |
363 } else { |
379 } else { |
364 /* Offline */ |
380 /* Offline */ |
365 ui->statusEdit->setText(tr("Offline")); |
381 ui->statusEdit->setText(tr("Offline")); |
|
382 ui->statusEdit->setStyleSheet("background-color: red"); |
366 ui->powerLED->setChecked(false); |
383 ui->powerLED->setChecked(false); |
367 ui->alarmLED->setChecked(true); |
384 ui->alarmLED->setChecked(true); |
368 ui->codeEdit->hide(); |
385 ui->codeEdit->hide(); |
369 ui->codePick->hide(); |
386 ui->codePick->hide(); |
370 ui->modeEdit->hide(); |
387 ui->modeEdit->hide(); |
483 } |
504 } |
484 |
505 |
485 |
506 |
486 void DetailFermenter::button1_pressed() |
507 void DetailFermenter::button1_pressed() |
487 { |
508 { |
|
509 #ifdef DEBUG_MONITOR |
488 qDebug() << "button1" << _profile; |
510 qDebug() << "button1" << _profile; |
|
511 #endif |
|
512 |
489 if (_profile == "OFF") { |
513 if (_profile == "OFF") { |
490 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"start\"}}"); |
514 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"start\"}}"); |
|
515 #ifdef DEBUG_MONITOR |
491 qDebug() << msg; |
516 qDebug() << msg; |
|
517 #endif |
492 webSocket->sendTextMessage(msg); |
518 webSocket->sendTextMessage(msg); |
493 return; |
519 return; |
494 } |
520 } |
495 |
521 |
496 if ((_profile == "RUN") || (_profile == "PAUSE")) { |
522 if ((_profile == "RUN") || (_profile == "PAUSE")) { |
497 int rc = QMessageBox::warning(this, tr("Profile running"), tr("Profile is active, really abort?"), |
523 int rc = QMessageBox::warning(this, tr("Profile running"), tr("Profile is active, really abort?"), |
498 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
524 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
499 if (rc == QMessageBox::Yes) { |
525 if (rc == QMessageBox::Yes) { |
500 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"abort\"}}"); |
526 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"abort\"}}"); |
|
527 #ifdef DEBUG_MONITOR |
501 qDebug() << msg; |
528 qDebug() << msg; |
|
529 #endif |
502 webSocket->sendTextMessage(msg); |
530 webSocket->sendTextMessage(msg); |
503 } |
531 } |
504 return; |
532 return; |
505 } |
533 } |
506 |
534 |
507 if (_profile == "DONE") { |
535 if (_profile == "DONE") { |
508 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"done\"}}"); |
536 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"done\"}}"); |
|
537 #ifdef DEBUG_MONITOR |
509 qDebug() << msg; |
538 qDebug() << msg; |
|
539 #endif |
510 webSocket->sendTextMessage(msg); |
540 webSocket->sendTextMessage(msg); |
511 } |
541 } |
512 } |
542 } |
513 |
543 |
514 |
544 |
515 void DetailFermenter::button2_pressed() |
545 void DetailFermenter::button2_pressed() |
516 { |
546 { |
|
547 #ifdef DEBUG_MONITOR |
517 qDebug() << "button2" << _profile; |
548 qDebug() << "button2" << _profile; |
|
549 #endif |
518 |
550 |
519 if ((_profile == "RUN") || (_profile == "PAUSE")) { |
551 if ((_profile == "RUN") || (_profile == "PAUSE")) { |
520 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"pause\"}}"); |
552 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"pause\"}}"); |
|
553 #ifdef DEBUG_MONITOR |
521 qDebug() << msg; |
554 qDebug() << msg; |
|
555 #endif |
522 webSocket->sendTextMessage(msg); |
556 webSocket->sendTextMessage(msg); |
523 } |
557 } |
524 } |
558 } |
525 |
559 |
526 |
560 |