O'Reilly logo

Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® by Robert Fonseca-Ensor, Karli Watson, Nick Lecrenski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

TABLE 6-2: Sensor Namespace Types

image

The SensorState enumeration defines a standard set of values for states appropriate to sensors. Table 6-3 shows these values.

TABLE 6-3: SensorState ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required