Started with change and signal functions. Implemented mode change for test. The MainWindow webSocket is now global so the Detail screens can send websocket messages.

Thu, 30 Jun 2022 21:05:30 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 30 Jun 2022 21:05:30 +0200
changeset 323
d053ffbbf3e9
parent 322
e7ca120d93c7
child 324
c1bb6b197763

Started with change and signal functions. Implemented mode change for test. The MainWindow webSocket is now global so the Detail screens can send websocket messages.

src/DetailFermenter.cpp file | annotate | diff | comparison | revisions
src/DetailFermenter.h file | annotate | diff | comparison | revisions
src/MainWindow.h file | annotate | diff | comparison | revisions
src/MonFermenters.cpp file | annotate | diff | comparison | revisions
src/MonFermenters.h file | annotate | diff | comparison | revisions
src/global.cpp file | annotate | diff | comparison | revisions
src/global.h file | annotate | diff | comparison | revisions
ui/DetailFermenter.ui file | annotate | diff | comparison | revisions
--- a/src/DetailFermenter.cpp	Thu Jun 30 21:01:50 2022 +0200
+++ b/src/DetailFermenter.cpp	Thu Jun 30 21:05:30 2022 +0200
@@ -16,24 +16,54 @@
  */
 #include "DetailFermenter.h"
 #include "../ui/ui_DetailFermenter.h"
+#include "global.h"
 #include "MainWindow.h"
 
 
 DetailFermenter::DetailFermenter(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailFermenter)
 {
+    QSqlQuery query;
+
     qDebug() << "DetailFermenter record:" << id;
     ui->setupUi(this);
     this->recno = id;
+    setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+    setWindowTitle(tr("BMSapp - Details Fermenter"));
 
-    WindowTitle();
+    ui->airThermo->setMaximum(45.0);
+    ui->airThermo->setNominal(15.0);
+    ui->airThermo->setCritical(20.0);
+    ui->airThermo->setSuffix(QString("°C"));
+
+    ui->beerThermo->setMaximum(45.0);
+    ui->beerThermo->setNominal(15.0);
+    ui->beerThermo->setCritical(20.0);
+    ui->beerThermo->setSuffix(QString("°C"));
+
+    ui->modeEdit->addItem("OFF");
+    ui->modeEdit->addItem("NONE");
+    ui->modeEdit->addItem("FRIDGE");
+    ui->modeEdit->addItem("BEER");
+    ui->modeEdit->addItem("PROFILE");
 
-    // srcMode = ['OFF', 'NONE', 'FRIDGE', 'BEER', 'PROFILE'];
-    // srcStage = ['PRIMARY', 'SECONDARY', 'TERTIARY', 'CARBONATION'];
-    //
-//    connect(ui->nameEdit, &QLineEdit::textChanged, this, &DetailFermenter::is_changed);
-//    connect(ui->unlimitedEdit, &QCheckBox::stateChanged, this, &DetailFermenter::is_changed);
-//    connect(ui->caEdit, &QDoubleSpinBox::textChanged, this, &DetailFermenter::water_changed);
+    ui->stageEdit->addItem("PRIMARY");
+    ui->stageEdit->addItem("SECONDARY");
+    ui->stageEdit->addItem("TERTIARY");
+    ui->stageEdit->addItem("CARBONATION");
 
+    ui->codePick->addItem("Free - Dummy");	// Will be replaced later
+    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");
+    while (query.next()) {
+	ui->codePick->addItem(query.value("code").toString()+" - "+query.value("name").toString());
+    }
+
+    connect(ui->loEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &DetailFermenter::lo_changed);
+    connect(ui->hiEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &DetailFermenter::hi_changed);
+    connect(ui->heatSwitch, SIGNAL(clicked()), this, SLOT(heat_switched()));
+    connect(ui->coolSwitch, SIGNAL(clicked()), this, SLOT(cool_switched()));
+    connect(ui->fanSwitch, SIGNAL(clicked()), this, SLOT(fan_switched()));
+    connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::mode_changed);
+    connect(parent, SIGNAL(updateFermenter(QString)), this, SLOT(refreshFermenter(QString)));
     emit refreshTable();
 }
 
