I followed the guide on this page -> https://steamcommunity.com/app/221410/discussions/0/558748653738497361/ to get my generic usb wired gamepad to work on my notebook. But as mentioned in the guide, the initialisation has to be done on each reboot. Also, as mentioned in the guide the initialisation command has to be included in, and I quote, "/etc/rc.local or whatever your distro calls it". I need the location of this "rc.local" in Ubuntu 18.04 based distro.
Also, this is my first time connecting a gamepad, so I have done some mistakes along the way, like not assigning the correct key combination for the gamepad. This has resulted in multiple "js" files, like "js0", "js1", .... "js5" input devices, with the "js5" being the successful gamepad entry. Can these additional input "js" devices be removed?
Also, is there a different way to permanently register my gamepad as an input device?
If it helps, the command I used for the last (and the successful) time was: sudo xboxdrv --evdev /dev/input/event21 --evdev-absmap ABS_Z=x1,ABS_Y=y1,ABS_RX=x2,ABS_RZ=y2,ABS_HAT0X=dpad_x,ABS_HAT0Y=dpad_y --axismap -Y1=Y1,-Y2=Y2 --evdev-keymap BTN_TOP=x,BTN_TRIGGER=y,BTN_THUMB2=a,BTN_THUMB=b,BTN_BASE3=back,BTN_BASE4=start,BTN_TOP2=lb,BTN_PINKIE=rb,BTN_BASE=lt,BTN_BASE2=rt,BTN_BASE5=tl,BTN_BASE6=tr --mimic-xpad --silent &
This command showed me an output: Your Xbox/Xbox360 controller should now be available as: /dev/input/js5 /dev/input/event22
Please help.
OK, so I have nearly got this thing in order.
I had asked this question in two other forums also and the only answer I got pointed me to the SDL2 Gamepad Tool (http://generalarcade.com/gamepadtool/). This tool was supposed to register my gamepad without using the xboxdrv command. This tool did recognize my gamepad, gave a name to my gamepad as "DragonRise_Inc. Generic USB Joystick" rather than what was previously displayed as just "Generic USB Joystick" and I could use my gamepad in the game. But the mapping was wrong, i.e., the right d-pad button would accelerate my player and other anomalies. Even by manually mapping the buttons in this tool, the same behavior was found.
So, this tool, to a degree was kind of helpful (maybe as its name suggests, it would be more helpful for SDL2 based games, and maybe the game that I wanted to play with the gamepad is not SDL2 based.) The game that I want to play with my gamepad is 'Teddy Floppy Ear - The Race' on Steam Linux.
Next, I was left with the same first problem. I searched and searched and found a question in this very website that helped me. The page link is How can I execute command on startup (rc.local alternative) on Ubuntu 16.10 According to this page, Ubuntu >= 16.10 do not have rc.local file, but a kind person has given the instructions to make one. So I went ahead and created this file.
The commands given on that page, to create the rc.local file are:
Next, I was not happy with the additional js input devices, so I searched some more. My search brought me to these two pages: https://github.com/RetroPie/RetroPie-Setup/wiki/Universal-Controller-Calibration-&-Mapping-Using-xboxdrv and https://retropie.org.uk/forum/topic/7096/xboxdrv-guidance-needed These pages have very dedicated discussion about the xboxdrv command. From these pages I got the command 'sudo killall xboxdrv'. This command removed all the additional js input devices. And showed that calling the xboxdrv initialization command with the name of the gamepad is a better way than using the event number. I also found that the event number changes if there are more/less usb devices attached to the notebook. Here, the gamepad name registered through the SDL2 Gamepad Tool came handy.
Now, I have a working setup. I have the rc.local file with these contents:
The double "sudo killall xboxdrv" command is required in my setup, I do not know the exact reason, but without this double there is a problem of having an additional js input device listed.
The one catch is that, I have to attach the gamepad to the notebook before booting it. If I attach the gamepad after booting the notebook, the gamepad is not initialized. I could just run the commands manually after attaching the gamepad, but it not possible for everyone using my notebook.
My next step is to find a way to create a script file with the commands, so that I can just double click the script file after attaching the gamepad and this would initialize the gamepad. But I have not yet found a way to incorporate the sudo command in a simple script.
Edit (14 Aug 2018): Ok, so I now have a way to call the initialization script without using the rc.local file. This is a much better solution and works anytime I want to connect the gamepad. (I got this method from another forum where I had asked this question).
I created my initialization script at /home/mark/.my-controller.sh (here, replace 'mark' with the name of your user)
This .my-controller.sh file has the following code:
Next, in the /etc/sudoers file add this text (replace /home/mark with the name of your home):
Next, create the .desktop file that will call this script (replace "/home/mark" with the name of your home) (and, replace 'sakura' with 'gnome-terminal' if you use that):
Now, when you want to use the gamepad, first attach the gamepad to the PC, then open the .desktop file. this will open a terminal asking for your password. Enter your password and the script is run that initializes the gamepad.