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>
|
2020-10-13 01:58:14 +02:00
|
|
|
#include <QJsonDocument>
|
2020-10-15 22:53:24 +02:00
|
|
|
#include <QCryptographicHash>
|
2020-10-18 01:39:59 +02:00
|
|
|
#include <QSettings>
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
#include <qbluetoothleuartclient.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-17 21:51:33 +02:00
|
|
|
Q_PROPERTY(QBluetoothLeUartClient* bleClient READ getBleClient NOTIFY bleClientChanged)
|
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)
|
2020-10-13 01:58:14 +02:00
|
|
|
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,
|
2020-10-18 03:26:02 +02:00
|
|
|
BluetoothOff,
|
|
|
|
LocationPermissionDenied,
|
2020-10-11 15:50:13 +02:00
|
|
|
Scanning,
|
|
|
|
ReadyToConnect,
|
|
|
|
Connecting,
|
2020-10-17 01:08:23 +02:00
|
|
|
AuthenticationRequired,
|
|
|
|
Authenticating,
|
2020-10-14 23:54:12 +02:00
|
|
|
Initing,
|
|
|
|
Connected,
|
|
|
|
Loading
|
2020-10-11 15:50:13 +02:00
|
|
|
};
|
|
|
|
Q_ENUM(OmobiDisplayAppState)
|
2020-10-08 20:06:57 +02:00
|
|
|
|
|
|
|
private:
|
2020-10-14 23:54:12 +02:00
|
|
|
enum OmobiDisplayCommand {
|
2020-10-18 01:39:59 +02:00
|
|
|
AuthenticateCommand = 0,
|
2020-10-15 16:57:07 +02:00
|
|
|
KeepAliveCommand = 1,
|
2020-10-14 23:54:12 +02:00
|
|
|
GetAllTextSetsCommand = 10,
|
|
|
|
GetTextSetParameterCommand = 11,
|
|
|
|
GetDisplayBrightnessCommand = 12,
|
|
|
|
SetTextSetParameterCommand = 20,
|
2020-10-17 03:22:37 +02:00
|
|
|
SetDisplayBrightnessCommand = 21,
|
|
|
|
SetDisplayCodeCommand = 22,
|
|
|
|
SetDisplayNameCommand = 23
|
2020-10-14 23:54:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum OmobiDisplayStatusCode {
|
|
|
|
Success = 200,
|
|
|
|
DisplayControllerError = 501
|
|
|
|
};
|
|
|
|
|
2020-10-11 15:50:13 +02:00
|
|
|
OmobiDisplayAppState state;
|
2020-10-17 21:51:33 +02:00
|
|
|
QBluetoothLeUartClient *bleClient;
|
2020-10-15 16:57:07 +02:00
|
|
|
QTimer *keepAliveTimer;
|
2020-10-11 21:01:21 +02:00
|
|
|
OmobiDisplayTextModel* displayTextModel;
|
2020-10-14 23:54:12 +02:00
|
|
|
int waitingCommands;
|
|
|
|
QList<QMap<int, QVariant>> textSetsBuffer;
|
2020-10-13 01:58:14 +02:00
|
|
|
int displayBrightness;
|
2020-10-08 20:06:57 +02:00
|
|
|
|
2020-10-18 01:39:59 +02:00
|
|
|
QSettings* settings;
|
|
|
|
QString lastDisplaySecret;
|
|
|
|
|
2020-10-09 00:03:50 +02:00
|
|
|
public slots:
|
2020-10-11 15:50:13 +02:00
|
|
|
Q_INVOKABLE void startScanning();
|
2020-10-17 01:08:23 +02:00
|
|
|
Q_INVOKABLE void authenticate(QString secret);
|
2020-10-17 21:51:33 +02:00
|
|
|
Q_INVOKABLE QBluetoothLeUartClient* getBleClient();
|
2020-10-11 15:50:13 +02:00
|
|
|
Q_INVOKABLE OmobiDisplayAppState getState();
|
2020-10-11 21:01:21 +02:00
|
|
|
Q_INVOKABLE OmobiDisplayTextModel* getDisplayTextModel();
|
2020-10-13 01:58:14 +02:00
|
|
|
Q_INVOKABLE int getDisplayBrightness();
|
|
|
|
Q_INVOKABLE void setDisplayBrightness(int brightness);
|
2020-10-17 03:22:37 +02:00
|
|
|
Q_INVOKABLE void setDisplayCode(QString code);
|
|
|
|
Q_INVOKABLE void setDisplayName(QString name);
|
2020-10-09 00:03:50 +02:00
|
|
|
|
2020-10-08 20:06:57 +02:00
|
|
|
private slots:
|
2020-10-17 21:51:33 +02:00
|
|
|
void handleBluetoothStateChange(QBluetoothLeUartClient::BluetoothLeUartClientState 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-18 03:26:02 +02:00
|
|
|
void handleBluetoothScanningError(QBluetoothLeUartClient::BluetoothScanError error);
|
2020-10-08 20:06:57 +02:00
|
|
|
|
2020-10-14 23:54:12 +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();
|
2020-10-14 23:54:12 +02:00
|
|
|
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
|
|
|
|
2020-10-14 23:54:12 +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-17 21:51:33 +02:00
|
|
|
void bleClientChanged();
|
2020-10-11 21:01:21 +02:00
|
|
|
void displayTextModelChanged();
|
2020-10-13 01:58:14 +02:00
|
|
|
void displayBrightnessChanged();
|
2020-10-08 20:06:57 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OMOBIDISPLAYBACKEND_H
|