OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/platform_sensor_ambient_light_iio.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "device/generic_sensor/public/cpp/device_sensors_consts.h" |
| 9 |
| 10 namespace device { |
| 11 |
| 12 PlatformSensorAmbientLightIio::PlatformSensorAmbientLightIio( |
| 13 mojom::SensorType type, |
| 14 mojo::ScopedSharedBufferMapping mapping, |
| 15 PlatformSensorProvider* provider, |
| 16 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner, |
| 17 std::unique_ptr<SensorReader> sensor_reader) |
| 18 : PlatformSensorIio(type, |
| 19 std::move(mapping), |
| 20 provider, |
| 21 std::move(polling_task_runner)), |
| 22 lux_value_(0.0), |
| 23 sensor_reader_(std::move(sensor_reader)), |
| 24 weak_factory_(this) { |
| 25 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 26 DCHECK(sensor_reader_); |
| 27 DCHECK_EQ(type, sensor_reader_->type()); |
| 28 } |
| 29 |
| 30 PlatformSensorAmbientLightIio::~PlatformSensorAmbientLightIio() { |
| 31 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 32 } |
| 33 |
| 34 mojom::ReportingMode PlatformSensorAmbientLightIio::GetReportingMode() { |
| 35 return mojom::ReportingMode::ON_CHANGE; |
| 36 } |
| 37 |
| 38 PlatformSensorConfiguration |
| 39 PlatformSensorAmbientLightIio::GetDefaultConfiguration() { |
| 40 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 41 return PlatformSensorConfiguration(kDefaultAmbientLightFrequencyHz); |
| 42 } |
| 43 |
| 44 void PlatformSensorAmbientLightIio::UpdateReading() { |
| 45 DCHECK(polling_thread_task_runner_->BelongsToCurrentThread()); |
| 46 |
| 47 double update = -1; |
| 48 if (!sensor_reader_->ReadSensorValue(&update)) { |
| 49 OnSensorReadFailed(); |
| 50 return; |
| 51 } |
| 52 |
| 53 if (lux_value_ == update) { |
| 54 return; |
| 55 } |
| 56 lux_value_ = update; |
| 57 |
| 58 SensorReading reading; |
| 59 reading.timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
| 60 reading.values[0] = lux_value_; |
| 61 |
| 62 bool needNotify = (GetReportingMode() == mojom::ReportingMode::ON_CHANGE); |
| 63 UpdateSensorReading(reading, needNotify); |
| 64 } |
| 65 |
| 66 } // namespace device |
OLD | NEW |