Skip to content

Commit

Permalink
scons: _check_ftdi(): refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Mar 5, 2024
1 parent 3c57722 commit 62bfa79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 8 additions & 3 deletions apio/managers/scons.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,17 @@ def _check_ftdi(board, board_data, ext_ftdi_id):
desc_pattern = f"^{board_desc}.*$"

# Match the discovered FTDI chips
ftdi_devices = System().get_ftdi_devices()

if len(ftdi_devices) == 0:
# -- Get the list of the connected FTDI devices
# -- (execute the command "lsftdi" from the apio System module)
system = System()
connected_devices = system.get_ftdi_devices()

if len(connected_devices) == 0:
# Board not available
raise AttributeError("board " + board + " not available")
for ftdi_device in ftdi_devices:

for ftdi_device in connected_devices:
index = ftdi_device.get("index")
# ftdi device indices can start at zero
if ext_ftdi_id is not None and ext_ftdi_id != index:
Expand Down
5 changes: 2 additions & 3 deletions apio/managers/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_ftdi_devices(self) -> list:
This list is obtained by running the "lsftdi" command
* OUTPUT: A list of objects with the FTDI devices
Ex. [{'index': '0', 'manufacturer': 'AlhambraBits',
Ex. [{'index': '0', 'manufacturer': 'AlhambraBits',
'description': 'Alhambra II v1.0A - B07-095'}]
It raises an exception in case of not being able to
Expand All @@ -141,7 +141,7 @@ def get_ftdi_devices(self) -> list:

# -- Get the list of the ftdi devices. It is read
# -- from the command stdout
# -- Ex: [{'index': '0', 'manufacturer': 'AlhambraBits',
# -- Ex: [{'index': '0', 'manufacturer': 'AlhambraBits',
# -- 'description': 'Alhambra II v1.0A - B07-095'}]
ftdi_devices = self._parse_ftdi_devices(result["out"])

Expand All @@ -152,7 +152,6 @@ def get_ftdi_devices(self) -> list:
# -- for reading the ftdi devices
raise RuntimeError("Error executing lsftdi")


def _run_command(self, command: str, silent=False) -> dict:
"""Execute the given system command
* INPUT:
Expand Down

0 comments on commit 62bfa79

Please sign in to comment.