@@ -49,22 +79,104 @@
     query.exec();
     if (query.next()) {
 
+	const QSignalBlocker blocker1(ui->codePick);
+	const QSignalBlocker blocker2(ui->modeEdit);
+
+	_node = query.value("node").toString();
+	_alias = query.value("alias").toString();
+
 	ui->uuidEdit->setText(query.value("uuid").toString());
-	ui->systemEdit->setText(query.value("node").toString()+"/"+query.value("alias").toString());
+	ui->systemEdit->setText(_node+"/"+_alias);
+	ui->codePick->setItemText(0, _alias.toUpper()+" - "+_alias);
 
 	if (query.value("online").toInt()) {
 	    ui->statusEdit->setText(tr("Online"));
-	    ui->codeEdit->setText(query.value("beercode").toString()+" - "+query.value("beername").toString());
+            ui->codeEdit->setText(query.value("beercode").toString()+" - "+query.value("beername").toString());
+	    ui->airThermo->setNominal(query.value("yeast_lo").toDouble());
+	    ui->airThermo->setCritical(query.value("yeast_hi").toDouble());
+	    ui->beerThermo->setNominal(query.value("yeast_lo").toDouble());
+            ui->beerThermo->setCritical(query.value("yeast_hi").toDouble());
+
+	    if (query.value("mode").toString() == "OFF")
+	    	ui->modeEdit->setCurrentIndex(0);
+            else if (query.value("mode").toString() == "NONE")
+	    	ui->modeEdit->setCurrentIndex(1);
+	    else if (query.value("mode").toString() == "FRIDGE")
+            	ui->modeEdit->setCurrentIndex(2);
+	    else if (query.value("mode").toString() == "BEER")
+            	ui->modeEdit->setCurrentIndex(3);
+	    else if (query.value("mode").toString() == "PROFILE")
+            	ui->modeEdit->setCurrentIndex(4);
+
+	    if (query.value("stage").toString() == "PRIMARY")
+		ui->stageEdit->setCurrentIndex(0);
+	    else if (query.value("stage").toString() == "SECONDARY")
+                ui->stageEdit->setCurrentIndex(1);
+	    else if (query.value("stage").toString() == "TERTIARY")
+                ui->stageEdit->setCurrentIndex(2);
+	    else if (query.value("stage").toString() == "CARBONATION")
+                ui->stageEdit->setCurrentIndex(3);
+
+	    if (query.value("door_address").toString() != "") {
+		ui->doorLED->show();
+                ui->doorLabel->show();
+		ui->doorLED->setChecked((query.value("door_state").toInt() != 0) ? true:false);
+	    } else {
+		ui->doorLED->hide();
+		ui->doorLabel->hide();
+	    }
+
+	    if (query.value("light_address").toString() != "") {
+                ui->lightLED->show();
+                ui->lightLabel->show();
+                ui->lightLED->setChecked((query.value("light_state").toInt() != 0) ? true:false);
+            } else {
+                ui->lightLED->hide();
+                ui->lightLabel->hide();
+            }
 
 	    if (query.value("mode").toString() == "OFF") {
 	    	ui->powerLED->setChecked(false);
-	    	// disable dropdowns select beer.
+		ui->codePick->show();
 	    } else {
 	    	ui->powerLED->setChecked(true);
-	    	// enable beerslect
+		ui->codePick->hide();
 	    }
 	    ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false);
 
+	    ui->tempsetBox->show();
+	    if ((query.value("mode").toString() == "FRIDGE") || (query.value("mode").toString() == "BEER")) {
+		ui->loEdit->setReadOnly(false);
+		ui->loEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows);
+		ui->hiEdit->setReadOnly(false);
+                ui->hiEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows);
+	    } else {
+		ui->loEdit->setReadOnly(true);
+		ui->loEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
+		ui->hiEdit->setReadOnly(true);
+                ui->hiEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
+	    }
+	    ui->loEdit->setValue(query.value("setpoint_low").toDouble());
+	    ui->hiEdit->setValue(query.value("setpoint_high").toDouble());
+
+	    ui->switchBox->show();
+	    ui->heatLED->setChecked((query.value("heater_state").toInt() != 0) ? true:false);
+	    ui->coolLED->setChecked((query.value("cooler_state").toInt() != 0) ? true:false);
+	    ui->fanLED->setChecked((query.value("fan_state").toInt() != 0) ? true:false);
+
+	    if (query.value("mode").toString() == "NONE") {
+		ui->heatSwitch->show();
+		ui->coolSwitch->show();
+		ui->fanSwitch->show();
+	    } else {
+		ui->heatSwitch->hide();
+                ui->coolSwitch->hide();
+                ui->fanSwitch->hide();
+	    }
+
+	    //webSocket->sendTextMessage(QString("dd"));
+
+	    ui->thermoBox->show();
 	    if (query.value("air_state").toString() == "OK") {
 	    	ui->airThermo->setValue(query.value("air_temperature").toDouble());
 	    }
