diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-07-10 15:47:41 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-07-16 08:28:46 +0200 |
commit | f399837b3a723af9add6d9ea2d2e988f64f76ae0 (patch) | |
tree | 2c2a17ff5c4cfd007af98c98c70a2bf8c5fe8984 /examples | |
parent | 8bf7e9986e359df46bb351dfb76e4140d9b04da7 (diff) |
Add simpler API to retrieve descriptor/characteristic for certain uuid
This new API is mostly syntactic sugar and reduces the amount of code
to be written by API users.
Change-Id: I51ff1ea706ac97199646d211e39e79c8140ee74b
Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bluetooth/heartlistener/heartrate.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/examples/bluetooth/heartlistener/heartrate.cpp b/examples/bluetooth/heartlistener/heartrate.cpp index 996d8a79..f0f4230e 100644 --- a/examples/bluetooth/heartlistener/heartrate.cpp +++ b/examples/bluetooth/heartlistener/heartrate.cpp @@ -245,25 +245,21 @@ void HeartRate::serviceStateChanged(QLowEnergyService::ServiceState s) switch (s) { case QLowEnergyService::ServiceDiscovered: { - const QList<QLowEnergyCharacteristic> chars = m_service->characteristics(); - for (int i = 0; i < chars.count(); i++) { - const QLowEnergyCharacteristic c = chars[i]; - if (c.uuid() == QBluetoothUuid(QBluetoothUuid::HeartRateMeasurement)) { - const QList<QLowEnergyDescriptor> descriptors = c.descriptors(); - //enable notification - for (int j = 0; j < descriptors.count(); j++) { - const QLowEnergyDescriptor desc = descriptors[j]; - if (desc.type() == QBluetoothUuid::ClientCharacteristicConfiguration) { - m_service->writeDescriptor(desc, QByteArray("0100")); - setMessage("Measuring"); - m_notificationDesc = desc; - m_start = QDateTime::currentDateTime(); - break; - } - } - break; - } + const QLowEnergyCharacteristic hrChar = m_service->characteristic( + QBluetoothUuid(QBluetoothUuid::HeartRateMeasurement)); + if (!hrChar.isValid()) { + setMessage("HR Data not found."); + break; + } + + const QLowEnergyDescriptor m_notificationDesc = hrChar.descriptor( + QBluetoothUuid::ClientCharacteristicConfiguration); + if (m_notificationDesc.isValid()) { + m_service->writeDescriptor(m_notificationDesc, QByteArray("0100")); + setMessage("Measuring"); + m_start = QDateTime::currentDateTime(); } + break; } default: |