pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by fruitbat on Thu 29th Jan 01:16
download | new post

  1. #!/usr/bin/python
  2. #Return IR device....
  3.  
  4. import usb,threading,time
  5. keep_going = True
  6.  
  7. #print dir(remote)
  8. #print "Vendor: ",remote.getString(remdev.iManufacturer,30)
  9. #print "Product: ",remote.getString(remdev.iProduct,30)
  10. #print "Serial: ",remote.getString(remdev.iSerialNumber,30)
  11. #for conf in remdev.configurations:
  12. #       print "Configuration:",conf.value
  13. #       for intf in conf.interfaces:
  14. #              print "\t Interface: ", intf[0].interfaceNumber
  15. #              for alt in intf:
  16. #                     print "\tAlt:",alt.alternateSetting
  17. #                     for ep in alt.endpoints:
  18. #                            print "\t\tEndpoint:",ep.address
  19. #                            print "\t\tType:",ep.type
  20. #                            print "\t\tMax packet size:",ep.maxPacketSize
  21. #                            print "\t\tInterval:",ep.interval
  22. #Endpoint 129 is the keyboard
  23. #Endpoint 130 is the mouse
  24.  
  25. class Interface(threading.Thread):
  26.         def getDevice(self,vendor,product):
  27.                 omnibus = usb.busses()
  28.                 for bus in omnibus:
  29.                         devices = bus.devices
  30.                         for dev in devices:
  31.                                 if dev.idVendor == vendor:
  32.                                         if dev.idProduct == product:
  33.                                                 #Will return the first device, dunno why you'd have 2 though..
  34.                                                 return dev
  35.                 return None
  36.         def __init__(self,interface):
  37.                 threading.Thread.__init__(self)
  38.                 self.interface = interface
  39.                 self.remdev = self.getDevice(4673,57344) #Hootek
  40.                 #self.remdev = self.getDevice(1894,516) #Cyberlink
  41.                 self.remote = self.remdev.open()
  42.                 self.remote.claimInterface(interface)
  43.                 self.endp = self.remdev.configurations[0].interfaces[interface][0].endpoints[0].address
  44.                 #self.remote.resetEndpoint(self.endp)
  45.                 print self.endp
  46.         def start(self):
  47.                 threading.Thread.start(self)
  48.                 print self.getName()
  49.         def run(self):
  50.                 while (keep_going):
  51.                         try:
  52.                                 data = self.remote.bulkRead(self.endp,8,500)
  53.                         except usb.USBError,e:
  54.                                 data = None
  55.                         if(data != None):
  56.                                 print self.getName(),":",str(data)
  57.                 print "Suicide ",self.getName()
  58.  
  59. # Setup threads
  60. keyboard = Interface(0)
  61. keyboard.setName("Keyboard")
  62. mouse = Interface(1)
  63. mouse.setName("Mouse")
  64. #Go....
  65. keyboard.start()
  66. mouse.start()
  67. print "Interfaces spawned"
  68. while (threading.activeCount() > 1):
  69.         try:
  70.                 time.sleep(1)
  71.         except KeyboardInterrupt:
  72.                 keep_going = False
  73. print "Bye Bye!"

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings