Skip to content

Instantly share code, notes, and snippets.

@ToadKing
Last active June 23, 2017 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToadKing/30d65150410df13763f26f45abbd3700 to your computer and use it in GitHub Desktop.
Save ToadKing/30d65150410df13763f26f45abbd3700 to your computer and use it in GitHub Desktop.
pro controller stuffs
#!/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