暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reset.py 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. import usb.core
  3. import usb.util
  4. CUSTOM_RQ_ECHO = 0 # send back wValue and wIndex, for testing comms reliability
  5. CUSTOM_RQ_RESET = 1 # reset to bootloader
  6. CUSTOM_RQ_GET = 2 # get ldr value
  7. def is_target_device(dev):
  8. if dev.manufacturer == "xythobuz.de" and dev.product == "AutoBrightness":
  9. return True
  10. return False
  11. # find our device
  12. dev = usb.core.find(idVendor=0x16c0, idProduct=0x05dc, custom_match=is_target_device)
  13. # was it found?
  14. if dev is None:
  15. raise ValueError('Device not found')
  16. # configure the device
  17. dev.set_configuration()
  18. # echo
  19. r = dev.ctrl_transfer(usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_IN, CUSTOM_RQ_ECHO, 42, 23, 4)
  20. print("echo", r)
  21. # reset
  22. r = dev.ctrl_transfer(usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_IN, CUSTOM_RQ_RESET, 0, 0, 1)
  23. print("reset-err", r)
  24. # value
  25. r = dev.ctrl_transfer(usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_IN, CUSTOM_RQ_GET, 0, 0, 2)
  26. print("value", r)
  27. # reset ok
  28. r = dev.ctrl_transfer(usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_IN, CUSTOM_RQ_RESET, 42, 23, 1)
  29. print("reset-ok", r)