diff options
author | Kari Hautamäki <kari.hautamaki@qt.io> | 2017-02-16 08:33:49 +0200 |
---|---|---|
committer | Maurice Kalinowski <maurice.kalinowski@qt.io> | 2017-02-28 13:16:09 +0000 |
commit | 35c1c07cd676b9c9afb23ad7266a67d5b6aef03a (patch) | |
tree | d43445955be5f1799ca9bb9db2c6e2cfd7915370 /tradeshow/iot-sensortag/demodataproviderpool.cpp | |
parent | dec3883a1d0d7d24c797cf517fa7fad85b24a1f2 (diff) |
iot-sensortag: Allow reconnect after a failed connection attempt
A disconnected sensor tag can be tried to be reconnected by clicking
on the chart area or starting rescan from the Sensor settings menu.
During a (re)connection process a progress indicator is shown to
the user.
The user has a possibility to disconnect (and reconnect) a
currently connect SensorDataProvider
A new state, 'NotFound' is added in SensorTagDataProvider to
distinguish between states when a Sensor Tag has not been discovered
at all, and when it has already been discovered but is has been
disconnected.
Change-Id: I54eea72d8c92a67a5ccbb3bc192ac8f33ada1c39
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'tradeshow/iot-sensortag/demodataproviderpool.cpp')
-rw-r--r-- | tradeshow/iot-sensortag/demodataproviderpool.cpp | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/tradeshow/iot-sensortag/demodataproviderpool.cpp b/tradeshow/iot-sensortag/demodataproviderpool.cpp index ccaf7fd..92c5e41 100644 --- a/tradeshow/iot-sensortag/demodataproviderpool.cpp +++ b/tradeshow/iot-sensortag/demodataproviderpool.cpp @@ -49,6 +49,7 @@ ****************************************************************************/ #include "demodataproviderpool.h" #include "mockdataprovider.h" +#include "bluetoothdataprovider.h" DemoCloudProvider::DemoCloudProvider(QObject *parent) : SensorTagDataProvider(parent) @@ -261,15 +262,16 @@ DemoDataProviderPool::DemoDataProviderPool(QObject *parent) : SensorTagDataProviderPool("Demo", parent) , m_mockData(false) , m_cloudProvider(0) + , m_initialized(false) { } void DemoDataProviderPool::startScanning() { - qDeleteAll(m_dataProviders); - m_dataProviders.clear(); - if (m_mockData) { + qDeleteAll(m_dataProviders); + m_dataProviders.clear(); + MockDataProvider* p = new MockDataProvider("MOCK_PROVIDER_1", this); p->setTagType(SensorTagDataProvider::ObjectTemperature | SensorTagDataProvider::AmbientTemperature | SensorTagDataProvider::Rotation); m_dataProviders.push_back(p); @@ -287,6 +289,42 @@ void DemoDataProviderPool::startScanning() finishScanning(); } else { + if (!m_initialized) { + // Create a DataProvider objects early on for UI to be able to + // show all data providers as available. The BT device information + // will be added later on when the Bluetooth device has been found + for (const QString& id : m_macFilters) { + BluetoothDataProvider *p = new BluetoothDataProvider(id, this); + m_dataProviders.push_back(p); + } + // Fake that we have set of sensors with different capabilities + // by removing some of the sensor data types from each sensor tag + if (m_dataProviders.length() > 0) { + SensorTagDataProvider *p = m_dataProviders.at(0); + p->setTagType(SensorTagDataProvider::ObjectTemperature | + SensorTagDataProvider::Light | + SensorTagDataProvider::Magnetometer | + SensorTagDataProvider::Accelometer); + emit dataProvidersChanged(); + if (m_dataProviders.length() > 1) { + p = m_dataProviders.at(1); + p->setTagType(SensorTagDataProvider::AmbientTemperature | + SensorTagDataProvider::Altitude | + SensorTagDataProvider::Humidity | + SensorTagDataProvider::Rotation | + SensorTagDataProvider::AirPressure); + emit dataProvidersChanged(); + } + } + m_initialized = true; + } + // Set initial state to Scanning for UI to be + // able to show "Connecting.." information + for (SensorTagDataProvider *p : m_dataProviders) { + if (p->state() == SensorTagDataProvider::NotFound) { + p->setState(SensorTagDataProvider::Scanning); + } + } SensorTagDataProviderPool::startScanning(); } } @@ -299,25 +337,13 @@ void DemoDataProviderPool::finishScanning() m_cloudProvider = m_dataProviders.at(0); emit providerForCloudChanged(); } else { - // Fake that we have set of sensors with different capabilities - // by removing some of the sensor data types from each sensor tag - for (SensorTagDataProvider *p : m_dataProviders) { - if (p->id() == QStringLiteral("A0:E6:F8:B6:5B:86")) { - p->setTagType(SensorTagDataProvider::ObjectTemperature | - SensorTagDataProvider::Light | - SensorTagDataProvider::Magnetometer | - SensorTagDataProvider::Accelometer); - } - else if (p->id() == QStringLiteral("A0:E6:F8:B6:44:01")) { - p->setTagType(SensorTagDataProvider::AmbientTemperature | - SensorTagDataProvider::Altitude | - SensorTagDataProvider::Humidity | - SensorTagDataProvider::Rotation | - SensorTagDataProvider::AirPressure); - } - } m_cloudProvider = new DemoCloudProvider(this); static_cast<DemoCloudProvider*>(m_cloudProvider)->setDataProviders(m_dataProviders); + for (SensorTagDataProvider *p : m_dataProviders) { + // If BluetoothDevice object is not attached, the device has not been found + if (!static_cast<BluetoothDataProvider*>(p)->device()) + p->setState(SensorTagDataProvider::NotFound); + } } emit dataProvidersChanged(); emit scanFinished(); @@ -332,4 +358,3 @@ SensorTagDataProvider *DemoDataProviderPool::providerForCloud() const { return m_cloudProvider; } - |