# HG changeset patch # User Michiel Broek # Date 1676046526 -3600 # Node ID c3a781b4d35bc61ccbe34a6b999a4414967da472 # Parent 76f3a96e82b54653e7f04a929e9421bbe1fdb322 ChartCarbonate saves the image path in the settings file. Conditional debug messages in a lot on monitor files. In Fermenter monitor details make the status background red if offline. A lot more generic variables instead of continuous expensive calls to MySQL. If fermenter values for the thermometers are not OK, then do not show anything. diff -r 76f3a96e82b5 -r c3a781b4d35b src/ChartCarbonate.cpp --- a/src/ChartCarbonate.cpp Fri Feb 10 14:06:47 2023 +0100 +++ b/src/ChartCarbonate.cpp Fri Feb 10 17:28:46 2023 +0100 @@ -120,12 +120,30 @@ void ChartCarbonate::savePNG() { - QString path = QFileDialog::getSaveFileName(this, tr("Save Image"), QDir::homePath() + "/carbonation.png", tr("Image (*.png)")); + QSettings settings(QSettings::IniFormat, QSettings::UserScope, "mbse", "bmsapp"); + QString dirName; + + /* + * First check if the directory stored in the settings file exists. + * It might be on a removable media that was last used ... + * If so, fallback to the user's home directory. + */ + dirName = settings.value("paths/download").toString(); + if (! QDir(dirName).exists()) { + dirName = QDir::homePath(); + } + + QString path = QFileDialog::getSaveFileName(this, tr("Save Image"), dirName + "/carbonation.png", tr("Image (*.png)")); if (path.isEmpty()) { QMessageBox::warning(this, tr("Save File"), tr("No image file selected.")); return; } + /* + * Update to current selected path + */ + settings.setValue("paths/download", QFileInfo(path).absolutePath()); + QImage img((chartView->size()), QImage::Format_ARGB32); QPainter painter; painter.begin(&img); diff -r 76f3a96e82b5 -r c3a781b4d35b src/DetailCO2meter.cpp --- a/src/DetailCO2meter.cpp Fri Feb 10 14:06:47 2023 +0100 +++ b/src/DetailCO2meter.cpp Fri Feb 10 17:28:46 2023 +0100 @@ -32,7 +32,10 @@ { QSqlQuery query; +#ifdef DEBUG_MONITOR qDebug() << "DetailCO2meter record:" << id; +#endif + ui->setupUi(this); this->recno = id; setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); @@ -65,8 +68,6 @@ QSqlQuery query, query2; QString sql = ""; -// qDebug() << "refreshTable co2meter rec:" << this->recno; - query.prepare("SELECT * FROM mon_co2meters WHERE record = :recno"); query.bindValue(":recno", this->recno); query.exec(); @@ -107,8 +108,6 @@ ui->minBar->setValue(barmin); ui->maxBar->setValue(barmax); ui->thisBar->setValue(barthis); -// qDebug() << " beerdata" << TSec << carbtemp << barmin << barmax << barthis; - ui->barMeter->setNominal(barmin); ui->barMeter->setCritical(barmax); } @@ -220,7 +219,9 @@ msg.append(QString("\"beername\":\"") + query.value("name").toString() + "\"}"); } +#ifdef DEBUG_MONITOR qDebug() << "code_changed" << val << msg; +#endif webSocket->sendTextMessage(msg); } 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); } diff -r 76f3a96e82b5 -r c3a781b4d35b src/MonCO2meters.cpp --- a/src/MonCO2meters.cpp Fri Feb 10 14:06:47 2023 +0100 +++ b/src/MonCO2meters.cpp Fri Feb 10 17:28:46 2023 +0100 @@ -27,7 +27,9 @@ */ MonCO2meters::MonCO2meters(QWidget *parent) : QDialog(parent) { +#ifdef DEBUG_MONITOR qDebug() << "MonCO2meters start"; +#endif gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); @@ -71,7 +73,6 @@ { QTableWidgetItem *item; - //qDebug() << "MonCO2meters reload"; QSqlQuery query("SELECT record,node,alias,online,mode,beercode,beername,temperature,pressure_bar FROM mon_co2meters ORDER BY node,alias"); const QStringList labels({tr("Node"), tr("Unit"), tr("Status"), tr("Mode"), tr("Beer"), tr("Temperature"), tr("Pressure"), tr("Details")}); @@ -144,7 +145,6 @@ void MonCO2meters::refreshCO2meters(QString data) { - //qDebug() << "refreshCO2meters" << data; emit refreshTable(); emit updateCO2meter(data); } diff -r 76f3a96e82b5 -r c3a781b4d35b src/MonFermenters.cpp --- a/src/MonFermenters.cpp Fri Feb 10 14:06:47 2023 +0100 +++ b/src/MonFermenters.cpp Fri Feb 10 17:28:46 2023 +0100 @@ -27,7 +27,9 @@ */ MonFermenters::MonFermenters(QWidget *parent) : QDialog(parent) { +#ifdef DEBUG_MONITOR qDebug() << "MonFermenters start"; +#endif gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); @@ -71,7 +73,6 @@ { QTableWidgetItem *item; - qDebug() << "MonFermenters reload"; QSqlQuery query("SELECT record,node,alias,online,beercode,beername,mode,air_temperature,beer_temperature FROM mon_fermenters ORDER BY node,alias"); const QStringList labels({tr("Node"), tr("Unit"), tr("Status"), tr("Mode"), tr("Beer"), tr("Air"), tr("Beer"), tr("Details")}); @@ -144,7 +145,6 @@ void MonFermenters::refreshFermenters(QString data) { - qDebug() << "refreshFermenters" << data; emit refreshTable(); emit updateFermenter(data); } diff -r 76f3a96e82b5 -r c3a781b4d35b src/MonNodes.cpp --- a/src/MonNodes.cpp Fri Feb 10 14:06:47 2023 +0100 +++ b/src/MonNodes.cpp Fri Feb 10 17:28:46 2023 +0100 @@ -27,7 +27,9 @@ */ MonNodes::MonNodes(QWidget *parent) : QDialog(parent) { +#ifdef DEBUG_MONITOR qDebug() << "MonNodes start"; +#endif gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); @@ -71,8 +73,6 @@ { QTableWidgetItem *item; - qDebug() << "MonNodes reload"; - QSqlQuery query("SELECT record,node,online,group_id,lastseen,net_address,up_interval FROM mon_nodes ORDER BY node"); const QStringList labels({tr("Node"), tr("Status"), tr("Group"), tr("Last seen"), tr("Address"), tr("Interval"), tr("Details")}); @@ -138,7 +138,6 @@ void MonNodes::refreshNodes(QString node) { - qDebug() << "refreshNodes" << node; emit refreshTable(); emit updateNode(node); } diff -r 76f3a96e82b5 -r c3a781b4d35b src/MoniSpindels.cpp --- a/src/MoniSpindels.cpp Fri Feb 10 14:06:47 2023 +0100 +++ b/src/MoniSpindels.cpp Fri Feb 10 17:28:46 2023 +0100 @@ -28,7 +28,9 @@ */ MoniSpindels::MoniSpindels(QWidget *parent) : QDialog(parent) { +#ifdef DEBUG_MONITOR qDebug() << "MoniSpindels start"; +#endif gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); @@ -72,8 +74,6 @@ { QTableWidgetItem *item; - qDebug() << "MoniSpindels reload"; - QSqlQuery query("SELECT record,alias,node,online,mode,temperature,gravity,beercode,beername FROM mon_ispindels ORDER BY alias"); const QStringList labels({tr("Unit"), tr("Node"), tr("Status"), tr("Beer"), tr("Temperature"), tr("SG"), tr("Details")}); @@ -146,7 +146,6 @@ void MoniSpindels::refreshiSpindels(QString data) { - qDebug() << "refreshiSpindels" << data; emit refreshTable(); emit updateiSpindel(data); } diff -r 76f3a96e82b5 -r c3a781b4d35b src/global.h --- a/src/global.h Fri Feb 10 14:06:47 2023 +0100 +++ b/src/global.h Fri Feb 10 17:28:46 2023 +0100 @@ -15,6 +15,7 @@ // #define DEBUG_FERMENTABLES 1 // #define DEBUG_YEAST 1 // #define DEBUG_WATER 1 +#define DEBUG_MONITOR 1 #define Ka1 0.0000004445 #define Ka2 0.0000000000468 diff -r 76f3a96e82b5 -r c3a781b4d35b translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Fri Feb 10 14:06:47 2023 +0100 +++ b/translations/bmsapp_en.ts Fri Feb 10 17:28:46 2023 +0100 @@ -77,22 +77,22 @@ - + Save Image - + Image (*.png) - + Save File - + No image file selected. @@ -429,17 +429,17 @@ - + BMSapp - Details Carbonation - + Online - + Offline @@ -637,63 +637,63 @@ - + Online - + Start - - Profile active %1% done - - - - - - Abort - - - - - Pause - - - - Profile paused %1% done + Profile active %1% done + + + + + + Abort - Continue + Pause + Profile paused %1% done + + + + + Continue + + + + Profile ready - + Profile Ok - + Offline - + Profile running - + Profile is active, really abort? @@ -9944,53 +9944,53 @@ MonCO2meters - + Quit - + Node - + Unit - + Status - + Mode - + Beer - + Temperature - + Pressure - - + + Details - + Total items: %1 @@ -9998,48 +9998,48 @@ MonFermenters - + Quit - + Node - + Unit - + Status - + Mode - + Beer - + Air - - + + Details - + Total items: %1 @@ -10047,7 +10047,7 @@ MonNodes - + Quit @@ -10096,7 +10096,7 @@ MoniSpindels - + Quit diff -r 76f3a96e82b5 -r c3a781b4d35b translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Fri Feb 10 14:06:47 2023 +0100 +++ b/translations/bmsapp_nl.ts Fri Feb 10 17:28:46 2023 +0100 @@ -107,22 +107,22 @@ Datum - + Save Image Opslaan plaatje - + Image (*.png) Plaatje (*.png) - + Save File Bestand opslaan - + No image file selected. Geen plaatjes bestand gekozen. @@ -460,7 +460,7 @@ Expected - Verwacht + Verwacht Maximum @@ -502,17 +502,17 @@ Log - + BMSapp - Details Carbonation BMSapp - Details carbonatie - + Online Online - + Offline Offline @@ -710,63 +710,63 @@ Wis profiel - + Online Online - + Start Start - - Profile active %1% done - Profiel aktief %1% gereed - - - - - Abort - Stoppen - - - - Pause - Pauze - - - Profile paused %1% done - Profiel pauze %1% gereed + Profile active %1% done + Profiel aktief %1% gereed + + + + + Abort + Stoppen - Continue - Ga door + Pause + Pauze + Profile paused %1% done + Profiel pauze %1% gereed + + + + Continue + Ga door + + + Profile ready Profiel gereed - + Profile Ok Profiel Ok - + Offline Offline - + Profile running Profiel draait - + Profile is active, really abort? Profiel is aktief, echt stoppen? @@ -11053,53 +11053,53 @@ MonCO2meters - + Quit Terug - + Node Systeem - + Unit Eenheid - + Status Status - + Beer Bier - + Temperature Temperatuur - + Pressure Druk - - + + Details Details - + Mode Werking - + Total items: %1 Totaal items: %1 @@ -11107,48 +11107,48 @@ MonFermenters - + Quit Terug - + Node Systeem - + Unit Eenheid - + Status Status - + Mode Werking - + Beer Bier - + Air Lucht - - + + Details Details - + Total items: %1 Totaal items: %1 @@ -11156,7 +11156,7 @@ MonNodes - + Quit Terug @@ -11205,7 +11205,7 @@ MoniSpindels - + Quit Terug