mirror of
https://github.com/moparisthebest/uinput-mapper
synced 2025-01-10 12:58:02 -05:00
More preprocessor options.
Maybe I am taking this too far...
This commit is contained in:
parent
8e73743889
commit
b4ddd24f5f
42
custom_map.h
42
custom_map.h
@ -9,6 +9,48 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef H_CONFIGURE_JOYSTICKS
|
||||||
|
#ifndef H_CONFIGURE_JOYSTICKS_SEEN
|
||||||
|
#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; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define JOYSTICK_SET_LIM(lim, val, key) \
|
||||||
|
uidev.lim[key] = val;
|
||||||
|
|
||||||
|
/* Configure first joystick */
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
JOYSTICK_ADD_KEY(ABS_HAT0X, UI_SET_ABSBIT, 1)
|
||||||
|
JOYSTICK_ADD_KEY(ABS_HAT0Y, UI_SET_ABSBIT, 1)
|
||||||
|
|
||||||
|
JOYSTICK_ADD_KEY(BTN_JOYSTICK, UI_SET_KEYBIT, 1)
|
||||||
|
JOYSTICK_ADD_KEY(BTN_0, UI_SET_KEYBIT, 1)
|
||||||
|
JOYSTICK_ADD_KEY(BTN_1, UI_SET_KEYBIT, 1)
|
||||||
|
JOYSTICK_ADD_KEY(BTN_2, UI_SET_KEYBIT, 1)
|
||||||
|
JOYSTICK_ADD_KEY(BTN_3, UI_SET_KEYBIT, 1)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Now follows keymapping, do not touch ifdef */
|
/* Now follows keymapping, do not touch ifdef */
|
||||||
#ifdef H_IN_CASE
|
#ifdef H_IN_CASE
|
||||||
#define KEYMAP(in_key, out_key, out_type, device, val) \
|
#define KEYMAP(in_key, out_key, out_type, device, val) \
|
||||||
|
40
map.c
40
map.c
@ -72,25 +72,11 @@ void free_js(int sig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int i, j, nowrite;
|
int j, nowrite;
|
||||||
int in; /* fds */
|
int in; /* fds */
|
||||||
struct input_event e, je;
|
struct input_event e, je;
|
||||||
struct uinput_user_dev uidev;
|
struct uinput_user_dev uidev;
|
||||||
|
|
||||||
int abskeyevs[] = {
|
|
||||||
ABS_HAT0X,
|
|
||||||
ABS_HAT0Y,
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
int evkeys[] = {
|
|
||||||
BTN_JOYSTICK, /* We need this to show up as Joystick */
|
|
||||||
BTN_0,
|
|
||||||
BTN_1,
|
|
||||||
BTN_2,
|
|
||||||
BTN_3,
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
@ -109,7 +95,6 @@ int main(int argc, char** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for(j = 0; j < JOYCOUNT; j++) {
|
for(j = 0; j < JOYCOUNT; j++) {
|
||||||
/* Memset because we are already setting the absmax/absmin */
|
/* Memset because we are already setting the absmax/absmin */
|
||||||
memset(&uidev, '\0', sizeof(struct uinput_user_dev));
|
memset(&uidev, '\0', sizeof(struct uinput_user_dev));
|
||||||
@ -130,27 +115,8 @@ int main(int argc, char** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Every ``button'' needs to be registered */
|
#define H_CONFIGURE_JOYSTICKS
|
||||||
i = 0;
|
#include "custom_map.h"
|
||||||
while(abskeyevs[i] != 0) {
|
|
||||||
if (ioctl(js[j], UI_SET_ABSBIT, abskeyevs[i]) < 0) {
|
|
||||||
perror("ioctl dynamic");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
uidev.absmax[abskeyevs[i]] = 1;
|
|
||||||
uidev.absmin[abskeyevs[i]] = -1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while(evkeys[i] != 0) {
|
|
||||||
if (ioctl(js[j], UI_SET_KEYBIT, evkeys[i]) < 0) {
|
|
||||||
perror("ioctl dynamic 2");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Allocate device info */
|
/* Allocate device info */
|
||||||
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "key2joy:%d", j);
|
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "key2joy:%d", j);
|
||||||
|
Loading…
Reference in New Issue
Block a user