mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-24 20:30:06 +01:00
Merge libevdev-print and libevdev-events into one binary
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
2159a7b154
commit
ea705612e1
3 changed files with 85 additions and 152 deletions
|
|
@ -1,11 +1,8 @@
|
|||
noinst_PROGRAMS = libevdev-print libevdev-events
|
||||
noinst_PROGRAMS = libevdev-events
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/libevdev
|
||||
libevdev_ldadd = $(top_builddir)/libevdev/libevdev.la
|
||||
|
||||
libevdev_print_SOURCES = libevdev-print.c event-names.h
|
||||
libevdev_print_LDADD = $(libevdev_ldadd)
|
||||
|
||||
libevdev_events_SOURCES = libevdev-events.c event-names.h
|
||||
libevdev_events_LDADD = $(libevdev_ldadd)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,79 @@
|
|||
#include "libevdev.h"
|
||||
#include "event-names.h"
|
||||
|
||||
static void
|
||||
print_abs_bits(struct libevdev *dev, int axis)
|
||||
{
|
||||
const struct input_absinfo *abs;
|
||||
|
||||
if (!libevdev_has_event_code(dev, EV_ABS, axis))
|
||||
return;
|
||||
|
||||
abs = libevdev_get_abs_info(dev, axis);
|
||||
|
||||
printf(" Value %6d\n", abs->value);
|
||||
printf(" Min %6d\n", abs->minimum);
|
||||
printf(" Max %6d\n", abs->maximum);
|
||||
if (abs->fuzz)
|
||||
printf(" Fuzz %6d\n", abs->fuzz);
|
||||
if (abs->flat)
|
||||
printf(" Flat %6d\n", abs->flat);
|
||||
if (abs->resolution)
|
||||
printf(" Resolution %6d\n", abs->resolution);
|
||||
}
|
||||
|
||||
static void
|
||||
print_code_bits(struct libevdev *dev, unsigned int type, unsigned int max)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i <= max; i++) {
|
||||
if (!libevdev_has_event_code(dev, type, i))
|
||||
continue;
|
||||
|
||||
printf(" Event code %i (%s)\n", i, event_get_code_name(type, i));
|
||||
if (type == EV_ABS)
|
||||
print_abs_bits(dev, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_bits(struct libevdev *dev)
|
||||
{
|
||||
unsigned int i;
|
||||
printf("Supported events:\n");
|
||||
|
||||
for (i = 0; i <= EV_MAX; i++) {
|
||||
if (libevdev_has_event_type(dev, i))
|
||||
printf(" Event type %d (%s)\n", i, event_get_type_name(i));
|
||||
switch(i) {
|
||||
case EV_KEY:
|
||||
print_code_bits(dev, EV_KEY, KEY_MAX);
|
||||
break;
|
||||
case EV_REL:
|
||||
print_code_bits(dev, EV_REL, REL_MAX);
|
||||
break;
|
||||
case EV_ABS:
|
||||
print_code_bits(dev, EV_ABS, ABS_MAX);
|
||||
break;
|
||||
case EV_LED:
|
||||
print_code_bits(dev, EV_LED, LED_MAX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_props(struct libevdev *dev)
|
||||
{
|
||||
unsigned int i;
|
||||
printf("Properties:\n");
|
||||
|
||||
for (i = 0; i <= INPUT_PROP_MAX; i++) {
|
||||
if (libevdev_has_property(dev, i))
|
||||
printf(" Property type %d (%s)\n", i, input_prop_map[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int print_event(struct input_event *ev)
|
||||
{
|
||||
if (ev->type == EV_SYN)
|
||||
|
|
@ -84,6 +157,17 @@ main(int argc, char **argv)
|
|||
goto out;
|
||||
}
|
||||
|
||||
printf("Input device ID: bus %#x vendor %#x product %#x\n",
|
||||
libevdev_get_bustype(dev),
|
||||
libevdev_get_vendor_id(dev),
|
||||
libevdev_get_product_id(dev));
|
||||
printf("Evdev version: %x\n", libevdev_get_driver_version(dev));
|
||||
printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
|
||||
printf("Phys location: %s\n", libevdev_get_phys(dev));
|
||||
printf("Uniq identifier: %s\n", libevdev_get_uniq(dev));
|
||||
print_bits(dev);
|
||||
print_props(dev);
|
||||
|
||||
do {
|
||||
struct input_event ev;
|
||||
rc = libevdev_next_event(dev, 0, &ev);
|
||||
|
|
|
|||
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2013 Red Hat, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting documentation, and
|
||||
* that the name of the copyright holders not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. The copyright holders make no representations
|
||||
* about the suitability of this software for any purpose. It is provided "as
|
||||
* is" without express or implied warranty.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
#include "libevdev.h"
|
||||
#include "event-names.h"
|
||||
|
||||
static void
|
||||
print_abs_bits(struct libevdev *dev, int axis)
|
||||
{
|
||||
const struct input_absinfo *abs;
|
||||
|
||||
if (!libevdev_has_event_code(dev, EV_ABS, axis))
|
||||
return;
|
||||
|
||||
abs = libevdev_get_abs_info(dev, axis);
|
||||
|
||||
printf(" Value %6d\n", abs->value);
|
||||
printf(" Min %6d\n", abs->minimum);
|
||||
printf(" Max %6d\n", abs->maximum);
|
||||
if (abs->fuzz)
|
||||
printf(" Fuzz %6d\n", abs->fuzz);
|
||||
if (abs->flat)
|
||||
printf(" Flat %6d\n", abs->flat);
|
||||
if (abs->resolution)
|
||||
printf(" Resolution %6d\n", abs->resolution);
|
||||
}
|
||||
|
||||
static void
|
||||
print_code_bits(struct libevdev *dev, unsigned int type, unsigned int max)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i <= max; i++) {
|
||||
if (!libevdev_has_event_code(dev, type, i))
|
||||
continue;
|
||||
|
||||
printf(" Event code %i (%s)\n", i, event_get_code_name(type, i));
|
||||
if (type == EV_ABS)
|
||||
print_abs_bits(dev, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_bits(struct libevdev *dev)
|
||||
{
|
||||
unsigned int i;
|
||||
printf("Supported events:\n");
|
||||
|
||||
for (i = 0; i <= EV_MAX; i++) {
|
||||
if (libevdev_has_event_type(dev, i))
|
||||
printf(" Event type %d (%s)\n", i, event_get_type_name(i));
|
||||
switch(i) {
|
||||
case EV_KEY:
|
||||
print_code_bits(dev, EV_KEY, KEY_MAX);
|
||||
break;
|
||||
case EV_REL:
|
||||
print_code_bits(dev, EV_REL, REL_MAX);
|
||||
break;
|
||||
case EV_ABS:
|
||||
print_code_bits(dev, EV_ABS, ABS_MAX);
|
||||
break;
|
||||
case EV_LED:
|
||||
print_code_bits(dev, EV_LED, LED_MAX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_props(struct libevdev *dev)
|
||||
{
|
||||
unsigned int i;
|
||||
printf("Properties:\n");
|
||||
|
||||
for (i = 0; i <= INPUT_PROP_MAX; i++) {
|
||||
if (libevdev_has_property(dev, i))
|
||||
printf(" Property type %d (%s)\n", i, input_prop_map[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct libevdev *dev;
|
||||
const char *file;
|
||||
int fd;
|
||||
int rc;
|
||||
|
||||
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
|
||||
file = argv[1];
|
||||
fd = open(file, O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
perror("Failed to open device");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = libevdev_new_from_fd(fd, &dev);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc));
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Input device ID: bus %#x vendor %#x product %#x\n",
|
||||
libevdev_get_bustype(dev),
|
||||
libevdev_get_vendor_id(dev),
|
||||
libevdev_get_product_id(dev));
|
||||
printf("Evdev version: %x\n", libevdev_get_driver_version(dev));
|
||||
printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
|
||||
printf("Phys location: %s\n", libevdev_get_phys(dev));
|
||||
printf("Uniq identifier: %s\n", libevdev_get_uniq(dev));
|
||||
print_bits(dev);
|
||||
print_props(dev);
|
||||
|
||||
libevdev_free(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue