Skip to content

Instantly share code, notes, and snippets.

@KrisDevelopment
Forked from dnmodder/fixcontroller.py
Last active April 11, 2024 22:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KrisDevelopment/8d5be0a579e2a54d5f169b64c2da255e to your computer and use it in GitHub Desktop.
Save KrisDevelopment/8d5be0a579e2a54d5f169b64c2da255e 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
# A shell script wrapper generation for externally managed environemnts (eg. deb12).
if not os.path.exists("run.sh"):
with open("run.sh", "w") as f:
shell_src = """#!/bin/bash
python3 -m venv venv
source venv/bin/activate
pip uninstall pyusb
pip install pyusb
echo "Running fixcontroller.py"
python3 fixcontroller.py
deactivate
"""
f.write(shell_src)
os.chmod("run.sh", 0o755)
print("Shell script created. Run it with ./run.sh")
# run the shell script
os.system("sudo ./run.sh")
exit()
# Gamepad USB fix
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)
print("Fixing controller...")
for d in dev:
if d.idVendor == 0x045e and d.idProduct == 0x028e:
d.ctrl_transfer(0xc1, 0x01, 0x0100, 0x00, 0x14)
print("Controller fixed")
finally:
sys.exit()
@Grimish-ng
Copy link

Getting an endless loop while polling my Guilikong controller. This seems like the logical solution but its not working for me at the moment.
usb 5-2.2: USB disconnect, device number 35
kernel: xpad 5-2.2:1.0: xpad_try_sending_next_out_packet - usb_submit_urb failed with result -19
kernel: usb 5-2.2: new full-speed USB device number 36 using xhci_hcd
kernel: usb 5-2.2: New USB device found, idVendor=045e, idProduct=028e, bcdDevice= 1.10
kernel: usb 5-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
kernel: usb 5-2.2: Product: Controller
kernel: usb 5-2.2: Manufacturer: ZhiXu

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