mirror of
https://github.com/moparisthebest/uinput-mapper
synced 2024-12-23 04:08:48 -05:00
Initial working commit.
This commit is contained in:
parent
21b316ae03
commit
78f545c1ae
21
KEYS
Normal file
21
KEYS
Normal file
@ -0,0 +1,21 @@
|
||||
[Left]
|
||||
KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN (type=EV_KEY, value={0,1})
|
||||
|
||||
Red:
|
||||
0: KEY_LEFTCTRL
|
||||
1: KEY_LEFTALT
|
||||
2: KEY_SPACE
|
||||
|
||||
Yellow:
|
||||
3: KEY_1
|
||||
|
||||
[Right]
|
||||
KEY_D, KEY_R, KEY_G, KEY_F (type=EV_KEY, value={0,1})
|
||||
|
||||
Red:
|
||||
0: KEY_A
|
||||
1: KEY_S
|
||||
2: KEY_Q
|
||||
|
||||
Yellow:
|
||||
3: KEY_2
|
110
map.c
Normal file
110
map.c
Normal file
@ -0,0 +1,110 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <linux/input.h>
|
||||
#include <linux/uinput.h>
|
||||
|
||||
#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"*/
|
||||
#define UINPUT_PATH "/dev/uinput"
|
||||
|
||||
/* TODO:
|
||||
* - Use atexit() to free joysticks
|
||||
* - Make joysticks static
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int in, uin;
|
||||
struct input_event e, je;
|
||||
struct uinput_user_dev uidev;
|
||||
|
||||
in = open(INPUT_PATH, O_RDONLY);
|
||||
if(in < 0) {
|
||||
perror("open in");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uin = open(UINPUT_PATH, O_WRONLY | O_NONBLOCK);
|
||||
if (uin < 0) {
|
||||
perror("open uin");
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Create devices */
|
||||
if (ioctl(uin, UI_SET_EVBIT, EV_ABS) < 0) {
|
||||
perror("ioctl EV_ABS");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ioctl(uin, UI_SET_EVBIT, EV_KEY) < 0) {
|
||||
perror("ioctl EV_KEY");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Every ``button'' needs to be registered */
|
||||
if (ioctl(uin, UI_SET_ABSBIT, ABS_HAT0Y) < 0) {
|
||||
perror("ioctl ABS_");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&uidev, '\0', sizeof(struct uinput_user_dev));
|
||||
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "key2joy:1");
|
||||
|
||||
uidev.id.bustype = BUS_USB;
|
||||
uidev.id.vendor = 0x42;
|
||||
uidev.id.product = 0xbebe;
|
||||
uidev.id.version = 1;
|
||||
|
||||
if (write(uin, &uidev, sizeof(uidev)) < 0) {
|
||||
perror("write");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ioctl(uin, UI_DEV_CREATE)) {
|
||||
perror("ioctl create");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
printf("in: %d, uin: %d\n", in, uin);
|
||||
if (read(in, &e, sizeof(struct input_event))) {
|
||||
printf("Event: (Type: %d, Code: %d, Value %d)\n", e.type, e.code, e.value);
|
||||
}
|
||||
|
||||
|
||||
if (e.type == EV_KEY && e.code == KEY_UP) {
|
||||
memset(&je, '\0', sizeof(struct input_event));
|
||||
je.type = EV_ABS;
|
||||
je.code = ABS_HAT0Y;
|
||||
je.value = -e.value;
|
||||
if(write(uin, &je, sizeof(struct input_event)) < 0) {
|
||||
perror("EV_ABS Write event");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (e.type == EV_SYN) {
|
||||
memset(&je, '\0', sizeof(struct input_event));
|
||||
printf("SYN event\n");
|
||||
|
||||
je.type = EV_SYN;
|
||||
je.code = 0;
|
||||
je.value = 0;
|
||||
|
||||
if (write(uin, &je, sizeof(struct input_event)) < 0) {
|
||||
perror("SYN write event");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
printf("---\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user