From 8211cafd394b8f2eedb7ecbbc7ac238258c74c3c Mon Sep 17 00:00:00 2001 From: "Dirk Hillbrecht (laptop)" Date: Tue, 22 Aug 2023 16:35:36 +0200 Subject: [PATCH] Split data for sending through HID API into appropriate chunks Each chunk must not be larger than 64 bytes, report ID must be prepended to each chunk. --- led-badge-11x44.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/led-badge-11x44.py b/led-badge-11x44.py index ac66a8f..179db19 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -419,6 +419,7 @@ def header(lengths, speeds, modes, blink, ants, brightness=100): parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description='Upload messages or graphics to a 11x44 led badge via USB HID.\nVersion %s from https://github.com/jnweiger/led-badge-ls32\n -- see there for more examples and for updates.' % __version, epilog='Example combining image and text:\n sudo %s "I:HEART2:you"' % sys.argv[0]) parser.add_argument('-t', '--type', default='11x44', help="Type of display: supported values are 12x48 or (default) 11x44. Rename the program to led-badge-12x48, to switch the default.") +parser.add_argument('-H', '--hid', default='0', help="Set to 1 to ensure connect via HID API, program will then not fallback to usb.core library") parser.add_argument('-s', '--speed', default='4', help="Scroll speed (Range 1..8). Up to 8 comma-separated values") parser.add_argument('-B', '--brightness', default='100', help="Brightness for the display in percent: 25, 50, 75, or 100") parser.add_argument('-m', '--mode', default='0', help="Up to 8 mode values: Scroll-left(0) -right(1) -up(2) -down(3); still-centered(4); animation(5); drop-down(6); curtain(7); laser(8); See '--mode-help' for more details.") @@ -453,6 +454,8 @@ if have_pyhidapi: devinfo = pyhidapi.hid_enumerate(0x0416, 0x5020) #dev = pyhidapi.hid_open(0x0416, 0x5020) else: + if args.hid != "0": + sys.exit("HID API access is needed but not initialized. Fix your setup") dev = usb.core.find(idVendor=0x0416, idProduct=0x5020) if have_pyhidapi: @@ -516,7 +519,12 @@ if len(buf) > 8192: sys.exit(1) if have_pyhidapi: - pyhidapi.hid_write(dev, buf) + for i in range(int(len(buf)/64)): + # sendbuf must contain "report ID" as first byte. "0" does the job here. + sendbuf=array('B',[0]) + # Then, put the 64 payload bytes into the buffer + sendbuf.extend(buf[i*64:i*64+64]) + pyhidapi.hid_write(dev,sendbuf) else: for i in range(int(len(buf)/64)): time.sleep(0.1)