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

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

Issue 200643005: Read and expose accelerometer values from cros-ec-accel trigger. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
7
8 #include <vector>
9
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "chromeos/chromeos_export.h"
13 #include "ui/gfx/geometry/vector3d_f.h"
14
15 namespace chromeos {
16
17 // Reads an accelerometer device and reports data back to an
18 // AccelerometerDelegate.
19 class CHROMEOS_EXPORT AccelerometerReader {
20 public:
21 // An interface to receive data from the AccelerometerReader.
22 class Delegate {
23 public:
24 virtual void HandleAccelerometerReading(const gfx::Vector3dF& base,
25 const gfx::Vector3dF& lid) = 0;
26 };
27
28 explicit AccelerometerReader(Delegate* delegate);
29 ~AccelerometerReader();
30
31 private:
32 // Detects and reads configuration of the accelerometer device.
33 void Initialize();
34
35 // Dispatched when initialization is complete. |has_accelerometer_| is true if
36 // an accelerometer was detected and all configuration parameters read.
37 void OnInitialized();
38
39 // Triggers an asynchronous read from the accelerometer, signalling
40 // OnDataRead with |read_sucess_| set to true if the read was successful.
41 void TriggerRead();
42
43 // Triggers the accelerometer and reads the sampled values. Sets
44 // |read_success_| to true and |base_reading_| and |lid_reading_| to the
45 // read values if successful.
46 void ReadAccelerometer();
47
48 // If |read_success_|, notifies the |delegate_| with the new readings.
49 // Triggers another read from the accelerometer at the current sampling rate.
50 void OnDataRead();
51
52 // A weak pointer to the delegate to send accelerometer readings to.
53 Delegate* delegate_;
54
55 // True after Initialize has run if an accelerometer sensor exists.
56 bool has_accelerometer_;
57
58 // The index of each axis of each accelerometer.
59 std::vector<unsigned int> accelerometer_index_;
60
61 // The scale of the base and lid accelerometers.
62 unsigned int accelerometer_base_scale_;
63 unsigned int accelerometer_lid_scale_;
64
65 // Set to false before triggering a read. If the read is successful, set to
66 // true by ReadAccelerometer.
67 bool read_success_;
68
69 // The last readings from the base and lid accelerometers. DO NOT directly
70 // read these as they are updated from the blocking thread pool. Instead,
71 // only use the values as passed to the |delegate_|.
72 // TODO(flackr): Pass the values back from the blocking thread pool to avoid
73 // the potential for them to be read while they're being updated.
74 gfx::Vector3dF base_reading_;
75 gfx::Vector3dF lid_reading_;
76
77 base::WeakPtrFactory<AccelerometerReader> weak_factory_;
78
79 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader);
80 };
81
82 } // namespace chromeos
83
84 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698