Add spectrometer status to backend

This commit is contained in:
2024-02-15 15:10:12 -03:00
parent 510af52e97
commit 56c16b8908
3 changed files with 115 additions and 9 deletions

View File

@@ -48,9 +48,6 @@ void Backend::setBrokerPort(int port) {
const QMqttClient::ClientState Backend::brokerState() const {
return this->m_client->state();
}
void Backend::setBrokerState(const QMqttClient::ClientState &state) {
this->m_client->setState(state);
}
void Backend::onBrokerStateChanged(const QMqttClient::ClientState &state) {
qWarning() << "State change" << state;
@@ -58,5 +55,9 @@ void Backend::onBrokerStateChanged(const QMqttClient::ClientState &state) {
if (state != QMqttClient::Connected)
return;
// TODO: subscribe
this->m_client->subscribe(QMqttTopicFilter("/spec"), 1);
}
const Spec::SpecStatus Backend::specStatus() const {
return this->m_specStatus;
}

View File

@@ -15,16 +15,46 @@
#include <QObject>
#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 {
Q_OBJECT
// Broker properties
Q_PROPERTY(QString brokerHost READ brokerHost WRITE setBrokerHost NOTIFY
brokerHostChanged)
Q_PROPERTY(int brokerPort READ brokerPort WRITE setBrokerPort NOTIFY
brokerPortChanged)
Q_PROPERTY(QMqttClient::ClientState brokerState READ brokerState WRITE
setBrokerState NOTIFY brokerStateChanged)
Q_PROPERTY(QMqttClient::ClientState brokerState READ brokerState NOTIFY
brokerStateChanged)
QML_NAMED_ELEMENT(Backend)
// Spectrometer properties
Q_PROPERTY(
Spec::SpecStatus specStatus READ specStatus NOTIFY specStatusChanged)
QML_EXTENDED_NAMESPACE(Spec)
public:
explicit Backend(QObject *parent = nullptr);
@@ -45,12 +75,14 @@ public:
void setBrokerPort(int port);
const QMqttClient::ClientState brokerState() const;
void setBrokerState(const QMqttClient::ClientState &state);
const Spec::SpecStatus specStatus() const;
signals:
void brokerHostChanged();
void brokerPortChanged();
void brokerStateChanged();
void specStatusChanged();
private slots:
void onBrokerStateChanged(const QMqttClient::ClientState &state);
@@ -58,4 +90,5 @@ private slots:
private:
Q_DISABLE_COPY(Backend)
QMqttClient *m_client;
Spec::SpecStatus m_specStatus = Spec::SPEC_UNKNOWN;
};

View File

@@ -7,7 +7,7 @@ import "PStyle"
import "Login"
import "."
Window {
ApplicationWindow {
visible: true
width: 640
height: 480
@@ -30,7 +30,10 @@ Window {
repeat: false
interval: 750
onTriggered: loader.source = "qrc:/Login/Login.qml"
onTriggered: {
loader.source = "qrc:/Login/Login.qml"
footer.visible = true
}
}
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"
}
}
}
}
}