@@ -74,9 +186,15 @@
 
 	} else {
 	    /* Offline */
+	    ui->statusEdit->setText(tr("Offline"));
 	    ui->powerLED->setChecked(false);
 	    ui->alarmLED->setChecked(true);
-
+	    ui->codePick->hide();
+	    ui->modeEdit->hide();
+	    ui->stageEdit->hide();
+	    ui->thermoBox->hide();
+	    ui->tempsetBox->hide();
+	    ui->switchBox->hide();
 	}
     }
 
@@ -92,14 +210,15 @@
 
 
 /*
- * Window header, mark any change with '**'
+ * Receive signals destined for all fermenters.
+ * Check if the signal is for us.
  */
-void DetailFermenter::WindowTitle()
+void DetailFermenter::refreshFermenter(QString data)
 {
-    QString txt;
-
-	txt = QString(tr("BMSapp - Edit brewing water %1").arg(this->recno));
-    setWindowTitle(txt);
+    if (_node+"/"+_alias == data) {
+	qDebug() << "for us";
+	emit refreshTable();
+    }
 }
 
 
@@ -108,3 +227,44 @@
     this->close();
     this->setResult(1);
 }
+
+
+void DetailFermenter::lo_changed(double val)
+{
+    qDebug() << "lo_changed" << val;
+}
+
+
+void DetailFermenter::hi_changed(double val)
+{
+    qDebug() << "hi_changed" << val;
+}
+
+
+void DetailFermenter::heat_switched()
+{
+    qDebug() << "heat_switched" << heat_state;
+}
+
+
+void DetailFermenter::cool_switched()
+{
+    qDebug() << "cool_switched" << cool_state;
+}
+
+
+void DetailFermenter::fan_switched()
+{
+    qDebug() << "fan_switched" << fan_state;
+}
+
+
+void DetailFermenter::mode_changed(int val)
+{
+    qDebug() << "mode_changed" << val;
+    QStringList mode ({ "OFF", "NONE", "FRIDGE", "BEER", "PROFiLE" });
+    QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"mode\":\"" + mode[val] + "\"}");
+    qDebug() << msg;
+    webSocket->sendTextMessage(msg);
+}
+
--- a/src/DetailFermenter.h	Thu Jun 30 21:01:50 2022 +0200
+++ b/src/DetailFermenter.h	Thu Jun 30 21:05:30 2022 +0200
@@ -2,6 +2,12 @@
 #define _DETAILFERMENTER_H
 
 #include <QDialog>
+#include <QDoubleSpinBox>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QRadioButton>
+#include <QLineEdit>
+#include <QDialogButtonBox>
 
 
 namespace Ui {
@@ -22,12 +28,23 @@
 private slots:
     void on_quitButton_clicked();
     void refreshTable(void);
+    void lo_changed(double val);
+    void hi_changed(double val);
+    void heat_switched();
+    void cool_switched();
+    void fan_switched();
+    void mode_changed(int val);
+
+public slots:
+    void refreshFermenter(QString);
 
 private:
     Ui::DetailFermenter *ui;
+    QString _node, _alias;
     int recno;
-
-    void WindowTitle();
+    bool heat_state = false;
+    bool cool_state = false;
+    bool fan_state = false;
 };
 
 #endif
