Gyrometer
Tip
This article covers Uno-specific information for Gyrometer. For a full description of the feature and instructions on using it, see Gyrometer Class.
- The
Windows.Devices.Sensors.Gyrometerclass allows measuring angular velocity applied on the device.
Supported features
| Feature | Windows | Android | iOS | Web (WASM) | macOS | Linux (Skia) | Win 7 (Skia) |
|---|---|---|---|---|---|---|---|
GetDefault |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
ReadingChanged |
✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✖ |
ReportInterval |
✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✖ |
Using Gyrometer with Uno
- The
GetDefaultmethod is available on all targets and will returnnullon those which do not supportGyrometeror devices that do not have such a sensor. - Ensure to unsubscribe from the
ReadingChangedevent when you no longer need the readings, so that the sensor is no longer active to avoid unnecessary battery consumption. ReportIntervalproperty on WASM is currently not supported directly. Uno uses an approximation in the form of raising theReadingChangedevent, only when enough time has passed since the last report. The event is raised a bit more often to make sure the gap caused by the filter is not too large, but this is in line with the behavior of Windows'Gyrometer.
Example
Capturing sensor readings
var gyrometer = Gyrometer.GetDefault();
gyrometer.ReadingChanged += Gyrometer_ReadingChanged;
private async void Gyrometer_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
{
// If you want to update the UI in some way, ensure the Dispatcher is used,
// as the ReadingChanged event handler does not run on the UI thread.
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AngularVelocityX = args.Reading.AngularVelocityX;
AngularVelocityY = args.Reading.AngularVelocityY;
AngularVelocityZ = args.Reading.AngularVelocityZ;
Timestamp = args.Reading.Timestamp.ToString("R");
});
}
Unsubscribing from the readings
gyrometer.ReadingChanged -= Gyrometer_ReadingChanged;