clzola
clzola

Reputation: 2025

Windows Phone 8.1, accelerometer gives wrong reading

I am developing application for windows phone 8.1 and need to detect phone movement.

For example, I need to detect one of two scenarios:

User leans phone down enter image description here

and user leans phone up enter image description here

And here is the screenshot of application showing acelerometer readings when the phone is in position like on the second picture.

enter image description here

X-Axis, Y-Axis and Z-Axis are same (Same on my device). In the second picture when phone is facing up, X = -0.5317. Looks like that for some reason all axis take this value.

Here is the code.

public RoundPage()
{
    this.InitializeComponent();

    // ...

    this._accelerometer = Accelerometer.GetDefault();
    this._accelerometer.ReadingChanged += _accelerometer_ReadingChanged;
}

async void _accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
    double xAxis = args.Reading.AccelerationX;
    double yAxis = args.Reading.AccelerationY;
    double zAxis = args.Reading.AccelerationZ;

    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            AccTextBlock.Text = String.Format("X: {0:f2}  Y: {0:f2}  Z: {0:f2}",
                xAxis,
                yAxis,
                zAxis);
        });
}

What am I doing wrong? What is correct way do detect this readings.

Upvotes: 0

Views: 66

Answers (1)

clzola
clzola

Reputation: 2025

I make mistake in String.Format method, I was always printing xAxis ({0}).

Upvotes: 1

Related Questions