LedDisplay/OmobiDisplayApp/omobidisplaybackend.h
Dorian Zedler 3062219099
- add android manifest
- add more fonts
- add proper checks for bluetooth state and permission
2020-10-18 03:26:02 +02:00

106 lines
3.5 KiB
C++

#ifndef OMOBIDISPLAYBACKEND_H
#define OMOBIDISPLAYBACKEND_H
#include <QObject>
#include <QTimer>
#include <QJsonDocument>
#include <QCryptographicHash>
#include <QSettings>
#include <qbluetoothleuartclient.h>
#include <omobidisplaytextmodel.h>
class OmobiDisplayBackend : public QObject
{
Q_OBJECT
Q_PROPERTY(QBluetoothLeUartClient* bleClient READ getBleClient NOTIFY bleClientChanged)
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,
BluetoothOff,
LocationPermissionDenied,
Scanning,
ReadyToConnect,
Connecting,
AuthenticationRequired,
Authenticating,
Initing,
Connected,
Loading
};
Q_ENUM(OmobiDisplayAppState)
private:
enum OmobiDisplayCommand {
AuthenticateCommand = 0,
KeepAliveCommand = 1,
GetAllTextSetsCommand = 10,
GetTextSetParameterCommand = 11,
GetDisplayBrightnessCommand = 12,
SetTextSetParameterCommand = 20,
SetDisplayBrightnessCommand = 21,
SetDisplayCodeCommand = 22,
SetDisplayNameCommand = 23
};
enum OmobiDisplayStatusCode {
Success = 200,
DisplayControllerError = 501
};
OmobiDisplayAppState state;
QBluetoothLeUartClient *bleClient;
QTimer *keepAliveTimer;
OmobiDisplayTextModel* displayTextModel;
int waitingCommands;
QList<QMap<int, QVariant>> textSetsBuffer;
int displayBrightness;
QSettings* settings;
QString lastDisplaySecret;
public slots:
Q_INVOKABLE void startScanning();
Q_INVOKABLE void authenticate(QString secret);
Q_INVOKABLE QBluetoothLeUartClient* getBleClient();
Q_INVOKABLE OmobiDisplayAppState getState();
Q_INVOKABLE OmobiDisplayTextModel* getDisplayTextModel();
Q_INVOKABLE int getDisplayBrightness();
Q_INVOKABLE void setDisplayBrightness(int brightness);
Q_INVOKABLE void setDisplayCode(QString code);
Q_INVOKABLE void setDisplayName(QString name);
private slots:
void handleBluetoothStateChange(QBluetoothLeUartClient::BluetoothLeUartClientState state);
void handleFoundNewDevice(QBluetoothLeUartDevice* device);
void handleBluetoothDeviceConected();
void handleBluetoothScanningError(QBluetoothLeUartClient::BluetoothScanError error);
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 bleClientChanged();
void displayTextModelChanged();
void displayBrightnessChanged();
};
#endif // OMOBIDISPLAYBACKEND_H