From 228b54c723a2f05e493eab6b67dece29ab7de687 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 5 Dec 2014 10:58:47 +0100 Subject: Bluetooth example - lowenergyscanner (OS X and iOS) Core Bluetooth hides addresses and uses unique UUIDs instead. This patch updates/adjusts lowenergyscanner example to work with UUIDs on iOS and OS X instead of (empty on these platforms) device addresses. Change-Id: Iad0b35250f434b736616fe60e356f2088e6dc279 Reviewed-by: Alex Blasche --- examples/bluetooth/lowenergyscanner/device.cpp | 6 ++++++ examples/bluetooth/lowenergyscanner/device.h | 1 + examples/bluetooth/lowenergyscanner/deviceinfo.cpp | 8 ++++++++ 3 files changed, 15 insertions(+) (limited to 'examples/bluetooth') diff --git a/examples/bluetooth/lowenergyscanner/device.cpp b/examples/bluetooth/lowenergyscanner/device.cpp index 0891f040..7ba27ad1 100644 --- a/examples/bluetooth/lowenergyscanner/device.cpp +++ b/examples/bluetooth/lowenergyscanner/device.cpp @@ -138,6 +138,7 @@ QString Device::getUpdate() void Device::scanServices(const QString &address) { // We need the current device for service discovery. + for (int i = 0; i < devices.size(); i++) { if (((DeviceInfo*)devices.at(i))->getAddress() == address ) currentDevice.setDevice(((DeviceInfo*)devices.at(i))->getDevice()); @@ -157,7 +158,12 @@ void Device::scanServices(const QString &address) setUpdate("Back\n(Connecting to device...)"); +#ifdef Q_OS_MAC + if (controller && m_previousAddress != currentDevice.getAddress()) { + m_previousAddress = currentDevice.getAddress(); +#else if (controller && controller->remoteAddress() != currentDevice.getDevice().address()) { +#endif controller->disconnectFromDevice(); delete controller; controller = 0; diff --git a/examples/bluetooth/lowenergyscanner/device.h b/examples/bluetooth/lowenergyscanner/device.h index a12f9e0e..756209da 100644 --- a/examples/bluetooth/lowenergyscanner/device.h +++ b/examples/bluetooth/lowenergyscanner/device.h @@ -119,6 +119,7 @@ private: QList devices; QList m_services; QList m_characteristics; + QString m_previousAddress; QString m_message; bool connected; QLowEnergyController *controller; diff --git a/examples/bluetooth/lowenergyscanner/deviceinfo.cpp b/examples/bluetooth/lowenergyscanner/deviceinfo.cpp index d6b7a734..d774cb22 100644 --- a/examples/bluetooth/lowenergyscanner/deviceinfo.cpp +++ b/examples/bluetooth/lowenergyscanner/deviceinfo.cpp @@ -39,6 +39,8 @@ ** ****************************************************************************/ +#include + #include "deviceinfo.h" DeviceInfo::DeviceInfo() @@ -52,7 +54,13 @@ DeviceInfo::DeviceInfo(const QBluetoothDeviceInfo &d) QString DeviceInfo::getAddress() const { +#ifdef Q_OS_MAC + // On OS X and iOS we do not have addresses, + // only unique UUIDs generated by Core Bluetooth. + return device.deviceUuid().toString(); +#else return device.address().toString(); +#endif } QString DeviceInfo::getName() const -- cgit v1.2.3