ACCELERATING WITH THE ACCELEROMETER
Every Windows Phone 7 device contains an accelerometer, which is basically a motion-detecting sensor. It measures acceleration in three dimensions and makes this information available to applications. This acceleration includes gravity, so the phone knows which way is up (used under the hood for orientation detection) as well as other sources, such as those imparted by a user.
There are a number of uses for accelerometer data, from user interface streamlining to gaming. Games developers in particular have been quick on the uptake, and already there are, for example, driving games that let you steer by tilting a device, and innumerable marble maze–type games.
In this section, you'll see how to access accelerometer data and see some examples of using that data in applications. You'll also look at how to simulate sensor data, which is essential when working in the emulator.
The AccelerometerSensor Sensor
The Windows Phone 7 SDK includes sensor types in the Microsoft.Devices.Sensors namespace, for which you need the Microsoft.Devices.Sensors.dll assembly referenced by your project. At the time of writing, there are four types in this namespace, as shown in Table 6-2.
The SensorState enumeration defines a standard set of values for states appropriate to sensors. Table 6-3 shows these values.
Get Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.