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 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_IIO_H_ |
| 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_IIO_H_ |
| 7 |
| 8 #include "device/generic_sensor/platform_sensor.h" |
| 9 |
| 10 #include "base/threading/thread.h" |
| 11 #include "base/timer/timer.h" |
| 12 #include "device/generic_sensor/iio/platform_sensor_utils_iio.h" |
| 13 #include "device/generic_sensor/iio/sensor_data_iio.h" |
| 14 |
| 15 namespace base { |
| 16 class SingleThreadTaskRunner; |
| 17 } |
| 18 |
| 19 namespace device { |
| 20 |
| 21 class PlatformSensorIio : public PlatformSensor { |
| 22 public: |
| 23 PlatformSensorIio(mojom::SensorType type, |
| 24 mojo::ScopedSharedBufferMapping mapping, |
| 25 PlatformSensorProvider* provider, |
| 26 const SensorDataIio& data, |
| 27 std::unique_ptr<base::Thread> polling_thread, |
| 28 std::unique_ptr<SensorReader> sensor_reader); |
| 29 |
| 30 // Thread safe. |
| 31 mojom::ReportingMode GetReportingMode() override; |
| 32 |
| 33 protected: |
| 34 ~PlatformSensorIio() override; |
| 35 bool StartSensor(const PlatformSensorConfiguration& configuration) override; |
| 36 void StopSensor() override; |
| 37 bool CheckSensorConfiguration( |
| 38 const PlatformSensorConfiguration& configuration) override; |
| 39 PlatformSensorConfiguration GetDefaultConfiguration() override; |
| 40 |
| 41 private: |
| 42 void BeginPoll(const PlatformSensorConfiguration& configuration); |
| 43 void StopPoll(); |
| 44 |
| 45 // Triggers |sensor_reader_| to read new sensor data. |
| 46 // If new data is read, UpdateSensorReading() is called. |
| 47 void PollForReadingData(); |
| 48 |
| 49 // Owned timer to be deleted on a polling thread. |
| 50 base::RepeatingTimer* timer_; |
| 51 |
| 52 const PlatformSensorConfiguration default_configuration_; |
| 53 const mojom::ReportingMode reporting_mode_; |
| 54 |
| 55 // A sensor reader that reads values from sensor files |
| 56 // and stores them to a SensorReading structure. |
| 57 std::unique_ptr<SensorReader> sensor_reader_; |
| 58 |
| 59 // A thread that is used to poll sensor data. |
| 60 std::unique_ptr<base::Thread> polling_thread_; |
| 61 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_; |
| 62 |
| 63 // Stores previously read values that are used to |
| 64 // determine whether the recent values are changed |
| 65 // and IPC can be notified that updates are available. |
| 66 SensorReading old_values_; |
| 67 |
| 68 base::WeakPtrFactory<PlatformSensorIio> weak_factory_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(PlatformSensorIio); |
| 71 }; |
| 72 |
| 73 } // namespace device |
| 74 |
| 75 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_IIO_H_ |
OLD | NEW |