Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2321)

Unified Diff: device/generic_sensor/ambient_light_reader_iio.cc

Issue 2370343002: [sensors] Ambient light sensor implementation for ChromeOS and Linux. (Closed)
Patch Set: changed implementation Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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[] =
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.
+ 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();
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.
+ std::string value;
+ 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
+ return false;
+
+ base::TrimWhitespaceASCII(value, base::TRIM_ALL, &value);
+ if (!base::StringToDouble(value, lux))
+ return false;
+ return true;
+}
+
+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.
+ // 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++) {
Mikhail 2016/10/11 14:46:46 nit: ++i
Mikhail 2016/10/11 14:46:46 s/unsigned int/uint32_t
+ 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

Powered by Google App Engine
This is Rietveld 408576698