From: Peter Hutterer Date: Thu, 21 May 2015 01:48:34 +0000 (+1000) Subject: tools: widen frequency resolution to µs in the DPI tool X-Git-Tag: libevdev-1.4.3~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e1d87fa6dfa9cdd3ade490911db49e48871a1295;p=platform%2Fupstream%2Flibevdev.git tools: widen frequency resolution to µs in the DPI tool 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 --- 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); }