feat(led-tool): browser settings editor with Web Serial
Add static editor, host_ports filtering, Flask /editor and REST APIs for ports and led-cli read/write; document standalone and embedded use. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
25
host_ports.py
Normal file
25
host_ports.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Host serial port list filtering for led-tool /ports API."""
|
||||
import re
|
||||
|
||||
# Exclude /dev/ttyS2 and higher (keep ttyS0, ttyS1; keep ttyACM*, ttyUSB*, etc.)
|
||||
_TTYS_HIGH = re.compile(r"^/dev/ttyS([2-9]|[1-9]\d+)$")
|
||||
|
||||
|
||||
def include_host_serial_device(device: str) -> bool:
|
||||
return not _TTYS_HIGH.match(device or "")
|
||||
|
||||
|
||||
def _is_na(value: str) -> bool:
|
||||
return (value or "").strip().lower() in ("n/a", "na")
|
||||
|
||||
|
||||
def include_host_serial_port(port: dict) -> bool:
|
||||
if not include_host_serial_device(port.get("device", "")):
|
||||
return False
|
||||
if _is_na(port.get("description")) or _is_na(port.get("hwid")):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def filter_port_dicts(ports: list) -> list:
|
||||
return [p for p in ports if include_host_serial_port(p)]
|
||||
Reference in New Issue
Block a user