Accessing Device Sensors

The PDK provides a set of unified APIs for accessing a number of device sensors.

Physical and Logical Sensors

Sensors are devices sensitive to light, movement, magnetic fields, and so on, such as accelerometers, gyroscopes and ambient light sensors (ALS) that transmit a signal to monitoring device software. Some of these sensors are physical, while others are logical, deriving their values from one or more physical sensor values.

In this section:

See also:


Advanced Sensor Use

Examples of advanced sensor use include:

Mobile Gaming

Mobile gaming improves significantly when mobile device motion directly controls game input. A 3-axis accelerometer can support basic gaming, with improved motion control enabled with a combination of accelerometer and gyroscope (or alternatively magnetometer).

Image Stablization

The latest generation of smartphones include high-definition (HD) camcorders, which benefit greatly from gyroscope assisted image stabilization to minimize handheld camera shake.

Augmented Reality

Augmented reality browsers, which superimpose web derived scene data onto a cellphone display, require precise heading information (provided by a compass) and also benefit from image stabilization to insure a stable display.

Navigation

Accurate navigation applications will rely heavily on data from multiple motion sensors. Net-connected cellphones, as a primary navigation device, both in-vehicle and for pedestrian use, are being increasingly used. While GPS provides accurate location outdoors, given technology limits, it is generally not available indoors or sporadically available in dense urban areas. Motion sensors support dead reckoning - tracking a user's position from the last known position - enabling accurate positioning indoors and in GPS-challenged areas.


Supported Sensors

The PDK currently supports the following sensors:


Sensor APIs and Basic Process

The PDK provides four APIs for calling sensors:

  1. PDL_SensorExists - Returns flag indicating if sensor exists on a device.

  2. PDL_EnableSensor - Enables or disables a sensor. Once enabled, your app can receive the sensor's events. Once disabled, the events stop.

  3. PDL_PollSensor - Gets events from a specific, enabled sensor.

  4. PDL_PollActiveSensors - Same as PDL_PollSensor, but returns the first event available for all the currently active sensors.

Basic Process for Accessing an Individual Sensor

As the above APIs suggest, the following is the basic process for accessing an individual sensor:

  1. Determine if sensor exists.

  2. If sensor exists, enable it.

  3. If sensor is enabled, poll on its events. Each sensor event returns the same union structure.

  4. Use data returned from sensor event.

  5. Disable sensor when done polling.

Including Sensor APIs and Data Types in Your Code

This is the same process as the one for including all PDK code:

The sensor API declarations and data types can be found in PDL_Sensor.h.


Here are links to more information about sensor technology.