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

Side by Side Diff: device/generic_sensor/platform_sensor_iio.h

Issue 2370343002: [sensors] Ambient light sensor implementation for ChromeOS and Linux. (Closed)
Patch Set: Newest version. and some comments 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 unified diff | Download patch
OLDNEW
(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 mojom::ReportingMode GetReportingMode() override;
31
32 protected:
33 ~PlatformSensorIio() override;
34 bool StartSensor(const PlatformSensorConfiguration& configuration) override;
35 void StopSensor() override;
36 bool CheckSensorConfiguration(
37 const PlatformSensorConfiguration& configuration) override;
38 PlatformSensorConfiguration GetDefaultConfiguration() override;
39
40 private:
41 void BeginPoll(const PlatformSensorConfiguration& configuration);
42 void StopPoll();
43
44 // Triggers |sensor_reader_| to read new sensor data.
45 // If new data is read, UpdateSensorReading() is called.
46 void PollForReadingData();
47
48 // Owned timer to be deleted on a polling thread.
49 base::RepeatingTimer* timer_;
50
51 const PlatformSensorConfiguration default_configuration_;
52 const mojom::ReportingMode reporting_mode_;
53
54 // A sensor reader that reads values from sensor files
55 // and stores them to a SensorReading structure.
56 std::unique_ptr<SensorReader> sensor_reader_;
57
58 // A thread that is used to poll sensor data.
59 std::unique_ptr<base::Thread> polling_thread_;
60 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_;
61
62 // Stores previously read values that are used to
63 // determine whether the recent values are changed
64 // and IPC can be notified that updates are available.
65 SensorReading old_values_;
66
67 base::WeakPtrFactory<PlatformSensorIio> weak_factory_;
68
69 DISALLOW_COPY_AND_ASSIGN(PlatformSensorIio);
70 };
71
72 } // namespace device
73
74 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_IIO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698