metalfinder.qml Example File
SensorDemo/assets/metalfinder.qml
import bb.cascades 1.0
import QtMobility.sensors 1.2
import bb.vibrationController 1.0
Container {
leftPadding: 20
rightPadding: 20
bottomPadding: 20
attachedObjects: [
Magnetometer {
id: metalfinder
property double baseline: 0
property double magnitude: 0
property double intensity: 0
property double x: 0
property double y: 0
property double z: 0
active: true
alwaysOn: true
onReadingChanged: {
magnitude = Math.sqrt(reading.x * reading.x + reading.y * reading.y + reading.z * reading.z);
if (0 == baseline) {
baseline = magnitude;
}
intensity = ((magnitude - baseline) / magnitude) * 100;
if (intensity > 0) {
vib.start(intensity, 100);
}
x = reading.x;
y = reading.y;
z = reading.z;
}
},
VibrationController {
id: vib
}
]
layout: DockLayout {}
Button {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: qsTr("Calibrate Metal Finder")
onClicked: {
metalfinder.baseline = metalfinder.magnitude
}
}
Container {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Bottom
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Label {
layoutProperties: StackLayoutProperties {
spaceQuota: 1
}
text: qsTr("X: %1").arg((metalfinder.x * 1000000).toPrecision(5))
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.White
}
}
Label {
layoutProperties: StackLayoutProperties {
spaceQuota: 1
}
text: qsTr("Y: %1").arg((metalfinder.y * 1000000).toPrecision(5))
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.White
}
}
Label {
layoutProperties: StackLayoutProperties {
spaceQuota: 1
}
text: qsTr("Z: %1").arg((metalfinder.z * 1000000).toPrecision(5))
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.White
}
}
}
}