12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
-
-
- import usb.core
- import usb.util
- import time
-
- CUSTOM_RQ_ECHO = 0
- CUSTOM_RQ_RESET = 1
- CUSTOM_RQ_GET = 2
- CUSTOM_RQ_RAW = 3
-
- max_comm_retries = 5;
-
- def is_target_device(dev):
- if dev.manufacturer == "xythobuz.de" and dev.product == "AutoBrightness":
- return True
- return False
-
-
- dev = usb.core.find(idVendor=0x16c0, idProduct=0x05dc, custom_match=is_target_device)
-
-
- if dev is None:
- raise ValueError('Device not found')
-
-
- dev.set_configuration()
-
- def read_val(req, w, a=0, b=0):
- for attempts in range(0, max_comm_retries):
- try:
- r = dev.ctrl_transfer(usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_IN, req, a, b, w)
- return int.from_bytes(r, "little")
- except usb.core.USBError as e:
- if attempts >= (max_comm_retries - 1):
- raise e
-
-
- if read_val(CUSTOM_RQ_ECHO, 4, 42, 23) != (42 | (23 << 16)):
- raise ValueError("invalid echo response")
-
-
- while True:
- v = read_val(CUSTOM_RQ_GET, 2)
- print(time.time(), ";", v, flush=True)
-
-
-
-
-
-
- time.sleep(0.25)
|