-
Notifications
You must be signed in to change notification settings - Fork 523
/
bleuart.h
93 lines (75 loc) · 2.76 KB
/
bleuart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Copyright 2017 Benjamin Vedder [email protected]
This file is part of VESC Tool.
VESC Tool is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VESC Tool is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BLEUART_H
#define BLEUART_H
#include <QObject>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothDeviceInfo>
#include <QLowEnergyController>
#include <QLowEnergyService>
#include <QVariantMap>
#include <QTimer>
class BleUart : public QObject
{
Q_OBJECT
public:
explicit BleUart(QObject *parent = nullptr);
~BleUart();
Q_INVOKABLE void startScan();
Q_INVOKABLE void startConnect(QString addr);
Q_INVOKABLE void disconnectBle();
Q_INVOKABLE bool isConnected();
Q_INVOKABLE bool isConnecting();
Q_INVOKABLE void emitScanDone();
signals:
void dataRx(QByteArray data);
void scanDone(QVariantMap devs, bool done);
void bleError(QString info);
void connected();
void unintentionalDisconnect();
public slots:
void writeData(QByteArray data);
private slots:
void addDevice(const QBluetoothDeviceInfo&dev);
void scanFinished();
void deviceScanError(QBluetoothDeviceDiscoveryAgent::Error e);
void serviceDiscovered(const QBluetoothUuid &);
void serviceScanDone();
void controllerError(QLowEnergyController::Error);
void deviceConnected();
void deviceDisconnected();
void serviceStateChanged(QLowEnergyService::ServiceState s);
void serviceError(QLowEnergyService::ServiceError e);
void updateData(const QLowEnergyCharacteristic &c, const QByteArray &value);
void confirmedDescriptorWrite(const QLowEnergyDescriptor &d, const QByteArray &value);
void controlStateChanged(QLowEnergyController::ControllerState state);
void connectionUpdated(const QLowEnergyConnectionParameters &newParameters);
private:
QBluetoothDeviceDiscoveryAgent *mDeviceDiscoveryAgent;
QLowEnergyController *mControl;
QLowEnergyService *mService;
QLowEnergyDescriptor mNotificationDescTx;
QVariantMap mDevs;
bool mUartServiceFound;
bool mConnectDone;
QString mServiceUuid;
QString mRxUuid;
QString mTxUuid;
bool mScanFinished;
bool mInitDone;
QTimer mConnectTimeoutTimer;
void init();
};
#endif // BLEUART_H