Created
November 22, 2018 11:41
-
-
Save tott/753d44545b1864b3f85a8e4314b2490b to your computer and use it in GitHub Desktop.
Read backlight for x230 / x330 taobao FHD mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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