来自Windows的陀螺仪和加速度计数据?

Jim*_*Jim 5 .net c# motion-detection

Microsoft Surface Pro具有陀螺仪和加速度计,Windows 8以及完整的.NET框架.

我发现大多数关于动作API的文章都指向Windows Phone 8 API.

我应该使用什么.NET Framework命名空间和类来获取陀螺仪和加速度计数据?

Lev*_*ler 4

我只是根据文档工作 - http://msdn.microsoft.com/en-us/library/ie/windows.devices.sensors

using Windows.Devices.Sensors;

private Accelerometer _accelerometer;

private void DoStuffWithAccel()
{
   _accelerometer = Accelerometer.GetDefault();
   if (_accelerometer != null)
   {
      AccelerometerReading reading = _accelerometer.GetCurrentReading();
      if (reading != null)
      double xreading = reading.AccelerationX;
      ... etc.
   }
}
Run Code Online (Sandbox Code Playgroud)

尚未测试它,但它应该适用于任何 Windows 应用商店应用程序 - 如果您尝试使其作为控制台/Windows 表单应用程序运行,则需要通过以下方式更改目标平台:

  1. 右键单击您的项目 -> 卸载项目
  2. 请遵循此https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications的其余部分