Add spectrometer status to backend
This commit is contained in:
@@ -48,9 +48,6 @@ void Backend::setBrokerPort(int port) {
|
|||||||
const QMqttClient::ClientState Backend::brokerState() const {
|
const QMqttClient::ClientState Backend::brokerState() const {
|
||||||
return this->m_client->state();
|
return this->m_client->state();
|
||||||
}
|
}
|
||||||
void Backend::setBrokerState(const QMqttClient::ClientState &state) {
|
|
||||||
this->m_client->setState(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Backend::onBrokerStateChanged(const QMqttClient::ClientState &state) {
|
void Backend::onBrokerStateChanged(const QMqttClient::ClientState &state) {
|
||||||
qWarning() << "State change" << state;
|
qWarning() << "State change" << state;
|
||||||
@@ -58,5 +55,9 @@ void Backend::onBrokerStateChanged(const QMqttClient::ClientState &state) {
|
|||||||
if (state != QMqttClient::Connected)
|
if (state != QMqttClient::Connected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: subscribe
|
this->m_client->subscribe(QMqttTopicFilter("/spec"), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Spec::SpecStatus Backend::specStatus() const {
|
||||||
|
return this->m_specStatus;
|
||||||
}
|
}
|
||||||
@@ -15,16 +15,46 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtQml>
|
#include <QtQml>
|
||||||
|
|
||||||
|
namespace Spec {
|
||||||
|
Q_NAMESPACE
|
||||||
|
|
||||||
|
enum SpecStatus {
|
||||||
|
SPEC_READY,
|
||||||
|
SPEC_ACQUIRING,
|
||||||
|
SPEC_NEEDS_CALIBRATION,
|
||||||
|
SPEC_ERROR,
|
||||||
|
SPEC_UNKNOWN,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ConnectionStatus {
|
||||||
|
BROKER_DISCONNECTED,
|
||||||
|
BROKER_CONNECTING,
|
||||||
|
BROKER_CONNECTED,
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_ENUM_NS(SpecStatus)
|
||||||
|
Q_ENUM_NS(ConnectionStatus)
|
||||||
|
|
||||||
|
} // namespace Spec
|
||||||
|
|
||||||
class Backend : public QObject {
|
class Backend : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
// Broker properties
|
||||||
Q_PROPERTY(QString brokerHost READ brokerHost WRITE setBrokerHost NOTIFY
|
Q_PROPERTY(QString brokerHost READ brokerHost WRITE setBrokerHost NOTIFY
|
||||||
brokerHostChanged)
|
brokerHostChanged)
|
||||||
Q_PROPERTY(int brokerPort READ brokerPort WRITE setBrokerPort NOTIFY
|
Q_PROPERTY(int brokerPort READ brokerPort WRITE setBrokerPort NOTIFY
|
||||||
brokerPortChanged)
|
brokerPortChanged)
|
||||||
Q_PROPERTY(QMqttClient::ClientState brokerState READ brokerState WRITE
|
Q_PROPERTY(QMqttClient::ClientState brokerState READ brokerState NOTIFY
|
||||||
setBrokerState NOTIFY brokerStateChanged)
|
brokerStateChanged)
|
||||||
QML_NAMED_ELEMENT(Backend)
|
QML_NAMED_ELEMENT(Backend)
|
||||||
|
|
||||||
|
// Spectrometer properties
|
||||||
|
Q_PROPERTY(
|
||||||
|
Spec::SpecStatus specStatus READ specStatus NOTIFY specStatusChanged)
|
||||||
|
|
||||||
|
QML_EXTENDED_NAMESPACE(Spec)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Backend(QObject *parent = nullptr);
|
explicit Backend(QObject *parent = nullptr);
|
||||||
|
|
||||||
@@ -45,12 +75,14 @@ public:
|
|||||||
void setBrokerPort(int port);
|
void setBrokerPort(int port);
|
||||||
|
|
||||||
const QMqttClient::ClientState brokerState() const;
|
const QMqttClient::ClientState brokerState() const;
|
||||||
void setBrokerState(const QMqttClient::ClientState &state);
|
|
||||||
|
const Spec::SpecStatus specStatus() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void brokerHostChanged();
|
void brokerHostChanged();
|
||||||
void brokerPortChanged();
|
void brokerPortChanged();
|
||||||
void brokerStateChanged();
|
void brokerStateChanged();
|
||||||
|
void specStatusChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onBrokerStateChanged(const QMqttClient::ClientState &state);
|
void onBrokerStateChanged(const QMqttClient::ClientState &state);
|
||||||
@@ -58,4 +90,5 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(Backend)
|
Q_DISABLE_COPY(Backend)
|
||||||
QMqttClient *m_client;
|
QMqttClient *m_client;
|
||||||
|
Spec::SpecStatus m_specStatus = Spec::SPEC_UNKNOWN;
|
||||||
};
|
};
|
||||||
@@ -7,7 +7,7 @@ import "PStyle"
|
|||||||
import "Login"
|
import "Login"
|
||||||
import "."
|
import "."
|
||||||
|
|
||||||
Window {
|
ApplicationWindow {
|
||||||
visible: true
|
visible: true
|
||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 480
|
||||||
@@ -30,7 +30,10 @@ Window {
|
|||||||
repeat: false
|
repeat: false
|
||||||
interval: 750
|
interval: 750
|
||||||
|
|
||||||
onTriggered: loader.source = "qrc:/Login/Login.qml"
|
onTriggered: {
|
||||||
|
loader.source = "qrc:/Login/Login.qml"
|
||||||
|
footer.visible = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
@@ -81,4 +84,73 @@ Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
footer: ToolBar {
|
||||||
|
visible: false
|
||||||
|
|
||||||
|
background: PBackground {
|
||||||
|
color: Qt.lighter(PStyle.backColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
|
spacing: 12
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
PText {
|
||||||
|
font: PStyle.getFont(10)
|
||||||
|
text: qsTr("Connection status:")
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
Layout.preferredHeight: 12
|
||||||
|
Layout.preferredWidth: 12
|
||||||
|
color:
|
||||||
|
App.brokerState == 2 ? "lime" :
|
||||||
|
App.brokerState == 1 ? "yellow" :
|
||||||
|
"red"
|
||||||
|
radius: width / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
PText {
|
||||||
|
font: PStyle.getFont(10)
|
||||||
|
text:
|
||||||
|
App.brokerState == 2 ? "connected" :
|
||||||
|
App.brokerState == 1 ? "connecting" :
|
||||||
|
"disconnected"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Layout.alignment: Qt.AlignRight
|
||||||
|
|
||||||
|
PText {
|
||||||
|
font: PStyle.getFont(10)
|
||||||
|
text: qsTr("Spectrometer status:")
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
Layout.preferredHeight: 12
|
||||||
|
Layout.preferredWidth: 12
|
||||||
|
color:
|
||||||
|
App.specStatus == App.SPEC_UNKNOWN ? "gray" :
|
||||||
|
App.specStatus == App.SPEC_ERROR ? "red" :
|
||||||
|
"lime"
|
||||||
|
radius: width / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
PText {
|
||||||
|
font: PStyle.getFont(10)
|
||||||
|
text:
|
||||||
|
App.specStatus == App.SPEC_ERROR ? "error" :
|
||||||
|
App.specStatus == App.SPEC_READY ? "ready" :
|
||||||
|
App.specStatus == App.SPEC_NEEDS_CALIBRATION ? "needs calibration" :
|
||||||
|
App.specStatus == App.SPEC_ACQUIRING ? "acquiring" :
|
||||||
|
"unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user