summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-08-21 15:42:39 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-08-22 19:35:58 -0700
commitc87e0286022a7fbfcef4de183cdcdb15af15010c (patch)
tree6fb760b46a36687267f021c0f9bc5449c27f2bf9
parentba3efae6e8335ff7b050ed03b4432aeda1a0d41a (diff)
downloadsubsurface-c87e0286022a7fbfcef4de183cdcdb15af15010c.tar.gz
core/bluetooth: stop discovery once the dive computer has been found
There is no need to continue to look, and at least with the Shearwater Peregrine having the scan run while we are trying to discover characteristics appeared to cause issues. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--core/btdiscovery.cpp16
-rw-r--r--core/btdiscovery.h1
2 files changed, 15 insertions, 2 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp
index 0e071c207..5d7122414 100644
--- a/core/btdiscovery.cpp
+++ b/core/btdiscovery.cpp
@@ -404,6 +404,14 @@ void BTDiscovery::discoverAddress(QString address)
}
}
+void BTDiscovery::stopAgent()
+{
+ if (!discoveryAgent)
+ return;
+ qDebug() << "---> stopping the discovery agent";
+ discoveryAgent->stop();
+}
+
bool isBluetoothAddress(const QString &address)
{
return extractBluetoothAddress(address) != QString();
@@ -442,8 +450,10 @@ void saveBtDeviceInfo(const QString &devaddr, QBluetoothDeviceInfo deviceInfo)
QBluetoothDeviceInfo getBtDeviceInfo(const QString &devaddr)
{
- if (btDeviceInfo.contains(devaddr))
+ if (btDeviceInfo.contains(devaddr)) {
+ BTDiscovery::instance()->stopAgent();
return btDeviceInfo[devaddr];
+ }
if(!btDeviceInfo.keys().contains(devaddr)) {
qDebug() << "still looking scan is still running, we should just wait for a few moments";
// wait for a maximum of 30 more seconds
@@ -451,8 +461,10 @@ QBluetoothDeviceInfo getBtDeviceInfo(const QString &devaddr)
QElapsedTimer timer;
timer.start();
do {
- if (btDeviceInfo.keys().contains(devaddr))
+ if (btDeviceInfo.keys().contains(devaddr)) {
+ BTDiscovery::instance()->stopAgent();
return btDeviceInfo[devaddr];
+ }
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
QThread::msleep(100);
} while (timer.elapsed() < 30000);
diff --git a/core/btdiscovery.h b/core/btdiscovery.h
index d6c25d8b0..d3a81bf39 100644
--- a/core/btdiscovery.h
+++ b/core/btdiscovery.h
@@ -47,6 +47,7 @@ public:
void btDeviceDiscoveredMain(const btPairedDevice &device);
bool btAvailable() const;
void showNonDiveComputers(bool show);
+ void stopAgent();
#if defined(Q_OS_ANDROID)
void getBluetoothDevices();