Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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)
- out_ep.write([0x80, 0x02])
- data = in_ep.read(64)
- print(''.join('{:02x}'.format(x) for x in data))
- out_ep.write([0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
- data = in_ep.read(64)
- print(''.join('{:02x}'.format(x) for x in data))
- out_ep.write([0x80, 0x04])
- data = in_ep.read(64)
- print(''.join('{:02x}'.format(x) for x in data))
- out_ep.write([0x80, 0x02])
- while 1:
- try:
- data = in_ep.read(64)
- print(''.join('{:02x}'.format(x) for x in data))
- except (KeyboardInterrupt, SystemExit):
- break
- except:
- raise
- if reattach:
- dev.attach_kernel_driver(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement