Allow multiple input devices.

This commit is contained in:
Merlijn Wajer 2012-12-11 17:41:21 +01:00
parent 4d202546a5
commit 9a551f21f2
4 changed files with 45 additions and 40 deletions

View File

@ -40,8 +40,8 @@
macro \
}
#define KEYMAP(in_type, in_key, out_key, out_type, device, val) \
if(e.type == in_type && e.code == in_key) {\
#define KEYMAP(in_type, in_key, out_key, out_type, device, in_device, val) \
if(e.type == in_type && e.code == in_key && (in_device == -1 || in_device == fdrr)) {\
je.type = out_type; \
je.code = out_key; \
je.value = val(e.value); \

View File

@ -66,6 +66,8 @@
/* Set up amount of input devices here */
#define INPUT_DEVICE_COUNT 2
#define INPUT_DEVICE_ANY 0
#endif
/* -------------------------------------------------------------------------- */
@ -156,36 +158,36 @@ JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 1)
LEGAL_VALUE(e.value == 1 || e.value == 0,
/* HAT */
KEYMAP(EV_KEY, KEY_UP, ABS_HAT0Y, EV_ABS, 0, -)
KEYMAP(EV_KEY, KEY_DOWN, ABS_HAT0Y, EV_ABS, 0, +)
KEYMAP(EV_KEY, KEY_LEFT, ABS_HAT0X, EV_ABS, 0, -)
KEYMAP(EV_KEY, KEY_RIGHT, ABS_HAT0X, EV_ABS, 0, +)
KEYMAP(EV_KEY, KEY_UP, ABS_HAT0Y, EV_ABS, 0, -1, -)
KEYMAP(EV_KEY, KEY_DOWN, ABS_HAT0Y, EV_ABS, 0, -1, +)
KEYMAP(EV_KEY, KEY_LEFT, ABS_HAT0X, EV_ABS, 0, -1, -)
KEYMAP(EV_KEY, KEY_RIGHT, ABS_HAT0X, EV_ABS, 0, -1, +)
/* Red buttons */
KEYMAP(EV_KEY, KEY_LEFTCTRL, BTN_0, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_LEFTALT, BTN_1, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_SPACE, BTN_2, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_LEFTCTRL, BTN_0, EV_KEY, 0, -1, +)
KEYMAP(EV_KEY, KEY_LEFTALT, BTN_1, EV_KEY, 0, -1, +)
KEYMAP(EV_KEY, KEY_SPACE, BTN_2, EV_KEY, 0, -1, +)
/* Yellow button */
KEYMAP(EV_KEY, KEY_1, BTN_3, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_1, BTN_3, EV_KEY, 0, -1, +)
)
/* Second joystick */
LEGAL_VALUE(e.value == 1 || e.value == 0,
/* HAT */
KEYMAP(EV_KEY, KEY_R, ABS_HAT0Y, EV_ABS, 1, -)
KEYMAP(EV_KEY, KEY_F, ABS_HAT0Y, EV_ABS, 1, +)
KEYMAP(EV_KEY, KEY_D, ABS_HAT0X, EV_ABS, 1, -)
KEYMAP(EV_KEY, KEY_G, ABS_HAT0X, EV_ABS, 1, +)
KEYMAP(EV_KEY, KEY_R, ABS_HAT0Y, EV_ABS, 1, -1, -)
KEYMAP(EV_KEY, KEY_F, ABS_HAT0Y, EV_ABS, 1, -1, +)
KEYMAP(EV_KEY, KEY_D, ABS_HAT0X, EV_ABS, 1, -1, -)
KEYMAP(EV_KEY, KEY_G, ABS_HAT0X, EV_ABS, 1, -1, +)
/* Red buttons */
KEYMAP(EV_KEY, KEY_A, BTN_0, EV_KEY, 1, +)
KEYMAP(EV_KEY, KEY_S, BTN_1, EV_KEY, 1, +)
KEYMAP(EV_KEY, KEY_Q, BTN_2, EV_KEY, 1, +)
KEYMAP(EV_KEY, KEY_A, BTN_0, EV_KEY, 1, -1, +)
KEYMAP(EV_KEY, KEY_S, BTN_1, EV_KEY, 1, -1, +)
KEYMAP(EV_KEY, KEY_Q, BTN_2, EV_KEY, 1, -1, +)
/* Yellow button */
KEYMAP(EV_KEY, KEY_2, BTN_3, EV_KEY, 1, +)
KEYMAP(EV_KEY, KEY_2, BTN_3, EV_KEY, 1, -1, +)
)
#endif

View File

@ -64,7 +64,9 @@
#define JOYCOUNT 2
/* Set up amount of input devices here */
#define INPUT_DEVICE_COUNT 1
#define INPUT_DEVICE_COUNT 2
#define INPUT_DEVICE_ANY 0
#endif
@ -76,7 +78,8 @@
#ifndef H_CONFIGURE_EVENTS_SEEN
#define H_CONFIGURE_EVENTS_SEEN
ADD_INPUT_PATH("/dev/input/by-path/platform-i8042-serio-0-event-kbd", 0)
ADD_INPUT_PATH("/dev/input/by-id/usb-Cypress_I-PAC_Arcade_Control_Interface-event-kbd", 0)
ADD_INPUT_PATH("usb-Dell_Dell_USB_Keyboard-event-kbd", 1)
#endif
#endif
@ -155,36 +158,36 @@ JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 1)
LEGAL_VALUE(e.value == 1 || e.value == 0,
/* HAT */
KEYMAP(EV_KEY, KEY_UP, ABS_HAT0Y, EV_ABS, 0, -)
KEYMAP(EV_KEY, KEY_DOWN, ABS_HAT0Y, EV_ABS, 0, +)
KEYMAP(EV_KEY, KEY_LEFT, ABS_HAT0X, EV_ABS, 0, -)
KEYMAP(EV_KEY, KEY_RIGHT, ABS_HAT0X, EV_ABS, 0, +)
KEYMAP(EV_KEY, KEY_UP, ABS_HAT0Y, EV_ABS, 0, -1, -)
KEYMAP(EV_KEY, KEY_DOWN, ABS_HAT0Y, EV_ABS, 0, -1, +)
KEYMAP(EV_KEY, KEY_LEFT, ABS_HAT0X, EV_ABS, 0, -1, -)
KEYMAP(EV_KEY, KEY_RIGHT, ABS_HAT0X, EV_ABS, 0, -1, +)
/* Red buttons */
KEYMAP(EV_KEY, KEY_LEFTCTRL, BTN_0, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_LEFTALT, BTN_1, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_SPACE, BTN_2, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_LEFTCTRL, BTN_0, EV_KEY, 0, -1, +)
KEYMAP(EV_KEY, KEY_LEFTALT, BTN_1, EV_KEY, 0, -1, +)
KEYMAP(EV_KEY, KEY_SPACE, BTN_2, EV_KEY, 0, -1, +)
/* Yellow button */
KEYMAP(EV_KEY, KEY_1, BTN_3, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_1, BTN_3, EV_KEY, 0, -1, +)
)
/* Second joystick */
LEGAL_VALUE(e.value == 1 || e.value == 0,
/* HAT */
KEYMAP(EV_KEY, KEY_R, ABS_HAT0Y, EV_ABS, 1, -)
KEYMAP(EV_KEY, KEY_F, ABS_HAT0Y, EV_ABS, 1, +)
KEYMAP(EV_KEY, KEY_D, ABS_HAT0X, EV_ABS, 1, -)
KEYMAP(EV_KEY, KEY_G, ABS_HAT0X, EV_ABS, 1, +)
KEYMAP(EV_KEY, KEY_R, ABS_HAT0Y, EV_ABS, 1, -1, -)
KEYMAP(EV_KEY, KEY_F, ABS_HAT0Y, EV_ABS, 1, -1, +)
KEYMAP(EV_KEY, KEY_D, ABS_HAT0X, EV_ABS, 1, -1, -)
KEYMAP(EV_KEY, KEY_G, ABS_HAT0X, EV_ABS, 1, -1, +)
/* Red buttons */
KEYMAP(EV_KEY, KEY_A, BTN_0, EV_KEY, 1, +)
KEYMAP(EV_KEY, KEY_S, BTN_1, EV_KEY, 1, +)
KEYMAP(EV_KEY, KEY_Q, BTN_2, EV_KEY, 1, +)
KEYMAP(EV_KEY, KEY_A, BTN_0, EV_KEY, 1, -1, +)
KEYMAP(EV_KEY, KEY_S, BTN_1, EV_KEY, 1, -1, +)
KEYMAP(EV_KEY, KEY_Q, BTN_2, EV_KEY, 1, -1, +)
/* Yellow button */
KEYMAP(EV_KEY, KEY_2, BTN_3, EV_KEY, 1, +)
KEYMAP(EV_KEY, KEY_2, BTN_3, EV_KEY, 1, -1, +)
)
#endif

8
map.c
View File

@ -172,10 +172,6 @@ int main(int argc, char** argv) {
printf("Event: (Type: %d, Code: %d, Value %d)\n", e.type, e.code, e.value);
}
/* Update poll read mechanism */
fdrr = (fdrr + 1) % INPUT_DEVICE_COUNT;
rfds -= 1;
/* Now handle received event */
memset(&je, '\0', sizeof(struct input_event));
nowrite = 1;
@ -184,6 +180,10 @@ int main(int argc, char** argv) {
#define H_JOYMAP
#include "config.h"
/* Update poll read mechanism */
fdrr = (fdrr + 1) % INPUT_DEVICE_COUNT;
rfds -= 1;
if (nowrite == 0) {
printf("Writing %d to %d\n", e.code, j);
if(write(js[j], &je, sizeof(struct input_event)) < 0) {