• entries
52
180
• views
43474

# Wireless USB gamepad working in Linux and Android Emulator!

1327 views

This will be a short technical one for anyone else facing the same problem. I can't pretend to have a clue what I was doing here, only the procedure I followed in the hope it will help others, I found little information online on this subject.

I am writing an Android game and want to put in gamepad support, for analogue controllers. This had proved incredibly difficult, because the Android Studio emulator has no built in support for trying out gamepad functionality. So I had bought a Tronsmart Mars G02 wireless gamepad (comes with a usb wireless dongle). It also supports bluetooth.

The problem I faced was that the gamepad worked fine on my Android tv box device, but wasn't working under Linux Mint, let alone in the emulator, and wasn't working via bluetooth on my tablet and phone. I needed it working in the emulator ideally to be able to debug (as the Android tv box was too far).

Here is how I solved it, for anyone else facing the same problem. Firstly the problem of getting the gamepad working and seen under linux, and then the separate problem of getting it seen under the Android emulator (this may work under Windows too).

## Under Linux

Unfortunately I couldn't get the bluetooth working as I didn't have up to date bluetooth, and none of my devices were seeing the gamepad. I plugged in the usb wireless dongle but no joy.

It turns out the way to find out what is going on with usb devices is to use the command:

lsusb

This gives a list of devices attached, along with a vendor id and device id (takes the form 20bc:5500).

It was identifying my dongle as an Xbox 360 controller. Yay! That was something at least, so I installed an xbox 360 gamepad driver by using:

sudo apt-get install xboxdrv

sudo xboxdrv --detach-kernel-driver

It still didn't seem to do anything, but I needed to test whether it worked so I installed a joystick test app, 'jstest-gtk' using apt-get.

The xbox gamepad showed up but didn't respond.

Then I realised I had read in the gamepad manual I might have to switch the controller mode for PC from D-input mode to X-input. I did this and it appeared as a PS3 controller (with a different USB id), and it was working in the jstest app!!

## Under Android Emulator

Next stage was to get it working in the Emulator. I gather the emulator used with Android Studio is qemu and I found this article:

I followed the instructions here, basically:

Navigate to emulator directory in the android sdk.

Then to run it from command line:

./emulator -avd YOUR_VM -qemu -usb -usbdevice host:1234:abcd

where the host is your usb vendor and id from lsusb command.

This doesn't work straight off, you need to give it a udev rule to be able to talk to the usb port. I think this gives it permission, I'm not sure.

Navigate to etc/udev/rules.d folder

You will need to create a file in there with your rules. You will need root privileges for this (choose to open the folder as root in Nemo or use the appropriate method for your OS).

I created a file called '10-local.rules' following the article.

In this I inserted the udev rule suggested in the stackoverflow article:

SUBSYSTEM!="usb", GOTO="end_skip_usb"
ATTRS{idVendor}=="2563", ATTRS{idProduct}=="0575", TAG+="uaccess"
LABEL="end_skip_usb"
SUBSYSTEM!="usb", GOTO="end_skip_usb"
ATTRS{idVendor}=="20bc", ATTRS{idProduct}=="5500", TAG+="uaccess"
LABEL="end_skip_usb"

Note that I actually put in two sets of rules because the usb vendor ID seemed to change once I had the emulator running, it originally gave me an UNKNOWN USB DEVICE error or some such in the emulator, so watch that the usb ID has not changed. I suspect only the latter one was needed in the end.

To get the udev rules 'refreshed', I unplugged and replugged the usb dongle. This may be necessary.

Once all this was done, and the emulator was 'cold booted' (you may need to wipe the data first for it to work) the emulator started, connected to the usb gamepad, and it worked!

This whole procedure was a bit daunting for me as a linux newbie, but if at first you don't succeed keep trying and googling. Because the usb device is simply passed to the emulator, the first step getting it recognised by linux itself may not be necessary, I'm not sure. And a modified version of the technique may work for getting a gamepad working under windows.

There are no comments to display.

## Create an account

Register a new account

• ### Similar Content

• I'm making a 2d platformer game as a learning experience, and I need a character and some backgrounds.
This game will make minimal revenue, because it'll be a free mobile game.
I'll give you more details if you respond.
Thanks.

• PROGRESS
Thought I'd reach out for some feedback on my little project. This is an android two-player game for top-down boxing matches. The core mechanics are all that I have accomplished thus far, later I want to add different configurations for your boxer (special effects, increased health or damage, etc) and maybe even a single player AI to practice against.

SCREENSHOTS
#1

*****************************************************************

#2

FEEDBACK
Right now the gameplay feedback I'm looking for is on the fundamental mechanics of the game.

One area of particular concern is the window of opportunity for a player to block after their opponent has begun a punch. Currently that window is one-tenth of a second, otherwise you will be to late to counter their blow. I want it to be difficult to successfully pull off a block and have it be something that requires real attention to accomplish. I'm wondering though if it isn't too difficult right now, which may encourage mindless button mashing, which is certainly not what I want to condone.

Another consideration is whether having three main actions (block, attack, charge) provides a good balance. My idea with having three main areas is that your two thumbs will have to leave one section uncovered at all times. This should result in hand movements that telegraph actions to the opponent.

Aside from these, any other constructive criticism is very welcome.

My game can be found at the Google Play Store here:

NOTE There is a known graphics error when performing a special punch. There are no doubt other unknown errors as well.

Thank you for your time, I hope you'll be able to find some fun in this little game!

• Random Number God has been updated to v1.1.0.
This is an incremental (although not idle) game about defeating randomized robots by rolling dice and playing cards that alter those dice and their effects.
Other than performance fixes, the game has been rebalanced from the ground up. Now it should progress in a more fluid fashion. An option to reset the game with a significant boost to your power has been added, allowing you to advance further than you could before.
There is also now an option to significantly speed up battle animations. Once you learn the rules of the game, a battle can easily take <2 min.

• i'm game designer without coding skills.
i came here looking for Companions with Compassion; i must Retrieve mobile gaming industry overview.
no matter where you live in this World; please step out it's about time. language barrier won't be problem between us.
startup is interesting, but im good.
• By MiTi
Dear everyone, this is my newest game, please check out and give me feedback. Thanks for your consideration.

Overview: Cross n Puzz is a creative and addicting word puzzle game. It not only challenges your brain but also improve memory and other types of cognitive function.

For IOS: https://itunes.apple.com/app/crossword-puzzle-image/id1435575074