LedDisplay/OmobiDisplayApp/omobidisplaybackend.h
Dorian Zedler ce6d436c85
- finished implementing protocol
- added Initializing and Loading states
- added color picker
2020-10-14 23:54:12 +02:00

86 lines
2.8 KiB
C++

#ifndef OMOBIDISPLAYBACKEND_H
#define OMOBIDISPLAYBACKEND_H
#include <QObject>
#include <QJsonDocument>
#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 {
GetAllTextSetsCommand = 10,
GetTextSetParameterCommand = 11,
GetDisplayBrightnessCommand = 12,
SetTextSetParameterCommand = 20,
SetDisplayBrightnessCommand = 21
};
enum OmobiDisplayStatusCode {
Success = 200,
DisplayControllerError = 501
};
OmobiDisplayAppState state;
QBluetoothLeUart *ble;
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 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