summaryrefslogtreecommitdiff
path: root/libs/input/VelocityControl.cpp
diff options
context:
space:
mode:
author Yeabkal Wubshit <yeabkal@google.com> 2022-08-27 05:48:51 +0000
committer Yeabkal Wubshit <yeabkal@google.com> 2022-09-07 16:25:32 -0700
commit37acf6e3b7ff4b30567eb3210560db3d73c20a58 (patch)
treedc84a2ffd7f3ae5f1c9540c9499f5d8f20d6b11c /libs/input/VelocityControl.cpp
parent89eca3248127fbe97a8669725bd2649163dd7831 (diff)
Make VelocityTracker 1D
Currently, VelocityTracker is strictly tied to X and Y axes. It's APIs act on both axes, and its component structs (e.g. Position, Estimator) are tied to both X and Y axes. As a step towards supporting more axes for velocity tracking, this change: - removes the Position struct: stores/processes data as pure floats, one axis at a time - makes Estimator and Strategy specific to a single axis, instead of dealing with both/only X and Y at the same time Furthermore, we have pulled into VelocityTracker the logic to compute all velocity. This helps making the immediate JNI layer light-weight in addition to allowing us to test the logic (which is non-trivial and benefits from tests). Bug: 32830165 Test: VelocityTracker_test unaffected (atest libinput_tests) Change-Id: I181af7a033eb647e9cb97db9b86a36ae972290a5
Diffstat (limited to 'libs/input/VelocityControl.cpp')
-rw-r--r--libs/input/VelocityControl.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/libs/input/VelocityControl.cpp b/libs/input/VelocityControl.cpp
index 6e991e98bb..e2bfb508e1 100644
--- a/libs/input/VelocityControl.cpp
+++ b/libs/input/VelocityControl.cpp
@@ -44,8 +44,8 @@ void VelocityControl::setParameters(const VelocityControlParameters& parameters)
void VelocityControl::reset() {
mLastMovementTime = LLONG_MIN;
- mRawPosition.x = 0;
- mRawPosition.y = 0;
+ mRawPositionX = 0;
+ mRawPositionY = 0;
mVelocityTracker.clear();
}
@@ -61,17 +61,20 @@ void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) {
mLastMovementTime = eventTime;
if (deltaX) {
- mRawPosition.x += *deltaX;
+ mRawPositionX += *deltaX;
}
if (deltaY) {
- mRawPosition.y += *deltaY;
+ mRawPositionY += *deltaY;
}
- mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)), {mRawPosition});
+ mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)),
+ {{AMOTION_EVENT_AXIS_X, {mRawPositionX}},
+ {AMOTION_EVENT_AXIS_Y, {mRawPositionY}}});
- float vx, vy;
+ std::optional<float> vx = mVelocityTracker.getVelocity(AMOTION_EVENT_AXIS_X, 0);
+ std::optional<float> vy = mVelocityTracker.getVelocity(AMOTION_EVENT_AXIS_Y, 0);
float scale = mParameters.scale;
- if (mVelocityTracker.getVelocity(0, &vx, &vy)) {
- float speed = hypotf(vx, vy) * scale;
+ if (vx && vy) {
+ float speed = hypotf(*vx, *vy) * scale;
if (speed >= mParameters.highThreshold) {
// Apply full acceleration above the high speed threshold.
scale *= mParameters.acceleration;
@@ -85,10 +88,9 @@ void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) {
if (DEBUG_ACCELERATION) {
ALOGD("VelocityControl(%0.3f, %0.3f, %0.3f, %0.3f): "
- "vx=%0.3f, vy=%0.3f, speed=%0.3f, accel=%0.3f",
- mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold,
- mParameters.acceleration,
- vx, vy, speed, scale / mParameters.scale);
+ "vx=%0.3f, vy=%0.3f, speed=%0.3f, accel=%0.3f",
+ mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold,
+ mParameters.acceleration, *vx, *vy, speed, scale / mParameters.scale);
}
} else {