LedDisplay/OmobiDisplayApp/omobidisplaybackend.h

93 lines
3 KiB
C
Raw Normal View History

2020-10-08 20:06:57 +02:00
#ifndef OMOBIDISPLAYBACKEND_H
#define OMOBIDISPLAYBACKEND_H
#include <QObject>
2020-10-15 16:57:07 +02:00
#include <QTimer>
#include <QJsonDocument>
#include <QCryptographicHash>
2020-10-08 22:03:30 +02:00
#include <qbluetoothleuart.h>
2020-10-11 21:01:21 +02:00
#include <omobidisplaytextmodel.h>
2020-10-08 20:06:57 +02:00
class OmobiDisplayBackend : public QObject
{
Q_OBJECT
2020-10-09 00:03:50 +02:00
Q_PROPERTY(QBluetoothLeUart* bleController READ getBleController NOTIFY bleControllerChanged)
2020-10-11 15:50:13 +02:00
Q_PROPERTY(OmobiDisplayAppState state READ getState WRITE setState NOTIFY stateChanged)
2020-10-11 21:01:21 +02:00
Q_PROPERTY(OmobiDisplayTextModel* displayTextModel READ getDisplayTextModel NOTIFY displayTextModelChanged)
Q_PROPERTY(int displayBrightness READ getDisplayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged)
2020-10-11 21:01:21 +02:00
2020-10-08 20:06:57 +02:00
public:
explicit OmobiDisplayBackend(QObject *parent = nullptr);
2020-10-11 15:50:13 +02:00
enum OmobiDisplayAppState {
Idle,
Scanning,
ReadyToConnect,
Connecting,
Initing,
Connected,
Loading
2020-10-11 15:50:13 +02:00
};
Q_ENUM(OmobiDisplayAppState)
2020-10-08 20:06:57 +02:00
private:
enum OmobiDisplayCommand {
2020-10-15 16:57:07 +02:00
AuthorizeSessionCommand = 0,
KeepAliveCommand = 1,
GetAllTextSetsCommand = 10,
GetTextSetParameterCommand = 11,
GetDisplayBrightnessCommand = 12,
SetTextSetParameterCommand = 20,
SetDisplayBrightnessCommand = 21
};
enum OmobiDisplayStatusCode {
Success = 200,
DisplayControllerError = 501
};
2020-10-11 15:50:13 +02:00
OmobiDisplayAppState state;
2020-10-08 20:06:57 +02:00
QBluetoothLeUart *ble;
2020-10-15 16:57:07 +02:00
QTimer *keepAliveTimer;
2020-10-11 21:01:21 +02:00
OmobiDisplayTextModel* displayTextModel;
int waitingCommands;
QList<QMap<int, QVariant>> textSetsBuffer;
int displayBrightness;
2020-10-08 20:06:57 +02:00
2020-10-09 00:03:50 +02:00
public slots:
2020-10-11 15:50:13 +02:00
Q_INVOKABLE void startScanning();
Q_INVOKABLE QBluetoothLeUart* getBleController();
Q_INVOKABLE OmobiDisplayAppState getState();
2020-10-11 21:01:21 +02:00
Q_INVOKABLE OmobiDisplayTextModel* getDisplayTextModel();
Q_INVOKABLE int getDisplayBrightness();
Q_INVOKABLE void setDisplayBrightness(int brightness);
2020-10-09 00:03:50 +02:00
2020-10-08 20:06:57 +02:00
private slots:
void handleBluetoothStateChange(QBluetoothLeUart::BluetoothLeUartState state);
2020-10-08 22:03:30 +02:00
void handleFoundNewDevice(QBluetoothLeUartDevice* device);
2020-10-09 00:03:50 +02:00
void handleBluetoothDeviceConected();
2020-10-08 20:06:57 +02:00
void handleDisplayTextModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
void handleDisplayTextModelRowsInserted(const QModelIndex &parent, int first, int last);
void handleDisplayTextModelRowsRemoved(const QModelIndex &parent, int first, int last);
void sendBluetoothCommand(OmobiDisplayCommand command, QVariant data = QVariant());
2020-10-15 16:57:07 +02:00
void sendBluetoothKeepAlive();
void handleBluetoothDataReceived(QString s);
void updateDisplayTextSetParameter(int index, int parameter);
void updateDisplayTextSetParameter(int index, int parameter, QString value);
2020-10-11 21:01:21 +02:00
void refreshLoadingState();
2020-10-11 15:50:13 +02:00
void setState(OmobiDisplayAppState state);
2020-10-08 20:06:57 +02:00
signals:
2020-10-11 15:50:13 +02:00
void stateChanged();
2020-10-09 00:03:50 +02:00
void bleControllerChanged();
2020-10-11 21:01:21 +02:00
void displayTextModelChanged();
void displayBrightnessChanged();
2020-10-08 20:06:57 +02:00
};
#endif // OMOBIDISPLAYBACKEND_H