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 |
| 14 namespace gfx { |
| 15 class Vector3dF; |
| 16 } |
| 17 |
| 18 namespace chromeos { |
| 19 |
| 20 // Reads an accelerometer device and reports data back to an |
| 21 // AccelerometerDelegate. |
| 22 class CHROMEOS_EXPORT AccelerometerReader { |
| 23 public: |
| 24 // An interface to receive data from the AccelerometerReader. |
| 25 class Delegate { |
| 26 public: |
| 27 virtual void HandleAccelerometerReading(const gfx::Vector3dF& base, |
| 28 const gfx::Vector3dF& lid) = 0; |
| 29 }; |
| 30 |
| 31 AccelerometerReader(Delegate* delegate); |
| 32 ~AccelerometerReader(); |
| 33 |
| 34 private: |
| 35 // Detects and reads configuration of the accelerometer device. |
| 36 bool Initialize(); |
| 37 |
| 38 // Triggers a read from the accelerometer, and posts a task to trigger another |
| 39 // read after the sampling interval. |
| 40 void TriggerRead(); |
| 41 |
| 42 // Triggers the accelerometer and reads the sampled values. On success, |
| 43 // notifies the |delegate_| with the read values. |
| 44 void ReadAccelerometer(); |
| 45 |
| 46 // A weak pointer to the delegate to send accelerometer readings to. |
| 47 Delegate* delegate_; |
| 48 |
| 49 // True after Initialize has run if an accelerometer sensor exists. |
| 50 bool has_accelerometer_; |
| 51 |
| 52 // The index of each axis of each accelerometer. |
| 53 std::vector<unsigned int> accelerometer_index_; |
| 54 |
| 55 // The scale of the base and lid accelerometers. |
| 56 unsigned int accelerometer_base_scale_; |
| 57 unsigned int accelerometer_lid_scale_; |
| 58 |
| 59 base::WeakPtrFactory<AccelerometerReader> weak_factory_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); |
| 62 }; |
| 63 |
| 64 } // namespace chromeos |
| 65 |
| 66 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ |
OLD | NEW |