2 * Copyright © 2013 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 #include <sys/types.h>
32 #include <linux/input.h>
37 print_abs_bits(struct libevdev *dev, int axis)
39 const struct input_absinfo *abs;
41 if (!libevdev_has_event_code(dev, EV_ABS, axis))
44 abs = libevdev_get_abs_info(dev, axis);
46 printf(" Value %6d\n", abs->value);
47 printf(" Min %6d\n", abs->minimum);
48 printf(" Max %6d\n", abs->maximum);
50 printf(" Fuzz %6d\n", abs->fuzz);
52 printf(" Flat %6d\n", abs->flat);
54 printf(" Resolution %6d\n", abs->resolution);
58 print_code_bits(struct libevdev *dev, unsigned int type, unsigned int max)
61 for (i = 0; i <= max; i++) {
62 if (!libevdev_has_event_code(dev, type, i))
65 printf(" Event code %i (%s)\n", i, libevdev_event_code_get_name(type, i));
67 print_abs_bits(dev, i);
72 print_bits(struct libevdev *dev)
75 printf("Supported events:\n");
77 for (i = 0; i <= EV_MAX; i++) {
78 if (libevdev_has_event_type(dev, i))
79 printf(" Event type %d (%s)\n", i, libevdev_event_type_get_name(i));
82 print_code_bits(dev, EV_KEY, KEY_MAX);
85 print_code_bits(dev, EV_REL, REL_MAX);
88 print_code_bits(dev, EV_ABS, ABS_MAX);
91 print_code_bits(dev, EV_LED, LED_MAX);
98 print_props(struct libevdev *dev)
101 printf("Properties:\n");
103 for (i = 0; i <= INPUT_PROP_MAX; i++) {
104 if (libevdev_has_property(dev, i))
105 printf(" Property type %d (%s)\n", i,
106 libevdev_property_get_name(i));
111 print_event(struct input_event *ev)
113 if (ev->type == EV_SYN)
114 printf("Event: time %ld.%06ld, ++++++++++++++++++++ %s +++++++++++++++\n",
117 libevdev_event_type_get_name(ev->type));
119 printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %d\n",
123 libevdev_event_type_get_name(ev->type),
125 libevdev_event_code_get_name(ev->type, ev->code),
131 print_sync_event(struct input_event *ev)
139 main(int argc, char **argv)
141 struct libevdev *dev = NULL;
150 fd = open(file, O_RDONLY);
152 perror("Failed to open device");
156 rc = libevdev_new_from_fd(fd, &dev);
158 fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc));
162 printf("Input device ID: bus %#x vendor %#x product %#x\n",
163 libevdev_get_id_bustype(dev),
164 libevdev_get_id_vendor(dev),
165 libevdev_get_id_product(dev));
166 printf("Evdev version: %x\n", libevdev_get_driver_version(dev));
167 printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
168 printf("Phys location: %s\n", libevdev_get_phys(dev));
169 printf("Uniq identifier: %s\n", libevdev_get_uniq(dev));
174 struct input_event ev;
175 rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL|LIBEVDEV_READ_FLAG_BLOCKING, &ev);
176 if (rc == LIBEVDEV_READ_STATUS_SYNC) {
177 printf("::::::::::::::::::::: dropped ::::::::::::::::::::::\n");
178 while (rc == LIBEVDEV_READ_STATUS_SYNC) {
179 print_sync_event(&ev);
180 rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev);
182 printf("::::::::::::::::::::: re-synced ::::::::::::::::::::::\n");
183 } else if (rc == LIBEVDEV_READ_STATUS_SUCCESS)
185 } while (rc == LIBEVDEV_READ_STATUS_SYNC || rc == LIBEVDEV_READ_STATUS_SUCCESS || rc == -EAGAIN);
187 if (rc != LIBEVDEV_READ_STATUS_SUCCESS && rc != -EAGAIN)
188 fprintf(stderr, "Failed to handle events: %s\n", strerror(rc));