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 "services/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" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/win/iunknown_impl.h" | 13 #include "base/win/iunknown_impl.h" |
14 #include "base/win/scoped_propvariant.h" | 14 #include "base/win/scoped_propvariant.h" |
15 #include "device/generic_sensor/generic_sensor_consts.h" | 15 #include "services/device/generic_sensor/generic_sensor_consts.h" |
16 #include "device/generic_sensor/public/cpp/platform_sensor_configuration.h" | 16 #include "services/device/public/cpp/generic_sensor/platform_sensor_configuratio
n.h" |
17 #include "device/generic_sensor/public/cpp/sensor_reading.h" | 17 #include "services/device/public/cpp/generic_sensor/sensor_reading.h" |
18 | 18 |
19 namespace device { | 19 namespace device { |
20 | 20 |
21 // Init params for the PlatformSensorReaderWin. | 21 // Init params for the PlatformSensorReaderWin. |
22 struct ReaderInitParams { | 22 struct ReaderInitParams { |
23 // ISensorDataReport::GetSensorValue is not const, therefore, report | 23 // ISensorDataReport::GetSensorValue is not const, therefore, report |
24 // cannot be passed as const ref. | 24 // cannot be passed as const ref. |
25 // ISensorDataReport& report - report that contains new sensor data. | 25 // ISensorDataReport& report - report that contains new sensor data. |
26 // SensorReading& reading - out parameter that must be populated. | 26 // SensorReading& reading - out parameter that must be populated. |
27 // Returns HRESULT - S_OK on success, otherwise error code. | 27 // Returns HRESULT - S_OK on success, otherwise error code. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 reading.values[2] = -z * kMeanGravity; | 97 reading.values[2] = -z * kMeanGravity; |
98 return S_OK; | 98 return S_OK; |
99 }); | 99 }); |
100 return params; | 100 return params; |
101 } | 101 } |
102 | 102 |
103 // Gyroscope sensor reader initialization parameters. | 103 // Gyroscope sensor reader initialization parameters. |
104 std::unique_ptr<ReaderInitParams> CreateGyroscopeReaderInitParams() { | 104 std::unique_ptr<ReaderInitParams> CreateGyroscopeReaderInitParams() { |
105 auto params = base::MakeUnique<ReaderInitParams>(); | 105 auto params = base::MakeUnique<ReaderInitParams>(); |
106 params->sensor_type_id = SENSOR_TYPE_GYROMETER_3D; | 106 params->sensor_type_id = SENSOR_TYPE_GYROMETER_3D; |
107 params->reader_func = base::Bind([](ISensorDataReport& report, | 107 params->reader_func = |
108 SensorReading& reading) { | 108 base::Bind([](ISensorDataReport& report, SensorReading& reading) { |
109 double x = 0.0; | 109 double x = 0.0; |
110 double y = 0.0; | 110 double y = 0.0; |
111 double z = 0.0; | 111 double z = 0.0; |
112 if (!GetReadingValueForProperty( | 112 if (!GetReadingValueForProperty( |
113 SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, report, | 113 SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, report, |
114 &x) || | 114 &x) || |
115 !GetReadingValueForProperty( | 115 !GetReadingValueForProperty( |
116 SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, report, | 116 SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, report, |
117 &y) || | 117 &y) || |
118 !GetReadingValueForProperty( | 118 !GetReadingValueForProperty( |
119 SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, report, | 119 SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, report, |
120 &z)) { | 120 &z)) { |
121 return E_FAIL; | 121 return E_FAIL; |
122 } | 122 } |
123 | 123 |
124 // Windows uses coordinate system where Z axis points down from device | 124 // Windows uses coordinate system where Z axis points down from device |
125 // screen, therefore, using right hand notation, we have to reverse | 125 // screen, therefore, using right hand notation, we have to reverse |
126 // sign for each axis. Values are converted from deg to rad. | 126 // sign for each axis. Values are converted from deg to rad. |
127 reading.values[0] = -x * kRadiansInDegrees; | 127 reading.values[0] = -x * kRadiansInDegrees; |
128 reading.values[1] = -y * kRadiansInDegrees; | 128 reading.values[1] = -y * kRadiansInDegrees; |
129 reading.values[2] = -z * kRadiansInDegrees; | 129 reading.values[2] = -z * kRadiansInDegrees; |
130 return S_OK; | 130 return S_OK; |
131 }); | 131 }); |
132 return params; | 132 return params; |
133 } | 133 } |
134 | 134 |
135 // Magnetometer sensor reader initialization parameters. | 135 // Magnetometer sensor reader initialization parameters. |
136 std::unique_ptr<ReaderInitParams> CreateMagnetometerReaderInitParams() { | 136 std::unique_ptr<ReaderInitParams> CreateMagnetometerReaderInitParams() { |
137 auto params = base::MakeUnique<ReaderInitParams>(); | 137 auto params = base::MakeUnique<ReaderInitParams>(); |
138 params->sensor_type_id = SENSOR_TYPE_COMPASS_3D; | 138 params->sensor_type_id = SENSOR_TYPE_COMPASS_3D; |
139 params->reader_func = | 139 params->reader_func = |
140 base::Bind([](ISensorDataReport& report, SensorReading& reading) { | 140 base::Bind([](ISensorDataReport& report, SensorReading& reading) { |
141 double x = 0.0; | 141 double x = 0.0; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 void PlatformSensorReaderWin::SensorError() { | 461 void PlatformSensorReaderWin::SensorError() { |
462 if (client_) | 462 if (client_) |
463 client_->OnSensorError(); | 463 client_->OnSensorError(); |
464 } | 464 } |
465 | 465 |
466 unsigned long PlatformSensorReaderWin::GetMinimalReportingIntervalMs() const { | 466 unsigned long PlatformSensorReaderWin::GetMinimalReportingIntervalMs() const { |
467 return init_params_->min_reporting_interval_ms; | 467 return init_params_->min_reporting_interval_ms; |
468 } | 468 } |
469 | 469 |
470 } // namespace device | 470 } // namespace device |
OLD | NEW |