adafruit / Adafruit_Python_PlatformDetect

MIT License
59 stars 236 forks source link

Added support for Radxa Rock 5C #357

Closed hajimef closed 4 months ago

hajimef commented 4 months ago

I added support for Radxa Rock 5C. I also added support for Radxa Rock 5C to Adafruit_Blinka.

hajimef commented 4 months ago

Close. Can you just put the check for 5C before the 5? The reason is because the 5C would always match the 5 string as well.

Because each board is judged using an if statement, if the if statement for ROCK 5C is executed first, the result will be overwritten by the if statement for ROCK 5 that follows. For this reason, I have made the judgement for ROCK 5C happen last. It may be better to modify it to an if ... elif form rather than an if ... if form.

def _rock_pi_id(self) -> Optional[str]:
    """Check what type of Rock Pi board."""
    board_value = self.detector.get_device_model()
    board_value_upper = board_value.upper()
    board = None
    if board_value and "ROCK Pi S" in board_value:
        board = boards.ROCK_PI_S
    elif board_value and "ROCK PI 4" in board_value_upper:
        board = boards.ROCK_PI_4
    elif board_value and "ROCK PI E" in board_value_upper:
        board = boards.ROCK_PI_E
    elif self.detector.check_board_name_value() == "ROCK Pi X":
        board = boards.ROCK_PI_X
    elif board_value and "ROCK 5C" in board_value_upper:
        board = boards.ROCK_PI_5C
    elif board_value and "ROCK 5" in board_value_upper:
        board = boards.ROCK_PI_5
    elif board_value and "RADXA ROCK 4C+" in board_value_upper:
        board = boards.ROCK_PI_4_C_PLUS
    elif board_value and "RADXA ROCK 4SE" in board_value_upper:
        board = boards.ROCK_PI_4_SE
    elif board_value and "ROCK3 Model A" in board_value:
        board = boards.ROCK_PI_3A
    return board
makermelissa commented 4 months ago

Because each board is judged using an if statement, if the if statement for ROCK 5C is executed first, the result will be overwritten by the if statement for ROCK 5 that follows.

There isn't anything that is being "overwritten". An if/else if statement like this stops looking once it finds a match. So once it sees that "ROCK 5" matches, it uses that and stops looking.

hajimef commented 4 months ago

I tested this commit with Rock 5B and Rock 5C with the following code.

import adafruit_platformdetect

detector = adafruit_platformdetect.Detector()
print("Chip id: ", detector.chip.id)
print("Board id: ", detector.board.id)

The results for Rock 5B are as follows:

Chip id: RK3588
Board id: ROCK_PI_5

The results for Rock 5C are as follows:

Chip id: RK3588
Board id: ROCK_PI_5C