MerlijnWajer / uinput-mapper

Maps input devices to (multiple) other (virtually, created) input devices. Supports cloning input devices and sharing them over the network. Very useful for applications and games that do not support certain input devices (like gamepads)
http://hetgrotebos.org/wiki/uinput-mapper
GNU General Public License v3.0
71 stars 11 forks source link

Need help to merge 2 joysticks into 1 #5

Open prog-amateur opened 5 years ago

prog-amateur commented 5 years ago

Hello, my question is not bug-related, but I think this is a used case which can help many people to easily use uinput-mapper.

Context : I have a Bartop (with Linux Debian), I play on it and I really enjoy. However, the Joystick is digital (ON/OFF only). Some games (racing, or walk moves in Mario/Zelda 3D, etc.) need an analog Joystick. So I have bought an analog Thumbstick which works well. However, when I try to set up the controls, the emulator considers 2 gamepads instead of one only.

Questions :

  1. How to know the joysticks names in order to use uinput-mapper ?
  2. Then, how can I merge them into one main game controller ?

Thank you very much.

MerlijnWajer commented 5 years ago

Hi, good question. Will be glad to help.

Can you run input-read on the /dev/input/eventX file which matches your two joysticks, and paste that here? (evtest is also fine)

prog-amateur commented 5 years ago

Thank you very much. As you can see, I am not a programmer expert, so it seems that I didn't succeed to install uinput-mapper well. Or maybe, I forgot something wrong (see below) :

What I am sure, is that I have many events, and to js (js0 and js1), so I guess those inputs are the joystick, is that correct ?

MerlijnWajer commented 5 years ago

You'd have to run it on /dev/input/event* files, not the /dev/input/js* files. The js* files are backed by an event* file, and you need to find the right ones.

prog-amateur commented 5 years ago

Sorry for my late reply, my thumbstick is broken (a soldering on the arduino module has broken ! so I have to solder it again). Anyway, the main panel is working :

** `ls -alh /dev/input/` gives this interesting line :


lrwxrwxrwx 1 root root   9 juil.  2 20:36 usb-DragonRise_Inc._Generic_USB_Joystick-event-joystick -> ../event4
lrwxrwxrwx 1 root root   6 juil.  2 20:36 usb-DragonRise_Inc._Generic_USB_Joystick-joystick -> ../js0
lrwxrwxrwx 1 root root   9 juil.  2 20:36 pci-0000:09:00.4-usb-0:1:1.0-event-joystick -> ../event4
lrwxrwxrwx 1 root root   6 juil.  2 20:36 pci-0000:09:00.4-usb-0:1:1.0-joystick -> ../js0

*** Also, using ./input-read /dev/input/event4 or ./input-read -C /dev/input/event4 or ./input-read -G /dev/input/event4 give the same error result :

Traceback (most recent call last):
  File "./input-read", line 6, in <module>
    import uinputmapper.linux_uinput
  File "/home/minitel/opt/uinput-mapper/uinputmapper/linux_uinput.py", line 3, in <module>
    import linux_input
  File "/home/minitel/opt/uinput-mapper/uinputmapper/linux_input.py", line 54, in <module>
    EV_SYN: syn,
NameError: name 'EV_SYN' is not defined

*** Last but not least, please find the cat /proc/bus/input/devices result :

I: Bus=0003 Vendor=0079 Product=0006 Version=0110
N: Name="DragonRise Inc.   Generic   USB  Joystick  "
P: Phys=usb-0000:09:00.4-1/input0
S: Sysfs=/devices/pci0000:00/0000:00:08.1/0000:09:00.4/usb5/5-1/5-1:1.0/0003:0079:0006.0001/input/input18
U: Uniq=
H: Handlers=event4 js0 
B: PROP=0
B: EV=20001b
B: KEY=fff00000000 0 0 0 0
B: ABS=30027
B: MSC=10
B: FF=107030000 0

I hope this will help to progress. Thank you again.

MerlijnWajer commented 5 years ago

Did you type make after git cloning uinput-mapper? That should fix the NameError.

MerlijnWajer commented 5 years ago

Did you ever figure this out?

Vegz78 commented 3 years ago

Hi @MerlijnWajer,

Great work and program, which I hope will solve my current problem!

I’m trying to achieve a similar thing as @prog-amateur; I want to merge two gamepads(both present at /dev/input/eventX and jsX) into a uniput (keyboard) device for a game that reads from only one /dev/input device, but can have 2 players which different button layouts.

The gamepads have the same input codes, example code 304 for BTN_SOUTH, which then for both gamepads needs to be remapped to different (keyboard) codes for each player as output to the same uinput device that the game can read; gamepad1 304 -> uinput 29 and gamepad2 -> uinput 100.

And it would also be very convenient if I could choose the event number that the new virtual/merged input device appears on, so that this new /dev/input/event15 could be hardcoded in the game’s controller config file?

UPDATE: It now seems to maps both controllers as intended, but only the first maps and outputs as expected, while the second controller gives an index out of bounds error: Traceback (most recent call last): File "./input-create", line 80, in <module> d = ofs[idx] IndexError: list index out of range verbose&error.log

This is the config file: config.py

And uinput-mapper is run like this from the console: ./input-read -C -D /dev/input/event11 /dev/input/event13 | ./input-create -C -v ./configs/arcade.py

If I try to increase the size of the of the nofd variable in input-create, it creates another uinput devices instead of mapping the two controllers to the same uinput device. Is this 2Input -> 1Output(uinput) possible to achieve out of the box, or with some small changes in the source code?

UPDATE2: Seems like setting idx in d = ofs[idx] to zero statically fixes the out of bounds issue and prevents the creation of a 2nd uinput device. So now my 2input->1output(uinput) case works great, thx!!! (https://github.com/Vegz78/McAirpos)

Would you be willing to update the source code, please, so that it indexes correctly for all cases with inputs >=< outputs(uinputs)?

Your help would be greatly appreciated and I’ll be sure to mention it in my ongoing project.

Hope to hear back from you soon!

Br, Vegard

MerlijnWajer commented 2 years ago

Hi @Vegz78 - sorry for my very delayed response, I was cleaning up my inbox and found this message. It looks like you already figured out some of the problems, and in fact continued working on uinput-mapper - maybe I should look at your efforts and merge it back into this repo? I also saw you ported it to Python 3!

Vegz78 commented 2 years ago

Hi @MerlijnWajer,

Thanks for your response and no worries; better late than never! ;-)

I really appreciate your work on uinput-mapper, which - with only a few modifications - solved all the challenges in my project.

Apart from some extra controller configs and my latest changes to uinput-mapper, which is more of a quick and dirty hybrid Frankenstein of Python 3 support combined with backward compatibility with Python 2.7 than a port, where I have not done or tested any more than exactly what was needed for it to run without errors for my use case, I also broke your 1 input to many outputs support by setting the above mentioned array to 0, to enable many to one support.

Since my fork of your project is mainly based on your efforts, you are of course welcome to use whatever you want from the uinput-mapper subtree in my repo.

Give me a wink if I can help you in any way, but being pretty noob to GitHub and given that I included your work as a subtree instead of a submodule with active links back to your repo, I am uncertain if and how I could contribute by making a pull request etc. So it is probably just as convenient for you that you just trawl through my code and keep/modify what you can use and discard the rest.

If I could suggest a feature/make a wish, it would be that your updated input-mapper project would support all 1:n, 1:1 and n:1 relationships between inputs and outputs, maybe as a config option(maybe it already does, but I never figured out the right config option, hehe…)

Keep up the great work!