| Index: device/generic_sensor/ambient_light_reader_iio.cc
|
| diff --git a/device/generic_sensor/ambient_light_reader_iio.cc b/device/generic_sensor/ambient_light_reader_iio.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9a62c33e5ccee1aa24695f54066422a4d16fd6b5
|
| --- /dev/null
|
| +++ b/device/generic_sensor/ambient_light_reader_iio.cc
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "device/generic_sensor/ambient_light_reader_iio.h"
|
| +
|
| +#include "base/files/file_enumerator.h"
|
| +#include "base/files/file_util.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/string_util.h"
|
| +
|
| +namespace device {
|
| +
|
| +namespace {
|
| +
|
| +// Base path where sensors are located.
|
| +const base::FilePath::CharType kAmbientLightIioBasePath[] =
|
| + FILE_PATH_LITERAL("/sys/bus/iio/devices");
|
| +
|
| +} // namespace
|
| +
|
| +AmbientLightSensorReaderIio::AmbientLightSensorReaderIio() = default;
|
| +AmbientLightSensorReaderIio::~AmbientLightSensorReaderIio() = default;
|
| +
|
| +bool AmbientLightSensorReaderIio::ReadSensorLuxValue(double* lux) {
|
| + *lux = std::numeric_limits<double>::infinity();
|
| + std::string value;
|
| + if (!base::ReadFileToString(sensor_path_, &value))
|
| + return false;
|
| +
|
| + base::TrimWhitespaceASCII(value, base::TRIM_ALL, &value);
|
| + if (!base::StringToDouble(value, lux))
|
| + return false;
|
| + return true;
|
| +}
|
| +
|
| +bool AmbientLightSensorReaderIio::DetectLightSensor() {
|
| + // Search the iio/devices directory for a subdirectory (eg "device0" or
|
| + // "iio:device0") that contains the "[in_]illuminance[0]_{input|raw}" file.
|
| + base::FileEnumerator dir_enumerator(base::FilePath(kAmbientLightIioBasePath),
|
| + false, base::FileEnumerator::DIRECTORIES);
|
| + const char* input_names[] = {
|
| + "in_illuminance0_input", "in_illuminance_input", "in_illuminance0_raw",
|
| + "in_illuminance_raw", "illuminance0_input",
|
| + };
|
| +
|
| + for (base::FilePath check_path = dir_enumerator.Next(); !check_path.empty();
|
| + check_path = dir_enumerator.Next()) {
|
| + for (unsigned int i = 0; i < arraysize(input_names); i++) {
|
| + base::FilePath als_path = check_path.Append(input_names[i]);
|
| + if (base::PathExists(als_path)) {
|
| + sensor_path_ = als_path;
|
| + return true;
|
| + }
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +} // namespace content
|
|
|