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

Side by Side Diff: chromeos/accelerometer/accelerometer_reader.h

Issue 500613003: Use standardized and extendable accelerometer update type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge and remove unused Vector3dF reference. Created 6 years, 3 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
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/chromeos_export.h" 13 #include "chromeos/chromeos_export.h"
14 #include "ui/gfx/geometry/vector3d_f.h" 14 #include "ui/accelerometer/accelerometer_types.h"
15 15
16 namespace base { 16 namespace base {
17 class TaskRunner; 17 class TaskRunner;
18 } 18 }
19 19
20 namespace chromeos { 20 namespace chromeos {
21 21
22 // Reads an accelerometer device and reports data back to an 22 // Reads an accelerometer device and reports data back to an
23 // AccelerometerDelegate. 23 // AccelerometerDelegate.
24 class CHROMEOS_EXPORT AccelerometerReader { 24 class CHROMEOS_EXPORT AccelerometerReader {
25 public: 25 public:
26 // Configuration structure for accelerometer device. 26 // Configuration structure for accelerometer device.
27 struct ConfigurationData { 27 struct ConfigurationData {
28 ConfigurationData(); 28 ConfigurationData();
29 ~ConfigurationData(); 29 ~ConfigurationData();
30 30
31 // Scale of accelerometers (i.e. raw value * 1.0f / scale = G's). 31 // Scale of accelerometers (i.e. raw value * 1.0f / scale = G's).
32 unsigned int base_scale; 32 unsigned int base_scale;
33 unsigned int lid_scale; 33 unsigned int lid_scale;
34 34
35 // Index of each accelerometer axis in data stream. 35 // Index of each accelerometer axis in data stream.
36 std::vector<unsigned int> index; 36 std::vector<unsigned int> index;
37 }; 37 };
38 typedef base::RefCountedData<ConfigurationData> Configuration; 38 typedef base::RefCountedData<ConfigurationData> Configuration;
39 typedef base::RefCountedData<char[12]> Reading; 39 typedef base::RefCountedData<char[12]> Reading;
40 40
41 // An interface to receive data from the AccelerometerReader. 41 // An interface to receive data from the AccelerometerReader.
42 class Delegate { 42 class Delegate {
43 public: 43 public:
44 virtual void HandleAccelerometerReading(const gfx::Vector3dF& base, 44 virtual void HandleAccelerometerUpdate(
45 const gfx::Vector3dF& lid) = 0; 45 const ui::AccelerometerUpdate& update) = 0;
46 }; 46 };
47 47
48 AccelerometerReader(base::TaskRunner* blocking_task_runner, 48 AccelerometerReader(base::TaskRunner* blocking_task_runner,
49 Delegate* delegate); 49 Delegate* delegate);
50 ~AccelerometerReader(); 50 ~AccelerometerReader();
51 51
52 private: 52 private:
53 // Dispatched when initialization is complete. If |success|, |configuration| 53 // Dispatched when initialization is complete. If |success|, |configuration|
54 // provides the details of the detected accelerometer. 54 // provides the details of the detected accelerometer.
55 void OnInitialized(scoped_refptr<Configuration> configuration, bool success); 55 void OnInitialized(scoped_refptr<Configuration> configuration, bool success);
56 56
57 // Triggers an asynchronous read from the accelerometer, signalling 57 // Triggers an asynchronous read from the accelerometer, signalling
58 // OnDataRead with the result. 58 // OnDataRead with the result.
59 void TriggerRead(); 59 void TriggerRead();
60 60
61 // If |success|, converts the raw reading to a pair of Vector3dF 61 // If |success|, converts the raw reading to an AccelerometerUpdate
62 // values and notifies the |delegate_| with the new readings. 62 // message and notifies the |delegate_| with the new readings.
63 // Triggers another read from the accelerometer at the current sampling rate. 63 // Triggers another read from the accelerometer at the current sampling rate.
64 void OnDataRead(scoped_refptr<Reading> reading, bool success); 64 void OnDataRead(scoped_refptr<Reading> reading, bool success);
65 65
66 // The task runner to use for blocking tasks. 66 // The task runner to use for blocking tasks.
67 scoped_refptr<base::TaskRunner> task_runner_; 67 scoped_refptr<base::TaskRunner> task_runner_;
68 68
69 // A weak pointer to the delegate to send accelerometer readings to. 69 // A weak pointer to the delegate to send accelerometer readings to.
70 Delegate* delegate_; 70 Delegate* delegate_;
71 71
72 // The last seen accelerometer data.
73 ui::AccelerometerUpdate update_;
74
72 // The accelerometer configuration. 75 // The accelerometer configuration.
73 scoped_refptr<Configuration> configuration_; 76 scoped_refptr<Configuration> configuration_;
74 77
75 base::WeakPtrFactory<AccelerometerReader> weak_factory_; 78 base::WeakPtrFactory<AccelerometerReader> weak_factory_;
76 79
77 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); 80 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader);
78 }; 81 };
79 82
80 } // namespace chromeos 83 } // namespace chromeos
81 84
82 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ 85 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698