From 8f7bb40c889ac1f74cc0e11660011cf1ee2d7b15 Mon Sep 17 00:00:00 2001 From: Titta Heikkala Date: Thu, 2 Mar 2017 09:10:49 +0200 Subject: iot-sensortag: Reduce waiting time for service scan Unnecessary 1s delay to start service scan removed. If all service details have been discovered there's no need to start the 5s service details timer. Change-Id: I6c8c89455fb3cfdbc1a28198234e95a4ed0b7e8b Reviewed-by: Maurice Kalinowski --- tradeshow/iot-sensortag/bluetoothdevice.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'tradeshow/iot-sensortag/bluetoothdevice.cpp') diff --git a/tradeshow/iot-sensortag/bluetoothdevice.cpp b/tradeshow/iot-sensortag/bluetoothdevice.cpp index 667e7a2..f2d3881 100644 --- a/tradeshow/iot-sensortag/bluetoothdevice.cpp +++ b/tradeshow/iot-sensortag/bluetoothdevice.cpp @@ -267,7 +267,7 @@ void BluetoothDevice::temperatureDetailsDiscovered(QLowEnergyService::ServiceSta } m_temperatureMeasurementStarted = true; - m_serviceDetailsTimer->start(); + updateServiceDetails(); } } @@ -306,7 +306,7 @@ void BluetoothDevice::barometerDetailsDiscovered(QLowEnergyService::ServiceState } m_barometerMeasurementStarted = true; - m_serviceDetailsTimer->start(); + updateServiceDetails(); } } @@ -346,7 +346,7 @@ void BluetoothDevice::humidityDetailsDiscovered(QLowEnergyService::ServiceState } m_humidityMeasurementStarted = true; - m_serviceDetailsTimer->start(); + updateServiceDetails(); } } @@ -386,7 +386,7 @@ void BluetoothDevice::lightIntensityDetailsDiscovered(QLowEnergyService::Service } m_lightIntensityMeasurementStarted = true; - m_serviceDetailsTimer->start(); + updateServiceDetails(); } } @@ -428,7 +428,7 @@ void BluetoothDevice::motionDetailsDiscovered(QLowEnergyService::ServiceState ne m_motionService->writeCharacteristic(characteristic, QByteArray::fromHex(SENSORTAG_RAPID_TIMER_TIMEOUT_STR), QLowEnergyService::WriteWithResponse); } m_motionMeasurementStarted = true; - m_serviceDetailsTimer->start(); + updateServiceDetails(); } } @@ -486,6 +486,21 @@ bool BluetoothDevice::isDeviceReady() const return false; } +void BluetoothDevice::updateServiceDetails() +{ + if (m_temperatureMeasurementStarted + && m_barometerMeasurementStarted + && m_humidityMeasurementStarted + && m_lightIntensityMeasurementStarted + && m_motionMeasurementStarted) { + qCDebug(boot2QtDemos) << "Service details timer stop. All service details found"; + m_serviceDetailsTimer->stop(); + setState(Connected); + } else { + m_serviceDetailsTimer->start(); + } +} + void BluetoothDevice::irTemperatureReceived(const QByteArray &value) { const unsigned int rawObjectTemperature = (((quint8)value.at(3)) << 8) + ((quint8)value.at(2)); -- cgit v1.2.3