diff --git a/led-badge-11x44.py b/led-badge-11x44.py index 43fe6b3..65b9059 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -495,34 +495,6 @@ if __name__ == '__main__': (No "rotation" or "smoothing"(?) effect can be expected, though) """ % sys.argv[0]) args = parser.parse_args() - if have_pyhidapi: - devinfo = pyhidapi.hid_enumerate(0x0416, 0x5020) - # dev = pyhidapi.hid_open(0x0416, 0x5020) - else: - dev = usb.core.find(idVendor=0x0416, idProduct=0x5020) - - if have_pyhidapi: - if devinfo: - dev = pyhidapi.hid_open_path(devinfo[0].path) - print("using [%s %s] int=%d page=%s via pyHIDAPI" % ( - devinfo[0].manufacturer_string, devinfo[0].product_string, devinfo[0].interface_number, devinfo[0].usage_page)) - else: - print("No led tag with vendorID 0x0416 and productID 0x5020 found.") - print("Connect the led tag and run this tool as root.") - sys.exit(1) - else: - if dev is None: - print("No led tag with vendorID 0x0416 and productID 0x5020 found.") - print("Connect the led tag and run this tool as root.") - sys.exit(1) - try: - # win32: NotImplementedError: is_kernel_driver_active - if dev.is_kernel_driver_active(0): - dev.detach_kernel_driver(0) - except: - pass - dev.set_configuration() - print("using [%s %s] bus=%d dev=%d" % (dev.manufacturer, dev.product, dev.bus, dev.address)) if args.preload: for file in args.preload: @@ -571,11 +543,32 @@ if __name__ == '__main__': sys.exit(1) if have_pyhidapi: + devinfo = pyhidapi.hid_enumerate(0x0416, 0x5020) + # dev = pyhidapi.hid_open(0x0416, 0x5020) + if devinfo: + dev = pyhidapi.hid_open_path(devinfo[0].path) + print("using [%s %s] int=%d page=%s via pyHIDAPI" % ( + devinfo[0].manufacturer_string, devinfo[0].product_string, devinfo[0].interface_number, devinfo[0].usage_page)) + else: + print("No led tag with vendorID 0x0416 and productID 0x5020 found.") + print("Connect the led tag and run this tool as root.") + sys.exit(1) pyhidapi.hid_write(dev, buf) + pyhidapi.hid_close(dev) else: + dev = usb.core.find(idVendor=0x0416, idProduct=0x5020) + if dev is None: + print("No led tag with vendorID 0x0416 and productID 0x5020 found.") + print("Connect the led tag and run this tool as root.") + sys.exit(1) + try: + # win32: NotImplementedError: is_kernel_driver_active + if dev.is_kernel_driver_active(0): + dev.detach_kernel_driver(0) + except: + pass + dev.set_configuration() + print("using [%s %s] bus=%d dev=%d" % (dev.manufacturer, dev.product, dev.bus, dev.address)) for i in range(int(len(buf) / 64)): time.sleep(0.1) dev.write(1, buf[i * 64:i * 64 + 64]) - - if have_pyhidapi: - pyhidapi.hid_close(dev)