From 0dd737bb0394a10bd7a47da9851dc4e55426d9ca Mon Sep 17 00:00:00 2001 From: mik-at Date: Sun, 5 May 2019 21:35:31 +0200 Subject: [PATCH 1/2] Update led-badge-11x44.py --- led-badge-11x44.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/led-badge-11x44.py b/led-badge-11x44.py index 6e80ca2..fd2d4f7 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -23,7 +23,10 @@ import sys, os, re, time, argparse from array import array -import usb.core +if sys.platform == "darwin": + import pyhidapi +else: + import usb.core __version = "0.6" @@ -335,16 +338,23 @@ parser.add_argument('--mode-help', action='version', help=argparse.SUPPRESS, ver (No "rotation" or "smothering"(?) effect can be expected, though) """ % sys.argv[0]) args = parser.parse_args() - -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) -if dev.is_kernel_driver_active(0): - dev.detach_kernel_driver(0) -dev.set_configuration() -print("using [%s %s] bus=%d dev=%d" % (dev.manufacturer, dev.product, dev.bus, dev.address)) +if sys.platform == "darwin": + pyhidapi.hid_init() + dev = pyhidapi.hid_open(0x0416, 0x5020) +else: + dev = usb.core.find(idVendor=0x0416, idProduct=0x5020) + +if sys.platform == "darwin": + print("using pyhidapi") +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) + if dev.is_kernel_driver_active(0): + dev.detach_kernel_driver(0) + 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: @@ -371,5 +381,8 @@ if needpadding: # print(buf) for i in range(int(len(buf)/64)): time.sleep(0.1) - dev.write(1, buf[i*64:i*64+64]) + if sys.platform == "darwin": + pyhidapi.hid_write(dev, buf[i*64:i*64+64]) + else: + dev.write(1, buf[i*64:i*64+64]) From c6f051bf9b2ac27a3d3f30b5e765afeff79f403d Mon Sep 17 00:00:00 2001 From: mik-at Date: Sun, 5 May 2019 21:57:42 +0200 Subject: [PATCH 2/2] Update led-badge-11x44.py --- led-badge-11x44.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/led-badge-11x44.py b/led-badge-11x44.py index fd2d4f7..e3c31ec 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -340,12 +340,19 @@ parser.add_argument('--mode-help', action='version', help=argparse.SUPPRESS, ver args = parser.parse_args() if sys.platform == "darwin": pyhidapi.hid_init() - dev = pyhidapi.hid_open(0x0416, 0x5020) + devinfo = pyhidapi.hid_enumerate(0x0416, 0x5020) + #dev = pyhidapi.hid_open(0x0416, 0x5020) else: dev = usb.core.find(idVendor=0x0416, idProduct=0x5020) if sys.platform == "darwin": - print("using pyhidapi") + if devinfo: + dev = pyhidapi.hid_open_path(devinfo[0].path) + print("using [%s %s] int=%d page=%s via HIDAPI" % (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.") @@ -386,3 +393,6 @@ for i in range(int(len(buf)/64)): else: dev.write(1, buf[i*64:i*64+64]) +if sys.platform == "darwin": + pyhidapi.hid_close(dev) +