summaryrefslogtreecommitdiff
path: root/src/filter.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2015-07-31 14:52:56 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2015-08-03 11:19:54 +1000
commit8a6825f1602aa9d9c4b29a83d296f55f68b316e0 (patch)
treee4ef1220edec8ea9c704bd1124bd1ddb263601bb /src/filter.c
parent26c8f2c442ac476027111ce7429c1a7897732d20 (diff)
filter: move the pointer acceleration profiles back to units/ms
There is no need here to use µs since we're just handling speeds/thresholds, not actual events where a ms granularity can be too high. Moving back to ms lets us drop a bunch of zeroes that clutter up the code, and since the acceleration functions are a bit magic anyway, having the various 1000.0 factors in there makes it even less obvious. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Diffstat (limited to 'src/filter.c')
-rw-r--r--src/filter.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/filter.c b/src/filter.c
index 54ae3978..2506ee27 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -77,7 +77,7 @@ filter_get_speed(struct motion_filter *filter)
* Default parameters for pointer acceleration profiles.
*/
-#define DEFAULT_THRESHOLD 0.0004 /* in units/us */
+#define DEFAULT_THRESHOLD 0.4 /* in units/ms */
#define DEFAULT_ACCELERATION 2.0 /* unitless factor */
#define DEFAULT_INCLINE 1.1 /* unitless factor */
@@ -85,7 +85,7 @@ filter_get_speed(struct motion_filter *filter)
* Pointer acceleration filter constants
*/
-#define MAX_VELOCITY_DIFF 0.001 /* units/us */
+#define MAX_VELOCITY_DIFF 1 /* units/ms */
#define MOTION_TIMEOUT ms2us(1000)
#define NUM_POINTER_TRACKERS 16
@@ -101,14 +101,14 @@ struct pointer_accelerator {
accel_profile_func_t profile;
- double velocity; /* units/us */
- double last_velocity; /* units/us */
+ double velocity; /* units/ms */
+ double last_velocity; /* units/ms */
struct normalized_coords last;
struct pointer_tracker *trackers;
int cur_tracker;
- double threshold; /* units/us */
+ double threshold; /* units/ms */
double accel; /* unitless factor */
double incline; /* incline of the function */
@@ -150,7 +150,7 @@ static double
calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time)
{
double tdelta = time - tracker->time + 1;
- return normalized_length(tracker->delta) / tdelta; /* units/us */
+ return normalized_length(tracker->delta) / tdelta * 1000.0; /* units/ms */
}
static inline double
@@ -220,7 +220,7 @@ calculate_velocity(struct pointer_accelerator *accel, uint64_t time)
}
}
- return result; /* units/us */
+ return result; /* units/ms */
}
static double
@@ -256,11 +256,11 @@ calculate_acceleration(struct pointer_accelerator *accel,
static struct normalized_coords
accelerator_filter(struct motion_filter *filter,
const struct normalized_coords *unaccelerated,
- void *data, uint64_t time)
+ void *data, uint64_t time /* in us */)
{
struct pointer_accelerator *accel =
(struct pointer_accelerator *) filter;
- double velocity; /* units/us */
+ double velocity; /* units/ms */
double accel_value; /* unitless factor */
struct normalized_coords accelerated;
struct normalized_coords unnormalized;
@@ -397,23 +397,23 @@ create_pointer_accelerator_filter(accel_profile_func_t profile,
double
pointer_accel_profile_linear_low_dpi(struct motion_filter *filter,
void *data,
- double speed_in, /* in device units (units/us) */
- uint64_t time)
+ double speed_in, /* in device units (units/ms) */
+ uint64_t time /* in us */)
{
struct pointer_accelerator *accel_filter =
(struct pointer_accelerator *)filter;
double s1, s2;
double max_accel = accel_filter->accel; /* unitless factor */
- const double threshold = accel_filter->threshold; /* units/us */
+ const double threshold = accel_filter->threshold; /* units/ms */
const double incline = accel_filter->incline;
double factor;
double dpi_factor = accel_filter->dpi_factor;
max_accel /= dpi_factor;
- s1 = min(1, 0.3 + speed_in * 10000.0);
- s2 = 1 + (speed_in * 1000.0 - threshold * dpi_factor * 1000.0) * incline;
+ s1 = min(1, 0.3 + speed_in * 10.0);
+ s2 = 1 + (speed_in - threshold * dpi_factor) * incline;
factor = min(max_accel, s2 > 1 ? s2 : s1);
@@ -424,19 +424,19 @@ double
pointer_accel_profile_linear(struct motion_filter *filter,
void *data,
double speed_in, /* 1000-dpi normalized */
- uint64_t time)
+ uint64_t time /* in us */)
{
struct pointer_accelerator *accel_filter =
(struct pointer_accelerator *)filter;
double s1, s2;
const double max_accel = accel_filter->accel; /* unitless factor */
- const double threshold = accel_filter->threshold; /* units/us */
+ const double threshold = accel_filter->threshold; /* units/ms */
const double incline = accel_filter->incline;
double factor;
- s1 = min(1, 0.3 + speed_in * 10 * 1000.0);
- s2 = 1 + (speed_in * 1000.0 - threshold * 1000.0) * incline;
+ s1 = min(1, 0.3 + speed_in * 10);
+ s2 = 1 + (speed_in - threshold) * incline;
factor = min(max_accel, s2 > 1 ? s2 : s1);
@@ -445,9 +445,9 @@ pointer_accel_profile_linear(struct motion_filter *filter,
double
touchpad_accel_profile_linear(struct motion_filter *filter,
- void *data,
- double speed_in,
- uint64_t time)
+ void *data,
+ double speed_in,
+ uint64_t time /* in us */)
{
/* Once normalized, touchpads see the same
acceleration as mice. that is technically correct but
@@ -468,7 +468,7 @@ double
touchpad_lenovo_x230_accel_profile(struct motion_filter *filter,
void *data,
double speed_in,
- uint64_t time)
+ uint64_t time /* in us */)
{
/* Keep the magic factor from touchpad_accel_profile_linear. */
const double TP_MAGIC_SLOWDOWN = 0.4;
@@ -488,13 +488,13 @@ touchpad_lenovo_x230_accel_profile(struct motion_filter *filter,
const double max_accel = accel_filter->accel *
TP_MAGIC_LOW_RES_FACTOR; /* unitless factor */
const double threshold = accel_filter->threshold /
- TP_MAGIC_LOW_RES_FACTOR; /* units/us */
+ TP_MAGIC_LOW_RES_FACTOR; /* units/ms */
const double incline = accel_filter->incline * TP_MAGIC_LOW_RES_FACTOR;
speed_in *= TP_MAGIC_SLOWDOWN / TP_MAGIC_LOW_RES_FACTOR;
- s1 = min(1, speed_in * 5 * 1000.0);
- s2 = 1 + (speed_in * 1000.0 - threshold * 1000.0) * incline;
+ s1 = min(1, speed_in * 5);
+ s2 = 1 + (speed_in - threshold) * incline;
speed_out = min(max_accel, s2 > 1 ? s2 : s1);