summaryrefslogtreecommitdiffstats
path: root/core/btdiscovery.cpp
diff options
context:
space:
mode:
authorGravatar Jan Mulder <jlmulder@xs4all.nl>2017-06-12 10:38:24 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-06-12 11:05:08 -0700
commit23df5938172cb1e76c5f154caf10a2d462916cfc (patch)
treef7c8fbe7f95fa151ad0f4930c9f53ef8ff901cac /core/btdiscovery.cpp
parent5142d7409f9dc9a102ae9b5898b43b57621c660c (diff)
downloadsubsurface-23df5938172cb1e76c5f154caf10a2d462916cfc.tar.gz
Mobile: wrap up fixes for BT download on Android
Major functional change in this commit is the addition of found static BT devices to the internal administration (on Android), in a way that is equivalent to mobile-on-desktop. So, in both cases, the list of devices in the app are as in the list of devices on the host OS (Linux or Android). To minimize code duplication, the btDeviceDiscovered slot is split in two parts, the part to act as slot for the Qt BT discovery agent (Linux, so mobile-on-desktop), and the part only needed for Android. Remaining to be fixed: the correct handling of the QML UI selection of vendor/product. The first default dive computer is correctly detected, all paired devices from the virtual vendow can be selected, but clicking through vendors results in non logical selections. It is obvious why this is, but a fix is not straigforward at this point. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/btdiscovery.cpp')
-rw-r--r--core/btdiscovery.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp
index 5a93174a6..2362c5b4b 100644
--- a/core/btdiscovery.cpp
+++ b/core/btdiscovery.cpp
@@ -52,6 +52,13 @@ BTDiscovery::BTDiscovery(QObject *parent)
#endif
#if defined(Q_OS_ANDROID) && defined(BT_SUPPORT)
getBluetoothDevices();
+ // and add the paired devices to the internal data
+ // So behaviour is same on Linux/Bluez stack and
+ // Android/Java stack with respect to discovery
+ for (int i = 0; i < btPairedDevices.length(); i++) {
+ btDeviceDiscoveredMain(btPairedDevices[i]);
+
+ }
#endif
for (int i = 0; i < btPairedDevices.length(); i++) {
qDebug() << "Paired =" << btPairedDevices[i].name << btPairedDevices[i].address.toString();
@@ -92,51 +99,58 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
this_d.address = device.address();
this_d.name = device.name();
btPairedDevices.append(this_d);
- struct btVendorProduct btVP;
-
- QString newDevice;
- dc_descriptor_t *newDC = getDeviceType(device.name());
- if (newDC)
- newDevice = dc_descriptor_get_product(newDC);
- else
- newDevice = device.name();
QList<QBluetoothUuid> serviceUuids = device.serviceUuids();
foreach (QBluetoothUuid id, serviceUuids) {
addBtUuid(id);
qDebug() << id.toByteArray();
}
- qDebug() << "Found new device:" << newDevice << device.address();
+
+ btDeviceDiscoveredMain(this_d);
+}
+
+void BTDiscovery::btDeviceDiscoveredMain(const btPairedDevice &device)
+{
+ btVendorProduct btVP;
+
+ QString newDevice;
+ dc_descriptor_t *newDC = getDeviceType(device.name);
+ if (newDC)
+ newDevice = dc_descriptor_get_product(newDC);
+ else
+ newDevice = device.name;
+
+ qDebug() << "Found new device:" << newDevice << device.address;
QString vendor;
if (newDC) foreach (vendor, productList.keys()) {
if (productList[vendor].contains(newDevice)) {
qDebug() << "this could be a " + vendor + " " +
(newDevice == "OSTC 3" ? "OSTC family" : newDevice);
- btVP.btdi = device;
+ btVP.btpdi = device;
btVP.dcDescriptor = newDC;
btVP.vendorIdx = vendorList.indexOf(vendor);
btVP.productIdx = productList[vendor].indexOf(newDevice);
- qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();;
+ qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btpdi.address;;
btDCs << btVP;
break;
}
}
- productList[QObject::tr("Paired Bluetooth Devices")].append(this_d.name + " (" + this_d.address.toString() + ")");
+ productList[QObject::tr("Paired Bluetooth Devices")].append(device.name + " (" + device.address.toString() + ")");
- btVP.btdi = device;
+ btVP.btpdi = device;
btVP.dcDescriptor = newDC;
btVP.vendorIdx = vendorList.indexOf(QObject::tr("Paired Bluetooth Devices"));
- btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(this_d.name);
- qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();
+ btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(device.name);
+ qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btpdi.address;
btAllDevices << btVP;
}
-QList <struct btVendorProduct> BTDiscovery::getBtDcs()
+QList<BTDiscovery::btVendorProduct> BTDiscovery::getBtDcs()
{
return btDCs;
}
-QList <struct btVendorProduct> BTDiscovery::getBtAllDevices()
+QList <BTDiscovery::btVendorProduct> BTDiscovery::getBtAllDevices()
{
return btAllDevices;
}