Dependency fixes and config changes.

- config.h Makefile dependency
- Remove case statement
- Add extra argument that defines the in_type
- Updated configs.
This commit is contained in:
Merlijn Wajer 2012-12-05 11:35:34 +01:00
parent bab8bb9ef2
commit 4a3011f08d
5 changed files with 48 additions and 45 deletions

View File

@ -9,7 +9,7 @@ default: map
def_keys.h:
echo '#include <linux/input.h>' | gcc -E -dM - | grep '#define KEY_' | cut -f2 -d" " | sed 's/KEY_.*/DEF_KEY(&)/' > def_keys.h
map: map.c def_keys.h
map: map.c def_keys.h config.h
$(CC) map.c $(CFLAGS) -o map
clean:

View File

@ -26,13 +26,18 @@
#define JOYSTICK_SET_LIM(lim, val, key) \
uidev.lim[key] = val;
#define LEGAL_VALUE(statement, macro) \
if (statement) { \
macro \
}
#define KEYMAP(in_key, out_key, out_type, device, val) \
case in_key: \
#define KEYMAP(in_type, in_key, out_key, out_type, device, val) \
if(e.type == in_type && e.code == in_key) {\
je.type = out_type; \
je.code = out_key; \
je.value = val(e.value); \
j = device; \
break;
nowrite = 0;\
}
#endif

View File

@ -44,11 +44,11 @@ JOYSTICK_ADD_KEY(REL_Y, UI_SET_RELBIT, 0)
#ifndef H_JOYMAP_SEEN
#define H_JOYMAP_SEEN
KEYMAP(KEY_3, BTN_LEFT, EV_KEY, 0, +)
KEYMAP(KEY_M, REL_X, EV_REL, 0, 10*)
KEYMAP(KEY_N, REL_X, EV_REL, 0, -10*)
KEYMAP(KEY_J, REL_Y, EV_REL, 0, 10*)
KEYMAP(KEY_K, REL_Y, EV_REL, 0, -10*)
KEYMAP(EV_KEY, KEY_3, BTN_LEFT, EV_KEY, 0, +)
KEYMAP(EV_KEY, KEY_M, REL_X, EV_REL, 0, 10*)
KEYMAP(EV_KEY, KEY_N, REL_X, EV_REL, 0, -10*)
KEYMAP(EV_KEY, KEY_J, REL_Y, EV_REL, 0, 10*)
KEYMAP(EV_KEY, KEY_K, REL_Y, EV_REL, 0, -10*)
#endif
#endif

View File

@ -133,35 +133,39 @@ JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 1)
/* First joystick */
/* HAT */
KEYMAP(KEY_UP, ABS_HAT0Y, EV_ABS, 0, -)
KEYMAP(KEY_DOWN, ABS_HAT0Y, EV_ABS, 0, +)
KEYMAP(KEY_LEFT, ABS_HAT0X, EV_ABS, 0, -)
KEYMAP(KEY_RIGHT, ABS_HAT0X, EV_ABS, 0, +)
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, +)
/* Red buttons */
KEYMAP(KEY_LEFTCTRL, BTN_0, EV_KEY, 0, +)
KEYMAP(KEY_LEFTALT, BTN_1, EV_KEY, 0, +)
KEYMAP(KEY_SPACE, BTN_2, EV_KEY, 0, +)
/* 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, +)
/* Yellow button */
KEYMAP(KEY_1, BTN_3, EV_KEY, 0, +)
/* Yellow button */
KEYMAP(EV_KEY, KEY_1, BTN_3, EV_KEY, 0, +)
)
/* Second joystick */
/* 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, -)
KEYMAP(KEY_G, ABS_HAT0X, EV_ABS, 1, +)
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, +)
/* Red buttons */
KEYMAP(KEY_A, BTN_0, EV_KEY, 1, +)
KEYMAP(KEY_S, BTN_1, EV_KEY, 1, +)
KEYMAP(KEY_Q, BTN_2, EV_KEY, 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, +)
/* Yellow button */
KEYMAP(KEY_2, BTN_3, EV_KEY, 1, +)
/* Yellow button */
KEYMAP(EV_KEY, KEY_2, BTN_3, EV_KEY, 1, +)
)
#endif
#endif

22
map.c
View File

@ -134,26 +134,20 @@ int main(int argc, char** argv) {
memset(&je, '\0', sizeof(struct input_event));
nowrite = 0;
nowrite = 1;
j = 0;
/* Only catch keys and ignore auto-repeat (value == 2) */
/* TODO: Remove this EV_KEY contraint and use it in the macro */
if (e.type == EV_KEY && e.value != 2) {
switch(e.code) {
#define H_JOYMAP
#include "config.h"
#define H_JOYMAP
#include "config.h"
default:
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("Event write event");
return -1;
}
if (nowrite == 0) {
printf("Writing %d to %d\n", e.code, j);
if(write(js[j], &je, sizeof(struct input_event)) < 0) {
perror("Event write event");
return -1;
}
}