Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Original Author: Michael Lelli <toadking@toadking.com>
  4.  
  5. import usb.core
  6. import usb.util
  7. import os
  8.  
  9. dev = usb.core.find(idVendor=0x057e, idProduct=0x2009)
  10.  
  11. if dev is None:
  12. raise ValueError('pro controller not found')
  13.  
  14. reattach = False
  15. if os.name != 'nt' and dev.is_kernel_driver_active(0):
  16. reattach = True
  17. dev.detach_kernel_driver(0)
  18.  
  19. dev.set_configuration()
  20. cfg = dev.get_active_configuration()
  21. intf = cfg[(0,0)]
  22.  
  23. out_ep = usb.util.find_descriptor(
  24. intf,
  25. custom_match = \
  26. lambda e: \
  27. usb.util.endpoint_direction(e.bEndpointAddress) == \
  28. usb.util.ENDPOINT_OUT)
  29.  
  30. in_ep = usb.util.find_descriptor(
  31. intf,
  32. custom_match = \
  33. lambda e: \
  34. usb.util.endpoint_direction(e.bEndpointAddress) == \
  35. usb.util.ENDPOINT_IN)
  36.  
  37. out_ep.write([0x80, 0x02])
  38. data = in_ep.read(64)
  39. print(''.join('{:02x}'.format(x) for x in data))
  40. 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])
  41. data = in_ep.read(64)
  42. print(''.join('{:02x}'.format(x) for x in data))
  43. out_ep.write([0x80, 0x04])
  44. data = in_ep.read(64)
  45. print(''.join('{:02x}'.format(x) for x in data))
  46. out_ep.write([0x80, 0x02])
  47.  
  48. while 1:
  49. try:
  50. data = in_ep.read(64)
  51. print(''.join('{:02x}'.format(x) for x in data))
  52. except (KeyboardInterrupt, SystemExit):
  53. break
  54. except:
  55. raise
  56.  
  57. if reattach:
  58. dev.attach_kernel_driver(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement