summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2016-07-19 09:17:30 +0200
committerAlex Blasche <alexander.blasche@theqtcompany.com>2016-07-19 09:34:06 +0000
commitb01389be13b40833fa3f50a862b164c5d8389d1a (patch)
treef67530b1ddaf825f711908994b4e19f5ed4eceff
parenta8a1a97b9a3f68245431a94ff670b91b340770b2 (diff)
downloadqtconnectivity-b01389be13b40833fa3f50a862b164c5d8389d1a.tar.gz
Disable notifications before disconnecting heartlistener client
The logic for this existed already. However an unintentional name override and proper QByteArray comparison prevented it from ever being activated. Change-Id: I73ac6c03b82cfbc11f5d755381ae89a3e8a3d9e5 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
-rw-r--r--examples/bluetooth/heartlistener/heartrate.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/examples/bluetooth/heartlistener/heartrate.cpp b/examples/bluetooth/heartlistener/heartrate.cpp
index 08433195..7077bf1c 100644
--- a/examples/bluetooth/heartlistener/heartrate.cpp
+++ b/examples/bluetooth/heartlistener/heartrate.cpp
@@ -234,8 +234,10 @@ void HeartRate::disconnectService()
return;
}
- //disable notifications
- if (m_notificationDesc.isValid() && m_service) {
+ //disable notifications before disconnecting
+ if (m_notificationDesc.isValid() && m_service
+ && m_notificationDesc.value() == QByteArray::fromHex("0100"))
+ {
m_service->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0000"));
} else {
m_control->disconnectFromDevice();
@@ -266,7 +268,7 @@ void HeartRate::serviceStateChanged(QLowEnergyService::ServiceState s)
break;
}
- const QLowEnergyDescriptor m_notificationDesc = hrChar.descriptor(
+ m_notificationDesc = hrChar.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
if (m_notificationDesc.isValid()) {
m_service->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0100"));
@@ -333,7 +335,7 @@ void HeartRate::updateHeartRateValue(const QLowEnergyCharacteristic &c,
void HeartRate::confirmedDescriptorWrite(const QLowEnergyDescriptor &d,
const QByteArray &value)
{
- if (d.isValid() && d == m_notificationDesc && value == QByteArray("0000")) {
+ if (d.isValid() && d == m_notificationDesc && value == QByteArray::fromHex("0000")) {
//disabled notifications -> assume disconnect intent
m_control->disconnectFromDevice();
delete m_service;