Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/generic_sensor/platform_sensor_reader_win.h" | 5 #include "device/generic_sensor/platform_sensor_reader_win.h" |
| 6 | 6 |
| 7 #include <Sensors.h> | 7 #include <Sensors.h> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // sign for each axis. Values are converted from Milligaus to | 157 // sign for each axis. Values are converted from Milligaus to |
| 158 // Microtesla. | 158 // Microtesla. |
| 159 reading.values[0] = -x * kMicroteslaInMilligauss; | 159 reading.values[0] = -x * kMicroteslaInMilligauss; |
| 160 reading.values[1] = -y * kMicroteslaInMilligauss; | 160 reading.values[1] = -y * kMicroteslaInMilligauss; |
| 161 reading.values[2] = -z * kMicroteslaInMilligauss; | 161 reading.values[2] = -z * kMicroteslaInMilligauss; |
| 162 return S_OK; | 162 return S_OK; |
| 163 }); | 163 }); |
| 164 return params; | 164 return params; |
| 165 } | 165 } |
| 166 | 166 |
| 167 // AbsoluteOrientation sensor reader initialization parameters. | |
| 168 std::unique_ptr<ReaderInitParams> CreateAbsoluteOrientationReaderInitParams() { | |
| 169 auto params = base::MakeUnique<ReaderInitParams>(); | |
| 170 params->sensor_type_id = SENSOR_TYPE_AGGREGATED_DEVICE_ORIENTATION; | |
| 171 params->reader_func = | |
| 172 base::Bind([](ISensorDataReport& report, SensorReading& reading) { | |
| 173 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.
| |
| 174 HRESULT hr = | |
| 175 report.GetSensorValue(SENSOR_DATA_TYPE_QUATERNION, &quat_variant); | |
| 176 if (FAILED(hr) || quat_variant.vt != (VT_VECTOR | VT_UI1) || | |
| 177 quat_variant.caub.cElems < 16) { | |
| 178 return E_FAIL; | |
| 179 } | |
| 180 | |
| 181 float* quat = (float*)quat_variant.caub.pElems; | |
| 182 | |
| 183 // Windows uses coordinate system where Z axis points down from device | |
| 184 // screen, therefore, using right hand notation, we have to reverse | |
| 185 // sign for each quaternion component. | |
| 186 reading.values[0] = -quat[0]; // x*sin(Theta/2) | |
| 187 reading.values[1] = -quat[1]; // y*sin(Theta/2) | |
| 188 reading.values[2] = -quat[2]; // z*sin(Theta/2) | |
| 189 reading.values[3] = quat[3]; // cos(Theta/2) | |
| 190 return S_OK; | |
| 191 }); | |
| 192 return params; | |
| 193 } | |
| 194 | |
| 167 // Creates ReaderInitParams params structure. To implement support for new | 195 // Creates ReaderInitParams params structure. To implement support for new |
| 168 // sensor types, new switch case should be added and appropriate fields must | 196 // sensor types, new switch case should be added and appropriate fields must |
| 169 // be set: | 197 // be set: |
| 170 // sensor_type_id - GUID of the sensor supported by Windows. | 198 // sensor_type_id - GUID of the sensor supported by Windows. |
| 171 // reader_func - Functor that is responsible to populate SensorReading from | 199 // reader_func - Functor that is responsible to populate SensorReading from |
| 172 // ISensorDataReport data. | 200 // ISensorDataReport data. |
| 173 std::unique_ptr<ReaderInitParams> CreateReaderInitParamsForSensor( | 201 std::unique_ptr<ReaderInitParams> CreateReaderInitParamsForSensor( |
| 174 mojom::SensorType type) { | 202 mojom::SensorType type) { |
| 175 switch (type) { | 203 switch (type) { |
| 176 case mojom::SensorType::AMBIENT_LIGHT: | 204 case mojom::SensorType::AMBIENT_LIGHT: |
| 177 return CreateAmbientLightReaderInitParams(); | 205 return CreateAmbientLightReaderInitParams(); |
| 178 case mojom::SensorType::ACCELEROMETER: | 206 case mojom::SensorType::ACCELEROMETER: |
| 179 return CreateAccelerometerReaderInitParams(); | 207 return CreateAccelerometerReaderInitParams(); |
| 180 case mojom::SensorType::GYROSCOPE: | 208 case mojom::SensorType::GYROSCOPE: |
| 181 return CreateGyroscopeReaderInitParams(); | 209 return CreateGyroscopeReaderInitParams(); |
| 182 case mojom::SensorType::MAGNETOMETER: | 210 case mojom::SensorType::MAGNETOMETER: |
| 183 return CreateMagnetometerReaderInitParams(); | 211 return CreateMagnetometerReaderInitParams(); |
| 212 case mojom::SensorType::ABSOLUTE_ORIENTATION: | |
| 213 return CreateAbsoluteOrientationReaderInitParams(); | |
| 184 default: | 214 default: |
| 185 NOTIMPLEMENTED(); | 215 NOTIMPLEMENTED(); |
| 186 return nullptr; | 216 return nullptr; |
| 187 } | 217 } |
| 188 } | 218 } |
| 189 | 219 |
| 190 } // namespace | 220 } // namespace |
| 191 | 221 |
| 192 // Class that implements ISensorEvents and IUnknown interfaces and used | 222 // Class that implements ISensorEvents and IUnknown interfaces and used |
| 193 // by ISensor interface to dispatch state and data change events. | 223 // by ISensor interface to dispatch state and data change events. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 void PlatformSensorReaderWin::SensorError() { | 460 void PlatformSensorReaderWin::SensorError() { |
| 431 if (client_) | 461 if (client_) |
| 432 client_->OnSensorError(); | 462 client_->OnSensorError(); |
| 433 } | 463 } |
| 434 | 464 |
| 435 unsigned long PlatformSensorReaderWin::GetMinimalReportingIntervalMs() const { | 465 unsigned long PlatformSensorReaderWin::GetMinimalReportingIntervalMs() const { |
| 436 return init_params_->min_reporting_interval_ms; | 466 return init_params_->min_reporting_interval_ms; |
| 437 } | 467 } |
| 438 | 468 |
| 439 } // namespace device | 469 } // namespace device |
| OLD | NEW |