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 UI_ACCEROMETER_ACCELEROMETER_TYPES_H_ | |
| 6 #define UI_ACCEROMETER_ACCELEROMETER_TYPES_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "ui/accelerometer/ui_accelerometer_export.h" | |
| 10 #include "ui/gfx/geometry/vector3d_f.h" | |
| 11 | |
| 12 namespace ui { | |
| 13 | |
| 14 enum AccelerometerSource { | |
| 15 // Accelerometer is located in the device's screen. In the screen's natural | |
| 16 // orientation, positive X points to the right, consistent with the pixel | |
| 17 // position. Positive Y points up the screen. Positive Z is perpendicular to | |
|
sky
2014/08/29 02:15:27
Don't we normally have positive y going down?
flackr
2014/08/29 03:09:52
Normally we do at least in pixel space, but not in
| |
| 18 // the screen, pointing outwards towards the user. The orientation is | |
| 19 // described at: | |
| 20 // http://www.html5rocks.com/en/tutorials/device/orientation/. | |
| 21 ACCELEROMETER_SOURCE_SCREEN = 0, | |
| 22 | |
| 23 // Accelerometer is located in a keyboard attached to the device's screen. | |
| 24 // If the device is open 180 degrees the orientation is consistent with the | |
| 25 // screen. I.e. Positive X points to the right, positive Y points up on the | |
| 26 // keyboard and positive Z is perpendicular to the keyboard pointing out | |
| 27 // towards the user. | |
| 28 ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | |
| 29 | |
| 30 ACCELEROMETER_SOURCE_COUNT | |
| 31 }; | |
| 32 | |
| 33 struct UI_ACCELEROMETER_EXPORT AccelerometerReading { | |
| 34 AccelerometerReading(); | |
| 35 ~AccelerometerReading(); | |
| 36 | |
| 37 // If true, this accelerometer is being updated. | |
| 38 bool present; | |
| 39 | |
| 40 // The reading from this accelerometer measured in m/s^2. | |
| 41 gfx::Vector3dF reading; | |
| 42 }; | |
| 43 | |
| 44 // An accelerometer update contains the last known value for each of the | |
| 45 // accelerometers present on the device. | |
| 46 class UI_ACCELEROMETER_EXPORT AccelerometerUpdate { | |
| 47 public: | |
| 48 AccelerometerUpdate(); | |
| 49 ~AccelerometerUpdate(); | |
| 50 | |
| 51 // Returns true if |source| has a valid value in this update. | |
| 52 bool has(AccelerometerSource source) const { | |
| 53 return data_[source].present; | |
| 54 } | |
| 55 | |
| 56 // Returns the last known value for |source|. | |
| 57 const gfx::Vector3dF& get(AccelerometerSource source) const { | |
| 58 return data_[source].reading; | |
| 59 } | |
| 60 | |
| 61 void Set(AccelerometerSource source, float x, float y, float z) { | |
| 62 data_[source].present = true; | |
| 63 data_[source].reading.set_x(x); | |
| 64 data_[source].reading.set_y(y); | |
| 65 data_[source].reading.set_z(z); | |
| 66 } | |
| 67 | |
| 68 protected: | |
| 69 AccelerometerReading data_[ACCELEROMETER_SOURCE_COUNT]; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(AccelerometerUpdate); | |
| 72 }; | |
| 73 | |
| 74 } // namespace chromeos | |
| 75 | |
| 76 #endif // UI_ACCEROMETER_ACCELEROMETER_TYPES_H_ | |
| OLD | NEW |