GyroscopeService

The IGyroscopeService allows a developer to access the gyroscope of a Windows Phone device.

Note that the Gyroscope service is available as separate assembly to make sure Catel.MVVM does also work on older devices without a Gyroscope

It is important that the service must be started and stopped to retrieve values

Check if the sensor is supported by the device

It is important to check whether the sensor is actually supported by the device. This can be done using the following code:

var dependencyResolver = this.GetDependencyResolver();
var gyroscopeService = dependencyResolver.Resolve<IGyroscopeService>();
if (gyroscopeService.IsSupported)
{
    // Sensor is supported
}

Starting the service

When a service is started, the service will start raising the CurrentValueChanged event as soon as new values come in from the sensor. To start the service, use the following code:

var dependencyResolver = this.GetDependencyResolver();
var gyroscopeService = dependencyResolver.Resolve<IGyroscopeService>();
gyroscopeService.CurrentValueChanged += OnGyroscopeValueChanged;
gyroscopeService.Start();

Stopping the service

It is important to stop the service when it is no longer needed by the application. To stop the service, use the following code:

var dependencyResolver = this.GetDependencyResolver();
var gyroscopeService = dependencyResolver.Resolve<IGyroscopeService>();
gyroscopeService.CurrentValueChanged -= OnGyroscopeValueChanged;
gyroscopeService.Stop();