From e1d87fa6dfa9cdd3ade490911db49e48871a1295 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 21 May 2015 11:48:34 +1000 Subject: [PATCH] =?UTF-8?q?tools:=20widen=20frequency=20resolution=20to=20?= =?UTF-8?q?=C2=B5s=20in=20the=20DPI=20tool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Microsoft Arc Touch Mouse claims 8000fps which is higher than we can measure in the current milliseconds resolution. http://www.cnet.com/products/microsoft-arc-touch-mouse-black-series/specs/ https://bugs.freedesktop.org/show_bug.cgi?id=90540 Signed-off-by: Peter Hutterer --- tools/mouse-dpi-tool.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/mouse-dpi-tool.c b/tools/mouse-dpi-tool.c index d05a4fd..7f0e7be 100644 --- a/tools/mouse-dpi-tool.c +++ b/tools/mouse-dpi-tool.c @@ -44,7 +44,7 @@ struct measurements { int distance; double frequency; - uint32_t ms; + uint64_t us; }; static int @@ -58,16 +58,16 @@ usage(void) { return 1; } -static inline uint32_t -tv2ms(const struct timeval *tv) +static inline uint64_t +tv2us(const struct timeval *tv) { - return tv->tv_sec * 1000 + tv->tv_usec/1000; + return tv->tv_sec * 1000000 + tv->tv_usec; } static inline double get_frequency(double last, double current) { - return 1000.0/(current - last); + return 1000000.0/(current - last); } static int @@ -98,17 +98,17 @@ static int handle_event(struct measurements *m, const struct input_event *ev) { if (ev->type == EV_SYN) { - const int idle_reset = 3000; /* ms */ - uint32_t last_millis = m->ms; + const int idle_reset = 3000000; /* us */ + uint64_t last_us = m->us; - m->ms = tv2ms(&ev->time); + m->us = tv2us(&ev->time); /* reset after pause */ - if (last_millis + idle_reset < m->ms) { + if (last_us + idle_reset < m->us) { m->frequency = 0.0; m->distance = 0; } else { - double freq = get_frequency(last_millis, m->ms); + double freq = get_frequency(last_us, m->us); m->frequency = max(freq, m->frequency); return print_current_values(m); }