mirror of
https://github.com/moparisthebest/uinput-mapper
synced 2024-11-29 10:22:15 -05:00
Allow amount of joysticks to be set.
This commit is contained in:
parent
8f7c8b7a88
commit
ce2a2a10e0
15
custom_map.h
15
custom_map.h
@ -1,3 +1,15 @@
|
|||||||
|
#ifndef H_GLOBAL_MAP
|
||||||
|
#define H_GLOBAL_MAP
|
||||||
|
|
||||||
|
/* Set up amount of joysticks here */
|
||||||
|
#define JOYCOUNT 2
|
||||||
|
|
||||||
|
/* Set up event to read from */
|
||||||
|
#define INPUT_PATH "/dev/input/by-path/platform-i8042-serio-0-event-kbd"
|
||||||
|
|
||||||
|
|
||||||
|
/* Now follows keymapping, do not touch ifdef */
|
||||||
|
#ifdef H_IN_CASE
|
||||||
#define KEYMAP(in_key, out_key, out_type, device, val) \
|
#define KEYMAP(in_key, out_key, out_type, device, val) \
|
||||||
case in_key: \
|
case in_key: \
|
||||||
je.type = out_type; \
|
je.type = out_type; \
|
||||||
@ -37,3 +49,6 @@ KEYMAP(KEY_Q, BTN_2, EV_KEY, 1, )
|
|||||||
|
|
||||||
/* Yellow button */
|
/* Yellow button */
|
||||||
KEYMAP(KEY_2, BTN_3, EV_KEY, 1,)
|
KEYMAP(KEY_2, BTN_3, EV_KEY, 1,)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
14
map.c
14
map.c
@ -21,8 +21,8 @@
|
|||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <linux/uinput.h>
|
#include <linux/uinput.h>
|
||||||
|
|
||||||
#define INPUT_PATH "/dev/input/by-path/platform-i8042-serio-0-event-kbd"
|
#include "custom_map.h"
|
||||||
/*#define INPUT_PATH "/dev/input/by-path/platform-i8042-serio-0-event-kbd"*/
|
|
||||||
#define UINPUT_PATH "/dev/uinput"
|
#define UINPUT_PATH "/dev/uinput"
|
||||||
|
|
||||||
/* Reverse mapping, for later use */
|
/* Reverse mapping, for later use */
|
||||||
@ -50,7 +50,7 @@ static int get_key_num(char* name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int js[2];
|
static int js[JOYCOUNT];
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
* - Add file parsing / reading
|
* - Add file parsing / reading
|
||||||
@ -59,7 +59,7 @@ static int js[2];
|
|||||||
|
|
||||||
void free_js(int sig) {
|
void free_js(int sig) {
|
||||||
int j;
|
int j;
|
||||||
for(j = 0; j < 2; j++) {
|
for(j = 0; j < JOYCOUNT; j++) {
|
||||||
printf("Freeing joystick: %d\n", j);
|
printf("Freeing joystick: %d\n", j);
|
||||||
if (ioctl(js[j], UI_DEV_DESTROY) < 0) {
|
if (ioctl(js[j], UI_DEV_DESTROY) < 0) {
|
||||||
perror("Error freeing joystick");
|
perror("Error freeing joystick");
|
||||||
@ -103,8 +103,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(j = 0; j < JOYCOUNT; j++) {
|
||||||
for(j = 0; j < 2; 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));
|
||||||
js[j] = open(UINPUT_PATH, O_WRONLY | O_NONBLOCK);
|
js[j] = open(UINPUT_PATH, O_WRONLY | O_NONBLOCK);
|
||||||
@ -147,7 +146,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
|
|
||||||
/* Allocate device info */
|
/* Allocate device info */
|
||||||
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "key2joy:1");
|
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "key2joy:%d", j);
|
||||||
|
|
||||||
uidev.id.bustype = BUS_USB;
|
uidev.id.bustype = BUS_USB;
|
||||||
uidev.id.vendor = 0x42;
|
uidev.id.vendor = 0x42;
|
||||||
@ -181,6 +180,7 @@ int main(int argc, char** argv) {
|
|||||||
if (e.type == EV_KEY && e.value != 2) {
|
if (e.type == EV_KEY && e.value != 2) {
|
||||||
switch(e.code) {
|
switch(e.code) {
|
||||||
|
|
||||||
|
#define H_IN_CASE
|
||||||
#include "custom_map.h"
|
#include "custom_map.h"
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user