summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@digia.com>2013-09-23 15:37:53 +0200
committerGatis Paeglis <gatis.paeglis@digia.com>2013-10-03 17:39:56 +0300
commitdae902e9d22f89a890252633c66fd7ee26636192 (patch)
tree0fd36990d97584c4259c7147177b9480391c2925
parent1bf9d73eff18fde3f7cfe0e6aa7e7edc39264e77 (diff)
Add sensor demo to basicsuite
Change-Id: I72d733ffe29aaf99fdf67e9b981ffbecb9dacc1a Reviewed-by: Gatis Paeglis <gatis.paeglis@digia.com>
-rw-r--r--basicsuite/Sensors/1.pngbin0 -> 33675 bytes
-rw-r--r--basicsuite/Sensors/2.pngbin0 -> 27754 bytes
-rw-r--r--basicsuite/Sensors/3.pngbin0 -> 27841 bytes
-rw-r--r--basicsuite/Sensors/Accelbubble.qml68
-rw-r--r--basicsuite/Sensors/Light.qml50
-rw-r--r--basicsuite/Sensors/bluebubble.pngbin0 -> 12815 bytes
-rw-r--r--basicsuite/Sensors/description.txt4
-rw-r--r--basicsuite/Sensors/main.qml28
-rw-r--r--basicsuite/Sensors/preview_l.jpgbin0 -> 18384 bytes
9 files changed, 150 insertions, 0 deletions
diff --git a/basicsuite/Sensors/1.png b/basicsuite/Sensors/1.png
new file mode 100644
index 0000000..8dd146b
--- /dev/null
+++ b/basicsuite/Sensors/1.png
Binary files differ
diff --git a/basicsuite/Sensors/2.png b/basicsuite/Sensors/2.png
new file mode 100644
index 0000000..362abaf
--- /dev/null
+++ b/basicsuite/Sensors/2.png
Binary files differ
diff --git a/basicsuite/Sensors/3.png b/basicsuite/Sensors/3.png
new file mode 100644
index 0000000..c8d3f8c
--- /dev/null
+++ b/basicsuite/Sensors/3.png
Binary files differ
diff --git a/basicsuite/Sensors/Accelbubble.qml b/basicsuite/Sensors/Accelbubble.qml
new file mode 100644
index 0000000..c5b75ad
--- /dev/null
+++ b/basicsuite/Sensors/Accelbubble.qml
@@ -0,0 +1,68 @@
+import QtQuick 2.0
+import QtSensors 5.0
+
+Item {
+ Rectangle {
+ id: field
+ color: "lightblue"
+ border.width: 1
+ border.color: "darkblue"
+ width: parent.width
+ height: parent.height
+ Accelerometer {
+ id: accel
+ active:true
+ onReadingChanged: {
+ var newX = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * .1)
+ var newY = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * .1)
+
+ if (newX < 0)
+ newX = 0
+ if (newY < 0)
+ newY = 0
+
+ var right = field.width - bubble.width
+ var bottom = field.height - bubble.height
+
+ if (newX > right)
+ newX = right
+ if (newY > bottom)
+ newY = bottom
+
+ bubble.x = newX
+ bubble.y = newY
+ }
+ }
+
+ Image {
+ id: bubble
+ source: "bluebubble.png"
+ property real centerX: parent.width / 2
+ property real centerY: parent.height / 2;
+ property real bubbleCenter: bubble.width / 2
+ x: centerX - bubbleCenter
+ y: centerY - bubbleCenter
+ smooth: true
+
+ Behavior on y {
+ SmoothedAnimation {
+ easing.type: Easing.Linear
+ duration: 100
+ }
+ }
+ Behavior on x {
+ SmoothedAnimation {
+ easing.type: Easing.Linear
+ duration: 100
+ }
+ }
+ }
+ }
+
+ function calcPitch(x,y,z) {
+ return Math.atan(y / Math.sqrt(x*x + z*z)) * 57.2957795;
+ }
+ function calcRoll(x,y,z) {
+ return Math.atan(x / Math.sqrt(y*y + z*z)) * 57.2957795;
+ }
+}
diff --git a/basicsuite/Sensors/Light.qml b/basicsuite/Sensors/Light.qml
new file mode 100644
index 0000000..fceecb7
--- /dev/null
+++ b/basicsuite/Sensors/Light.qml
@@ -0,0 +1,50 @@
+import QtQuick 2.0
+import QtSensors 5.0
+
+Item {
+ rotation: 180
+ Rectangle {
+ id: bg
+ width: parent.width
+ height: parent.height
+ Text {
+ id: illuminanceLevel
+ anchors.horizontalCenter: parent.horizontalCenter
+ font.pointSize: 26
+ anchors.top: parent.top
+ }
+ Image {
+ id: avatar
+ anchors.top: illuminanceLevel.bottom
+ anchors.topMargin: 30
+ anchors.centerIn: parent
+ }
+
+ AmbientLightSensor {
+ active: true
+ onReadingChanged: {
+ if (reading.lightLevel === AmbientLightReading.Dark) {
+ avatar.source = "3.png"
+ bg.color = "midnightblue"
+ } else if (reading.lightLevel === AmbientLightReading.Twilight
+ || reading.lightLevel === AmbientLightReading.Light) {
+ avatar.source = "2.png"
+ bg.color = "steelblue"
+ } else if (reading.lightLevel === AmbientLightReading.Bright
+ || reading.lightLevel === AmbientLightReading.Sunny) {
+ avatar.source = "1.png"
+ bg.color = "yellow"
+ } else {
+ avatar.text = "Unknown light level"
+ }
+ }
+ }
+
+ LightSensor {
+ active: true
+ onReadingChanged: {
+ illuminanceLevel.text = "Illuminance: " + reading.illuminance
+ }
+ }
+ }
+}
diff --git a/basicsuite/Sensors/bluebubble.png b/basicsuite/Sensors/bluebubble.png
new file mode 100644
index 0000000..f96126e
--- /dev/null
+++ b/basicsuite/Sensors/bluebubble.png
Binary files differ
diff --git a/basicsuite/Sensors/description.txt b/basicsuite/Sensors/description.txt
new file mode 100644
index 0000000..f6048cc
--- /dev/null
+++ b/basicsuite/Sensors/description.txt
@@ -0,0 +1,4 @@
+This demo utilizes the accelerometer and light sensor readings in an application.
+
+For the accelometer, tilting the device moves the bubble around. For the light sensor,
+exposing the device to different lighting conditions changes the display.
diff --git a/basicsuite/Sensors/main.qml b/basicsuite/Sensors/main.qml
new file mode 100644
index 0000000..2e1b820
--- /dev/null
+++ b/basicsuite/Sensors/main.qml
@@ -0,0 +1,28 @@
+import QtQuick 2.0
+import QtSensors 5.0
+
+Item {
+ id: root
+ width: 800
+ height: 1280
+ Rectangle {
+ id: main
+ width: root.height
+ height: root.width
+ anchors.centerIn: parent
+ rotation: 90
+ border.width: 1
+
+ Light {
+ id: lys
+ width: main.width
+ height: main.height / 2
+ }
+
+ Accelbubble {
+ width: main.width
+ height: main.height / 2
+ anchors.top: lys.bottom
+ }
+ }
+}
diff --git a/basicsuite/Sensors/preview_l.jpg b/basicsuite/Sensors/preview_l.jpg
new file mode 100644
index 0000000..3682cdf
--- /dev/null
+++ b/basicsuite/Sensors/preview_l.jpg
Binary files differ