diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-09-17 15:40:16 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-09-17 15:40:16 -0700 |
commit | ae209a3d9f8ed36e2228834d421ff4a6ac345ad9 (patch) | |
tree | 046937d0c944d3b6ad8ff9a8c49ab8bdcc3136d9 /core | |
parent | 58b7c6f8ef703009e098351774b8db521cce48e3 (diff) | |
parent | 49fe120d9530682cf539d562c4ffcae3e195b9ab (diff) | |
download | subsurface-ae209a3d9f8ed36e2228834d421ff4a6ac345ad9.tar.gz |
Merge branch 'macBLE' of github.com:Subsurface-divelog/subsurface
Diffstat (limited to 'core')
-rw-r--r-- | core/btdiscovery.cpp | 23 | ||||
-rw-r--r-- | core/btdiscovery.h | 3 | ||||
-rw-r--r-- | core/libdivecomputer.c | 1 | ||||
-rw-r--r-- | core/qt-ble.cpp | 21 |
4 files changed, 38 insertions, 10 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index cab44b4a6..729ee9851 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -174,11 +174,10 @@ QString markBLEAddress(const QBluetoothDeviceInfo *device) flags = device->coreConfigurations(); if (flags == QBluetoothDeviceInfo::LowEnergyCoreConfiguration) prefix = "LE:"; -#if defined(Q_OS_IOS) - return prefix + device->deviceUuid().toString(); -#else - return prefix + device->address().toString(); -#endif + if (device->address().isNull()) + return prefix + device->deviceUuid().toString(); + else + return prefix + device->address().toString(); } void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device) @@ -308,4 +307,18 @@ bool BTDiscovery::checkException(const char* method, const QAndroidJniObject *ob } #endif // Q_OS_ANDROID +QHash<QString, QBluetoothDeviceInfo> btDeviceInfo; + +void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo) +{ + btDeviceInfo[devaddr] = deviceInfo; +} + +QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr) +{ + if (btDeviceInfo.contains(devaddr)) + return btDeviceInfo[devaddr]; + qDebug() << "need to scan for" << devaddr; + return QBluetoothDeviceInfo(); +} #endif // BT_SUPPORT diff --git a/core/btdiscovery.h b/core/btdiscovery.h index 71df24f24..160890c73 100644 --- a/core/btdiscovery.h +++ b/core/btdiscovery.h @@ -18,6 +18,9 @@ #include <QAndroidJniEnvironment> #endif +void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo); +QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr); + class ConnectionListModel : public QAbstractListModel { Q_OBJECT public: diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index ebffad2bf..e6b600644 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -1121,6 +1121,7 @@ const char *do_libdivecomputer_import(device_data_t *data) /* TODO: Show the logfile to the user on error. */ dc_device_close(data->device); data->device = NULL; + dev_info(data, translate("gettextFromC", "No new dives downloaded from dive computer")); } dc_context_free(data->context); diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 9867528c8..92a78ae65 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -16,6 +16,7 @@ #include "libdivecomputer.h" #include "core/qt-ble.h" +#include "core/btdiscovery.h" #if defined(SSRF_CUSTOM_IO) @@ -287,12 +288,11 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d if (!strncmp(devaddr, "LE:", 3)) devaddr += 3; - QBluetoothAddress remoteDeviceAddress(devaddr); - // HACK ALERT! Qt 5.9 needs this for proper Bluez operation qputenv("QT_DEFAULT_CENTRAL_SERVICES", "1"); - QLowEnergyController *controller = new QLowEnergyController(remoteDeviceAddress); + QBluetoothDeviceInfo remoteDevice = getBtDeviceInfo(devaddr); + QLowEnergyController *controller = QLowEnergyController::createCentral(remoteDevice); qDebug() << "qt_ble_open(" << devaddr << ")"; @@ -382,8 +382,19 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d qDebug() << "Descriptor:" << d.name() << "uuid:" << d.uuid().toString(); if (!l.isEmpty()) { - d = l.first(); - qDebug() << "now writing \"0x0100\" to the first descriptor"; + bool foundCCC = false; + foreach (d, l) { + if (d.type() == QBluetoothUuid::ClientCharacteristicConfiguration) { + // pick the correct characteristic + foundCCC = true; + break; + } + } + if (!foundCCC) + // if we didn't find a ClientCharacteristicConfiguration, try the first one + d = l.first(); + + qDebug() << "now writing \"0x0100\" to the descriptor" << d.uuid().toString(); ble->preferredService()->writeDescriptor(d, QByteArray::fromHex("0100")); } |