LedDisplay/OmobiDisplayApp/omobidisplaybackend.h

92 lines
3 KiB
C++

#ifndef OMOBIDISPLAYBACKEND_H
#define OMOBIDISPLAYBACKEND_H
#include <QObject>
#include <QTimer>
#include <QJsonDocument>
#include <QCryptographicHash>
#include <qbluetoothleuart.h>
#include <omobidisplaytextmodel.h>
class OmobiDisplayBackend : public QObject
{
Q_OBJECT
Q_PROPERTY(QBluetoothLeUart* bleController READ getBleController NOTIFY bleControllerChanged)
Q_PROPERTY(OmobiDisplayAppState state READ getState WRITE setState NOTIFY stateChanged)
Q_PROPERTY(OmobiDisplayTextModel* displayTextModel READ getDisplayTextModel NOTIFY displayTextModelChanged)
Q_PROPERTY(int displayBrightness READ getDisplayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged)
public:
explicit OmobiDisplayBackend(QObject *parent = nullptr);
enum OmobiDisplayAppState {
Idle,
Scanning,
ReadyToConnect,
Connecting,
Initing,
Connected,
Loading
};
Q_ENUM(OmobiDisplayAppState)
private:
enum OmobiDisplayCommand {
AuthorizeSessionCommand = 0,
KeepAliveCommand = 1,
GetAllTextSetsCommand = 10,
GetTextSetParameterCommand = 11,
GetDisplayBrightnessCommand = 12,
SetTextSetParameterCommand = 20,
SetDisplayBrightnessCommand = 21
};
enum OmobiDisplayStatusCode {
Success = 200,
DisplayControllerError = 501
};
OmobiDisplayAppState state;
QBluetoothLeUart *ble;
QTimer *keepAliveTimer;
OmobiDisplayTextModel* displayTextModel;
int waitingCommands;
QList<QMap<int, QVariant>> textSetsBuffer;
int displayBrightness;
public slots:
Q_INVOKABLE void startScanning();
Q_INVOKABLE QBluetoothLeUart* getBleController();
Q_INVOKABLE OmobiDisplayAppState getState();
Q_INVOKABLE OmobiDisplayTextModel* getDisplayTextModel();
Q_INVOKABLE int getDisplayBrightness();
Q_INVOKABLE void setDisplayBrightness(int brightness);
private slots:
void handleBluetoothStateChange(QBluetoothLeUart::BluetoothLeUartState state);
void handleFoundNewDevice(QBluetoothLeUartDevice* device);
void handleBluetoothDeviceConected();
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());
void sendBluetoothKeepAlive();
void handleBluetoothDataReceived(QString s);
void updateDisplayTextSetParameter(int index, int parameter);
void updateDisplayTextSetParameter(int index, int parameter, QString value);
void refreshLoadingState();
void setState(OmobiDisplayAppState state);
signals:
void stateChanged();
void bleControllerChanged();
void displayTextModelChanged();
void displayBrightnessChanged();
};
#endif // OMOBIDISPLAYBACKEND_H