Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 // An interface to receive data from the AccelerometerReader. | |
| 18 class AccelerometerDelegate { | |
|
Daniel Erat
2014/03/26 22:26:14
maybe move this be a public internal class of Acce
flackr
2014/03/27 15:21:07
Done.
| |
| 19 public: | |
| 20 virtual void OnAccelerometerRead(const gfx::Vector3dF& base, | |
| 21 const gfx::Vector3dF& lid) = 0; | |
| 22 }; | |
| 23 | |
| 24 // Reads an accelerometer device and reports data back to an | |
| 25 // AccelerometerDelegate. | |
| 26 class CHROMEOS_EXPORT AccelerometerReader { | |
| 27 public: | |
| 28 AccelerometerReader(AccelerometerDelegate* delegate); | |
|
Daniel Erat
2014/03/26 22:26:14
nit: explicit
flackr
2014/03/27 15:21:07
Done.
| |
| 29 virtual ~AccelerometerReader(); | |
|
Daniel Erat
2014/03/26 22:26:14
nit: don't need virtual
flackr
2014/03/27 15:21:07
Done.
| |
| 30 | |
| 31 private: | |
| 32 // Detects and reads configuration of the accelerometer device. | |
| 33 bool Initialize(); | |
| 34 | |
| 35 // Dispatched when initialization is complete. |success| is true if an | |
| 36 // accelerometer was detected and all configuration paramaters read. | |
|
Daniel Erat
2014/03/26 22:26:14
nit: s/paramaters/parameters/
flackr
2014/03/27 15:21:07
Done.
| |
| 37 void OnInitialized(bool success); | |
| 38 | |
| 39 // Triggers an asynchronous read from the accelerometer, signalling | |
| 40 // OnDataRead with the result of the read. | |
| 41 void TriggerRead(); | |
| 42 | |
| 43 // Triggers the accelerometer and reads the sampled values. Returns true if | |
| 44 // successful, in which case base_accelerometer_ and lid_accelerometer_ | |
| 45 // contain the current values. | |
| 46 bool ReadAccelerometer(); | |
| 47 | |
| 48 // If |success|, notifies the delegate_ with the new readings. Triggers | |
|
Daniel Erat
2014/03/26 22:26:14
nit: s/delegate_/|delegate_|/ (also in other comme
flackr
2014/03/27 15:21:07
Done.
| |
| 49 // another read from the accelerometer at the current sampling rate. | |
| 50 void OnDataRead(bool success); | |
| 51 | |
| 52 // A weak pointer to the delegate to send accelerometer readings to. | |
| 53 AccelerometerDelegate* 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 // The last reading from the base accelerometer. | |
| 66 gfx::Vector3dF base_accelerometer_; | |
|
Daniel Erat
2014/03/26 22:26:14
nit: base_reading_? base_value_?
flackr
2014/03/27 15:21:07
Done.
| |
| 67 | |
| 68 // The last reading from the lid accelerometer. | |
| 69 gfx::Vector3dF lid_accelerometer_; | |
|
Daniel Erat
2014/03/26 22:26:14
nit: lid_reading_? lid_value_?
flackr
2014/03/27 15:21:07
Done.
| |
| 70 | |
| 71 base::WeakPtrFactory<AccelerometerReader> weak_factory_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); | |
| 74 }; | |
| 75 | |
| 76 } // namespace chromeos | |
| 77 | |
| 78 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ | |
| OLD | NEW |