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.
5 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_
6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "chromeos/chromeos_export.h"
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
18 // the screen, pointing outwards towards the user. The orientation is
20 // http://www.html5rocks.com/en/tutorials/device/orientation/.
21 ACCELEROMETER_SOURCE_SCREEN
= 0,
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
28 ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD
,
30 ACCELEROMETER_SOURCE_COUNT
33 struct CHROMEOS_EXPORT AccelerometerReading
{
34 AccelerometerReading();
35 ~AccelerometerReading();
37 // If true, this accelerometer is being updated.
40 // The readings from this accelerometer measured in m/s^2.
46 // An accelerometer update contains the last known value for each of the
47 // accelerometers present on the device.
48 class CHROMEOS_EXPORT AccelerometerUpdate
49 : public base::RefCountedThreadSafe
<AccelerometerUpdate
> {
51 AccelerometerUpdate();
53 // Returns true if |source| has a valid value in this update.
54 bool has(AccelerometerSource source
) const { return data_
[source
].present
; }
56 // Returns the last known value for |source|.
57 const AccelerometerReading
& get(AccelerometerSource source
) const {
61 void Set(AccelerometerSource source
, float x
, float y
, float z
) {
62 data_
[source
].present
= true;
69 AccelerometerReading data_
[ACCELEROMETER_SOURCE_COUNT
];
72 friend class base::RefCountedThreadSafe
<AccelerometerUpdate
>;
74 virtual ~AccelerometerUpdate();
76 DISALLOW_COPY_AND_ASSIGN(AccelerometerUpdate
);
79 } // namespace chromeos
81 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_