2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _LIBINPUT_VELOCITY_CONTROL_H
18 #define _LIBINPUT_VELOCITY_CONTROL_H
20 #include <input/Input.h>
21 #include <input/VelocityTracker.h>
22 #include <utils/Timers.h>
27 * Specifies parameters that govern pointer or wheel acceleration.
29 struct VelocityControlParameters {
30 // A scale factor that is multiplied with the raw velocity deltas
31 // prior to applying any other velocity control factors. The scale
32 // factor should be used to adapt the input device resolution
33 // (eg. counts per inch) to the output device resolution (eg. pixels per inch).
35 // Must be a positive value.
36 // Default is 1.0 (no scaling).
39 // The scaled speed at which acceleration begins to be applied.
40 // This value establishes the upper bound of a low speed regime for
41 // small precise motions that are performed without any acceleration.
43 // Must be a non-negative value.
44 // Default is 0.0 (no low threshold).
47 // The scaled speed at which maximum acceleration is applied.
48 // The difference between highThreshold and lowThreshold controls
49 // the range of speeds over which the acceleration factor is interpolated.
50 // The wider the range, the smoother the acceleration.
52 // Must be a non-negative value greater than or equal to lowThreshold.
53 // Default is 0.0 (no high threshold).
56 // The acceleration factor.
57 // When the speed is above the low speed threshold, the velocity will scaled
58 // by an interpolated value between 1.0 and this amount.
60 // Must be a positive greater than or equal to 1.0.
61 // Default is 1.0 (no acceleration).
64 VelocityControlParameters() :
65 scale(1.0f), lowThreshold(0.0f), highThreshold(0.0f), acceleration(1.0f) {
68 VelocityControlParameters(float scale, float lowThreshold,
69 float highThreshold, float acceleration) :
70 scale(scale), lowThreshold(lowThreshold),
71 highThreshold(highThreshold), acceleration(acceleration) {
76 * Implements mouse pointer and wheel speed control and acceleration.
78 class VelocityControl {
82 /* Sets the various parameters. */
83 void setParameters(const VelocityControlParameters& parameters);
85 /* Resets the current movement counters to zero.
86 * This has the effect of nullifying any acceleration. */
89 /* Translates a raw movement delta into an appropriately
90 * scaled / accelerated delta based on the current velocity. */
91 void move(nsecs_t eventTime, float* deltaX, float* deltaY);
94 // If no movements are received within this amount of time,
95 // we assume the movement has stopped and reset the movement counters.
96 static const nsecs_t STOP_TIME = 500 * 1000000; // 500 ms
98 VelocityControlParameters mParameters;
100 nsecs_t mLastMovementTime;
101 VelocityTracker::Position mRawPosition;
102 VelocityTracker mVelocityTracker;
105 } // namespace android
107 #endif // _LIBINPUT_VELOCITY_CONTROL_H