summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/lowenergyscanner
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-07-14 13:01:47 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-07-16 08:28:58 +0200
commitba3c1f4f2a2efe635e12c9dad22edeac89611729 (patch)
tree88da0300aa76a46934c0c93fea348f6ead20c993 /examples/bluetooth/lowenergyscanner
parent9234d5391c5e94a4b00ad4e81336f519fc496caa (diff)
Various improvements to lowenergyscanner example
1.) Improves UI flow 2.) Improves error behavior (e.g. device disconnects) 3.) Adds missing signal/model updates whcih caused unexpected UI flow Change-Id: Icc7edf4945df0e964b5c91b407ce5976a1585b81 Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'examples/bluetooth/lowenergyscanner')
-rw-r--r--examples/bluetooth/lowenergyscanner/assets/Characteristics.qml26
-rw-r--r--examples/bluetooth/lowenergyscanner/assets/Services.qml23
-rw-r--r--examples/bluetooth/lowenergyscanner/device.cpp13
-rw-r--r--examples/bluetooth/lowenergyscanner/device.h1
4 files changed, 43 insertions, 20 deletions
diff --git a/examples/bluetooth/lowenergyscanner/assets/Characteristics.qml b/examples/bluetooth/lowenergyscanner/assets/Characteristics.qml
index ef1538ab..4a7db471 100644
--- a/examples/bluetooth/lowenergyscanner/assets/Characteristics.qml
+++ b/examples/bluetooth/lowenergyscanner/assets/Characteristics.qml
@@ -54,12 +54,23 @@ Rectangle {
Dialog {
id: info
anchors.centerIn: parent
- visible: false
+ visible: true
+ dialogText: "Scanning for characteristics...";
}
- Component.onCompleted: {
- info.visible = true;
- info.dialogText = "Scanning for characteristics...";
+ Connections {
+ target: device
+ onCharacteristicsUpdated: {
+ menu.menuText = "Back"
+ if (characteristicview.count === 0)
+ info.dialogText = "No characteristic found"
+ else
+ info.visible = false;
+ }
+
+ onDisconnected: {
+ pageLoader.source = "main.qml"
+ }
}
ListView {
@@ -80,11 +91,6 @@ Rectangle {
border.color: "black"
radius: 5
- Component.onCompleted: {
- menu.menuText = "Back"
- info.visible = false
- }
-
Label {
id: characteristicName
textContent: modelData.characteristicName
@@ -132,7 +138,7 @@ Rectangle {
id: menu
anchors.bottom: parent.bottom
menuWidth: parent.width
- menuText: device.update
+ menuText: "Scanning"
menuHeight: (parent.height/6)
onButtonClick: {
pageLoader.source = "Services.qml"
diff --git a/examples/bluetooth/lowenergyscanner/assets/Services.qml b/examples/bluetooth/lowenergyscanner/assets/Services.qml
index de3eb187..361f14c1 100644
--- a/examples/bluetooth/lowenergyscanner/assets/Services.qml
+++ b/examples/bluetooth/lowenergyscanner/assets/Services.qml
@@ -54,12 +54,22 @@ Rectangle {
Dialog {
id: info
anchors.centerIn: parent
- visible: false
+ visible: true
+ dialogText: "Scanning for services...";
}
- Component.onCompleted: {
- info.visible = true;
- info.dialogText = "Scanning for services...";
+ Connections {
+ target: device
+ onServicesUpdated: {
+ if (servicesview.count === 0)
+ info.dialogText = "No services found"
+ else
+ info.visible = false;
+ }
+
+ onDisconnected: {
+ pageLoader.source = "main.qml"
+ }
}
ListView {
@@ -78,7 +88,9 @@ Rectangle {
border.color: "black"
radius: 5
width: parent.width
- Component.onCompleted: info.visible = false
+ Component.onCompleted: {
+ info.visible = false
+ }
MouseArea {
anchors.fill: parent
@@ -113,7 +125,6 @@ Rectangle {
menuHeight: (parent.height/6)
onButtonClick: {
device.disconnectFromDevice()
- pageLoader.source = "main.qml"
}
}
}
diff --git a/examples/bluetooth/lowenergyscanner/device.cpp b/examples/bluetooth/lowenergyscanner/device.cpp
index 58454185..e1bb63fe 100644
--- a/examples/bluetooth/lowenergyscanner/device.cpp
+++ b/examples/bluetooth/lowenergyscanner/device.cpp
@@ -47,6 +47,7 @@
#include <qbluetoothservicediscoveryagent.h>
#include <QDebug>
#include <QList>
+#include <QTimer>
Device::Device():
connected(false), controller(0), m_deviceScanState(false)
@@ -77,6 +78,8 @@ void Device::startDeviceDiscovery()
{
qDeleteAll(devices);
devices.clear();
+ emit devicesUpdated();
+
setUpdate("Scanning for devices ...");
discoveryAgent->start();
m_deviceScanState = true;
@@ -138,9 +141,10 @@ void Device::scanServices(const QString &address)
qDeleteAll(m_characteristics);
m_characteristics.clear();
+ emit characteristicsUpdated();
qDeleteAll(m_services);
m_services.clear();
-
+ emit servicesUpdated();
setUpdate("Connecting to device...");
@@ -202,6 +206,7 @@ void Device::connectToService(const QString &uuid)
qDeleteAll(m_characteristics);
m_characteristics.clear();
+ emit characteristicsUpdated();
if (service->state() == QLowEnergyService::DiscoveryRequired) {
connect(service, SIGNAL(stateChanged(QLowEnergyService::ServiceState)),
@@ -217,12 +222,11 @@ void Device::connectToService(const QString &uuid)
m_characteristics.append(cInfo);
}
- emit characteristicsUpdated();
+ QTimer::singleShot(0, this, SIGNAL(characteristicsUpdated()));
}
void Device::deviceConnected()
{
-
setUpdate("Discovering services!");
connected = true;
controller->discoverServices();
@@ -248,7 +252,8 @@ void Device::disconnectFromDevice()
void Device::deviceDisconnected()
{
- //setUpdate("Device disconnected " + currentDevice.getName());
+ qWarning() << "Disconnect from device";
+ emit disconnected();
}
void Device::serviceDetailsDiscovered(QLowEnergyService::ServiceState newState)
diff --git a/examples/bluetooth/lowenergyscanner/device.h b/examples/bluetooth/lowenergyscanner/device.h
index 053b04f1..bb99ffe0 100644
--- a/examples/bluetooth/lowenergyscanner/device.h
+++ b/examples/bluetooth/lowenergyscanner/device.h
@@ -104,6 +104,7 @@ Q_SIGNALS:
void characteristicsUpdated();
void updateChanged();
void stateChanged();
+ void disconnected();
private:
void setUpdate(QString message);