Bumping manifests a=b2g-bump
[gecko.git] / widget / gonk / ProcessOrientation.h
blobd565e7fde4c84e72f279de0e98feca7d732765a8
1 /*
2 * Copyright (c) 2013, Linux Foundation. All rights reserved
4 * Copyright (C) 2008 The Android Open Source Project
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #ifndef ProcessOrientation_h
20 #define ProcessOrientation_h
22 #include "mozilla/Hal.h"
24 namespace mozilla {
26 // History of observed tilt angles.
27 #define TILT_HISTORY_SIZE 40
29 class ProcessOrientation {
30 public:
31 ProcessOrientation() {};
32 ~ProcessOrientation() {};
34 int OnSensorChanged(const mozilla::hal::SensorData& event, int deviceCurrentRotation);
35 int Reset();
37 private:
38 int GetProposedRotation();
40 // Returns true if the tilt angle is acceptable for a given predicted
41 // rotation.
42 bool IsTiltAngleAcceptable(int rotation, int tiltAngle);
44 // Returns true if the orientation angle is acceptable for a given predicted
45 // rotation. This function takes into account the gap between adjacent
46 // orientations for hysteresis.
47 bool IsOrientationAngleAcceptable(int rotation, int orientationAngle,
48 int currentRotation);
50 // Returns true if the predicted rotation is ready to be advertised as a
51 // proposed rotation.
52 bool IsPredictedRotationAcceptable(int64_t now);
54 void ClearPredictedRotation();
55 void UpdatePredictedRotation(int64_t now, int rotation);
56 bool IsAccelerating(float magnitude);
57 void ClearTiltHistory();
58 void AddTiltHistoryEntry(int64_t now, float tilt);
59 bool IsFlat(int64_t now);
60 bool IsSwinging(int64_t now, float tilt);
61 int NextTiltHistoryIndex(int index);
62 float RemainingMS(int64_t now, int64_t until);
64 // The tilt angle range in degrees for each orientation. Beyond these tilt
65 // angles, we don't even consider transitioning into the specified orientation.
66 // We place more stringent requirements on unnatural orientations than natural
67 // ones to make it less likely to accidentally transition into those states.
68 // The first value of each pair is negative so it applies a limit when the
69 // device is facing down (overhead reading in bed). The second value of each
70 // pair is positive so it applies a limit when the device is facing up
71 // (resting on a table). The ideal tilt angle is 0 (when the device is vertical)
72 // so the limits establish how close to vertical the device must be in order
73 // to change orientation.
74 static const int tiltTolerance[][4];
76 // Timestamp and value of the last accelerometer sample.
77 int64_t mLastFilteredTimestampNanos;
78 float mLastFilteredX, mLastFilteredY, mLastFilteredZ;
80 // The last proposed rotation, -1 if unknown.
81 int mProposedRotation;
83 // Value of the current predicted rotation, -1 if unknown.
84 int mPredictedRotation;
86 // Timestamp of when the predicted rotation most recently changed.
87 int64_t mPredictedRotationTimestampNanos;
89 // Timestamp when the device last appeared to be flat for sure (the flat delay
90 // elapsed).
91 int64_t mFlatTimestampNanos;
93 // Timestamp when the device last appeared to be swinging.
94 int64_t mSwingTimestampNanos;
96 // Timestamp when the device last appeared to be undergoing external
97 // acceleration.
98 int64_t mAccelerationTimestampNanos;
100 struct {
101 struct {
102 float tiltAngle;
103 int64_t timestampNanos;
104 } history[TILT_HISTORY_SIZE];
105 int index;
106 } mTiltHistory;
109 } // namespace mozilla
110 #endif