Skip to content

Commit

Permalink
Phantom Multiple Port
Browse files Browse the repository at this point in the history
  • Loading branch information
kunwarsahni01 committed Dec 13, 2022
1 parent 4d0bb49 commit 55593a3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pros/serial/devices/vex/v5_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def natural_key(chunk: str):
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]
else:
raise ValueError(f'Invalid port type specified: {p_type}')
Expand Down Expand Up @@ -215,7 +219,7 @@ def can_compress(self):
def is_wireless(self):
version = self.query_system_version()
return version.product == V5Device.SystemVersion.Product.CONTROLLER and \
V5Device.SystemVersion.ControllerFlags.CONNECTED in version.product_flags
V5Device.SystemVersion.ControllerFlags.CONNECTED in version.product_flags

def generate_cold_hash(self, project: Project, extra: dict):
keys = {k: t.version for k, t in project.templates.items()}
Expand Down Expand Up @@ -835,7 +839,7 @@ def get_system_status(self) -> SystemStatus:
logger(__name__).debug('Sending ext 0x22 command')
version = self.query_system_version()
if (version.product == V5Device.SystemVersion.Product.BRAIN and version.system_version in Spec('<1.0.13')) or \
(version.product == V5Device.SystemVersion.Product.CONTROLLER and version.system_version in Spec('<1.0.0-0.70')):
(version.product == V5Device.SystemVersion.Product.CONTROLLER and version.system_version in Spec('<1.0.0-0.70')):
schema = '<x12B3xBI12x'
else:
schema = '<x12B3xBI12xB3x'
Expand Down Expand Up @@ -916,7 +920,7 @@ def kv_write(self, kv: str, payload: Union[Iterable, bytes, bytearray, str]):
payload = payload[:kv_to_max_bytes.get(kv, 254)] + "\0"
if isinstance(payload, str):
payload = payload.encode(encoding='ascii')
tx_fmt =f'<{len(encoded_kv)}s{len(payload)}s'
tx_fmt = f'<{len(encoded_kv)}s{len(payload)}s'
tx_payload = struct.pack(tx_fmt, encoded_kv, payload)
ret = self._txrx_ext_packet(0x2f, tx_payload, 1, check_length=False, check_ack=True)
logger(__name__).debug('Completed ext 0x2f command')
Expand Down Expand Up @@ -985,7 +989,8 @@ def _rx_ext_packet(cls, msg: Message, command: int, rx_length: int, check_ack: b
if len(msg) < rx_length and check_length:
raise VEXCommError(f'Received length is less than {rx_length} (got {len(msg)}).', msg)
elif len(msg) > rx_length and check_length:
ui.echo(f'WARNING: Recieved length is more than {rx_length} (got {len(msg)}). Consider upgrading the PROS (CLI Version: {get_version()}).')
ui.echo(
f'WARNING: Recieved length is more than {rx_length} (got {len(msg)}). Consider upgrading the PROS (CLI Version: {get_version()}).')
return msg

def _txrx_ext_packet(self, command: int, tx_data: Union[Iterable, bytes, bytearray],
Expand Down

0 comments on commit 55593a3

Please sign in to comment.