Using the Gyroscope Sensor

The gyroscope sensor is not a required component of Windows Phone devices. It is therefore important to verify that it is supported before attempting to use it. For this, the static Gyroscope.IsSupported property is used, as demonstrated in the GyroscopeViewModel class (see Listing 16.9). The Start method of the GyroscopeViewModel oversees the creation of the Gyroscope instance.

The default value of the Gyroscope’s TimeBetweenUpdates property is 20 milliseconds, which on my test device was the minimum allowed value.

As with all sensor types, the CurrentValueChanged event is used to receive periodic updates from the sensor.

LISTING 16.9. GyroscopeViewModel.Start Method

public void Start() ...

Get Windows® Phone 8 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.