Author Topic: How to multiple controllers on Linux  (Read 3333 times)

0 Members and 1 Guest are viewing this topic.

Offline Shevvek

  • 21
    • Steam
    • Twitter
How to multiple controllers on Linux
I recently got a CH Throttle and Fighterstick, thanks to viewers of my Twitch stream, and the first thing I wanted to do, of course, was use them to play Freespace. Turns out that Freespace right now only supports one controller, so I spent the weekend hacking together a way to combine the throttle and stick into a virtual device. That's easy on Windows, but I wasn't able to find anybody on Linux reporting success, so I thought I would share what I did. I use Kubuntu 14.04.

My starting point was this post: http://steamcommunity.com/app/2820/discussions/0/616189106604260432/. Below is the process I went through. Most of it is already mentioned in some way on the link, but I thought it might be helpful to present it all together. I'll organize this by topic, not by the order things need to happen, so make sure to read all of it before getting frustrated that it doesn't work.

Writing the Map

After downloading and compiling joymap, I had to figure out how to write a map file for my set up. This turns out not to be terribly difficult, since joymap comes with a PDF describing most of the options. Referring to this example was also helpful: http://www.triplesix.co.uk/CH-sidewinder.map.

Mostly, all I did was map buttons to buttons and axes to axes. I experimented with mapping the hat axes to buttons using the "plus" and "minus" flags, but I found the result either missed button presses or registered extra ones, so I wouldn't recommend that. As long as you map the hat axes to axis 16 and 17, anyway, Freespace will let you map the hat as buttons, so it's not really necessary to do that in the map file. I also was able to set up a "shift" mode, but Freespace currently doesn't recognize more than 32 buttons (something I only learned by dropping into IRC). If you want to set up a shift mode, try putting the "shift" flag between quotation (") marks.

evtest is the best way to test if your configuration is working. jscal and similar programs use a higher level abstraction and will lie to you about the configuration of the device, so don't use them. To test buttons without getting spammed by axis noise, I found the command evtest | grep -v 'SYN\|ABS' helpful.

Sometimes, incremental button numbering doesn't work, so you need to check evtest for the right "src" number for a particular button. That said, most buttons worked for me with incremental numbering, even though evtest showed numbers in the hundreds.

Fixing permissions

There were two sticking points that the user in the comments of the Steam discussion faced, and I encountered both. First, I found that when I ran ./loadmap, it gave control of my mouse cursor to the joystick, to great annoyance. The solution to this turns out to be simple. First, do xinput list, and find the virtual joystick listed under Pointers, then note the number of that device and do xinput disable 12, substituting the correct number for 12. Problem solved!

The second problem is that when you run evtest without root permissions, the only controllers you will see are the hardware devices and a virtual "code" device with an address like /dev/input/event256 or something like that. There are two things wrong with this picture: evtest can't actually access devices with index numbers that high, and even if it could, it would not register any input. What you really need is to access a virtual device that only root can see, in my case /dev/input/event20 (you can find it by running evtest with root permissions). All you need to do is change the permissions on that file, so run chmod o+r /dev/input/event20 (with root permissions, obviously). Now when you run evtest without root permissions, it should list the working virtual device. The working virtual device should also show up as an option in the Freespace launcher. Huzzah!

It is somewhat annoying to have to redo xinput and chmod every time you restart loadmap. I am sure there is a better way to solve both of those issues automatically, but it works, so I don't really feel like messing around with udev rules and whatnot. If anyone is motivated to come up with a better way to do it, hopefully this shows how to do it.

Compiling the things

In order to get my joystick and throttle working properly, I did have to hardcode some maximum and minimum values into loadmap and recompile it, according to the instructions in the Steam link. evtest allowed me to identify the range of motion of each axis. Since the example configuration he gives is also for a CH Throttle, I just copied and pasted his numbers for that part. It turns out that the CH Flightstick axes all run precisely 0 to 255.

I don't know if this is necessary, but on the advice of a nice fellow in the FreeSpace IRC, I compiled an Antipodes build of FSO. If you have trouble getting the game to recognize all of the mapped buttons, this might help. Anyway, it seems to work great for me.

I can now play Freespace with both joystick and throttle, and I only look forward to a future update when I can use more than 32 buttons and 1 hat in game.

 

Offline pecenipicek

  • Roast Chicken
  • 211
  • Powered by copious amounts of coffee and nicotine
    • Skype
    • Steam
    • Twitter
    • PeceniPicek's own deviantart page
Re: How to multiple controllers on Linux
i think you could've solved a bit of your issues by adding yourself to the joystick group... check permissions on the device files with ls -la
Skype: vrganjko
Ho, ho, ho, to the bottle I go
to heal my heart and drown my woe!
Rain may fall and wind may blow,
and many miles be still to go,
but under a tall tree I will lie!

The Apocalypse Project needs YOU! - recruiting info thread.

 

Offline ngld

  • Administrator
  • 29
  • Knossos dev
Re: How to multiple controllers on Linux
There were two sticking points that the user in the comments of the Steam discussion faced, and I encountered both. First, I found that when I ran ./loadmap, it gave control of my mouse cursor to the joystick, to great annoyance. The solution to this turns out to be simple. First, do xinput list, and find the virtual joystick listed under Pointers, then note the number of that device and do xinput disable 12, substituting the correct number for 12. Problem solved!
This might be a simpler and more permanent solution.

i think you could've solved a bit of your issues by adding yourself to the joystick group... check permissions on the device files with ls -la
It could also be the input group.

  

Offline pecenipicek

  • Roast Chicken
  • 211
  • Powered by copious amounts of coffee and nicotine
    • Skype
    • Steam
    • Twitter
    • PeceniPicek's own deviantart page
Re: How to multiple controllers on Linux
i think you could've solved a bit of your issues by adding yourself to the joystick group... check permissions on the device files with ls -la
It could also be the input group.
could be, dont have kubuntu on hand to check right now.
as i said, ls -l on the device itself should answer it :p
Skype: vrganjko
Ho, ho, ho, to the bottle I go
to heal my heart and drown my woe!
Rain may fall and wind may blow,
and many miles be still to go,
but under a tall tree I will lie!

The Apocalypse Project needs YOU! - recruiting info thread.