Skip to content

Move UART device selection into uart_io.__connect()#10

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-uart-io-device-selection
Closed

Move UART device selection into uart_io.__connect()#10
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-uart-io-device-selection

Conversation

Copy link
Contributor

Copilot AI commented Feb 14, 2026

Device selection logic was duplicated across main.py, test_ultrasonic.py, and uart_raw.py. Moved it into uart_io.__connect() where it belongs.

Changes

  • uart_io.connect(): Made port parameter optional (defaults to None)

    • Auto-selects first USB device (/dev/ttyUSB* or /dev/ttyACM*) when port=None
    • Falls back to any available UART device
    • Raises RuntimeError if no devices found
  • Callers: Simplified to uart_dev.connect(baud_rate, timeout)

Before:

uart_dev = uart_io()
uart_devices = uart_dev.list_ports()
usb_devices = [d for d in uart_devices if 'USB' in d.device or 'ACM' in d.device]
selected = usb_devices[0] if usb_devices else uart_devices[0]
uart_dev.connect(selected.device, consts.UART_BAUD_RATE, consts.UART_TIMEOUT)

After:

uart_dev = uart_io()
uart_dev.connect(consts.UART_BAUD_RATE, consts.UART_TIMEOUT)

Port can still be specified explicitly: uart_dev.connect(baud_rate, timeout, port='/dev/ttyUSB0')

Original prompt

I think the uart io is currently choosing a device on main.py, but can you make it choose on the uart_io's __connect function?

Created from Copilot CLI via the copilot delegate command.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: rotarymars <144909199+rotarymars@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor device selection in uart_io's __connect function Move UART device selection into uart_io.__connect() Feb 14, 2026
Copilot AI requested a review from rotarymars February 14, 2026 02:20
@rotarymars rotarymars marked this pull request as ready for review February 15, 2026 07:59
Copilot AI review requested due to automatic review settings February 15, 2026 07:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors UART device selection by centralizing the auto-selection logic into the uart_io.__connect() method, eliminating code duplication across multiple entry points. The change makes the API cleaner by making the port parameter optional and handling device selection internally.

Changes:

  • Moved USB device auto-selection logic from callers into uart_io.__connect()
  • Made port parameter optional (defaults to None) with auto-selection when not specified
  • Updated parameter order to (baud_rate, timeout, port=None) for better ergonomics
  • Simplified all three callers (main.py, test_ultrasonic.py, uart_raw.py)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
modules/robot.py Added auto-selection logic in __connect() method; changed connect() signature to make port optional with default None
main.py Removed duplicate device selection code; simplified to call connect() with only baud_rate and timeout
test_ultrasonic.py Removed duplicate device selection code and unused sys import; simplified connection call
uart_raw.py Removed duplicate device selection code and unused sys import; simplified connection call

@rotarymars
Copy link
Member

Squash merged manually from local

@rotarymars rotarymars closed this Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments