summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-09-21 15:54:12 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-09-21 15:54:27 +1000
commit0bee8cadcb99f1d95f7455537359e372e55177a9 (patch)
treef06145088a06de430390a125d74611e59792805e
parentc940ea7bd99079a0d12d3691d1d873808a3f66d7 (diff)
tools: add evemu-print for human-readable device descriptionsevemu
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--tools/Makefile.am1
-rw-r--r--tools/evemu-print.c134
2 files changed, 135 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 49609ab..0d91784 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -5,6 +5,7 @@ bin_PROGRAMS = \
evtest \
evemu-describe \
evemu-device \
+ evemu-print \
evemu-record \
evemu-play
diff --git a/tools/evemu-print.c b/tools/evemu-print.c
new file mode 100644
index 0000000..f4e9f45
--- /dev/null
+++ b/tools/evemu-print.c
@@ -0,0 +1,134 @@
+/*****************************************************************************
+ *
+ * evemu - Kernel device emulation
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ ****************************************************************************/
+
+#include <evemu.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+static int print_events(FILE *fp) {
+ struct input_event ev;
+ int ret = 0;
+
+ while(evemu_read_event(fp, &ev) > 0) {
+ const char *type, *code;
+ type = evemu_get_type_name(ev.type);
+ code = evemu_get_code_name(ev.type, ev.code);
+
+ printf("Event: time %ld.%06ld, ", ev.time.tv_sec, ev.time.tv_usec);
+
+ if (ev.type == EV_SYN) {
+ if (ev.code == SYN_MT_REPORT)
+ printf("++++++++++++++ %s ++++++++++++\n", code);
+ else
+ printf("-------------- %s ------------\n", code);
+ } else {
+ printf("type %d (%s), code %d (%s), ", ev.type, type, ev.code, code);
+
+ if (ev.type == EV_MSC && (ev.code == MSC_RAW || ev.code == MSC_SCAN))
+ printf("value %02x\n", ev.value);
+ else
+ printf("value %d\n", ev.value);
+ }
+ }
+
+ return ret;
+}
+
+static int print_device(FILE *fp)
+{
+ struct evemu_device *dev;
+ int type, code;
+
+ dev = evemu_new(NULL);
+ if (!evemu_read(dev, stdin))
+ return -1;
+
+ printf("Name: %s\n", evemu_get_name(dev));
+ printf("ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
+ evemu_get_id_bustype(dev),
+ evemu_get_id_vendor(dev),
+ evemu_get_id_product(dev),
+ evemu_get_id_version(dev));
+
+ printf("Input device name: \"%s\"\n", evemu_get_name(dev));
+
+ printf("Supported events:\n");
+
+ for (type = 0; type < EV_MAX; type++) {
+ for (code = 0; code < KEY_MAX; code++) {
+ if (evemu_has_event(dev, type, code)) {
+ printf(" Event type %d (%s) code %d (%s)\n",
+ type, evemu_get_type_name(type),
+ code, evemu_get_code_name(type, code));
+
+ if (type == EV_ABS) {
+ printf(" min: %d max: %d fuzz: %d flat: %d res: %d\n",
+ evemu_get_abs_minimum(dev, code),
+ evemu_get_abs_maximum(dev, code),
+ evemu_get_abs_fuzz(dev, code),
+ evemu_get_abs_flat(dev, code),
+ evemu_get_abs_resolution(dev, code));
+ }
+ }
+ }
+ }
+ evemu_delete(dev);
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+
+ if (argc != 1) {
+ fprintf(stderr, "Usage: %s\n", argv[0]);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Event data is read from standard input.\n");
+ return -1;
+ }
+
+ print_device(stdin);
+ print_events(stdin);
+
+ return 0;
+}