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 "base/sys_info.h" | 5 #include "base/sys_info.h" |
6 #include "base/version.h" | 6 #include "base/version.h" |
7 #include "device/generic_sensor/generic_sensor_consts.h" | 7 #include "device/generic_sensor/generic_sensor_consts.h" |
8 #include "device/generic_sensor/linux/sensor_data_linux.h" | 8 #include "device/generic_sensor/linux/sensor_data_linux.h" |
9 #include "device/generic_sensor/public/cpp/sensor_reading.h" | 9 #include "device/generic_sensor/public/cpp/sensor_reading.h" |
10 | 10 |
11 namespace device { | 11 namespace device { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 using mojom::SensorType; | 15 using mojom::SensorType; |
16 | 16 |
17 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
18 // ChromeOS kernel version, when axes were changed to XYZ. Before 3.18, | 18 // ChromeOS kernel version, when axes were changed to XYZ. Before 3.18, |
19 // they were YXZ. | 19 // they were YXZ. |
20 const char kChangedAxisKernelVersion[] = "3.18.0"; | 20 const char kChangedAxisKernelVersion[] = "3.18.0"; |
21 #endif | 21 #endif |
22 | 22 |
23 const base::FilePath::CharType* kSensorsBasePath = | |
24 FILE_PATH_LITERAL("/sys/bus/iio/devices"); | |
25 | |
26 void InitAmbientLightSensorData(SensorPathsLinux* data) { | 23 void InitAmbientLightSensorData(SensorPathsLinux* data) { |
27 std::vector<std::string> file_names{ | 24 std::vector<std::string> file_names{ |
28 "in_illuminance0_input", "in_illuminance_input", "in_illuminance0_raw", | 25 "in_illuminance0_input", "in_illuminance_input", "in_illuminance0_raw", |
29 "in_illuminance_raw"}; | 26 "in_illuminance_raw", "in_intensity_both_raw"}; |
30 data->sensor_file_names.push_back(std::move(file_names)); | 27 data->sensor_file_names.push_back(std::move(file_names)); |
| 28 data->sensor_frequency_file_name = "in_intensity_sampling_frequency"; |
| 29 data->sensor_scale_name = "in_intensity_scale"; |
| 30 data->apply_scaling_func = base::Bind( |
| 31 [](double scaling_value, double offset, SensorReading& reading) { |
| 32 reading.values[0] = scaling_value * (reading.values[0] + offset); |
| 33 }); |
31 data->default_configuration = | 34 data->default_configuration = |
32 PlatformSensorConfiguration(kDefaultAmbientLightFrequencyHz); | 35 PlatformSensorConfiguration(kDefaultAmbientLightFrequencyHz); |
33 } | 36 } |
34 | 37 |
35 // Depending on a kernel version, CrOS has a different axes plane. | 38 // Depending on a kernel version, CrOS has a different axes plane. |
36 // Before 3.18 it was YXZ and after XYZ. | 39 // Before 3.18 it was YXZ and after XYZ. |
37 // TODO(maksims): Track crbug.com/501184. 3.14 will have the same sensor stack | 40 // TODO(maksims): Track crbug.com/501184. 3.14 will have the same sensor stack |
38 // as 3.18 has, which will probably change the order of axes. | 41 // as 3.18 has, which will probably change the order of axes. |
39 void MaybeCheckKernelVersionAndAssignFileNames( | 42 void MaybeCheckKernelVersionAndAssignFileNames( |
40 const std::vector<std::string>& file_names_x, | 43 const std::vector<std::string>& file_names_x, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 }); | 156 }); |
154 | 157 |
155 MaybeCheckKernelVersionAndAssignFileNames(file_names_x, file_names_y, | 158 MaybeCheckKernelVersionAndAssignFileNames(file_names_x, file_names_y, |
156 file_names_z, data); | 159 file_names_z, data); |
157 data->default_configuration = | 160 data->default_configuration = |
158 PlatformSensorConfiguration(kDefaultMagnetometerFrequencyHz); | 161 PlatformSensorConfiguration(kDefaultMagnetometerFrequencyHz); |
159 } | 162 } |
160 | 163 |
161 } // namespace | 164 } // namespace |
162 | 165 |
163 SensorPathsLinux::SensorPathsLinux() | 166 SensorPathsLinux::SensorPathsLinux() = default; |
164 : base_path_sensor_linux(kSensorsBasePath) {} | |
165 | |
166 SensorPathsLinux::~SensorPathsLinux() = default; | 167 SensorPathsLinux::~SensorPathsLinux() = default; |
167 | |
168 SensorPathsLinux::SensorPathsLinux(const SensorPathsLinux& other) = default; | 168 SensorPathsLinux::SensorPathsLinux(const SensorPathsLinux& other) = default; |
169 | 169 |
170 bool InitSensorData(SensorType type, SensorPathsLinux* data) { | 170 bool InitSensorData(SensorType type, SensorPathsLinux* data) { |
171 DCHECK(data); | 171 DCHECK(data); |
172 | 172 |
173 data->type = type; | 173 data->type = type; |
174 switch (type) { | 174 switch (type) { |
175 case SensorType::AMBIENT_LIGHT: | 175 case SensorType::AMBIENT_LIGHT: |
176 InitAmbientLightSensorData(data); | 176 InitAmbientLightSensorData(data); |
177 break; | 177 break; |
(...skipping 25 matching lines...) Expand all Loading... |
203 device_frequency(sensor_device_frequency), | 203 device_frequency(sensor_device_frequency), |
204 device_scaling_value(sensor_device_scaling_value), | 204 device_scaling_value(sensor_device_scaling_value), |
205 device_offset_value(sensor_device_offset_value), | 205 device_offset_value(sensor_device_offset_value), |
206 reporting_mode(mode), | 206 reporting_mode(mode), |
207 apply_scaling_func(scaling_func), | 207 apply_scaling_func(scaling_func), |
208 device_reading_files(std::move(device_reading_files)) {} | 208 device_reading_files(std::move(device_reading_files)) {} |
209 | 209 |
210 SensorInfoLinux::~SensorInfoLinux() = default; | 210 SensorInfoLinux::~SensorInfoLinux() = default; |
211 | 211 |
212 } // namespace device | 212 } // namespace device |
OLD | NEW |