mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-03 15:43:09 +00:00
Mobile: add BT name to vendor/product capability
This adds a central function to convert a BT name to a vendor/product pair known to Subsurface. This allows interfacing from a paired BT dive computer, without actively selecting its type, but by selecting it from the list of paired BT devices. So, after this, downloading from multiple (paired) DCs is also possible. And not the niced piece of code ... Signed-off-by: Jan Mulder <jlmulder@xs4all.nl> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
a43cafa515
commit
5142d7409f
5 changed files with 109 additions and 8 deletions
|
@ -2,10 +2,36 @@
|
||||||
|
|
||||||
#include "btdiscovery.h"
|
#include "btdiscovery.h"
|
||||||
#include "downloadfromdcthread.h"
|
#include "downloadfromdcthread.h"
|
||||||
|
#include "core/libdivecomputer.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
extern QMap<QString, dc_descriptor_t *> descriptorLookup;
|
||||||
|
|
||||||
BTDiscovery *BTDiscovery::m_instance = NULL;
|
BTDiscovery *BTDiscovery::m_instance = NULL;
|
||||||
|
|
||||||
|
static dc_descriptor_t *getDeviceType(QString btName)
|
||||||
|
// central function to convert a BT name to a Subsurface known vendor/model pair
|
||||||
|
{
|
||||||
|
QString vendor, product;
|
||||||
|
|
||||||
|
if (btName.startsWith("OSTC")) {
|
||||||
|
vendor = "Heinrichs Weikamp";
|
||||||
|
if (btName.mid(4,2) == "3#") product = "OSTC 3";
|
||||||
|
else if (btName.mid(4,2) == "3+") product = "OSTC 3+";
|
||||||
|
else if (btName.mid(4,2) == "s#") product = "OSTC Sport";
|
||||||
|
else if (btName.mid(4,2) == "4-") product = "OSTC 4";
|
||||||
|
else if (btName.mid(4,2) == "2-") product = "OSTC 2N";
|
||||||
|
// all OSTCs are HW_FAMILY_OSTC_3, so when we do not know,
|
||||||
|
// just try this
|
||||||
|
else product = "OSTC 3"; // all OSTCs are HW_FAMILY_OSTC_3
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vendor.isEmpty() && !product.isEmpty())
|
||||||
|
return(descriptorLookup[vendor + product]);
|
||||||
|
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
BTDiscovery::BTDiscovery(QObject *parent)
|
BTDiscovery::BTDiscovery(QObject *parent)
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
@ -68,11 +94,13 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
|
||||||
btPairedDevices.append(this_d);
|
btPairedDevices.append(this_d);
|
||||||
struct btVendorProduct btVP;
|
struct btVendorProduct btVP;
|
||||||
|
|
||||||
QString newDevice = device.name();
|
QString newDevice;
|
||||||
|
dc_descriptor_t *newDC = getDeviceType(device.name());
|
||||||
|
if (newDC)
|
||||||
|
newDevice = dc_descriptor_get_product(newDC);
|
||||||
|
else
|
||||||
|
newDevice = device.name();
|
||||||
|
|
||||||
// all the HW OSTC BT computers show up as "OSTC" + some other text, depending on model
|
|
||||||
if (newDevice.startsWith("OSTC"))
|
|
||||||
newDevice = "OSTC 3";
|
|
||||||
QList<QBluetoothUuid> serviceUuids = device.serviceUuids();
|
QList<QBluetoothUuid> serviceUuids = device.serviceUuids();
|
||||||
foreach (QBluetoothUuid id, serviceUuids) {
|
foreach (QBluetoothUuid id, serviceUuids) {
|
||||||
addBtUuid(id);
|
addBtUuid(id);
|
||||||
|
@ -80,11 +108,12 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
|
||||||
}
|
}
|
||||||
qDebug() << "Found new device:" << newDevice << device.address();
|
qDebug() << "Found new device:" << newDevice << device.address();
|
||||||
QString vendor;
|
QString vendor;
|
||||||
foreach (vendor, productList.keys()) {
|
if (newDC) foreach (vendor, productList.keys()) {
|
||||||
if (productList[vendor].contains(newDevice)) {
|
if (productList[vendor].contains(newDevice)) {
|
||||||
qDebug() << "this could be a " + vendor + " " +
|
qDebug() << "this could be a " + vendor + " " +
|
||||||
(newDevice == "OSTC 3" ? "OSTC family" : newDevice);
|
(newDevice == "OSTC 3" ? "OSTC family" : newDevice);
|
||||||
btVP.btdi = device;
|
btVP.btdi = device;
|
||||||
|
btVP.dcDescriptor = newDC;
|
||||||
btVP.vendorIdx = vendorList.indexOf(vendor);
|
btVP.vendorIdx = vendorList.indexOf(vendor);
|
||||||
btVP.productIdx = productList[vendor].indexOf(newDevice);
|
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.btdi.address();;
|
||||||
|
@ -95,6 +124,7 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
|
||||||
productList[QObject::tr("Paired Bluetooth Devices")].append(this_d.name + " (" + this_d.address.toString() + ")");
|
productList[QObject::tr("Paired Bluetooth Devices")].append(this_d.name + " (" + this_d.address.toString() + ")");
|
||||||
|
|
||||||
btVP.btdi = device;
|
btVP.btdi = device;
|
||||||
|
btVP.dcDescriptor = newDC;
|
||||||
btVP.vendorIdx = vendorList.indexOf(QObject::tr("Paired Bluetooth Devices"));
|
btVP.vendorIdx = vendorList.indexOf(QObject::tr("Paired Bluetooth Devices"));
|
||||||
btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(this_d.name);
|
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();
|
qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();
|
||||||
|
@ -174,4 +204,5 @@ bool BTDiscovery::checkException(const char* method, const QAndroidJniObject *ob
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif // Q_OS_ANDROID
|
#endif // Q_OS_ANDROID
|
||||||
|
|
||||||
#endif // BT_SUPPORT
|
#endif // BT_SUPPORT
|
||||||
|
|
|
@ -9,13 +9,17 @@
|
||||||
#include <QBluetoothLocalDevice>
|
#include <QBluetoothLocalDevice>
|
||||||
#include <QBluetoothDeviceDiscoveryAgent>
|
#include <QBluetoothDeviceDiscoveryAgent>
|
||||||
#include <QBluetoothUuid>
|
#include <QBluetoothUuid>
|
||||||
|
#include "core/libdivecomputer.h"
|
||||||
|
|
||||||
struct btVendorProduct {
|
struct btVendorProduct {
|
||||||
QBluetoothDeviceInfo btdi;
|
QBluetoothDeviceInfo btdi;
|
||||||
|
dc_descriptor_t *dcDescriptor;
|
||||||
int vendorIdx;
|
int vendorIdx;
|
||||||
int productIdx;
|
int productIdx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static dc_descriptor_t *getDeviceType(QString btName);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
#include <QAndroidJniObject>
|
#include <QAndroidJniObject>
|
||||||
|
|
|
@ -249,7 +249,7 @@ int DCDeviceData::getDetectedVendorIndex(const QString ¤tText)
|
||||||
QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
|
QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
|
||||||
|
|
||||||
// Pick the vendor of the first confirmed find of a DC (if any), but
|
// Pick the vendor of the first confirmed find of a DC (if any), but
|
||||||
// only return a true vendow, and not our virtual one
|
// only return a true vendor, and not our virtual one
|
||||||
if (!btDCs.isEmpty() && currentText != QObject::tr("Paired Bluetooth Devices")) {
|
if (!btDCs.isEmpty() && currentText != QObject::tr("Paired Bluetooth Devices")) {
|
||||||
qDebug() << "getDetectedVendorIndex" << currentText << btDCs.first().vendorIdx;
|
qDebug() << "getDetectedVendorIndex" << currentText << btDCs.first().vendorIdx;
|
||||||
return btDCs.first().vendorIdx;
|
return btDCs.first().vendorIdx;
|
||||||
|
@ -311,7 +311,62 @@ QString DCDeviceData::getDetectedDeviceAddress(const QString ¤tVendorText,
|
||||||
qDebug() << "getDetectedDeviceAddress" << btAddr;
|
qDebug() << "getDetectedDeviceAddress" << btAddr;
|
||||||
return btAddr;
|
return btAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString();
|
|
||||||
#endif
|
#endif
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DCDeviceData::getDeviceDescriptorVendor(const QString ¤tVendorText,
|
||||||
|
const QString ¤tProductText)
|
||||||
|
{
|
||||||
|
#if defined(BT_SUPPORT)
|
||||||
|
QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
|
||||||
|
QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
|
||||||
|
|
||||||
|
// Pull the vendor from the first found dive computer that is been
|
||||||
|
// detected as a possible real dive computer (and not some other paired
|
||||||
|
// BT device
|
||||||
|
if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) {
|
||||||
|
QString dcVendor = dc_descriptor_get_vendor(btDCs.first().dcDescriptor);
|
||||||
|
qDebug() << "getDeviceDescriptorVendor" << dcVendor;
|
||||||
|
return dcVendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the above fails, pull vendor from the selected paired device
|
||||||
|
// unsure being a dive computer
|
||||||
|
if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) {
|
||||||
|
int i = productList[currentVendorText].indexOf(currentProductText);
|
||||||
|
QString dcVendor = dc_descriptor_get_vendor(btAllDevices[i].dcDescriptor);
|
||||||
|
qDebug() << "getDeviceDescriptorVendor" << dcVendor;
|
||||||
|
return dcVendor;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DCDeviceData::getDeviceDescriptorProduct(const QString ¤tVendorText,
|
||||||
|
const QString ¤tProductText)
|
||||||
|
{
|
||||||
|
#if defined(BT_SUPPORT)
|
||||||
|
QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
|
||||||
|
QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
|
||||||
|
|
||||||
|
// Pull the product from the first found dive computer that is been
|
||||||
|
// detected as a possible real dive computer (and not some other paired
|
||||||
|
// BT device
|
||||||
|
if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) {
|
||||||
|
QString dcProduct = dc_descriptor_get_product(btDCs.first().dcDescriptor);
|
||||||
|
qDebug() << "getDeviceDescriptorProduct" << dcProduct;
|
||||||
|
return dcProduct;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the above fails, pull product from the selected paired device
|
||||||
|
// unsure being a dive computer
|
||||||
|
if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) {
|
||||||
|
int i = productList[currentVendorText].indexOf(currentProductText);
|
||||||
|
QString dcProduct = dc_descriptor_get_product(btAllDevices[i].dcDescriptor);
|
||||||
|
qDebug() << "getDeviceDescriptorProduct" << dcProduct;
|
||||||
|
return dcProduct;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,10 @@ public:
|
||||||
const QString ¤tProductText);
|
const QString ¤tProductText);
|
||||||
Q_INVOKABLE QString getDetectedDeviceAddress(const QString ¤tVendorText,
|
Q_INVOKABLE QString getDetectedDeviceAddress(const QString ¤tVendorText,
|
||||||
const QString ¤tProductText);
|
const QString ¤tProductText);
|
||||||
|
Q_INVOKABLE QString getDeviceDescriptorVendor(const QString ¤tVendorText,
|
||||||
|
const QString ¤tProductText);
|
||||||
|
Q_INVOKABLE QString getDeviceDescriptorProduct(const QString ¤tVendorText,
|
||||||
|
const QString ¤tProductText);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setVendor(const QString& vendor);
|
void setVendor(const QString& vendor);
|
||||||
|
|
|
@ -93,6 +93,13 @@ Kirigami.Page {
|
||||||
comboProduct.currentText)
|
comboProduct.currentText)
|
||||||
if (addr !== "")
|
if (addr !== "")
|
||||||
downloadThread.deviceData.devName = addr
|
downloadThread.deviceData.devName = addr
|
||||||
|
var vendor = downloadThread.deviceData.getDeviceDescriptorVendor(comboVendor.currentText,
|
||||||
|
comboProduct.currentText)
|
||||||
|
downloadThread.deviceData.vendor = vendor;
|
||||||
|
|
||||||
|
var product = downloadThread.deviceData.getDeviceDescriptorProduct(comboVendor.currentText,
|
||||||
|
comboProduct.currentText)
|
||||||
|
downloadThread.deviceData.product = product;
|
||||||
}
|
}
|
||||||
manager.appendTextToLog("DCDownloadThread started for " + downloadThread.deviceData.devName)
|
manager.appendTextToLog("DCDownloadThread started for " + downloadThread.deviceData.devName)
|
||||||
downloadThread.start()
|
downloadThread.start()
|
||||||
|
|
Loading…
Reference in a new issue