Skip to content

Instantly share code, notes, and snippets.

@dnmodder
Last active March 10, 2024 14:25
  • Star 43 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dnmodder/de2df973323b7c6acf45f40dc66e8db3 to your computer and use it in GitHub Desktop.
This script should no longer be necessary thanks to the latest changes made to the master branch of the xpad [https://github.com/paroj/xpad] driver, please give it a try and report any regressions you find.
#!/usr/bin/env python3
import os
import sys
try:
import usb.core
import usb.util
except ImportError:
print("First, install the pyusb module with PIP or your package manager.")
else:
if os.geteuid() != 0:
print("You need to run this script with sudo")
sys.exit()
dev = usb.core.find(find_all=True)
for d in dev:
if d.idVendor == 0x045e and d.idProduct == 0x028e:
d.ctrl_transfer(0xc1, 0x01, 0x0100, 0x00, 0x14)
finally:
sys.exit()
@AruMoon
Copy link

AruMoon commented May 8, 2021

Thank you for the fix! My gamepad 'GameSir G3w' now works great on MX Linux.

Edit: I notcied that you have to run the script each time after a reboot. It's no big deal, but is there a way to make the changes permanently?

If you still didn't resolved your question, add udev rule as in https://gist.github.com/dnmodder/de2df973323b7c6acf45f40dc66e8db3#gistcomment-3582029 or https://gist.github.com/pavel-kirienko/86b9d039151405451130a0fb3896887c

@adnanh
Copy link

adnanh commented Jun 15, 2021

Thank you!

This also fixes Corsair Esperanza EG106 wired PC/PS2/PS3 controller :-)

@amardhruva
Copy link

Had to modify this script to make it work with my ANT Esports GP100 controller. I have posted the modified script to https://github.com/flashrocket/shanwan-controller-fix.

@Barthezz666
Copy link

wow, its working on Trust GXT540
Bus 001 Device 005: ID 045e:028e Microsoft Corp. Xbox360 Controller

THANKS ~!

@amardhruva
Copy link

Guys. The xpad driver now has the shanwan controller support built in. No need for workaround scripts. You can install the new driver from https://github.com/paroj/xpad and help test the controller and iron out any problems.

@Technohacker
Copy link

@flashrocket any idea if they're planning on upstreaming those changes to mainline later?

@amardhruva
Copy link

@Technohacker No idea bud. @paroj may be able to let us know.

@paroj
Copy link

paroj commented Sep 21, 2021

these changes are now in https://github.com/paroj/xpad master. If they turn out to work without side-effects, we can think of sending them to linux upstream.

@lumin9ry
Copy link

thank you so much for this

@amardhruva
Copy link

@Lumin4ry you can use the new xpad driver itself instead of using the script.

@TryToWork6354
Copy link

TryToWork6354 commented Aug 9, 2022

(FIXED)when i try to execute the script it tells me to install the pyusb module even tho i installed it already. i don't know whats wrong
I install pyusb then i do "python fixcontroller.py" and then it says ''First, install the pyusb module with PIP or your package manager.''

I was using pythton 2.7 then i switch to python 3.8 and the it worked

@amardhruva
Copy link

If you are using ubuntu try installing using apt. That seems to work for me.

@Breakthru
Copy link

thank you so much for this fix.
Can confirm it makes my USB device 045e:028e work on Ubuntu 20.04 with kernel 5.15.0-52-generic
Both xpad kernel module and xboxdrv receive no events from the joystick until I run this fix, and then the controller works fine after.

@amardhruva
Copy link

@Breakthru have you tried using the updated xpad driver?

@Breakthru
Copy link

Breakthru commented Nov 12, 2022 via email

@amardhruva
Copy link

Try the one in paroj xpad repo with branch fantech. It has all the fixes for the game pad and needs more testing.

@itsSagarBro
Copy link

(FIXED)when i try to execute the script it tells me to install the pyusb module even tho i installed it already. i don't know whats wrong I install pyusb then i do "python fixcontroller.py" and then it says ''First, install the pyusb module with PIP or your package manager.''

I was using pythton 2.7 then i switch to python 3.8 and the it worked

I'm facing the same problem, Please tell me how you managed to fix this issue.

@amardhruva
Copy link

@itsSagarBro
Two options.

sudo apt install python3-pyusb
sudo pip3 install pyusb

@Breakthru
Copy link

@amardhruva I have tried the xpad kernel driver and can confirm it fixes the problem without having to run the workaround script.

@zyriab
Copy link

zyriab commented Nov 27, 2022

Thank you! I've tried everything on the net and this fixed my controller being detected but not outputting anything on Kali Linux 6.0.0

@alfem
Copy link

alfem commented Jun 13, 2023

Unfortunately this script does nothing in my G-LAB Thorium Gamepad (detected as Shanwan Android gamepad), even when usb ids are 25a7:fa23 :-(

@alfem
Copy link

alfem commented Jun 13, 2023

Hi @dnmodder, Could you give me a clue of how to extract the required hex sequence from the wireshark usb capture? I suppose control sequence must be among the Configuration Requests I read in my capture file, but I do not know what values are.

@zyriab
Copy link

zyriab commented Aug 20, 2023

Also works well on Ubuntu Budgie 22.04.3 LTS - Kernel 6.2.0-26-generic
Make sure to sudo apt install python3-usb first and run the script with sudo
I also have to run xboxdrv (and let it run) beforehand
You da man

@KrisDevelopment
Copy link

KrisDevelopment commented Feb 19, 2024

Here, if you have trouble with pip, try this: fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment