Discovering Windows Phone 7 #2 – The AccelerometerSensor

Microsoft.Devices.Sensors.Sensor.AccelerometerSensor implement is a physic device that measure force applied on the 3 axes of your device over time.

image

As explained here http://live.visitmix.com/MIX10/Sessions/CL16, if the device is sitting on the desk with the screen upside, the force will be –1 gravity on Z, if it’s sitting in portrait orientation the force will be –1G on Y, if it’s sitting in Landscape mode the force will be –1 on X.

Unfortunately the Emulator does not support yet the AccelerometerSensor, and unfortunately we do not have a Windows Phone yet.

Thanks to Pete Blois and his Labyrinth Sample for Windows Phone (http://blois.us/blog/2010/03/labyrinth-sample-for-windows-phone.html) there’s a simple way to test your app and use your mouse to apply G forces on X and Z.
He created a clever AccelerometerProxy that use the mouse movement to generate fake forces that you can use on your app.

The proxy also include a cleverer AccelerometerEventArgs that replace the original AccelerometerReadingAsyncEventArgs. With the original one, to get the X and Y forces you had to type e.Value.Value.X, while on the AccelerometerEventArgs you can simply use e.X and e.Z.

Here (http://cid-a117aa5e007a0648.skydrive.live.com/self.aspx/Windows%20Mobile%207%20Examples/WindowsPhoneAccelerometerApplication.zip) you can download my working example of the “One Button” example demoed in the CL16 session using the fake accelerometer.

To test it, click the button, then click somewhere else on the emulator screen and drag the mouse.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s