Skip to content

Instantly share code, notes, and snippets.

@hangst
Last active July 7, 2020 17:08
Show Gist options
  • Save hangst/e18b426ffaef6dbbc59f7657d4e21c7f to your computer and use it in GitHub Desktop.
Save hangst/e18b426ffaef6dbbc59f7657d4e21c7f to your computer and use it in GitHub Desktop.
Configure Corsair M55 without iCUE
#!/usr/bin/env python3
import argparse
import usb
def find_interface(dev):
for config in dev:
for iface in config:
ep_out, ep_in = None, None
for ep in iface:
dir = usb.util.endpoint_direction(ep.bEndpointAddress)
if dir == usb.util.ENDPOINT_OUT: ep_out = ep.bEndpointAddress
elif dir == usb.util.ENDPOINT_IN : ep_in = ep.bEndpointAddress
if ep_out is not None and ep_in is not None:
return iface.bInterfaceNumber, ep_in, ep_out
raise Exception("Could not find interface with both IN and OUT endpoints")
class Device(object):
def __init__(self, idVendor, idProduct):
self.dev = usb.core.find(idVendor=idVendor, idProduct=idProduct)
if self.dev is None:
raise Exception("Device %s:%s not found" % (idVendor, idProduct))
self.iface, self.ep_in, self.ep_out = find_interface(self.dev)
if not self.dev.is_kernel_driver_active(self.iface):
raise Exception("Interface %s not active" % self.iface)
self.dev.detach_kernel_driver(self.iface)
usb.util.claim_interface(self.dev, self.iface)
def __enter__(self): return self
def __exit__(self, *_):
usb.util.release_interface(self.dev, self.iface)
self.dev.attach_kernel_driver(self.iface)
def write(self, data): self.dev.write(self.ep_out, data)
def setup_m55(args):
with Device(idVendor=0x1b1c, idProduct=0x1b70) as dev:
dev.write([0x08, 0x01, 0x02, 0x00, args.brightness])
dev.write([0x08, 0x01, 0x03, 0x00, 0x02]) # Software mode
dev.write([0x08, 0x01, 0x20, 0x00, 0x00, args.dpi_value // 250 - 1])
dev.write([0x08, 0x01, 0x52, 0x00, args.left_hand])
dev.write([0x08, 0x0d, 0x00, 0x01]) # Configure RGB LEDs
dev.write([0x08, 0x06, 0x00, 0x06, 0x00, 0x00, 0x00,
args.rgb_dpi[0], args.rgb_logo[0],
args.rgb_dpi[1], args.rgb_logo[1],
args.rgb_dpi[2], args.rgb_logo[2], 0xff])
dev.write([0x08, 0x0d, 0x00, 0x02]) # Configure buttons
dev.write([0x08, 0x06, 0x00, 0x08, 0x00, 0x00, 0x00,
args.button_l , args.button_r , args.button_m,
args.button_lb, args.button_lf,
args.button_rb, args.button_rf])
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--dpi_value" , help="DPI value from 250 to 12400" , default=2000, type=int , metavar="")
parser.add_argument("--rgb_logo" , help="Logo LED color" , default=[ 0,16,32], type=int, nargs=3, metavar=("R", "G", "B"))
parser.add_argument("--rgb_dpi" , help="DPI indicator LED color" , default=[32,32,32], type=int, nargs=3, metavar=("R", "G", "B"))
parser.add_argument("--brightness", help="LED brightness" , default=255 , type=int, metavar="")
parser.add_argument("--left_hand" , help="Left hand mode" , default=False, type=bool, metavar="")
parser.add_argument("--button_l" , help="Enable left button" , default=True , type=bool, metavar="")
parser.add_argument("--button_r" , help="Enable right button" , default=True , type=bool, metavar="")
parser.add_argument("--button_m" , help="Enable middle button" , default=False, type=bool, metavar="")
parser.add_argument("--button_lb" , help="Enable left side back button" , default=False, type=bool, metavar="")
parser.add_argument("--button_lf" , help="Enable left side front button" , default=False, type=bool, metavar="")
parser.add_argument("--button_rb" , help="Enable right side back button" , default=False, type=bool, metavar="")
parser.add_argument("--button_rf" , help="Enable right side front button", default=False, type=bool, metavar="")
setup_m55(parser.parse_args())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment