src/MoniSpindels.cpp

Sun, 23 Jun 2024 11:51:22 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 23 Jun 2024 11:51:22 +0200
changeset 539
e5972bf6e50c
parent 537
48de0f61e5ea
permissions
-rw-r--r--

Archive products on code and on date all use the packaging date.

310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * MoniSpindels.cpp is part of bmsapp.
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "MoniSpindels.h"
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
18 #include "DetailiSpindel.h"
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
19 #include "CalibrateiSpindel.h"
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include "MainWindow.h"
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
21 #include "Utils.h"
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 #include "config.h"
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 /*
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 * Build the table and buttons on the mainscreen.
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 * Don't use a ui file, do it dynamicly.
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 */
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 MoniSpindels::MoniSpindels(QWidget *parent) : QDialog(parent)
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 {
492
c3a781b4d35b 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.
Michiel Broek <mbroek@mbse.eu>
parents: 329
diff changeset
32 #ifdef DEBUG_MONITOR
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 qDebug() << "MoniSpindels start";
492
c3a781b4d35b 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.
Michiel Broek <mbroek@mbse.eu>
parents: 329
diff changeset
34 #endif
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 gridLayout = new QGridLayout(this);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
38 tableiSpindels = new QTableWidget(this);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
39 tableiSpindels->setObjectName(QString::fromUtf8("tableiSpindels"));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
40 tableiSpindels->setEnabled(true);
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 sizePolicy.setHorizontalStretch(0);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 sizePolicy.setVerticalStretch(0);
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
44 sizePolicy.setHeightForWidth(tableiSpindels->sizePolicy().hasHeightForWidth());
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
45 tableiSpindels->setSizePolicy(sizePolicy);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
46 tableiSpindels->setMinimumSize(QSize(1054, 0));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
47 gridLayout->addWidget(tableiSpindels, 0, 0, 1, 1);
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 groupBox = new QGroupBox(this);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 groupBox->setObjectName(QString::fromUtf8("groupBox"));
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 groupBox->setEnabled(true);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 groupBox->setFlat(false);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 horizontalLayout = new QHBoxLayout(groupBox);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 horizontalLayout->setSpacing(6);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 horizontalLayout->setContentsMargins(0, 0, 0, 0);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 quitButton = new QPushButton(groupBox);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 quitButton->setObjectName(QString::fromUtf8("quitButton"));
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 quitButton->setMinimumSize(QSize(80, 24));
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 quitButton->setText(tr("Quit"));
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 QIcon icon;
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 quitButton->setIcon(icon);
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
64 horizontalLayout->addWidget(quitButton, 0, Qt::AlignCenter);
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromMoniSpindels()));
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
69 connect(parent, SIGNAL(updateiSpindels(QString)), this, SLOT(refreshiSpindels(QString)));
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 emit refreshTable();
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 }
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 void MoniSpindels::refreshTable()
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 {
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
76 QTableWidgetItem *item;
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
77 double plato, poly[4];
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
78
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
79 QSqlQuery query("SELECT record,alias,node,online,mode,temperature,gravity,angle,calibrate,beercode,beername FROM mon_ispindels ORDER BY alias");
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
80 const QStringList labels({tr("Unit"), tr("Node"), tr("Status"), tr("Beer"), tr("Temperature"), tr("SG"), tr("Cal"), tr("Details")});
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
82 this->tableiSpindels->setColumnCount(8);
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
83 this->tableiSpindels->setColumnWidth(0, 150); /* Alias */
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
84 this->tableiSpindels->setColumnWidth(1, 120); /* Node */
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
85 this->tableiSpindels->setColumnWidth(2, 100); /* Status */
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
86 this->tableiSpindels->setColumnWidth(3, 330); /* Beer */
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
87 this->tableiSpindels->setColumnWidth(4, 90); /* Temperature */
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
88 this->tableiSpindels->setColumnWidth(5, 90); /* Gravity */
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
89 this->tableiSpindels->setColumnWidth(6, 60); /* Calibrate */
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
90 this->tableiSpindels->setColumnWidth(7, 90); /* Edit button */
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
91 this->tableiSpindels->setRowCount(query.size());
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
92 this->tableiSpindels->setHorizontalHeaderLabels(labels);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
93 this->tableiSpindels->verticalHeader()->hide();
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 /* Set the widget size to 1054 x 575 in the ui. */
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 query.first();
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
97 for (int i = 0 ; i < query.size() ; i++ ) {
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
98 this->tableiSpindels->setItem(i, 0, new QTableWidgetItem(query.value("alias").toString()));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
99 this->tableiSpindels->setItem(i, 1, new QTableWidgetItem(query.value("node").toString()));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
100
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
101 if (query.value("online").toInt()) {
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
102 item = new QTableWidgetItem(QString("Ok"));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
103 } else {
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
104 item = new QTableWidgetItem(QString("Offline"));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
105 item->setForeground(QBrush(QColor(Qt::red)));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
106 }
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
107 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
108 this->tableiSpindels->setItem(i, 2, item);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
109
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
110 if (query.value("mode").toString() == "ON") {
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
111 item = new QTableWidgetItem(query.value("beercode").toString()+" - "+query.value("beername").toString());
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
112 this->tableiSpindels->setItem(i, 3, item);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
113 } else {
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
114 this->tableiSpindels->setItem(i, 3, new QTableWidgetItem(QString("")));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
115 }
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
116
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
117 if (query.value("online").toInt()) {
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
118 /*
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
119 * Try to use the calibrate poly to recalcultate the SG.
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
120 */
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
121 plato = query.value("gravity").toDouble();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
122 QJsonParseError parseError;
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
123 const auto& json = query.value("calibrate").toString();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
124 if (!json.trimmed().isEmpty()) {
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
125 const auto& formattedJson = QString("%1").arg(json);
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
126 QJsonDocument jsonResponse = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
127 QJsonObject jsonObj = jsonResponse.object();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
128 QJsonArray polyData = jsonObj.value("polyData").toArray();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
129 if (polyData.size() == 4) {
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
130 for (int i = 0; i < polyData.size(); i++) {
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
131 poly[i] = polyData.at(i).toDouble();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
132 }
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
133 double angle = query.value("angle").toDouble();
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
134 /* New plato from current polynomial */
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
135 plato = (poly[0] * pow(angle, 3)) + (poly[1] * pow(angle, 2)) + (poly[2] * angle) + poly[3];
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
136 }
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
137 }
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
138
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
139 item = new QTableWidgetItem(QString("%1°C").arg(query.value("temperature").toDouble(), 4, 'f', 3, '0'));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
140 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
141 this->tableiSpindels->setItem(i, 4, item);
537
48de0f61e5ea The iSpindel monitor, detail and chart screens try to use the polynomial calibration data to show the SG. Fallback to already logged data if this fails.
Michiel Broek <mbroek@mbse.eu>
parents: 503
diff changeset
142 double sg = Utils::plato_to_sg(plato);
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
143 item = new QTableWidgetItem(QString("%1").arg(sg, 5, 'f', 4, '0'));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
144 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
145 this->tableiSpindels->setItem(i, 5, item);
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
146 } else {
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
147 this->tableiSpindels->setItem(i, 4, new QTableWidgetItem(QString("")));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
148 this->tableiSpindels->setItem(i, 5, new QTableWidgetItem(QString("")));
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
149 }
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
151 /* Add the Calibrate button */
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
152 QWidget* cWidget = new QWidget();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
153 QPushButton* btn_cal = new QPushButton();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
154 btn_cal->setObjectName(QString("%1").arg(query.value("record").toString())); /* Send record with the button */
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
155 btn_cal->setText(tr("Cal"));
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
156 connect(btn_cal, SIGNAL(clicked()), this, SLOT(on_calButton_clicked()));
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
157 QHBoxLayout* cLayout = new QHBoxLayout(cWidget);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
158 cLayout->addWidget(btn_cal);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
159 cLayout->setContentsMargins(5, 0, 5, 0);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
160 cWidget->setLayout(cLayout);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
161 this->tableiSpindels->setCellWidget(i, 6, cWidget);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
162
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
163 /* Add the Details button */
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 QWidget* pWidget = new QWidget();
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 QPushButton* btn_edit = new QPushButton();
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
166 btn_edit->setObjectName(QString("%1").arg(query.value("record").toString())); /* Send record with the button */
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
167 btn_edit->setText(tr("Details"));
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 pLayout->addWidget(btn_edit);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 pLayout->setContentsMargins(5, 0, 5, 0);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 pWidget->setLayout(pLayout);
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
173 this->tableiSpindels->setCellWidget(i, 7, pWidget);
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 query.next();
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 }
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 }
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 MoniSpindels::~MoniSpindels() {}
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
183 void MoniSpindels::refreshiSpindels(QString data)
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
184 {
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
185 emit refreshTable();
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
186 emit updateiSpindel(data);
311
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
187 }
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
188
449116c083bd Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
189
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 void MoniSpindels::edit(int recno)
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 {
329
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
192 DetailiSpindel dialog(recno, this);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
193 dialog.setModal(true);
b57299738980 Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
194 dialog.exec();
310
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 }
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 void MoniSpindels::on_editButton_clicked()
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 {
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 int recno = pb->objectName().toInt();
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 edit(recno);
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 }
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204
bdaac24b86ed Added monitor nodes overview
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
206 void MoniSpindels::cal(int recno)
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
207 {
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
208 CalibrateiSpindel dialog(recno, this);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
209 dialog.setModal(true);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
210 dialog.exec();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
211 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
212
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
213
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
214 void MoniSpindels::on_calButton_clicked()
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
215 {
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
216 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
217 int recno = pb->objectName().toInt();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
218 cal(recno);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
219 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
220

mercurial