From 11909fb055a0e7df7ce8c1a34e5d01ea546c9560 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Wed, 5 Dec 2012 00:13:19 +0100 Subject: [PATCH] Some debug and fixes. --- custom_map.h | 34 +++++++++++++++++++++++++--------- map.c | 1 + 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/custom_map.h b/custom_map.h index 86422e4..416eff2 100644 --- a/custom_map.h +++ b/custom_map.h @@ -15,31 +15,45 @@ #define H_CONFIGURE_JOYSTICKS_SEEN #define JOYSTICK_ADD_KEY(key, bit, device) \ - printf("JOYSTICK_ADD_KEY for device %d, key %s, bit: %s\n", device, #key, #bit); \ - if(device == j && ioctl(js[device], bit, key) < 0) { \ - perror("Error in JOYSTICK_ADD_KEY"); \ - fprintf(stderr, "ERROR: JOYSTICK_ADD_KEY for device %d, key %s, bit: %s\n", device, #key, #bit); \ - return 1; \ + if (device == j) { \ + if(ioctl(js[device], bit, key) < 0) { \ + perror("Error in JOYSTICK_ADD_KEY"); \ + fprintf(stderr, "ERROR: JOYSTICK_ADD_KEY for device %d, key %s, bit: %s\n", device, #key, #bit); \ + return 1; \ + } else { \ + printf("JOYSTICK_ADD_KEY for device %d, key %s, bit: %s\n", device, #key, #bit); \ + } \ } + #define JOYSTICK_SET_LIM(lim, val, key) \ uidev.lim[key] = val; -/* Configure first joystick */ +/* Configure first joystick. + * + * Here we just tell the program what keys we want to use. + * If a key is not enabled here, it will never be passed. + */ + +/* Hats. + * + * We set the absmax and absmin; otherwise the hats make no sense. + */ JOYSTICK_ADD_KEY(ABS_HAT0X, UI_SET_ABSBIT, 0) JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0X) JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0X) - JOYSTICK_ADD_KEY(ABS_HAT0Y, UI_SET_ABSBIT, 0) JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0Y) JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0Y) +/* Buttons. */ JOYSTICK_ADD_KEY(BTN_JOYSTICK, UI_SET_KEYBIT, 0) JOYSTICK_ADD_KEY(BTN_0, UI_SET_KEYBIT, 0) JOYSTICK_ADD_KEY(BTN_1, UI_SET_KEYBIT, 0) JOYSTICK_ADD_KEY(BTN_2, UI_SET_KEYBIT, 0) JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 0) +/* Second joystick ; same comments as first one */ JOYSTICK_ADD_KEY(ABS_HAT0X, UI_SET_ABSBIT, 1) JOYSTICK_SET_LIM(absmax, 1, ABS_HAT0X) JOYSTICK_SET_LIM(absmin, -1, ABS_HAT0X) @@ -58,6 +72,8 @@ JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 1) /* Now follows keymapping, do not touch ifdef */ #ifdef H_IN_CASE +#ifndef H_IN_CASE_SEEN +#define H_IN_CASE_SEEN #define KEYMAP(in_key, out_key, out_type, device, val) \ case in_key: \ je.type = out_type; \ @@ -84,7 +100,7 @@ KEYMAP(KEY_1, BTN_3, EV_KEY, 0, +) /* Second joystick */ -/* HAT*/ +/* HAT */ KEYMAP(KEY_R, ABS_HAT0Y, EV_ABS, 1, -) KEYMAP(KEY_F, ABS_HAT0Y, EV_ABS, 1, +) KEYMAP(KEY_D, ABS_HAT0X, EV_ABS, 1, -) @@ -98,4 +114,4 @@ 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 12aad84..f4883ff 100644 --- a/map.c +++ b/map.c @@ -160,6 +160,7 @@ int main(int argc, char** argv) { nowrite = 1; } if (nowrite == 0) { + printf("Writing %d to %d\n", e.code, j); if(write(js[j], &je, sizeof(struct input_event)) < 0) { perror("EV_ABS Write event"); return -1;