Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions docs/platform-integration/device/sensors.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Accessing device sensors overview
title: Accessing device sensors
description: "Learn how to use and monitor sensors provided by your device, with .NET MAUI. You can monitor the following sensors: accelerometer, barometer, compass, shake, gyroscope, magnetometer, orientation."
ms.topic: overview
ms.date: 02/02/2023
Expand All @@ -16,23 +16,34 @@ Device sensor-related types are available in the `Microsoft.Maui.Devices.Sensors

## Sensor speed

Sensor speed sets the speed in which a sensor will return data to your app. When you start a sensor, you provide the desired sensor speed with the <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed> enumeration.
Sensor speed sets the speed in which a sensor will return data to your app. When you start a sensor, you provide the desired sensor speed with the <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed> enumeration:

- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Fastest>\
Get the sensor data as fast as possible (not guaranteed to return on UI thread).

- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Game>\
Rate suitable for games (not guaranteed to return on UI thread).

- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Default>\
Default rate suitable for screen orientation changes.

- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.UI>\
Rate suitable for general user interface.

- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Default>\
Default rate suitable for screen orientation changes.

> [!WARNING]
> Monitoring too many sensors at once may affect the rate sensor data is returned to your app.

::: moniker range=">=net-maui-8.0"

In .NET 8, <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed> intervals are identical across all platforms:

- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Default> uses an interval of 200ms.
- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.UI> uses an interval of 60ms.
- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Game> uses an interval of 20ms.
- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Fastest> uses an interval of 5ms.

::: moniker-end

### Sensor event handlers

Event handlers added to sensors with either the <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Game> or <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed.Fastest> speeds **aren't** guaranteed to run on the UI thread. If the event handler needs to access user-interface elements, use the [`MainThread.BeginInvokeOnMainThread`](../appmodel/main-thread.md) method to run that code on the UI thread.
Expand Down
1 change: 1 addition & 0 deletions docs/whats-new/dotnet-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ For information about what's new in .NET 8, see [What's new in .NET 8](/dotnet/c
- <xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView> gains a `StartPath` property, a `TryDispatchAsync` method, and enhanced logging capabilities. For more information, see [Host a Blazor web app in a .NET MAUI app using BlazorWebView](~/user-interface/controls/blazorwebview.md).
- <xref:Microsoft.Maui.Controls.PointerGestureRecognizer> gains `PointerPressedCommand`, `PointerPressedCommandParameter`, `PointerReleasedCommand`, `PointerReleasedCommandParameter` properties, and `PointerPressed` and `PointerReleased` events. For more information, see [Recognize a pointer gesture](~/fundamentals/gestures/pointer.md).
- <xref:Microsoft.Maui.Devices.Flashlight> gains a `IsSupportedAsync` method that determines whether a flashlight is available on the device. For more information, see [Flashlight](~/platform-integration/device/flashlight.md).
- <xref:Microsoft.Maui.Devices.Sensors.SensorSpeed> intervals have been unified across all platforms. For more information, see [Accessing device sensors](~/platform-integration/device/sensors.md).

The following members have been deprecated:

Expand Down