From ce2a2a10e0a29d99e127db8c47f232a697d75ad3 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Tue, 4 Dec 2012 20:05:00 +0100 Subject: [PATCH] Allow amount of joysticks to be set. --- custom_map.h | 15 +++++++++++++++ map.c | 14 +++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/custom_map.h b/custom_map.h index 99d8f4e..83a9da0 100644 --- a/custom_map.h +++ b/custom_map.h @@ -1,3 +1,15 @@ +#ifndef H_GLOBAL_MAP +#define H_GLOBAL_MAP + +/* Set up amount of joysticks here */ +#define JOYCOUNT 2 + +/* Set up event to read from */ +#define INPUT_PATH "/dev/input/by-path/platform-i8042-serio-0-event-kbd" + + +/* Now follows keymapping, do not touch ifdef */ +#ifdef H_IN_CASE #define KEYMAP(in_key, out_key, out_type, device, val) \ case in_key: \ je.type = out_type; \ @@ -37,3 +49,6 @@ KEYMAP(KEY_Q, BTN_2, EV_KEY, 1, ) /* Yellow button */ KEYMAP(KEY_2, BTN_3, EV_KEY, 1,) +#endif + +#endif diff --git a/map.c b/map.c index a693943..3efd35a 100644 --- a/map.c +++ b/map.c @@ -21,8 +21,8 @@ #include #include -#define INPUT_PATH "/dev/input/by-path/platform-i8042-serio-0-event-kbd" -/*#define INPUT_PATH "/dev/input/by-path/platform-i8042-serio-0-event-kbd"*/ +#include "custom_map.h" + #define UINPUT_PATH "/dev/uinput" /* Reverse mapping, for later use */ @@ -50,7 +50,7 @@ static int get_key_num(char* name) return -1; } -static int js[2]; +static int js[JOYCOUNT]; /* TODO: * - Add file parsing / reading @@ -59,7 +59,7 @@ static int js[2]; void free_js(int sig) { int j; - for(j = 0; j < 2; j++) { + for(j = 0; j < JOYCOUNT; j++) { printf("Freeing joystick: %d\n", j); if (ioctl(js[j], UI_DEV_DESTROY) < 0) { perror("Error freeing joystick"); @@ -103,8 +103,7 @@ int main(int argc, char** argv) { } - - for(j = 0; j < 2; j++) { + for(j = 0; j < JOYCOUNT; j++) { /* Memset because we are already setting the absmax/absmin */ memset(&uidev, '\0', sizeof(struct uinput_user_dev)); js[j] = open(UINPUT_PATH, O_WRONLY | O_NONBLOCK); @@ -147,7 +146,7 @@ int main(int argc, char** argv) { /* Allocate device info */ - snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "key2joy:1"); + snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "key2joy:%d", j); uidev.id.bustype = BUS_USB; uidev.id.vendor = 0x42; @@ -181,6 +180,7 @@ int main(int argc, char** argv) { if (e.type == EV_KEY && e.value != 2) { switch(e.code) { + #define H_IN_CASE #include "custom_map.h" default: