Merge pull request #4 from mik-at/patch-1

Add macOS compatibiltiy
pull/1/head
Jürgen Weigert 6 years ago committed by GitHub
commit c6c0e9f870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      led-badge-11x44.py

@ -23,6 +23,9 @@
import sys, os, re, time, argparse
from array import array
if sys.platform == "darwin":
import pyhidapi
else:
import usb.core
__version = "0.6"
@ -335,8 +338,22 @@ 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()
if sys.platform == "darwin":
pyhidapi.hid_init()
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":
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.")
print("Connect the led tag and run this tool as root.")
@ -371,5 +388,11 @@ if needpadding:
# print(buf)
for i in range(int(len(buf)/64)):
time.sleep(0.1)
if sys.platform == "darwin":
pyhidapi.hid_write(dev, buf[i*64:i*64+64])
else:
dev.write(1, buf[i*64:i*64+64])
if sys.platform == "darwin":
pyhidapi.hid_close(dev)

Loading…
Cancel
Save