aboutsummaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/lowenergyscanner/Scanner
diff options
context:
space:
mode:
Diffstat (limited to 'examples/bluetooth/lowenergyscanner/Scanner')
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/Characteristics.qml121
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/Devices.qml121
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/Dialog.qml48
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/Header.qml25
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/Label.qml16
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/Main.qml31
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/Menu.qml55
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/Services.qml115
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/assets/busy_dark.pngbin0 -> 1130 bytes
-rw-r--r--examples/bluetooth/lowenergyscanner/Scanner/qmldir10
10 files changed, 542 insertions, 0 deletions
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/Characteristics.qml b/examples/bluetooth/lowenergyscanner/Scanner/Characteristics.qml
new file mode 100644
index 000000000..bd3ccbfcb
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/Characteristics.qml
@@ -0,0 +1,121 @@
+// Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+pragma ComponentBehavior: Bound
+import QtQuick
+
+Rectangle {
+ id: characteristicsPage
+
+ signal showServices
+ signal showDevices
+
+ width: 300
+ height: 600
+
+ Header {
+ id: header
+ anchors.top: parent.top
+ headerText: "Characteristics list"
+ }
+
+ Dialog {
+ id: info
+ anchors.centerIn: parent
+ visible: true
+ dialogText: "Scanning for characteristics..."
+ }
+
+ Connections {
+ target: Device
+ function oncharacteristics_pdated() {
+ menu.menuText = "Back"
+ if (characteristicview.count === 0) {
+ info.dialogText = "No characteristic found"
+ info.busyImage = false
+ } else {
+ info.visible = false
+ info.busyImage = true
+ }
+ }
+
+ function onDisconnected() {
+ characteristicsPage.showDevices()
+ }
+ }
+
+ ListView {
+ id: characteristicview
+ width: parent.width
+ clip: true
+
+ anchors.top: header.bottom
+ anchors.bottom: menu.top
+ model: Device.characteristicList
+
+ delegate: Rectangle {
+ required property var modelData
+ id: box
+ height: 300
+ width: characteristicview.width
+ color: "lightsteelblue"
+ border.width: 2
+ border.color: "black"
+ radius: 5
+
+ Label {
+ id: characteristicName
+ textContent: box.modelData.characteristic_name
+ anchors.top: parent.top
+ anchors.topMargin: 5
+ }
+
+ Label {
+ id: characteristicUuid
+ font.pointSize: characteristicName.font.pointSize * 0.7
+ textContent: box.modelData.characteristic_uuid
+ anchors.top: characteristicName.bottom
+ anchors.topMargin: 5
+ }
+
+ Label {
+ id: characteristicValue
+ font.pointSize: characteristicName.font.pointSize * 0.7
+ textContent: ("Value: " + box.modelData.characteristic_value)
+ anchors.bottom: characteristicHandle.top
+ horizontalAlignment: Text.AlignHCenter
+ anchors.topMargin: 5
+ }
+
+ Label {
+ id: characteristicHandle
+ font.pointSize: characteristicName.font.pointSize * 0.7
+ textContent: ("Handlers: " + box.modelData.characteristic_handle)
+ anchors.bottom: characteristicPermission.top
+ anchors.topMargin: 5
+ }
+
+ Label {
+ id: characteristicPermission
+ font.pointSize: characteristicName.font.pointSize * 0.7
+ textContent: box.modelData.characteristic_permission
+ anchors.bottom: parent.bottom
+ anchors.topMargin: 5
+ anchors.bottomMargin: 5
+ }
+ }
+ }
+
+ Menu {
+ id: menu
+ anchors.bottom: parent.bottom
+ menuWidth: parent.width
+ menuText: Device.update
+ menuHeight: (parent.height / 6)
+ onButtonClick: {
+ characteristicsPage.showServices()
+ Device.update = "Back"
+ }
+ }
+}
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/Devices.qml b/examples/bluetooth/lowenergyscanner/Scanner/Devices.qml
new file mode 100644
index 000000000..6e5e85a52
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/Devices.qml
@@ -0,0 +1,121 @@
+// Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+pragma ComponentBehavior: Bound
+import QtQuick
+
+Rectangle {
+ id: devicesPage
+
+ property bool deviceState: Device.state
+ signal showServices
+
+ width: 300
+ height: 600
+
+ onDeviceStateChanged: {
+ if (!Device.state)
+ info.visible = false
+ }
+
+ Header {
+ id: header
+ anchors.top: parent.top
+ headerText: {
+ if (Device.state)
+ return "Discovering"
+
+ if (Device.devices_list.length > 0)
+ return "Select a device"
+
+ return "Start Discovery"
+ }
+ }
+
+ Dialog {
+ id: info
+ anchors.centerIn: parent
+ visible: false
+ }
+
+ ListView {
+ id: theListView
+ width: parent.width
+ clip: true
+
+ anchors.top: header.bottom
+ anchors.bottom: connectToggle.top
+ model: Device.devices_list
+
+ delegate: Rectangle {
+ required property var modelData
+ id: box
+ height: 100
+ width: theListView.width
+ color: "lightsteelblue"
+ border.width: 2
+ border.color: "black"
+ radius: 5
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ Device.scan_services(box.modelData.device_address)
+ showServices()
+ }
+ }
+
+ Label {
+ id: deviceName
+ textContent: box.modelData.device_name
+ anchors.top: parent.top
+ anchors.topMargin: 5
+ }
+
+ Label {
+ id: deviceAddress
+ textContent: box.modelData.device_address
+ font.pointSize: deviceName.font.pointSize * 0.7
+ anchors.bottom: box.bottom
+ anchors.bottomMargin: 5
+ }
+ }
+ }
+
+ Menu {
+ id: connectToggle
+
+ menuWidth: parent.width
+ anchors.bottom: menu.top
+ menuText: {
+ visible = Device.devices_list.length > 0
+ if (Device.use_random_address)
+ return "Address type: Random"
+ else
+ return "Address type: Public"
+ }
+
+ onButtonClick: Device.use_random_address = !Device.use_random_address
+ }
+
+ Menu {
+ id: menu
+ anchors.bottom: parent.bottom
+ menuWidth: parent.width
+ menuHeight: (parent.height / 6)
+ menuText: Device.update
+ onButtonClick: {
+ if (!Device.state) {
+ Device.start_device_discovery()
+ // if start_device_discovery() failed Device.state is not set
+ if (Device.state) {
+ info.dialogText = "Searching..."
+ info.visible = true
+ }
+ } else {
+ Device.stop_device_discovery()
+ }
+ }
+ }
+}
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/Dialog.qml b/examples/bluetooth/lowenergyscanner/Scanner/Dialog.qml
new file mode 100644
index 000000000..75e82642a
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/Dialog.qml
@@ -0,0 +1,48 @@
+// Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+
+Rectangle {
+ id: dialog
+ width: parent.width / 3 * 2
+ height: dialogTextId.height + background.height + 20
+ z: 50
+ property string dialogText: ""
+ property bool busyImage: true
+ border.width: 1
+ border.color: "#363636"
+ radius: 10
+
+ Text {
+ id: dialogTextId
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.top: parent.top
+ anchors.topMargin: 10
+
+ elide: Text.ElideMiddle
+ text: dialog.dialogText
+ color: "#363636"
+ wrapMode: Text.Wrap
+ }
+
+ Image {
+ id: background
+
+ width: 20
+ height: 20
+ anchors.top: dialogTextId.bottom
+ anchors.horizontalCenter: dialogTextId.horizontalCenter
+ visible: parent.busyImage
+ source: "assets/busy_dark.png"
+ fillMode: Image.PreserveAspectFit
+ NumberAnimation on rotation {
+ duration: 3000
+ from: 0
+ to: 360
+ loops: Animation.Infinite
+ }
+ }
+}
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/Header.qml b/examples/bluetooth/lowenergyscanner/Scanner/Header.qml
new file mode 100644
index 000000000..c95385dd3
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/Header.qml
@@ -0,0 +1,25 @@
+// Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+
+Rectangle {
+ id: header
+ width: parent.width
+ height: 70
+ border.width: 1
+ border.color: "#363636"
+ radius: 5
+ property string headerText: ""
+
+ Text {
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ anchors.fill: parent
+ text: header.headerText
+ font.bold: true
+ font.pointSize: 20
+ elide: Text.ElideMiddle
+ color: "#363636"
+ }
+}
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/Label.qml b/examples/bluetooth/lowenergyscanner/Scanner/Label.qml
new file mode 100644
index 000000000..e31156740
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/Label.qml
@@ -0,0 +1,16 @@
+// Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+
+Text {
+ property string textContent: ""
+ font.pointSize: 20
+ anchors.horizontalCenter: parent.horizontalCenter
+ color: "#363636"
+ horizontalAlignment: Text.AlignHCenter
+ elide: Text.ElideMiddle
+ width: parent.width
+ wrapMode: Text.Wrap
+ text: textContent
+}
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/Main.qml b/examples/bluetooth/lowenergyscanner/Scanner/Main.qml
new file mode 100644
index 000000000..88600bace
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/Main.qml
@@ -0,0 +1,31 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+import QtQuick.Layouts
+
+Window {
+ id: main
+
+ width: 300
+ height: 600
+ visible: true
+
+ StackLayout {
+ id: pagesLayout
+ anchors.fill: parent
+ currentIndex: 0
+
+ Devices {
+ onShowServices: pagesLayout.currentIndex = 1
+ }
+ Services {
+ onShowDevices: pagesLayout.currentIndex = 0
+ onShowCharacteristics: pagesLayout.currentIndex = 2
+ }
+ Characteristics {
+ onShowDevices: pagesLayout.currentIndex = 0
+ onShowServices: pagesLayout.currentIndex = 1
+ }
+ }
+}
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/Menu.qml b/examples/bluetooth/lowenergyscanner/Scanner/Menu.qml
new file mode 100644
index 000000000..ef69c895e
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/Menu.qml
@@ -0,0 +1,55 @@
+// Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+
+Rectangle {
+ id: menu
+
+ property real menuWidth: 100
+ property real menuHeight: 50
+ property string menuText: "Search"
+ signal buttonClick
+
+ height: menuHeight
+ width: menuWidth
+
+ Rectangle {
+ id: search
+ width: parent.width
+ height: parent.height
+ anchors.centerIn: parent
+ color: "#363636"
+ border.width: 1
+ border.color: "#E3E3E3"
+ radius: 5
+ Text {
+ id: searchText
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ anchors.fill: parent
+ text: menu.menuText
+ elide: Text.ElideMiddle
+ color: "#E3E3E3"
+ wrapMode: Text.WordWrap
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onPressed: {
+ search.width = search.width - 7
+ search.height = search.height - 5
+ }
+
+ onReleased: {
+ search.width = search.width + 7
+ search.height = search.height + 5
+ }
+
+ onClicked: {
+ menu.buttonClick()
+ }
+ }
+ }
+}
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/Services.qml b/examples/bluetooth/lowenergyscanner/Scanner/Services.qml
new file mode 100644
index 000000000..70326242e
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/Services.qml
@@ -0,0 +1,115 @@
+// Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+pragma ComponentBehavior: Bound
+import QtQuick
+
+Rectangle {
+ id: servicesPage
+
+ signal showCharacteristics
+ signal showDevices
+
+ width: 300
+ height: 600
+
+ Component.onCompleted: {
+ // Loading this page may take longer than QLEController
+ // stopping with an error, go back and readjust this view
+ // based on controller errors
+ if (Device.controller_error) {
+ info.visible = false
+ menu.menuText = Device.update
+ }
+ }
+
+ Header {
+ id: header
+ anchors.top: parent.top
+ headerText: "Services list"
+ }
+
+ Dialog {
+ id: info
+ anchors.centerIn: parent
+ visible: true
+ dialogText: "Scanning for services..."
+ }
+
+ Connections {
+ target: Device
+ function onservices_updated() {
+ if (servicesview.count === 0)
+ info.dialogText = "No services found"
+ else
+ info.visible = false
+ }
+
+ function ondisconnected() {
+ servicesPage.showDevices()
+ }
+ }
+
+ ListView {
+ id: servicesview
+ width: parent.width
+ anchors.top: header.bottom
+ anchors.bottom: menu.top
+ model: Device.servicesList
+ clip: true
+
+ delegate: Rectangle {
+ required property var modelData
+ id: box
+ height: 100
+ color: "lightsteelblue"
+ border.width: 2
+ border.color: "black"
+ radius: 5
+ width: servicesview.width
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ Device.connectToService(box.modelData.service_uuid)
+ servicesPage.showCharacteristics()
+ }
+ }
+
+ Label {
+ id: serviceName
+ textContent: box.modelData.service_name
+ anchors.top: parent.top
+ anchors.topMargin: 5
+ }
+
+ Label {
+ textContent: box.modelData.service_type
+ font.pointSize: serviceName.font.pointSize * 0.5
+ anchors.top: serviceName.bottom
+ }
+
+ Label {
+ id: serviceUuid
+ font.pointSize: serviceName.font.pointSize * 0.5
+ textContent: box.modelData.service_uuid
+ anchors.bottom: box.bottom
+ anchors.bottomMargin: 5
+ }
+ }
+ }
+
+ Menu {
+ id: menu
+ anchors.bottom: parent.bottom
+ menuWidth: parent.width
+ menuText: Device.update
+ menuHeight: (parent.height / 6)
+ onButtonClick: {
+ Device.disconnect_from_device()
+ servicesPage.showDevices()
+ Device.update = "Search"
+ }
+ }
+}
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/assets/busy_dark.png b/examples/bluetooth/lowenergyscanner/Scanner/assets/busy_dark.png
new file mode 100644
index 000000000..3a1059531
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/assets/busy_dark.png
Binary files differ
diff --git a/examples/bluetooth/lowenergyscanner/Scanner/qmldir b/examples/bluetooth/lowenergyscanner/Scanner/qmldir
new file mode 100644
index 000000000..0adf6fb19
--- /dev/null
+++ b/examples/bluetooth/lowenergyscanner/Scanner/qmldir
@@ -0,0 +1,10 @@
+module Scanner
+typeinfo scanner.qmltypes
+Characteristics 1.0 Characteristics.qml
+Devices 1.0 Devices.qml
+Dialog 1.0 Dialog.qml
+Header 1.0 Header.qml
+Label 1.0 Label.qml
+Main 1.0 Main.qml
+Menu 1.0 Menu.qml
+Services 1.0 Services.qml