mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-20 13:50:16 +01:00
tools: print the mean frequency together with the max frequency
And if they're 30% out, print a warning. On the ThinkPad X1 Wireless Touch Mouse (when connected via bluetooth) we get a bunch of events at the start of the movement, all less than 1ms apart. Best guess is that the device goes to low-power, then notices the movement and buffers the event until the BT connection is back up. Then it sends all events at once. Usually they're less than 1ms apart, but at one recording showed a 37ms delay before we go back to the normal 70ms (~15Hz) the mouse has otherwise. This is unpredictable enough that we can't just work around it so instead print a warning to the user so they can go investigate. https://bugs.freedesktop.org/show_bug.cgi?id=97812 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
parent
55c43b19cf
commit
61f0a0f9ad
1 changed files with 39 additions and 4 deletions
|
|
@ -44,6 +44,9 @@
|
|||
struct measurements {
|
||||
int distance;
|
||||
double max_frequency;
|
||||
double *frequencies;
|
||||
size_t frequencies_sz;
|
||||
size_t nfrequencies;
|
||||
uint64_t us;
|
||||
};
|
||||
|
||||
|
|
@ -70,6 +73,21 @@ get_frequency(uint64_t last, uint64_t current)
|
|||
return 1000000.0/(current - last);
|
||||
}
|
||||
|
||||
static inline void
|
||||
push_frequency(struct measurements *m, double freq)
|
||||
{
|
||||
if (m->nfrequencies == m->frequencies_sz) {
|
||||
m->frequencies_sz += 100;
|
||||
m->frequencies = realloc(m->frequencies,
|
||||
m->frequencies_sz * sizeof *m->frequencies);
|
||||
if (!m->frequencies)
|
||||
abort();
|
||||
}
|
||||
|
||||
m->frequencies[m->nfrequencies] = freq;
|
||||
m->nfrequencies++;
|
||||
}
|
||||
|
||||
static int
|
||||
print_current_values(const struct measurements *m)
|
||||
{
|
||||
|
|
@ -109,8 +127,8 @@ handle_event(struct measurements *m, const struct input_event *ev)
|
|||
m->distance = 0;
|
||||
} else {
|
||||
double freq = get_frequency(last_us, m->us);
|
||||
if (freq < 1200)
|
||||
m->max_frequency = max(freq, m->max_frequency);
|
||||
push_frequency(m, freq);
|
||||
m->max_frequency = max(freq, m->max_frequency);
|
||||
return print_current_values(m);
|
||||
}
|
||||
|
||||
|
|
@ -166,12 +184,29 @@ mainloop(struct libevdev *dev, struct measurements *m) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline double
|
||||
mean_frequency(struct measurements *m)
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = m->nfrequencies/2;
|
||||
return m->frequencies[idx];
|
||||
}
|
||||
|
||||
static void
|
||||
print_summary(struct measurements *m)
|
||||
{
|
||||
int res;
|
||||
int max_freq = (int)m->max_frequency,
|
||||
mean_freq = (int)mean_frequency(m);
|
||||
|
||||
printf("Estimated sampling frequency: %dHz (mean %dHz)\n",
|
||||
max_freq, mean_freq);
|
||||
|
||||
if (max_freq > mean_freq * 1.3)
|
||||
printf("WARNING: Max frequency is more than 30%% higher "
|
||||
"than mean frequency. Manual verification required!\n");
|
||||
|
||||
printf("Estimated sampling frequency: %dHz\n", (int)m->max_frequency);
|
||||
printf("To calculate resolution, measure physical distance covered\n"
|
||||
"and look up the matching resolution in the table below\n");
|
||||
|
||||
|
|
@ -213,7 +248,7 @@ main (int argc, char **argv) {
|
|||
int fd;
|
||||
const char *path;
|
||||
struct libevdev *dev;
|
||||
struct measurements measurements = {0, 0, 0};
|
||||
struct measurements measurements = {0};
|
||||
|
||||
if (argc < 2)
|
||||
return usage();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue