summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2017-02-13 12:36:45 +0100
committerKari Hautamäki <kari.hautamaki@qt.io>2017-02-14 13:08:22 +0000
commit2a0f4339dfd31e648fcc10394352f648369fd40c (patch)
treebf0d30581789c83210eb3e48c99233fc499e6ae7
parentf8aa599c5d3acc3ca52010837e4cbf9935908135 (diff)
iot-sensortag: Do not hardcode characteristic handles
Depending on the tag's firmware version the characteristics' handle values might be different. Following TI's advice we should do a proper lookup instead of hardcoding them. Change-Id: I95934e554563e99118fc8ffe87de44e87d409ecf Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io> Reviewed-by: Kari Hautamäki <kari.hautamaki@qt.io>
-rw-r--r--tradeshow/iot-sensortag/bluetoothdevice.cpp27
-rw-r--r--tradeshow/iot-sensortag/bluetoothdevice.h5
2 files changed, 17 insertions, 15 deletions
diff --git a/tradeshow/iot-sensortag/bluetoothdevice.cpp b/tradeshow/iot-sensortag/bluetoothdevice.cpp
index 0ef6bc8..82dbf01 100644
--- a/tradeshow/iot-sensortag/bluetoothdevice.cpp
+++ b/tradeshow/iot-sensortag/bluetoothdevice.cpp
@@ -296,6 +296,7 @@ void BluetoothDevice::temperatureDetailsDiscovered(QLowEnergyService::ServiceSta
if (id.toString().contains("f000aa01-0451-4000-b000-000000000000")) {
//RN
irTemperatureService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
+ irTemperatureHandle = characteristic.handle();
}
if (id.toString().contains("f000aa02-0451-4000-b000-000000000000")) {
//RW
@@ -328,6 +329,7 @@ void BluetoothDevice::barometerDetailsDiscovered(QLowEnergyService::ServiceState
if (id.toString().contains("f000aa41-0451-4000-b000-000000000000")) {
baroService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
+ baroHandle = characteristic.handle();
}
if (id.toString().contains("f000aa42-0451-4000-b000-000000000000")) {
baroService->writeCharacteristic(characteristic, QByteArray::fromHex(START_MEASUREMENT_STR), QLowEnergyService::WriteWithResponse); // Start
@@ -359,6 +361,7 @@ void BluetoothDevice::humidityDetailsDiscovered(QLowEnergyService::ServiceState
if (id.toString().contains("f000aa21-0451-4000-b000-000000000000")) {
humidityService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
+ humidityHandle = characteristic.handle();
}
if (id.toString().contains("f000aa22-0451-4000-b000-000000000000")) {
humidityService->writeCharacteristic(characteristic, QByteArray::fromHex(START_MEASUREMENT_STR), QLowEnergyService::WriteWithResponse); // Start
@@ -390,6 +393,7 @@ void BluetoothDevice::lightIntensityDetailsDiscovered(QLowEnergyService::Service
if (id.toString().contains("f000aa71-0451-4000-b000-000000000000")) {
lightService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
+ lightHandle = characteristic.handle();
}
if (id.toString().contains("f000aa72-0451-4000-b000-000000000000")) {
lightService->writeCharacteristic(characteristic, QByteArray::fromHex(START_MEASUREMENT_STR), QLowEnergyService::WriteWithResponse); // Start
@@ -424,6 +428,7 @@ void BluetoothDevice::motionDetailsDiscovered(QLowEnergyService::ServiceState ne
if (id.toString().contains("f000aa81-0451-4000-b000-000000000000")) {
motionService->writeDescriptor(characteristic.descriptors().at(0), QByteArray::fromHex(ENABLE_NOTIF_STR));
+ motionHandle = characteristic.handle();
}
if (id.toString().contains("f000aa82-0451-4000-b000-000000000000")) {
motionService->writeCharacteristic(characteristic, QByteArray::fromHex(MOVEMENT_ENABLE_SENSORS_BITMASK_VALUE), QLowEnergyService::WriteWithResponse);
@@ -438,27 +443,19 @@ void BluetoothDevice::motionDetailsDiscovered(QLowEnergyService::ServiceState ne
void BluetoothDevice::characteristicsRead(const QLowEnergyCharacteristic &info, const QByteArray &value)
{
- switch (info.handle())
- {
- case 0x0021:
+ const QLowEnergyHandle handle = info.handle();
+ if (handle == irTemperatureHandle)
irTemperatureReceived(value);
- break;
- case 0x0029:
+ else if (handle == humidityHandle)
humidityReceived(value);
- break;
- case 0x0031:
+ else if (handle == baroHandle)
barometerReceived(value);
- break;
- case 0x0039:
+ else if (handle == motionHandle)
motionReceived(value);
- break;
- case 0x0041:
+ else if (handle == lightHandle)
lightIntensityReceived(value);
- break;
- default:
+ else
qWarning() << "Invalid handle" << info.handle() << "in characteristicsRead!";
- break;
- }
}
void BluetoothDevice::setState(BluetoothDevice::DeviceState state)
diff --git a/tradeshow/iot-sensortag/bluetoothdevice.h b/tradeshow/iot-sensortag/bluetoothdevice.h
index 26ad814..435fd22 100644
--- a/tradeshow/iot-sensortag/bluetoothdevice.h
+++ b/tradeshow/iot-sensortag/bluetoothdevice.h
@@ -181,6 +181,11 @@ private:
QLowEnergyService* humidityService;
QLowEnergyService* lightService;
QLowEnergyService* motionService;
+ QLowEnergyHandle irTemperatureHandle;
+ QLowEnergyHandle baroHandle;
+ QLowEnergyHandle humidityHandle;
+ QLowEnergyHandle lightHandle;
+ QLowEnergyHandle motionHandle;
DeviceState m_deviceState;
bool m_temperatureMeasurementStarted;
bool m_barometerMeasurementStarted;