From c23d95f83c7771bb3da2e54cdc0d2799004976d3 Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Mon, 19 Jun 2017 22:13:35 +0200 Subject: [PATCH] Provide more debugging information for controllers --- src/input/evdev.c | 13 ++++++++++--- src/input/evdev.h | 2 +- src/input/mapping.c | 6 ++++-- src/input/mapping.h | 2 +- src/input/udev.c | 9 +++++---- src/input/udev.h | 2 +- src/main.c | 6 +++--- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/input/evdev.c b/src/input/evdev.c index bcf2ac3..6464bd5 100644 --- a/src/input/evdev.c +++ b/src/input/evdev.c @@ -397,7 +397,7 @@ static int evdev_handle(int fd) { return LOOP_OK; } -void evdev_create(const char* device, struct mapping* mappings) { +void evdev_create(const char* device, struct mapping* mappings, bool verbose) { int fd = open(device, O_RDONLY|O_NONBLOCK); if (fd <= 0) { fprintf(stderr, "Failed to open device %s\n", device); @@ -419,14 +419,21 @@ void evdev_create(const char* device, struct mapping* mappings) { for (int i = 0; i < 16; i++) buf += sprintf(buf, "%02x", ((unsigned char*) guid)[i]); - while (mappings != NULL && strncmp(str_guid, mappings->guid, 32) != 0) + while (mappings != NULL) { + if (strncmp(str_guid, mappings->guid, 32) == 0) { + if (verbose) + printf("Detected %s (%s) on %s\n", mappings->name, str_guid, device); + + break; + } mappings = mappings->next; + } bool is_keyboard = libevdev_has_event_code(evdev, EV_KEY, KEY_Q); bool is_mouse = libevdev_has_event_type(evdev, EV_REL) || libevdev_has_event_code(evdev, EV_KEY, BTN_LEFT); if (mappings == NULL && !(is_keyboard || is_mouse)) - fprintf(stderr, "No mapping available for %s\n", device); + fprintf(stderr, "No mapping available for %s (%s)\n", device, str_guid); int dev = numDevices; numDevices++; diff --git a/src/input/evdev.h b/src/input/evdev.h index c3330e4..706c376 100644 --- a/src/input/evdev.h +++ b/src/input/evdev.h @@ -19,7 +19,7 @@ #include "mapping.h" -void evdev_create(const char* device, struct mapping* mappings); +void evdev_create(const char* device, struct mapping* mappings, bool verbose); void evdev_loop(); void evdev_init(); diff --git a/src/input/mapping.c b/src/input/mapping.c index 029f1a7..51bbe01 100644 --- a/src/input/mapping.c +++ b/src/input/mapping.c @@ -21,16 +21,18 @@ #include #include +#include #include -struct mapping* mapping_load(char* fileName) { +struct mapping* mapping_load(char* fileName, bool verbose) { struct mapping* mappings = NULL; struct mapping* map = NULL; FILE* fd = fopen(fileName, "r"); if (fd == NULL) { fprintf(stderr, "Can't open mapping file: %s\n", fileName); exit(EXIT_FAILURE); - } + } else if (verbose) + printf("Loading mappingfile %s\n", fileName); char *line = NULL; size_t len = 0; diff --git a/src/input/mapping.h b/src/input/mapping.h index c80b0a5..84d73ee 100644 --- a/src/input/mapping.h +++ b/src/input/mapping.h @@ -47,4 +47,4 @@ struct mapping { struct mapping* next; }; -struct mapping* mapping_load(char* fileName); +struct mapping* mapping_load(char* fileName, bool verbose); diff --git a/src/input/udev.c b/src/input/udev.c index 6766b91..9598653 100644 --- a/src/input/udev.c +++ b/src/input/udev.c @@ -31,7 +31,7 @@ #include #include -static bool autoadd; +static bool autoadd, debug; static struct mapping* defaultMappings; static struct udev *udev; @@ -46,7 +46,7 @@ static int udev_handle(int fd) { const char *devnode = udev_device_get_devnode(dev); int id; if (devnode != NULL && sscanf(devnode, "/dev/input/event%d", &id) == 1) { - evdev_create(devnode, defaultMappings); + evdev_create(devnode, defaultMappings, debug); } } udev_device_unref(dev); @@ -54,8 +54,9 @@ static int udev_handle(int fd) { return LOOP_OK; } -void udev_init(bool autoload, struct mapping* mappings) { +void udev_init(bool autoload, struct mapping* mappings, bool verbose) { udev = udev_new(); + debug = verbose; if (!udev) { fprintf(stderr, "Can't create udev\n"); exit(1); @@ -75,7 +76,7 @@ void udev_init(bool autoload, struct mapping* mappings) { const char *devnode = udev_device_get_devnode(dev); int id; if (devnode != NULL && sscanf(devnode, "/dev/input/event%d", &id) == 1) { - evdev_create(devnode, mappings); + evdev_create(devnode, mappings, verbose); } udev_device_unref(dev); } diff --git a/src/input/udev.h b/src/input/udev.h index 9414b6a..b0223e3 100644 --- a/src/input/udev.h +++ b/src/input/udev.h @@ -19,5 +19,5 @@ #include "mapping.h" -void udev_init(bool autoload, struct mapping* mappings); +void udev_init(bool autoload, struct mapping* mappings, bool verbose); void evdev_destroy(); diff --git a/src/main.c b/src/main.c index 71df729..695d129 100644 --- a/src/main.c +++ b/src/main.c @@ -256,16 +256,16 @@ int main(int argc, char* argv[]) { fprintf(stderr, "Please specify mapping file as default mapping could not be found.\n"); exit(-1); } - struct mapping* mappings = mapping_load(config.mapping); + struct mapping* mappings = mapping_load(config.mapping, config.debug_level > 0); for (int i=0;i 0) printf("Add input %s...\n", config.inputs[i]); - evdev_create(config.inputs[i], mappings); + evdev_create(config.inputs[i], mappings, config.debug_level > 0); } - udev_init(!inputAdded, mappings); + udev_init(!inputAdded, mappings, config.debug_level > 0); evdev_init(); #ifdef HAVE_LIBCEC cec_init();