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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 AccelerometerReader(); | 57 AccelerometerReader(); |
58 ~AccelerometerReader(); | 58 ~AccelerometerReader(); |
59 | 59 |
60 void Initialize(scoped_refptr<base::TaskRunner> blocking_task_runner); | 60 void Initialize(scoped_refptr<base::TaskRunner> blocking_task_runner); |
61 | 61 |
62 // Add/Remove observers. | 62 // Add/Remove observers. |
63 void AddObserver(Observer* observer); | 63 void AddObserver(Observer* observer); |
64 void RemoveObserver(Observer* observer); | 64 void RemoveObserver(Observer* observer); |
65 | 65 |
| 66 // A reading is considered stable if its deviation from gravity is small. This |
| 67 // returns false if the deviation is too higher, or if |source| is not present |
| 68 // in the update. |
| 69 static bool IsReadingStable(const ui::AccelerometerUpdate& update, |
| 70 ui::AccelerometerSource source); |
| 71 |
66 private: | 72 private: |
67 // Dispatched when initialization is complete. If |success|, |configuration| | 73 // Dispatched when initialization is complete. If |success|, |configuration| |
68 // provides the details of the detected accelerometer. | 74 // provides the details of the detected accelerometer. |
69 void OnInitialized(scoped_refptr<Configuration> configuration, bool success); | 75 void OnInitialized(scoped_refptr<Configuration> configuration, bool success); |
70 | 76 |
71 // Triggers an asynchronous read from the accelerometer, signalling | 77 // Triggers an asynchronous read from the accelerometer, signalling |
72 // OnDataRead with the result. | 78 // OnDataRead with the result. |
73 void TriggerRead(); | 79 void TriggerRead(); |
74 | 80 |
75 // If |success|, converts the raw reading to an AccelerometerUpdate | 81 // If |success|, converts the raw reading to an AccelerometerUpdate |
(...skipping 13 matching lines...) Expand all Loading... |
89 ObserverList<Observer, true> observers_; | 95 ObserverList<Observer, true> observers_; |
90 | 96 |
91 base::WeakPtrFactory<AccelerometerReader> weak_factory_; | 97 base::WeakPtrFactory<AccelerometerReader> weak_factory_; |
92 | 98 |
93 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); | 99 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader); |
94 }; | 100 }; |
95 | 101 |
96 } // namespace chromeos | 102 } // namespace chromeos |
97 | 103 |
98 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ | 104 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_ |
OLD | NEW |