Instantly share code, notes, and snippets.

Embed
What would you like to do?
Read backlight for x230 / x330 taobao FHD mod
#!/usr/bin/env python
import sys
import array
import usb.core
import usb.util
import os
path = "/tmp/backlight-value"
# decimal vendor and product values
dev = usb.core.find(idVendor=0x10c4, idProduct=0x83ce)
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
interface = 0
read_ep = usb.util.find_descriptor(
intf,
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
assert read_ep is not None
if dev.is_kernel_driver_active(interface) is True:
dev.detach_kernel_driver(interface)
usb.util.claim_interface(dev, interface)
while 1:
try:
data = dev.read(read_ep.bEndpointAddress,read_ep.wMaxPacketSize)
tmp = open(path, "w")
tmp.write("%d\r\n" % data[-1])
tmp.close()
except usb.core.USBError as e:
data = None
if e.args == ('Operation timed out',):
continue
usb.util.release_interface(dev, interface)
dev.attach_kernel_driver(interface)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment