summaryrefslogtreecommitdiffstats
path: root/tradeshow/iot-sensortag
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2017-02-14 14:15:15 +0100
committerKari Hautamäki <kari.hautamaki@qt.io>2017-02-14 14:15:03 +0000
commitcacd82b316c8632edde4c37e92d0c0e9747bf5d6 (patch)
treed76bd4e0a3f694f328ee83ed69ff23ae384e771f /tradeshow/iot-sensortag
parent261d5018ac2990acc4739895e29f86c8d94b62a5 (diff)
iot-sensortag: Use dedicated slots for characteristic changes
By using a dedicated slot for each kind of sensor we can avoid one indirection and get rid of the characteristic handle members. Change-Id: I5da16fd4fab55c4085aa1ed141b69a3c442b8fb3 Reviewed-by: Kari Hautamäki <kari.hautamaki@qt.io>
Diffstat (limited to 'tradeshow/iot-sensortag')
-rw-r--r--tradeshow/iot-sensortag/bluetoothdevice.cpp51
-rw-r--r--tradeshow/iot-sensortag/bluetoothdevice.h17
2 files changed, 37 insertions, 31 deletions
diff --git a/tradeshow/iot-sensortag/bluetoothdevice.cpp b/tradeshow/iot-sensortag/bluetoothdevice.cpp
index 4fe7ea7..4f6abe9 100644
--- a/tradeshow/iot-sensortag/bluetoothdevice.cpp
+++ b/tradeshow/iot-sensortag/bluetoothdevice.cpp
@@ -159,7 +159,7 @@ void BluetoothDevice::addLowEnergyService(const QBluetoothUuid &serviceUuid)
return;
}
connect(irTemperatureService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::temperatureDetailsDiscovered);
- connect(irTemperatureService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
+ connect(irTemperatureService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::updateTemperature);
irTemperatureService->discoverDetails();
} else if (serviceUuid == QBluetoothUuid(QLatin1String(BAROMETER_SERVICE_UUID))) {
qCDebug(boot2QtDemos) << "Found barometer service.";
@@ -169,7 +169,7 @@ void BluetoothDevice::addLowEnergyService(const QBluetoothUuid &serviceUuid)
return;
}
connect(baroService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::barometerDetailsDiscovered);
- connect(baroService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
+ connect(baroService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::updatePressure);
baroService->discoverDetails();
} else if (serviceUuid == QBluetoothUuid(QLatin1String(HUMIDITYSENSOR_SERVICE_UUID))) {
qCDebug(boot2QtDemos) << "Found humidity service.";
@@ -179,7 +179,7 @@ void BluetoothDevice::addLowEnergyService(const QBluetoothUuid &serviceUuid)
return;
}
connect(humidityService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::humidityDetailsDiscovered);
- connect(humidityService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
+ connect(humidityService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::updateHumidity);
humidityService->discoverDetails();
} else if (serviceUuid == QBluetoothUuid(QLatin1String(LIGHTSENSOR_SERVICE_UUID))) {
qCDebug(boot2QtDemos) << "Found light service.";
@@ -189,7 +189,7 @@ void BluetoothDevice::addLowEnergyService(const QBluetoothUuid &serviceUuid)
return;
}
connect(lightService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::lightIntensityDetailsDiscovered);
- connect(lightService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
+ connect(lightService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::updateLight);
lightService->discoverDetails();
} else if (serviceUuid == QBluetoothUuid(QLatin1String(MOTIONSENSOR_SERVICE_UUID))) {
qCDebug(boot2QtDemos) << "Found motion service.";
@@ -199,7 +199,7 @@ void BluetoothDevice::addLowEnergyService(const QBluetoothUuid &serviceUuid)
return;
}
connect(motionService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::motionDetailsDiscovered);
- connect(motionService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
+ connect(motionService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::updateMotionValue);
motionService->discoverDetails();
} else {
qCDebug(boot2QtDemos) << "Found unhandled service with id" << serviceUuid << ".";
@@ -244,7 +244,6 @@ void BluetoothDevice::temperatureDetailsDiscovered(QLowEnergyService::ServiceSta
QLowEnergyCharacteristic characteristic = irTemperatureService->characteristic(
QBluetoothUuid(QLatin1String("f000aa01-0451-4000-b000-000000000000")));
if (characteristic.isValid()) {
- irTemperatureHandle = characteristic.handle();
const QLowEnergyDescriptor notificationDescriptor = characteristic.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
if (notificationDescriptor.isValid())
@@ -283,7 +282,6 @@ void BluetoothDevice::barometerDetailsDiscovered(QLowEnergyService::ServiceState
QLowEnergyCharacteristic characteristic = baroService->characteristic(
QBluetoothUuid(QLatin1String("f000aa41-0451-4000-b000-000000000000")));
if (characteristic.isValid()) {
- baroHandle = characteristic.handle();
const QLowEnergyDescriptor notificationDescriptor = characteristic.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
if (notificationDescriptor.isValid())
@@ -323,7 +321,6 @@ void BluetoothDevice::humidityDetailsDiscovered(QLowEnergyService::ServiceState
QLowEnergyCharacteristic characteristic = humidityService->characteristic(
QBluetoothUuid(QLatin1String("f000aa21-0451-4000-b000-000000000000")));
if (characteristic.isValid()) {
- humidityHandle = characteristic.handle();
const QLowEnergyDescriptor notificationDescriptor = characteristic.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
if (notificationDescriptor.isValid())
@@ -363,7 +360,6 @@ void BluetoothDevice::lightIntensityDetailsDiscovered(QLowEnergyService::Service
QLowEnergyCharacteristic characteristic = lightService->characteristic(
QBluetoothUuid(QLatin1String("f000aa71-0451-4000-b000-000000000000")));
if (characteristic.isValid()) {
- lightHandle = characteristic.handle();
const QLowEnergyDescriptor notificationDescriptor = characteristic.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
if (notificationDescriptor.isValid())
@@ -406,7 +402,6 @@ void BluetoothDevice::motionDetailsDiscovered(QLowEnergyService::ServiceState ne
QLowEnergyCharacteristic characteristic = motionService->characteristic(
QBluetoothUuid(QLatin1String("f000aa81-0451-4000-b000-000000000000")));
if (characteristic.isValid()) {
- motionHandle = characteristic.handle();
const QLowEnergyDescriptor notificationDescriptor = characteristic.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
if (notificationDescriptor.isValid())
@@ -429,21 +424,29 @@ void BluetoothDevice::motionDetailsDiscovered(QLowEnergyService::ServiceState ne
}
}
-void BluetoothDevice::characteristicsRead(const QLowEnergyCharacteristic &info, const QByteArray &value)
+void BluetoothDevice::updateTemperature(const QLowEnergyCharacteristic &, const QByteArray &value)
{
- const QLowEnergyHandle handle = info.handle();
- if (handle == irTemperatureHandle)
- irTemperatureReceived(value);
- else if (handle == humidityHandle)
- humidityReceived(value);
- else if (handle == baroHandle)
- barometerReceived(value);
- else if (handle == motionHandle)
- motionReceived(value);
- else if (handle == lightHandle)
- lightIntensityReceived(value);
- else
- qWarning() << "Invalid handle" << info.handle() << "in characteristicsRead!";
+ irTemperatureReceived(value);
+}
+
+void BluetoothDevice::updatePressure(const QLowEnergyCharacteristic &, const QByteArray &value)
+{
+ barometerReceived(value);
+}
+
+void BluetoothDevice::updateHumidity(const QLowEnergyCharacteristic &, const QByteArray &value)
+{
+ humidityReceived(value);
+}
+
+void BluetoothDevice::updateLight(const QLowEnergyCharacteristic &, const QByteArray &value)
+{
+ lightIntensityReceived(value);
+}
+
+void BluetoothDevice::updateMotionValue(const QLowEnergyCharacteristic &, const QByteArray &value)
+{
+ motionReceived(value);
}
void BluetoothDevice::setState(BluetoothDevice::DeviceState state)
diff --git a/tradeshow/iot-sensortag/bluetoothdevice.h b/tradeshow/iot-sensortag/bluetoothdevice.h
index c093006..39a344e 100644
--- a/tradeshow/iot-sensortag/bluetoothdevice.h
+++ b/tradeshow/iot-sensortag/bluetoothdevice.h
@@ -148,8 +148,16 @@ private slots:
void deviceDisconnected();
// QLowEnergyService related
- void characteristicsRead(const QLowEnergyCharacteristic &info,
- const QByteArray &value);
+ void updateTemperature(const QLowEnergyCharacteristic &info,
+ const QByteArray &value);
+ void updatePressure(const QLowEnergyCharacteristic &info,
+ const QByteArray &value);
+ void updateHumidity(const QLowEnergyCharacteristic &info,
+ const QByteArray &value);
+ void updateLight(const QLowEnergyCharacteristic &info,
+ const QByteArray &value);
+ void updateMotionValue(const QLowEnergyCharacteristic &info,
+ const QByteArray &value);
private:
void setState(DeviceState state);
@@ -170,11 +178,6 @@ 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;