Tighten serial detection for linux

This commit is contained in:
Joey Yakimowich-Payne 2025-11-25 17:51:21 -07:00
commit 5ce26f2181
No known key found for this signature in database
GPG key ID: 6BFE655FA5ABD1E1

View file

@ -97,12 +97,27 @@ DPAD_BUTTONS = {
def is_usb_serial(path: str) -> bool:
"""Heuristic for USB serial path prefixes."""
if path.startswith("/dev/tty.") and not path.startswith("/dev/tty.usb"):
"""
Heuristic for USB serial path prefixes (best-effort when VID/PID are missing).
Accepts common USB-adapter patterns; rejects generic /dev/tty* unless they
clearly indicate USB.
"""
lower = path.lower()
usb_prefixes = (
"/dev/ttyusb", # Linux USB serial
"/dev/ttyacm", # Linux CDC ACM
"/dev/cu.usb", # macOS cu/tty USB adapters
"/dev/tty.usb",
)
if lower.startswith(usb_prefixes):
return True
if "usb" in lower:
return True
if lower.startswith(("/dev/tty", "/dev/cu", "com")):
return False
if path.startswith("/dev/cu.") and not path.startswith("/dev/cu.usb"):
return False
return True
# Default to False for unknown paths; caller can include_non_usb to override.
return False
def is_usb_serial_port(port: list_ports_common.ListPortInfo) -> bool: