mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
bluetooth discovery: report more information about progress
We certainly should log errors and the complete list of discovered devices. Also, it's good practice to set a specific search time (I picked three minutes). This way we won't constantly scan and drain resources. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ca23147228
commit
5b48585092
2 changed files with 18 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
int productIdx;
|
||||
};
|
||||
|
||||
void btDeviceDiscoveryFinished();
|
||||
void btDeviceDiscovered(const QBluetoothDeviceInfo &device);
|
||||
void btDeviceDiscoveredMain(const btPairedDevice &device, bool fromPaired);
|
||||
bool btAvailable() const;
|
||||
|
|
Loading…
Reference in a new issue