Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import usb.core
- import usb.util
- print("Hello!")
- dev = usb.core.find(idVendor=0x04d9,idProduct=0xa070) #Found this using lsusb and also from the USBlyzer.
- #Can be found by name "Holtek gaming mouse" or "Anker 2000 DPI Game Mouse" other names also exist.
- interface = 1
- if dev is None:
- raise ValueError("Device is not connected")
- if dev.is_kernel_driver_active(interface) is True:
- try:
- dev.detach_kernel_driver(interface)
- except usb.core.USBError as e:
- raise ValueError("Failed to detatch kernel driver: %s" % str(e))
- dev.detach_kernel_driver(1) #Interface 0 seems to be what we use.
- usb.util.claim_interface(dev, interface)
- dev.set_interface_altsetting(interface=interface,alternate_setting=0)
- #Hardcoded commands just for testing. (Length is always 8 bytes?)
- start = [0x07, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00] #This is always sent before sending settings to the mouse.
- end = [0x07, 0x13, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00] #This is always sent after the settings have been sent to the mouse.
- color1 = [0x07, 0x09, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00] #This sets the color to blue
- bnm1 = [0x07, 0x0C, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00] #This sets the brightness to high and pulse mode to fast.
- #bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001 from USBlyzer
- dev.ctrl_transfer(bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001, data_or_wLength=start,timeout=1000) #Fails at here
- dev.ctrl_transfer(bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001, data_or_wLength=color1,timeout=1000)
- dev.ctrl_transfer(bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001, data_or_wLength=bnm1,timeout=1000)
- dev.ctrl_transfer(bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001, data_or_wLength=end,timeout=1000)
- print("End")
- usb.util.release_interface(dev, interface)
- dev.attach_kernel_driver(interface)
- print("Released interface and attached kernel driver(?)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement