From b01389be13b40833fa3f50a862b164c5d8389d1a Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 19 Jul 2016 09:17:30 +0200 Subject: 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 --- examples/bluetooth/heartlistener/heartrate.cpp | 10 ++++++---- 1 file 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; -- cgit v1.2.3