diff -r 76f3a96e82b5 -r c3a781b4d35b src/DetailFermenter.cpp --- a/src/DetailFermenter.cpp Fri Feb 10 14:06:47 2023 +0100 +++ b/src/DetailFermenter.cpp Fri Feb 10 17:28:46 2023 +0100 @@ -96,7 +96,9 @@ { QSqlQuery query; +#ifdef DEBUG_MONITOR qDebug() << "refreshTable fermenter rec:" << this->recno; +#endif QIcon icon_done, icon_start, icon_abort, icon_pause, icon_cont; icon_done.addFile(QString::fromUtf8(":icons/silk/accept.png"), QSize(), QIcon::Normal, QIcon::Off); @@ -124,12 +126,18 @@ _webcam_url = query.value("webcam_url").toString(); _webcam_light = query.value("webcam_light").toInt(); + QString mode = query.value("mode").toString(); + QString stage = query.value("stage").toString(); + bool online = (query.value("online").toInt() != 0) ? true:false; + bool alarm = (query.value("alarm").toInt() != 0) ? true:false; + ui->uuidEdit->setText(_uuid); ui->systemEdit->setText(_node+"/"+_alias); ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias); - if (query.value("online").toInt()) { + if (online) { ui->statusEdit->setText(tr("Online")); + ui->statusEdit->setStyleSheet(""); ui->codeEdit->show(); ui->codeEdit->setText(_beercode+" - "+_beername); ui->airThermo->setNominal(query.value("yeast_lo").toDouble()); @@ -138,28 +146,28 @@ ui->beerThermo->setCritical(query.value("yeast_hi").toDouble()); ui->modeEdit->show(); - if (query.value("mode").toString() == "OFF") + if (mode == "OFF") ui->modeEdit->setCurrentIndex(0); - else if (query.value("mode").toString() == "NONE") + else if (mode == "NONE") ui->modeEdit->setCurrentIndex(1); - else if (query.value("mode").toString() == "FRIDGE") + else if (mode == "FRIDGE") ui->modeEdit->setCurrentIndex(2); - else if (query.value("mode").toString() == "BEER") + else if (mode == "BEER") ui->modeEdit->setCurrentIndex(3); - else if (query.value("mode").toString() == "PROFILE") + else if (mode == "PROFILE") ui->modeEdit->setCurrentIndex(4); ui->stageEdit->show(); - if (query.value("stage").toString() == "PRIMARY") + if (stage == "PRIMARY") ui->stageEdit->setCurrentIndex(0); - else if (query.value("stage").toString() == "SECONDARY") + else if (stage == "SECONDARY") ui->stageEdit->setCurrentIndex(1); - else if (query.value("stage").toString() == "TERTIARY") + else if (stage == "TERTIARY") ui->stageEdit->setCurrentIndex(2); - else if (query.value("stage").toString() == "CARBONATION") + else if (stage == "CARBONATION") ui->stageEdit->setCurrentIndex(3); - if (query.value("door_address").toString() != "") { + if (query.value("door_address").toString().length() == 36) { ui->doorLED->show(); ui->doorLabel->show(); ui->doorLED->setChecked((query.value("door_state").toInt() != 0) ? true:false); @@ -168,7 +176,7 @@ ui->doorLabel->hide(); } - if (query.value("light_address").toString() != "") { + if (query.value("light_address").toString().length() == 36) { ui->lightLED->show(); ui->lightLabel->show(); ui->lightLED->setChecked((query.value("light_state").toInt() != 0) ? true:false); @@ -177,17 +185,17 @@ ui->lightLabel->hide(); } - if (query.value("mode").toString() == "OFF") { + if (mode == "OFF") { ui->powerLED->setChecked(false); ui->codePick->show(); } else { ui->powerLED->setChecked(true); ui->codePick->hide(); } - ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false); + ui->alarmLED->setChecked(alarm); ui->tempsetBox->show(); - if ((query.value("mode").toString() == "OFF") || (query.value("mode").toString() == "NONE")) { + if ((mode == "OFF") || (mode == "NONE")) { ui->loEdit->hide(); ui->loLabel->hide(); ui->hiEdit->hide(); @@ -197,7 +205,7 @@ ui->loLabel->show(); ui->hiEdit->show(); ui->hiLabel->show(); - if ((query.value("mode").toString() == "FRIDGE") || (query.value("mode").toString() == "BEER")) { + if ((mode == "FRIDGE") || (mode == "BEER")) { ui->loEdit->setReadOnly(false); ui->loEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows); ui->hiEdit->setReadOnly(false); @@ -219,7 +227,7 @@ ui->heatLED->show(); ui->heatLabel->show(); ui->heatLED->setChecked((query.value("heater_state").toInt() != 0) ? true:false); - if (query.value("mode").toString() == "NONE") { + if (mode == "NONE") { ui->heatSwitch->show(); heat_state = (query.value("heater_state").toInt()) ? true:false; ui->heatSwitch->setChecked(heat_state); @@ -236,7 +244,7 @@ ui->coolLED->show(); ui->coolLabel->show(); ui->coolLED->setChecked((query.value("cooler_state").toInt() != 0) ? true:false); - if (query.value("mode").toString() == "NONE") { + if (mode == "NONE") { ui->coolSwitch->show(); cool_state = (query.value("cooler_state").toInt()) ? true:false; ui->coolSwitch->setChecked(cool_state); @@ -253,7 +261,7 @@ ui->fanLED->show(); ui->fanLabel->show(); ui->fanLED->setChecked((query.value("fan_state").toInt() != 0) ? true:false); - if (query.value("mode").toString() == "NONE") { + if (mode == "NONE") { ui->fanSwitch->show(); fan_state = (query.value("fan_state").toInt()) ? true:false; ui->fanSwitch->setChecked(fan_state); @@ -275,17 +283,19 @@ ui->profileEdit->show(); ui->profileEdit->setText(query.value("profile_name").toString()); - if (query.value("mode").toString() == "PROFILE") { + if (mode == "PROFILE") { _profile = query.value("profile_state").toString(); // So we know the profile state anywhere. - qDebug() << "profile state" << query.value("profile_state").toString(); - if (query.value("profile_state").toString() == "OFF") { +#ifdef DEBUG_MONITOR + qDebug() << "profile state" << _profile; +#endif + if (_profile == "OFF") { ui->profilePick->show(); ui->profileShow->hide(); // Both on the same location. ui->modeButton1->show(); ui->modeButton1->setText(tr("Start")); ui->modeButton1->setIcon(icon_start); ui->modeButton2->hide(); - } else if (query.value("profile_state").toString() == "RUN") { + } else if (_profile == "RUN") { ui->profilePick->hide(); ui->profileShow->show(); ui->profileShow->setText(QString(tr("Profile active %1% done")).arg(query.value("profile_percent").toDouble())); @@ -295,7 +305,7 @@ ui->modeButton2->show(); ui->modeButton2->setText(tr("Pause")); ui->modeButton2->setIcon(icon_pause); - } else if (query.value("profile_state").toString() == "PAUSE") { + } else if (_profile == "PAUSE") { ui->profilePick->hide(); ui->profileShow->show(); ui->profileShow->setText(QString(tr("Profile paused %1% done")).arg(query.value("profile_percent").toDouble())); @@ -305,7 +315,7 @@ ui->modeButton2->show(); ui->modeButton2->setText(tr("Continue")); ui->modeButton2->setIcon(icon_cont); - } else if (query.value("profile_state").toString() == "DONE") { + } else if (_profile == "DONE") { ui->profilePick->hide(); ui->profileShow->show(); ui->profileShow->setText(QString(tr("Profile ready"))); @@ -334,7 +344,9 @@ ui->airLabel->show(); if (query.value("air_state").toString() == "OK") { ui->airThermo->setValue(query.value("air_temperature").toDouble()); - } + } else { + ui->airThermo->setValue(NAN); + } } else { ui->airThermo->hide(); ui->airLabel->hide(); @@ -344,7 +356,9 @@ ui->beerLabel->show(); if (query.value("beer_state").toString() == "OK") { ui->beerThermo->setValue(query.value("beer_temperature").toDouble()); - } + } else { + ui->beerThermo->setValue(NAN); + } } else { ui->beerThermo->hide(); ui->beerLabel->hide(); @@ -354,7 +368,9 @@ ui->chillerLabel->show(); if (query.value("chiller_state").toString() == "OK") { ui->chillerThermo->setValue(query.value("chiller_temperature").toDouble()); - } + } else { + ui->chillerThermo->setValue(NAN); + } } else { ui->chillerThermo->hide(); ui->chillerLabel->hide(); @@ -363,6 +379,7 @@ } else { /* Offline */ ui->statusEdit->setText(tr("Offline")); + ui->statusEdit->setStyleSheet("background-color: red"); ui->powerLED->setChecked(false); ui->alarmLED->setChecked(true); ui->codeEdit->hide(); @@ -434,7 +451,9 @@ hi = val + 0.1; QString msg = QString("{\"device\":\"fermenters\",\"node\":\""+_node+"\",\"unit\":\""+_alias+"\",\"setpoint_low\":%1,\"setpoint_high\":%2}") .arg(val, 2, 'f', 1, '0').arg(hi, 2, 'f', 1, '0'); +#ifdef DEBUG_MONITOR qDebug() << "lo_changed" << val << msg; +#endif webSocket->sendTextMessage(msg); } @@ -447,7 +466,9 @@ lo = val - 0.1; QString msg = QString("{\"device\":\"fermenters\",\"node\":\""+_node+"\",\"unit\":\""+_alias+"\",\"setpoint_low\":%1,\"setpoint_high\":%2}") .arg(lo, 2, 'f', 1, '0').arg(val, 2, 'f', 1, '0'); +#ifdef DEBUG_MONITOR qDebug() << "hi_changed" << val << msg; +#endif webSocket->sendTextMessage(msg); } @@ -485,10 +506,15 @@ void DetailFermenter::button1_pressed() { +#ifdef DEBUG_MONITOR qDebug() << "button1" << _profile; +#endif + if (_profile == "OFF") { QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"start\"}}"); +#ifdef DEBUG_MONITOR qDebug() << msg; +#endif webSocket->sendTextMessage(msg); return; } @@ -498,7 +524,9 @@ QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (rc == QMessageBox::Yes) { QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"abort\"}}"); +#ifdef DEBUG_MONITOR qDebug() << msg; +#endif webSocket->sendTextMessage(msg); } return; @@ -506,7 +534,9 @@ if (_profile == "DONE") { QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"done\"}}"); +#ifdef DEBUG_MONITOR qDebug() << msg; +#endif webSocket->sendTextMessage(msg); } } @@ -514,11 +544,15 @@ void DetailFermenter::button2_pressed() { +#ifdef DEBUG_MONITOR qDebug() << "button2" << _profile; +#endif if ((_profile == "RUN") || (_profile == "PAUSE")) { QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"profile\":{\"command\":\"pause\"}}"); +#ifdef DEBUG_MONITOR qDebug() << msg; +#endif webSocket->sendTextMessage(msg); } } @@ -585,7 +619,9 @@ msg.append(QString("\"yeast_hi\":%1}").arg(yh)); } +#ifdef DEBUG_MONITOR qDebug() << "code_changed" << val << msg; +#endif webSocket->sendTextMessage(msg); } @@ -648,7 +684,9 @@ payload.append(QString("]}")); } QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",%1}").arg(payload); +#ifdef DEBUG_MONITOR qDebug() << "profile_changed" << val << msg; +#endif webSocket->sendTextMessage(msg); }