Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_reader_win.cc |
| diff --git a/device/generic_sensor/platform_sensor_reader_win.cc b/device/generic_sensor/platform_sensor_reader_win.cc |
| index 5b77b6c86336736ee4bbed9a0ea2408772dbfdf2..c53ad866b2ec45205aaf549f9c3a70eafd94baab 100644 |
| --- a/device/generic_sensor/platform_sensor_reader_win.cc |
| +++ b/device/generic_sensor/platform_sensor_reader_win.cc |
| @@ -164,6 +164,34 @@ std::unique_ptr<ReaderInitParams> CreateMagnetometerReaderInitParams() { |
| return params; |
| } |
| +// AbsoluteOrientation sensor reader initialization parameters. |
| +std::unique_ptr<ReaderInitParams> CreateAbsoluteOrientationReaderInitParams() { |
| + auto params = base::MakeUnique<ReaderInitParams>(); |
| + params->sensor_type_id = SENSOR_TYPE_AGGREGATED_DEVICE_ORIENTATION; |
| + params->reader_func = |
| + base::Bind([](ISensorDataReport& report, SensorReading& reading) { |
| + PROPVARIANT quat_variant = {}; |
|
Reilly Grant (use Gerrit)
2017/03/21 18:25:06
This should also be a base::win::ScopedPropVariant
shalamov
2017/03/23 13:35:29
Done.
|
| + HRESULT hr = |
| + report.GetSensorValue(SENSOR_DATA_TYPE_QUATERNION, &quat_variant); |
| + if (FAILED(hr) || quat_variant.vt != (VT_VECTOR | VT_UI1) || |
| + quat_variant.caub.cElems < 16) { |
| + return E_FAIL; |
| + } |
| + |
| + float* quat = (float*)quat_variant.caub.pElems; |
| + |
| + // Windows uses coordinate system where Z axis points down from device |
| + // screen, therefore, using right hand notation, we have to reverse |
| + // sign for each quaternion component. |
| + reading.values[0] = -quat[0]; // x*sin(Theta/2) |
| + reading.values[1] = -quat[1]; // y*sin(Theta/2) |
| + reading.values[2] = -quat[2]; // z*sin(Theta/2) |
| + reading.values[3] = quat[3]; // cos(Theta/2) |
| + return S_OK; |
| + }); |
| + return params; |
| +} |
| + |
| // Creates ReaderInitParams params structure. To implement support for new |
| // sensor types, new switch case should be added and appropriate fields must |
| // be set: |
| @@ -181,6 +209,8 @@ std::unique_ptr<ReaderInitParams> CreateReaderInitParamsForSensor( |
| return CreateGyroscopeReaderInitParams(); |
| case mojom::SensorType::MAGNETOMETER: |
| return CreateMagnetometerReaderInitParams(); |
| + case mojom::SensorType::ABSOLUTE_ORIENTATION: |
| + return CreateAbsoluteOrientationReaderInitParams(); |
| default: |
| NOTIMPLEMENTED(); |
| return nullptr; |