Skip to content

Commit 8116f0f

Browse files
committed
tools: improve flags for hidconsole
1 parent a0e1928 commit 8116f0f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/hidapi/hidconsole.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ def matchfn(bid, vid, pid, _a, _b):
136136
return {"vid": vid}
137137

138138
device = args.path
139+
d = None
139140
if not device:
140141
for d in hidapi.enumerate(matchfn):
141-
if (d.hidpp_short or d.hidpp_long) and (args.usb is None or args.usb.lower() == d.product_id.lower()):
142+
if (d.hidpp_short or d.hidpp_long) and (args.id is None or args.id.lower() == d.product_id.lower()):
142143
device = d.path
143144
break
144145
if not device:
@@ -151,7 +152,12 @@ def matchfn(bid, vid, pid, _a, _b):
151152
sys.exit(f"!! Failed to open {device}, aborting.")
152153
print(
153154
".. Opened device %r, vendor %r product %r serial %r."
154-
% (device, hidapi.get_manufacturer(handle), hidapi.get_product(handle), hidapi.get_serial(handle))
155+
% (
156+
device,
157+
hidapi.get_manufacturer(handle) or d.vendor_id if d else None,
158+
hidapi.get_product(handle) or d.product_id if d else None,
159+
hidapi.get_serial(handle),
160+
)
155161
)
156162
if args.hidpp:
157163
if hidapi.get_manufacturer(handle) is not None and hidapi.get_manufacturer(handle) != b"Logitech":
@@ -172,7 +178,7 @@ def _parse_arguments():
172178
arg_parser.add_argument("command", nargs="?", help="command to send (otherwise get commands from input)")
173179
group = arg_parser.add_mutually_exclusive_group()
174180
group.add_argument("-p", "--path", help="HID raw device to connect to (/dev/hidrawX); ")
175-
group.add_argument("-u", "--usb", help="USB model of device to connect to (XXXX)")
181+
group.add_argument("-i", "--id", help="product ID of device to connect to (XXXX)")
176182
return arg_parser.parse_args()
177183

178184

0 commit comments

Comments
 (0)