Index: device/generic_sensor/platform_sensor_ambient_light_iio.cc |
diff --git a/device/generic_sensor/platform_sensor_ambient_light_iio.cc b/device/generic_sensor/platform_sensor_ambient_light_iio.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..06bbc997d513f676c9d32d55ec454c851eaead84 |
--- /dev/null |
+++ b/device/generic_sensor/platform_sensor_ambient_light_iio.cc |
@@ -0,0 +1,66 @@ |
+// 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/platform_sensor_ambient_light_iio.h" |
+ |
+#include "base/bind.h" |
+#include "device/generic_sensor/public/cpp/device_sensors_consts.h" |
+ |
+namespace device { |
+ |
+PlatformSensorAmbientLightIio::PlatformSensorAmbientLightIio( |
+ mojom::SensorType type, |
+ mojo::ScopedSharedBufferMapping mapping, |
+ PlatformSensorProvider* provider, |
+ scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner, |
+ std::unique_ptr<SensorReader> sensor_reader) |
+ : PlatformSensorIio(type, |
+ std::move(mapping), |
+ provider, |
+ std::move(polling_task_runner)), |
+ lux_value_(0.0), |
+ sensor_reader_(std::move(sensor_reader)), |
+ weak_factory_(this) { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ DCHECK(sensor_reader_); |
+ DCHECK_EQ(type, sensor_reader_->type()); |
+} |
+ |
+PlatformSensorAmbientLightIio::~PlatformSensorAmbientLightIio() { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+} |
+ |
+mojom::ReportingMode PlatformSensorAmbientLightIio::GetReportingMode() { |
+ return mojom::ReportingMode::ON_CHANGE; |
+} |
+ |
+PlatformSensorConfiguration |
+PlatformSensorAmbientLightIio::GetDefaultConfiguration() { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ return PlatformSensorConfiguration(kDefaultAmbientLightFrequencyHz); |
+} |
+ |
+void PlatformSensorAmbientLightIio::UpdateReading() { |
+ DCHECK(polling_thread_task_runner_->BelongsToCurrentThread()); |
+ |
+ double update = -1; |
+ if (!sensor_reader_->ReadSensorValue(&update)) { |
+ OnSensorReadFailed(); |
+ return; |
+ } |
+ |
+ if (lux_value_ == update) { |
+ return; |
+ } |
+ lux_value_ = update; |
+ |
+ SensorReading reading; |
+ reading.timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
+ reading.values[0] = lux_value_; |
+ |
+ bool needNotify = (GetReportingMode() == mojom::ReportingMode::ON_CHANGE); |
+ UpdateSensorReading(reading, needNotify); |
+} |
+ |
+} // namespace device |