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