Move UART device selection into uart_io.__connect()#10
Closed
Conversation
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
Contributor
There was a problem hiding this comment.
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
portparameter optional (defaults toNone) 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 |
Member
|
Squash merged manually from local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Device selection logic was duplicated across
main.py,test_ultrasonic.py, anduart_raw.py. Moved it intouart_io.__connect()where it belongs.Changes
uart_io.connect(): Madeportparameter optional (defaults toNone)/dev/ttyUSB*or/dev/ttyACM*) whenport=NoneRuntimeErrorif no devices foundCallers: Simplified to
uart_dev.connect(baud_rate, timeout)Before:
After:
Port can still be specified explicitly:
uart_dev.connect(baud_rate, timeout, port='/dev/ttyUSB0')Original prompt
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.