OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ | 5 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ |
6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ | 6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "chromeos/accelerometer/accelerometer_types.h" |
13 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
14 #include "ui/gfx/geometry/vector3d_f.h" | 15 #include "ui/gfx/geometry/vector3d_f.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class TaskRunner; | 18 class TaskRunner; |
18 } | 19 } |
19 | 20 |
20 namespace chromeos { | 21 namespace chromeos { |
21 | 22 |
22 // Reads an accelerometer device and reports data back to an | 23 // Reads an accelerometer device and reports data back to an |
(...skipping 11 matching lines...) Expand all Loading... |
34 | 35 |
35 // Index of each accelerometer axis in data stream. | 36 // Index of each accelerometer axis in data stream. |
36 std::vector<unsigned int> index; | 37 std::vector<unsigned int> index; |
37 }; | 38 }; |
38 typedef base::RefCountedData<ConfigurationData> Configuration; | 39 typedef base::RefCountedData<ConfigurationData> Configuration; |
39 typedef base::RefCountedData<char[12]> Reading; | 40 typedef base::RefCountedData<char[12]> Reading; |
40 | 41 |
41 // An interface to receive data from the AccelerometerReader. | 42 // An interface to receive data from the AccelerometerReader. |
42 class Delegate { | 43 class Delegate { |
43 public: | 44 public: |
44 virtual void HandleAccelerometerReading(const gfx::Vector3dF& base, | 45 virtual void HandleAccelerometerUpdate( |
45 const gfx::Vector3dF& lid) = 0; | 46 const AccelerometerUpdate& update) = 0; |
46 }; | 47 }; |
47 | 48 |
48 AccelerometerReader(base::TaskRunner* blocking_task_runner, | 49 AccelerometerReader(base::TaskRunner* blocking_task_runner, |
49 Delegate* delegate); | 50 Delegate* delegate); |
50 ~AccelerometerReader(); | 51 ~AccelerometerReader(); |
51 | 52 |
52 private: | 53 private: |
53 // Dispatched when initialization is complete. If |success|, |configuration| | 54 // Dispatched when initialization is complete. If |success|, |configuration| |
54 // provides the details of the detected accelerometer. | 55 // provides the details of the detected accelerometer. |
55 void OnInitialized(scoped_refptr<Configuration> configuration, bool success); | 56 void OnInitialized(scoped_refptr<Configuration> configuration, bool success); |
56 | 57 |
57 // Triggers an asynchronous read from the accelerometer, signalling | 58 // Triggers an asynchronous read from the accelerometer, signalling |
58 // OnDataRead with the result. | 59 // OnDataRead with the result. |
59 void TriggerRead(); | 60 void TriggerRead(); |
60 | 61 |
61 // If |success|, converts the raw reading to a pair of Vector3dF | 62 // If |success|, converts the raw reading to a pair of Vector3dF |
62 // values and notifies the |delegate_| with the new readings. | 63 // values and notifies the |delegate_| with the new readings. |
63 // Triggers another read from the accelerometer at the current sampling rate. | 64 // Triggers another read from the accelerometer at the current sampling rate. |
64 void OnDataRead(scoped_refptr<Reading> reading, bool success); | 65 void OnDataRead(scoped_refptr<Reading> reading, bool success); |
65 | 66 |
66 // The task runner to use for blocking tasks. | 67 // The task runner to use for blocking tasks. |
67 scoped_refptr<base::TaskRunner> task_runner_; | 68 scoped_refptr<base::TaskRunner> task_runner_; |
68 | 69 |
69 // A weak pointer to the delegate to send accelerometer readings to. | 70 // A weak pointer to the delegate to send accelerometer readings to. |
70 Delegate* delegate_; | 71 Delegate* delegate_; |
71 | 72 |
| 73 // The last seen accelerometer data. |
| 74 AccelerometerUpdate update_; |
| 75 |
72 // The accelerometer configuration. | 76 // The accelerometer configuration. |
73 scoped_refptr<Configuration> configuration_; | 77 scoped_refptr<Configuration> configuration_; |
74 | 78 |
75 base::WeakPtrFactory<AccelerometerReader> weak_factory_; | 79 base::WeakPtrFactory<AccelerometerReader> weak_factory_; |
76 | 80 |
77 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); | 81 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); |
78 }; | 82 }; |
79 | 83 |
80 } // namespace chromeos | 84 } // namespace chromeos |
81 | 85 |
82 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ | 86 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ |
OLD | NEW |