Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/port-selection' into fea…
Browse files Browse the repository at this point in the history
…ture/port-selection
  • Loading branch information
Rocky14683 committed Feb 2, 2024
2 parents 74ba776 + 6c0501f commit 80f3b3e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pros/serial/devices/vex/v5_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,26 @@ def filter_v5_ports_mac(p, device):
# natural sort based on: https://stackoverflow.com/a/16090640
def natural_key(chunk: str):
return [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', chunk)]

brain_ports = []
ports = sorted(ports, key=lambda p: natural_key(p.device))
if p_type.lower() == 'user':
return [ports[1]]
elif p_type.lower() == 'system':
# check if ports contain the word Brain in the description and return that port
for port in ports:
if "Brain" in port.description:
return [port]
return [ports[0], *joystick_ports]
brain_ports.append(port)
if len(brain_ports) == 0:
return [ports[0], *joystick_ports]
elif len(brain_ports) == 1:
return [brain_ports[0]]
else:
target_port = click.prompt('Multiple {} ports were found. Please choose one: [{}]'
.format('v5', '|'.join([p.device for p in brain_ports])),
default=ports[0].device,
show_default=False,
type=click.Choice([p.device for p in brain_ports]))
return [target_port]
else:
raise ValueError(f'Invalid port type specified: {p_type}')
# these can now also be used as user ports
Expand Down

0 comments on commit 80f3b3e

Please sign in to comment.