Last active
June 23, 2017 04:27
-
-
Save ToadKing/30d65150410df13763f26f45abbd3700 to your computer and use it in GitHub Desktop.
pro controller stuffs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Original Author: Michael Lelli <toadking@toadking.com> | |
import usb.core | |
import usb.util | |
import os | |
dev = usb.core.find(idVendor=0x057e, idProduct=0x2009) | |
if dev is None: | |
raise ValueError('pro controller not found') | |
reattach = False | |
if os.name != 'nt' and dev.is_kernel_driver_active(0): | |
reattach = True | |
dev.detach_kernel_driver(0) | |
dev.set_configuration() | |
cfg = dev.get_active_configuration() | |
intf = cfg[(0,0)] | |
out_ep = usb.util.find_descriptor( | |
intf, | |
custom_match = \ | |
lambda e: \ | |
usb.util.endpoint_direction(e.bEndpointAddress) == \ | |
usb.util.ENDPOINT_OUT) | |
in_ep = usb.util.find_descriptor( | |
intf, | |
custom_match = \ | |
lambda e: \ | |
usb.util.endpoint_direction(e.bEndpointAddress) == \ | |
usb.util.ENDPOINT_IN) | |
# make sure we read all pending packets | |
try: | |
for i in range(1, 10): | |
data = in_ep.read(64, 100) | |
print(''.join('{:02x}'.format(x) for x in data)) | |
except: | |
pass | |
out_ep.write([0x80, 0x02]) | |
data = in_ep.read(64) | |
print(''.join('{:02x}'.format(x) for x in data)) | |
out_ep.write([0x80, 0x04]) | |
while 1: | |
try: | |
data = in_ep.read(64, 1000) | |
print(''.join('{:02x}'.format(x) for x in data)) | |
except (KeyboardInterrupt, SystemExit): | |
break | |
except: | |
raise | |
if reattach: | |
dev.attach_kernel_driver(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment