Skip to content

Commit

Permalink
add board cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed May 21, 2024
1 parent c8aab61 commit c01ed6c
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@


class Detector:
@staticmethod
def detect_linux_board() -> Optional[FlightController]:
last_detected_linux_board: Optional[FlightController] = None
misses = 0 # tracker for the number of times a Linux board was not detected in a row

@classmethod
def detect_linux_board(cls) -> Optional[FlightController]:
"""Returns Linux board if connected.
Check for connection using the sensors on the I²C and SPI buses.
Expand Down Expand Up @@ -50,12 +53,20 @@ def is_argonot_r1_connected() -> bool:
logger.debug("Trying to detect Linux board.")
if is_navigator_r5_connected():
logger.debug("Navigator R5 detected.")
return FlightController(name="Navigator", manufacturer="Blue Robotics", platform=Platform.Navigator)
board = FlightController(name="Navigator", manufacturer="Blue Robotics", platform=Platform.Navigator)
if is_argonot_r1_connected():
logger.debug("Argonot R1 detected.")
return FlightController(name="Argonot", manufacturer="SymbyTech", platform=Platform.Argonot)
board = FlightController(name="Argonot", manufacturer="SymbyTech", platform=Platform.Argonot)
if board:
cls.misses = 0
cls.last_detected_linux_board = board
return board
logger.debug("No Linux board detected.")
return None
cls.misses += 1
if cls.misses > 3:
cls.last_detected_linux_board = None
logger.debug(f"Returning ached Linux board: {cls.last_detected_linux_board}")
return cls.last_detected_linux_board

@staticmethod
def is_serial_bootloader(port: SysFS) -> bool:
Expand Down

0 comments on commit c01ed6c

Please sign in to comment.