diff options
-rw-r--r-- | core/btdiscovery.cpp | 17 | ||||
-rw-r--r-- | core/btdiscovery.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index 31cf7fa5d..6538ba117 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -184,7 +184,15 @@ void BTDiscovery::BTDiscoveryReDiscover() #if !defined(Q_OS_ANDROID) if (discoveryAgent == nullptr) { discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); + discoveryAgent->setLowEnergyDiscoveryTimeout(3 * 60 * 1000); // search for three minutes connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BTDiscovery::btDeviceDiscovered); + connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &BTDiscovery::btDeviceDiscoveryFinished); + connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &BTDiscovery::btDeviceDiscoveryFinished); + connect(discoveryAgent, QOverload<QBluetoothDeviceDiscoveryAgent::Error>::of(&QBluetoothDeviceDiscoveryAgent::error), + [this](QBluetoothDeviceDiscoveryAgent::Error error){ + qDebug() << "device discovery received error" << discoveryAgent->errorString(); + }); + qDebug() << "discovery methods" << (int)QBluetoothDeviceDiscoveryAgent::supportedDiscoveryMethods(); } qDebug() << "starting BLE discovery"; discoveryAgent->start(); @@ -247,6 +255,15 @@ QString markBLEAddress(const QBluetoothDeviceInfo *device) return btDeviceAddress(device, isBle); } +void BTDiscovery::btDeviceDiscoveryFinished() +{ + qDebug() << "BT/BLE finished discovery"; + QList<QBluetoothDeviceInfo> devList = discoveryAgent->discoveredDevices(); + for (QBluetoothDeviceInfo device: devList) { + qDebug() << device.name() << device.address().toString(); + } +} + void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device) { btPairedDevice this_d; diff --git a/core/btdiscovery.h b/core/btdiscovery.h index 953e707b4..85f2d4d4a 100644 --- a/core/btdiscovery.h +++ b/core/btdiscovery.h @@ -43,6 +43,7 @@ public: int productIdx; }; + void btDeviceDiscoveryFinished(); void btDeviceDiscovered(const QBluetoothDeviceInfo &device); void btDeviceDiscoveredMain(const btPairedDevice &device, bool fromPaired); bool btAvailable() const; |