| 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_TYPES_H_ | 5 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_ |
| 6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_ | 6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 9 #include "chromeos/chromeos_export.h" | 10 #include "chromeos/chromeos_export.h" |
| 10 | 11 |
| 11 namespace chromeos { | 12 namespace chromeos { |
| 12 | 13 |
| 13 enum AccelerometerSource { | 14 enum AccelerometerSource { |
| 14 // Accelerometer is located in the device's screen. In the screen's natural | 15 // Accelerometer is located in the device's screen. In the screen's natural |
| 15 // orientation, positive X points to the right, consistent with the pixel | 16 // orientation, positive X points to the right, consistent with the pixel |
| 16 // position. Positive Y points up the screen. Positive Z is perpendicular to | 17 // position. Positive Y points up the screen. Positive Z is perpendicular to |
| 17 // the screen, pointing outwards towards the user. The orientation is | 18 // the screen, pointing outwards towards the user. The orientation is |
| 18 // described at: | 19 // described at: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 37 bool present; | 38 bool present; |
| 38 | 39 |
| 39 // The readings from this accelerometer measured in m/s^2. | 40 // The readings from this accelerometer measured in m/s^2. |
| 40 float x; | 41 float x; |
| 41 float y; | 42 float y; |
| 42 float z; | 43 float z; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 // An accelerometer update contains the last known value for each of the | 46 // An accelerometer update contains the last known value for each of the |
| 46 // accelerometers present on the device. | 47 // accelerometers present on the device. |
| 47 class CHROMEOS_EXPORT AccelerometerUpdate { | 48 class CHROMEOS_EXPORT AccelerometerUpdate |
| 49 : public base::RefCountedThreadSafe<AccelerometerUpdate> { |
| 48 public: | 50 public: |
| 49 AccelerometerUpdate(); | 51 AccelerometerUpdate(); |
| 50 ~AccelerometerUpdate(); | |
| 51 | 52 |
| 52 // Returns true if |source| has a valid value in this update. | 53 // Returns true if |source| has a valid value in this update. |
| 53 bool has(AccelerometerSource source) const { return data_[source].present; } | 54 bool has(AccelerometerSource source) const { return data_[source].present; } |
| 54 | 55 |
| 55 // Returns the last known value for |source|. | 56 // Returns the last known value for |source|. |
| 56 const AccelerometerReading& get(AccelerometerSource source) const { | 57 const AccelerometerReading& get(AccelerometerSource source) const { |
| 57 return data_[source]; | 58 return data_[source]; |
| 58 } | 59 } |
| 59 | 60 |
| 60 void Set(AccelerometerSource source, float x, float y, float z) { | 61 void Set(AccelerometerSource source, float x, float y, float z) { |
| 61 data_[source].present = true; | 62 data_[source].present = true; |
| 62 data_[source].x = x; | 63 data_[source].x = x; |
| 63 data_[source].y = y; | 64 data_[source].y = y; |
| 64 data_[source].z = z; | 65 data_[source].z = z; |
| 65 } | 66 } |
| 66 | 67 |
| 67 protected: | 68 protected: |
| 68 AccelerometerReading data_[ACCELEROMETER_SOURCE_COUNT]; | 69 AccelerometerReading data_[ACCELEROMETER_SOURCE_COUNT]; |
| 69 | 70 |
| 70 private: | 71 private: |
| 72 friend class base::RefCountedThreadSafe<AccelerometerUpdate>; |
| 73 |
| 74 virtual ~AccelerometerUpdate(); |
| 75 |
| 71 DISALLOW_COPY_AND_ASSIGN(AccelerometerUpdate); | 76 DISALLOW_COPY_AND_ASSIGN(AccelerometerUpdate); |
| 72 }; | 77 }; |
| 73 | 78 |
| 74 } // namespace chromeos | 79 } // namespace chromeos |
| 75 | 80 |
| 76 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_ | 81 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_ |
| OLD | NEW |