--- a/src/MainWindow.h	Thu Jun 30 21:01:50 2022 +0200
+++ b/src/MainWindow.h	Thu Jun 30 21:05:30 2022 +0200
@@ -199,7 +199,6 @@
 
 private:
     Ui::MainWindow *ui;
-    QWebSocket *webSocket;
 
     /**
      * @brief Load profile_setup record and set global variables.
--- a/src/MonFermenters.cpp	Thu Jun 30 21:01:50 2022 +0200
+++ b/src/MonFermenters.cpp	Thu Jun 30 21:05:30 2022 +0200
@@ -146,6 +146,7 @@
 {
     qDebug() << "refreshFermenters" << data;
     emit refreshTable();
+    emit updateFermenter(data);
 }
 
 
--- a/src/MonFermenters.h	Thu Jun 30 21:01:50 2022 +0200
+++ b/src/MonFermenters.h	Thu Jun 30 21:05:30 2022 +0200
@@ -23,6 +23,7 @@
 
 signals:
     void setStatus(QString);
+    void updateFermenter(QString);
 
 private slots:
     void on_editButton_clicked();
--- a/src/global.cpp	Thu Jun 30 21:01:50 2022 +0200
+++ b/src/global.cpp	Thu Jun 30 21:05:30 2022 +0200
@@ -2,7 +2,8 @@
 
 #include "global.h"
 
-QList<Acid>      my_acids;
+QWebSocket	*webSocket;
+QList<Acid>	my_acids;
 
 QString my_brewery_name = "No-name";
 QByteArray my_logoByteArray = 0;
--- a/src/global.h	Thu Jun 30 21:01:50 2022 +0200
+++ b/src/global.h	Thu Jun 30 21:05:30 2022 +0200
@@ -6,7 +6,7 @@
 #include <QTranslator>
 #include <QDate>
 #include <QJsonDocument>
-
+#include <QWebSocket>
 
 #define Ka1		0.0000004445
 #define Ka2		0.0000000000468
@@ -35,6 +35,8 @@
 #define equip_tun_specific_heat	0.110
 #define MaltVolume		0.87	// l/kg 0.688 volgens internetbronnen, gemeten 0.874 l/kg, na enige tijd maischen 0,715 l/kg (A3 Otten).
 
+extern QWebSocket *webSocket;
+
 struct Acid
 {
     QString     name_en;
--- a/ui/DetailFermenter.ui	Thu Jun 30 21:01:50 2022 +0200
+++ b/ui/DetailFermenter.ui	Thu Jun 30 21:05:30 2022 +0200
@@ -457,6 +457,9 @@
       </widget>
      </widget>
      <widget class="QGroupBox" name="thermoBox">
+      <property name="enabled">
+       <bool>true</bool>
+      </property>
       <property name="geometry">
        <rect>
         <x>20</x>
@@ -469,7 +472,7 @@
        <property name="geometry">
         <rect>
          <x>290</x>
-         <y>150</y>
+         <y>160</y>
          <width>101</width>
          <height>20</height>
         </rect>
@@ -484,9 +487,9 @@
       <widget class="QLabel" name="airLabel">
        <property name="geometry">
         <rect>
-         <x>80</x>
+         <x>70</x>
          <y>240</y>
-         <width>101</width>
+         <width>111</width>
          <height>20</height>
         </rect>
        </property>
@@ -502,7 +505,7 @@
         <rect>
          <x>500</x>
          <y>240</y>
-         <width>101</width>
+         <width>111</width>
          <height>20</height>
         </rect>
        </property>
@@ -519,10 +522,10 @@
        </property>
        <property name="geometry">
         <rect>
-         <x>290</x>
-         <y>30</y>
-         <width>100</width>
-         <height>100</height>
+         <x>269</x>
+         <y>10</y>
+         <width>141</width>
+         <height>141</height>
         </rect>
        </property>
        <property name="toolTip">
@@ -531,26 +534,14 @@
        <property name="whatsThis">
         <string>The bar meter widget displays the pressure attached to it</string>
        </property>
-       <property name="minimum">
-        <double>-15.000000000000000</double>
-       </property>
-       <property name="maximum">
-        <double>25.000000000000000</double>
-       </property>
-       <property name="nominal">
-        <double>0.000000000000000</double>
-       </property>
-       <property name="critical">
-        <double>15.000000000000000</double>
-       </property>
       </widget>
       <widget class="ManoMeter" name="beerThermo">
        <property name="geometry">
         <rect>
-         <x>450</x>
-         <y>30</y>
-         <width>201</width>
-         <height>201</height>
+         <x>440</x>
+         <y>10</y>
+         <width>231</width>
+         <height>231</height>
         </rect>
        </property>
        <property name="toolTip">
@@ -559,23 +550,27 @@
        <property name="whatsThis">
         <string>The bar meter widget displays the pressure attached to it</string>
        </property>
-       <property name="maximum">
-        <double>45.000000000000000</double>
+       <property name="valueFont">
+        <font>
+         <pointsize>18</pointsize>
+        </font>
        </property>
-       <property name="nominal">
-        <double>15.000000000000000</double>
+       <property name="digitFont">
+        <font>
+         <pointsize>14</pointsize>
+        </font>
        </property>
-       <property name="critical">
-        <double>20.000000000000000</double>
+       <property name="digitOffset">
+        <double>110.000000000000000</double>
        </property>
       </widget>
       <widget class="ManoMeter" name="airThermo">
        <property name="geometry">
         <rect>
-         <x>30</x>
-         <y>30</y>
-         <width>201</width>
-         <height>201</height>
+         <x>10</x>
+         <y>10</y>
+         <width>231</width>
+         <height>231</height>
         </rect>
        </property>
        <property name="toolTip">
@@ -585,22 +580,20 @@
         <string>The bar meter widget displays the pressure attached to it</string>
        </property>
        <property name="autoFillBackground">
-        <bool>true</bool>
-       </property>
-       <property name="maximum">
-        <double>45.000000000000000</double>
+        <bool>false</bool>
        </property>
-       <property name="nominal">
-        <double>15.000000000000000</double>
+       <property name="valueFont">
+        <font>
+         <pointsize>18</pointsize>
+        </font>
        </property>
-       <property name="critical">
-        <double>20.000000000000000</double>
-       </property>
-       <property name="valueOffset">
-        <double>-100.000000000000000</double>
+       <property name="digitFont">
+        <font>
+         <pointsize>14</pointsize>
+        </font>
        </property>
        <property name="digitOffset">
-        <double>105.000000000000000</double>
+        <double>110.000000000000000</double>
        </property>
       </widget>
      </widget>
@@ -622,6 +615,18 @@
          <height>24</height>
         </rect>
        </property>
+       <property name="accelerated">
+        <bool>true</bool>
+       </property>
+       <property name="decimals">
+        <number>1</number>
+       </property>
+       <property name="maximum">
+        <double>45.000000000000000</double>
+       </property>
+       <property name="singleStep">
+        <double>0.100000000000000</double>
+       </property>
       </widget>
       <widget class="QDoubleSpinBox" name="hiEdit">
        <property name="geometry">
@@ -632,6 +637,18 @@
          <height>24</height>
         </rect>
        </property>
+       <property name="accelerated">
+        <bool>true</bool>
+       </property>
+       <property name="decimals">
+        <number>1</number>
+       </property>
+       <property name="maximum">
+        <double>45.000000000000000</double>
+       </property>
+       <property name="singleStep">
+        <double>0.100000000000000</double>
+       </property>
       </widget>
       <widget class="QLabel" name="loLabel">
        <property name="geometry">
@@ -814,7 +831,7 @@
         <bool>false</bool>
        </property>
       </widget>
-      <widget class="QToolButton" name="heatSwitch_2">
+      <widget class="QToolButton" name="coolSwitch">
        <property name="geometry">
         <rect>
          <x>116</x>
@@ -830,7 +847,7 @@
         <bool>true</bool>
        </property>
       </widget>
-      <widget class="QToolButton" name="heatSwitch_3">
+      <widget class="QToolButton" name="fanSwitch">
        <property name="geometry">
         <rect>
          <x>196</x>

mercurial