Tighten serial detection for linux
This commit is contained in:
parent
05ea1a3f91
commit
fba378e8e6
1 changed files with 20 additions and 5 deletions
|
|
@ -97,12 +97,27 @@ DPAD_BUTTONS = {
|
||||||
|
|
||||||
|
|
||||||
def is_usb_serial(path: str) -> bool:
|
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
|
return False
|
||||||
if path.startswith("/dev/cu.") and not path.startswith("/dev/cu.usb"):
|
# Default to False for unknown paths; caller can include_non_usb to override.
|
||||||
return False
|
return False
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def is_usb_serial_port(port: list_ports_common.ListPortInfo) -> bool:
|
def is_usb_serial_port(port: list_ports_common.ListPortInfo) -> bool:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue