Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "device/generic_sensor/ambient_light_reader_iio.h" | |
| 6 | |
| 7 #include "base/files/file_enumerator.h" | |
| 8 #include "base/files/file_util.h" | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/string_util.h" | |
| 11 | |
| 12 namespace device { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Base path where sensors are located. | |
| 17 const base::FilePath::CharType kAmbientLightIioBasePath[] = | |
|
Mikhail
2016/10/11 14:46:46
better make it a constructor argument than hide he
maksims (do not use this acc)
2016/10/14 12:31:44
Done.
| |
| 18 FILE_PATH_LITERAL("/sys/bus/iio/devices"); | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 AmbientLightSensorReaderIio::AmbientLightSensorReaderIio() = default; | |
| 23 AmbientLightSensorReaderIio::~AmbientLightSensorReaderIio() = default; | |
| 24 | |
| 25 bool AmbientLightSensorReaderIio::ReadSensorLuxValue(double* lux) { | |
| 26 *lux = std::numeric_limits<double>::infinity(); | |
|
Mikhail
2016/10/11 14:46:46
you should not modify the output parameter on call
maksims (do not use this acc)
2016/10/14 12:31:44
Done.
| |
| 27 std::string value; | |
| 28 if (!base::ReadFileToString(sensor_path_, &value)) | |
|
Mikhail
2016/10/11 14:46:46
how do you know if 'sensor_path_' has been initial
maksims (do not use this acc)
2016/10/14 12:31:45
Right now, sensor_paths_ is a vector of path. If i
| |
| 29 return false; | |
| 30 | |
| 31 base::TrimWhitespaceASCII(value, base::TRIM_ALL, &value); | |
| 32 if (!base::StringToDouble(value, lux)) | |
| 33 return false; | |
| 34 return true; | |
| 35 } | |
| 36 | |
| 37 bool AmbientLightSensorReaderIio::DetectLightSensor() { | |
|
Mikhail
2016/10/11 14:46:46
should be renamed to smth like 'InitLightSensorPat
maksims (do not use this acc)
2016/10/14 12:31:45
Done.
| |
| 38 // Search the iio/devices directory for a subdirectory (eg "device0" or | |
| 39 // "iio:device0") that contains the "[in_]illuminance[0]_{input|raw}" file. | |
| 40 base::FileEnumerator dir_enumerator(base::FilePath(kAmbientLightIioBasePath), | |
| 41 false, base::FileEnumerator::DIRECTORIES); | |
| 42 const char* input_names[] = { | |
| 43 "in_illuminance0_input", "in_illuminance_input", "in_illuminance0_raw", | |
| 44 "in_illuminance_raw", "illuminance0_input", | |
| 45 }; | |
| 46 | |
| 47 for (base::FilePath check_path = dir_enumerator.Next(); !check_path.empty(); | |
| 48 check_path = dir_enumerator.Next()) { | |
| 49 for (unsigned int i = 0; i < arraysize(input_names); i++) { | |
|
Mikhail
2016/10/11 14:46:46
nit: ++i
Mikhail
2016/10/11 14:46:46
s/unsigned int/uint32_t
| |
| 50 base::FilePath als_path = check_path.Append(input_names[i]); | |
| 51 if (base::PathExists(als_path)) { | |
| 52 sensor_path_ = als_path; | |
| 53 return true; | |
| 54 } | |
| 55 } | |
| 56 } | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 } // namespace content | |
| OLD | NEW |