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

Unified Diff: device/generic_sensor/iio/sensor_data_iio.cc

Issue 2370343002: [sensors] Ambient light sensor implementation for ChromeOS and Linux. (Closed)
Patch Set: change SetTaskRunner to SetFileTaskRunner as per offline discussion with Mikhail 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/iio/sensor_data_iio.cc
diff --git a/device/generic_sensor/iio/sensor_data_iio.cc b/device/generic_sensor/iio/sensor_data_iio.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5f0b6b1c6df3425da663a47be0d872d3696a0558
--- /dev/null
+++ b/device/generic_sensor/iio/sensor_data_iio.cc
@@ -0,0 +1,51 @@
+// Copyright 2016 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/iio/sensor_data_iio.h"
+#include "device/sensors/public/cpp/device_sensors_consts.h"
+
+namespace device {
+
+namespace {
+
+using mojom::SensorType;
+
+const base::FilePath::CharType* kSensorsBasePath =
+ FILE_PATH_LITERAL("/sys/bus/iio/devices");
+
+const std::string kAmbientLightFileNames[] = {
+ "in_illuminance0_input", "in_illuminance_input", "in_illuminance0_raw",
+ "in_illuminance_raw", "illuminance0_input"};
+
+} // namespace
+
+SensorDataIio::SensorDataIio() : base_path_sensor_iio(kSensorsBasePath) {}
+
+SensorDataIio::~SensorDataIio() = default;
+
+SensorDataIio::SensorDataIio(const SensorDataIio& other) = default;
+
+bool InitSensorData(SensorType type, SensorDataIio* data) {
+ DCHECK(data);
+
+ switch (type) {
+ case SensorType::AMBIENT_LIGHT: {
+ std::vector<std::string> file_names(
+ kAmbientLightFileNames,
+ kAmbientLightFileNames + arraysize(kAmbientLightFileNames));
+ data->sensor_file_names.push_back(file_names);
Reilly Grant (use Gerrit) 2016/10/31 21:18:09 nit: use swap unless preserving any values already
maksims (do not use this acc) 2016/11/01 08:14:08 As I said. std::vector<std::string> != std::vector
Reilly Grant (use Gerrit) 2016/11/01 18:58:16 Ah, right. You can use std::move(file_names) to av
+ data->reporting_mode = mojom::ReportingMode::ON_CHANGE;
+ data->default_configuration =
+ PlatformSensorConfiguration(kDefaultAmbientLightFrequencyHz);
+ break;
+ }
+ default: {
+ NOTIMPLEMENTED();
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698