Uart opening warning
This commit is contained in:
parent
92abe29340
commit
bd21dc5ea6
1 changed files with 12 additions and 4 deletions
|
|
@ -354,6 +354,14 @@ def try_open_uart(port: str, baud: int) -> Optional[PicoUART]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def open_uart_or_warn(port: str, baud: int, console: Console) -> Optional[PicoUART]:
|
||||||
|
try:
|
||||||
|
return PicoUART(port, baud)
|
||||||
|
except Exception as exc:
|
||||||
|
console.print(f"[yellow]Failed to open UART {port}: {exc}[/yellow]")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def start_rumble_listener(ctx: ControllerContext) -> threading.Thread:
|
def start_rumble_listener(ctx: ControllerContext) -> threading.Thread:
|
||||||
# No-op placeholder (rumble is polled in the main loop for hotplug safety).
|
# No-op placeholder (rumble is polled in the main loop for hotplug safety).
|
||||||
return None
|
return None
|
||||||
|
|
@ -532,7 +540,7 @@ def main() -> None:
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
console.print(f"[red]Failed to open controller {index}: {exc}[/red]")
|
console.print(f"[red]Failed to open controller {index}: {exc}[/red]")
|
||||||
continue
|
continue
|
||||||
uart = try_open_uart(port, args.baud) if port else None
|
uart = open_uart_or_warn(port, args.baud, console) if port else None
|
||||||
if uart:
|
if uart:
|
||||||
uarts.append(uart)
|
uarts.append(uart)
|
||||||
console.print(f"[green]Controller {index} ({instance_id}) paired to {port}[/green]")
|
console.print(f"[green]Controller {index} ({instance_id}) paired to {port}[/green]")
|
||||||
|
|
@ -581,7 +589,7 @@ def main() -> None:
|
||||||
if port_choice is None:
|
if port_choice is None:
|
||||||
continue
|
continue
|
||||||
ctx.port = port_choice
|
ctx.port = port_choice
|
||||||
uart = try_open_uart(port_choice, args.baud)
|
uart = open_uart_or_warn(port_choice, args.baud, console)
|
||||||
ctx.last_reopen_attempt = time.monotonic()
|
ctx.last_reopen_attempt = time.monotonic()
|
||||||
if uart:
|
if uart:
|
||||||
uarts.append(uart)
|
uarts.append(uart)
|
||||||
|
|
@ -668,7 +676,7 @@ def main() -> None:
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
console.print(f"[red]Hotplug open failed for controller {idx}: {exc}[/red]")
|
console.print(f"[red]Hotplug open failed for controller {idx}: {exc}[/red]")
|
||||||
continue
|
continue
|
||||||
uart = try_open_uart(port, args.baud) if port else None
|
uart = open_uart_or_warn(port, args.baud, console) if port else None
|
||||||
if uart:
|
if uart:
|
||||||
uarts.append(uart)
|
uarts.append(uart)
|
||||||
console.print(f"[green]Controller {idx} ({instance_id}) paired to {port}[/green]")
|
console.print(f"[green]Controller {idx} ({instance_id}) paired to {port}[/green]")
|
||||||
|
|
@ -713,7 +721,7 @@ def main() -> None:
|
||||||
# Reconnect UART if needed.
|
# Reconnect UART if needed.
|
||||||
if ctx.port and ctx.uart is None and (now - ctx.last_reopen_attempt) > 1.0:
|
if ctx.port and ctx.uart is None and (now - ctx.last_reopen_attempt) > 1.0:
|
||||||
ctx.last_reopen_attempt = now
|
ctx.last_reopen_attempt = now
|
||||||
uart = try_open_uart(ctx.port, args.baud)
|
uart = open_uart_or_warn(ctx.port, args.baud, console)
|
||||||
if uart:
|
if uart:
|
||||||
uarts.append(uart)
|
uarts.append(uart)
|
||||||
console.print(f"[green]Reconnected UART {ctx.port} for controller {ctx.controller_index}[/green]")
|
console.print(f"[green]Reconnected UART {ctx.port} for controller {ctx.controller_index}[/green]")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue