added some basic controls
This commit is contained in:
parent
cf1e6d2881
commit
049951ebed
3 changed files with 34 additions and 6 deletions
|
@ -27,14 +27,13 @@ QBluetoothLeUart::~QBluetoothLeUart(){
|
||||||
|
|
||||||
void QBluetoothLeUart::init() {
|
void QBluetoothLeUart::init() {
|
||||||
#ifdef QBluetoothLeUart_QML
|
#ifdef QBluetoothLeUart_QML
|
||||||
qmlRegisterUncreatableType<QBluetoothLeUartDevice>("de.itsblue.bluetoothleuart", 1, 0, "BluetoothDeviceInfo", "BluetoothDeviceInfo cannot be created");
|
qmlRegisterUncreatableType<QBluetoothLeUartDevice>("de.itsblue.bluetoothleuart", 1, 0, "QBluetoothDeviceInfo", "BluetoothDeviceInfo cannot be created");
|
||||||
qmlRegisterType<QBluetoothLeUart>("de.itsblue.bluetoothleuart", 1, 0, "BluetoothLeUART");
|
qmlRegisterType<QBluetoothLeUart>("de.itsblue.bluetoothleuart", 1, 0, "QBluetoothLeUART");
|
||||||
qRegisterMetaType<QBluetoothLeUart::BluetoothLeUartState>("QBluetoothLeUart::BluetoothLeUartState");
|
qRegisterMetaType<QBluetoothLeUart::BluetoothLeUartState>("QBluetoothLeUart::BluetoothLeUartState");
|
||||||
qRegisterMetaType<QBluetoothLeUart::BluetoothScanError>("QBluetoothLeUart::BluetoothScanError");
|
qRegisterMetaType<QBluetoothLeUart::BluetoothScanError>("QBluetoothLeUart::BluetoothScanError");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QBluetoothLeUart::startScanningForDevices(){
|
void QBluetoothLeUart::startScanningForDevices(){
|
||||||
|
|
||||||
foreach(QBluetoothLeUartDevice* oldDevice, this->availableDevices)
|
foreach(QBluetoothLeUartDevice* oldDevice, this->availableDevices)
|
||||||
|
@ -79,6 +78,25 @@ QList<QBluetoothLeUartDevice*> QBluetoothLeUart::getAvailableDevices() {
|
||||||
return this->availableDevices;
|
return this->availableDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantList QBluetoothLeUart::getAvailableDevicesQML() {
|
||||||
|
QVariantList result;
|
||||||
|
|
||||||
|
for(int i=0; i < this->availableDevices.length(); i++) {
|
||||||
|
if(this->availableDevices[i]->getName().isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QVariantMap device;
|
||||||
|
|
||||||
|
device.insert("id", i);
|
||||||
|
device.insert("name", this->availableDevices[i]->getName());
|
||||||
|
device.insert("address", this->availableDevices[i]->getAddress());
|
||||||
|
|
||||||
|
result.append(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void QBluetoothLeUart::handleDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error error)
|
void QBluetoothLeUart::handleDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error error)
|
||||||
{
|
{
|
||||||
if (error == QBluetoothDeviceDiscoveryAgent::PoweredOffError)
|
if (error == QBluetoothDeviceDiscoveryAgent::PoweredOffError)
|
||||||
|
@ -90,6 +108,14 @@ void QBluetoothLeUart::handleDeviceScanError(QBluetoothDeviceDiscoveryAgent::Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void QBluetoothLeUart::connectToDevice(int deviceId) {
|
||||||
|
if(deviceId < 0 || deviceId >= this->availableDevices.length())
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->connectToDevice(this->availableDevices[deviceId]);
|
||||||
|
}
|
||||||
|
|
||||||
void QBluetoothLeUart::connectToDevice(QBluetoothLeUartDevice *device){
|
void QBluetoothLeUart::connectToDevice(QBluetoothLeUartDevice *device){
|
||||||
|
|
||||||
m_qvMeasurements.clear();
|
m_qvMeasurements.clear();
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
class QBluetoothLeUart : public QObject
|
class QBluetoothLeUart : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QList<QBluetoothLeUartDevice*> avaliableDevices READ getAvailableDevices NOTIFY avaliableDevicesChanged)
|
Q_PROPERTY(QVariantList avaliableDevices READ getAvailableDevicesQML NOTIFY avaliableDevicesChanged)
|
||||||
Q_PROPERTY(BluetoothLeUartState state READ getState NOTIFY stateChanged)
|
Q_PROPERTY(BluetoothLeUartState state READ getState NOTIFY stateChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -70,7 +70,9 @@ public slots:
|
||||||
Q_INVOKABLE void startScanningForDevices();
|
Q_INVOKABLE void startScanningForDevices();
|
||||||
Q_INVOKABLE void stopScanningForDevices();
|
Q_INVOKABLE void stopScanningForDevices();
|
||||||
Q_INVOKABLE QList<QBluetoothLeUartDevice*> getAvailableDevices();
|
Q_INVOKABLE QList<QBluetoothLeUartDevice*> getAvailableDevices();
|
||||||
|
Q_INVOKABLE QVariantList getAvailableDevicesQML();
|
||||||
Q_INVOKABLE void connectToDevice(QBluetoothLeUartDevice *device);
|
Q_INVOKABLE void connectToDevice(QBluetoothLeUartDevice *device);
|
||||||
|
Q_INVOKABLE void connectToDevice(int deviceId);
|
||||||
Q_INVOKABLE void sendData(QString s);
|
Q_INVOKABLE void sendData(QString s);
|
||||||
Q_INVOKABLE void disconnectFromDevice();
|
Q_INVOKABLE void disconnectFromDevice();
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ public:
|
||||||
|
|
||||||
friend class QBluetoothLeUart;
|
friend class QBluetoothLeUart;
|
||||||
|
|
||||||
QString getName();
|
Q_INVOKABLE QString getName();
|
||||||
QString getAddress();
|
Q_INVOKABLE QString getAddress();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QBluetoothDeviceInfo getDevice();
|
QBluetoothDeviceInfo getDevice();
|
||||||
|
|
Loading…
Reference in a new issue