#ifndef OMOBIDISPLAYBACKEND_H #define OMOBIDISPLAYBACKEND_H #include #include #include #include #include #include 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, AuthenticationRequired, Authenticating, Initing, Connected, Loading }; Q_ENUM(OmobiDisplayAppState) private: enum OmobiDisplayCommand { AuthorizeSessionCommand = 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; QBluetoothLeUart *ble; QTimer *keepAliveTimer; OmobiDisplayTextModel* displayTextModel; int waitingCommands; QList> textSetsBuffer; int displayBrightness; public slots: Q_INVOKABLE void startScanning(); Q_INVOKABLE void authenticate(QString secret); Q_INVOKABLE QBluetoothLeUart* getBleController(); 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(QBluetoothLeUart::BluetoothLeUartState state); void handleFoundNewDevice(QBluetoothLeUartDevice* device); void handleBluetoothDeviceConected(); void handleDisplayTextModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); 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