Gyrometer 類別

定義

表示陀螺儀感應器,提供與 x、y 和 Z 軸相關的角度速度值。

public ref class Gyrometer sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Gyrometer final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class Gyrometer
Public NotInheritable Class Gyrometer
繼承
Object Platform::Object IInspectable Gyrometer
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

如需範例實作,請參閱陀螺儀範例

備註

感應器資料會相對於裝置的固定感應器座標系統提供,而且與顯示方向無關。 對於依賴感應器資料進行輸入控制項或操作螢幕上元素的應用程式,開發人員必須將目前的顯示方向納入考慮,並適當地補償資料。 如需感應器座標系統的詳細資訊,請參閱 感應器資料和顯示方向

下列範例示範使用 XAML 和 C# 建置的 UWP 應用程式如何使用 GetDefault 方法來建立與陀螺儀的連線。 如果找不到整合式陀螺儀,方法會傳回 Null 值。

_gyrometer = Gyrometer.GetDefault();

下列範例示範如何使用 XAML 建置的 UWP 應用程式註冊 ReadingChanged 事件處理常式。

private void ScenarioEnable(object sender, RoutedEventArgs e)
{
    if (_gyrometer != null)
    {
        // Establish the report interval
        _gyrometer.ReportInterval = _desiredReportInterval;

        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _gyrometer.ReadingChanged += new TypedEventHandler<Gyrometer, GyrometerReadingChangedEventArgs>(ReadingChanged);

        ScenarioEnableButton.IsEnabled = false;
        ScenarioDisableButton.IsEnabled = true;
    }
    else
    {
        rootPage.NotifyUser("No gyrometer found", NotifyType.StatusMessage);
    }
}

下列範例顯示 ReadingChanged 事件處理常式。

async private void ReadingChanged(object sender, GyrometerReadingChangedEventArgs e)
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        GyrometerReading reading = e.Reading;
        ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AngularVelocityX);
        ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AngularVelocityY);
        ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AngularVelocityZ);
    });
}

版本歷程記錄

Windows 版本 SDK 版本 新增值
1709 16299 FromIdAsync
1709 16299 GetDeviceSelector
1709 16299 MaxBatchSize
1709 16299 ReportLatency
2004 19041 ReportThreshold

屬性

DeviceId

取得裝置識別碼。

MaxBatchSize

取得感應器可批次處理的事件數目上限。

MinimumReportInterval

取得陀螺儀所支援的最小報告間隔。

ReadingTransform

取得或設定需要套用至感應器資料的轉換。 要套用的轉換會系結至要對齊感應器資料的顯示方向。

ReportInterval

取得或設定陀螺儀的目前報告間隔。

ReportLatency

取得或設定感應器資訊批次之間的延遲。

ReportThreshold

取得陀螺儀感應器的 GyrometerDataThreshold

方法

FromIdAsync(String)

以非同步方式從其識別碼取得感應器。

GetCurrentReading()

取得目前的陀螺儀讀數。

GetDefault()

傳回預設陀螺儀。

GetDeviceSelector()

取得裝置選取器。

事件

ReadingChanged

每次陀螺儀報告目前感應器讀數時發生。

適用於

另請參閱