Example #1
0
def init() -> None:
    if isinstance(board, Unknown):
        log.error("Unsupported board: %s",
                  adafruit_platformdetect.Detector().board.id)
    elif board.id == board_ids.GENERIC_LINUX_PC:
        log.info("Detected board: %s", board.id)
        log.warn("This device does not support GPIO pins")
    else:
        log.info("Detected board: %s", board.id)

        if common.cdev:
            log.debug("Detected GPIO character device")
        elif os.access(f"/dev/gpiochip{board.chips[0]}",
                       os.F_OK,
                       effective_ids=True):
            log.warn(
                "Detected GPIO character device but this account (%s) does not have R/W "
                "permissions",
                os.getlogin(),
            )
            log.warn(
                "Read/Write access is required on the following files: %s",
                [f"/dev/gpiochip{chip}" for chip in board.chips],
            )
            log.warn("Attempting to fall back to sysfs")
            if common.sysfs:
                log.debug("Falling back to sysfs")
            elif os.access("/sys/class/gpio/export",
                           os.F_OK,
                           effective_ids=True):
                log.warn(
                    "Detected sysfs GPIO but this account (%s) does not have R/W "
                    "permissions",
                    os.getlogin(),
                )
                log.warn(
                    "Read/Write access is required on the following directory: "
                    "'/sys/class/gpio/export'")

        else:
            if common.sysfs:
                log.debug("Detected sysfs GPIO interface")
            elif os.access("/sys/class/gpio/export",
                           os.F_OK,
                           effective_ids=True):
                log.warn(
                    "Detected sysfs GPIO but this account (%s) does not have R/W "
                    "permissions",
                    os.getlogin(),
                )
                log.warn(
                    "Read/Write access is required on the following directory: "
                    "'/sys/class/gpio/export'")

        if not common.cdev and not common.sysfs:
            log.warn(
                "No GPIO interface is available, some features may not work")
#!/usr/bin/env python3

import adafruit_platformdetect

detector = adafruit_platformdetect.Detector()

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

print("Is this a DragonBoard 410c?", detector.board.DRAGONBOARD_410C)
print("Is this a Pi 3B+?", detector.board.RASPBERRY_PI_3B_PLUS)
print("Is this a Pi 4B?", detector.board.RASPBERRY_PI_4B)
print("Is this a 40-pin Raspberry Pi?", detector.board.any_raspberry_pi_40_pin)
print("Is this a Raspberry Pi Compute Module?",
      detector.board.any_raspberry_pi_cm)
print("Is this a BeagleBone Board?", detector.board.any_beaglebone)
print("Is this a Giant Board?", detector.board.GIANT_BOARD)
print("Is this a Coral Dev Board?", detector.board.CORAL_EDGE_TPU_DEV)
print("Is this a Coral Dev Board Mini?",
      detector.board.CORAL_EDGE_TPU_DEV_MINI)
print("Is this a SiFive Unleashed? ", detector.board.SIFIVE_UNLEASHED)
print("Is this a PYNQ Board?", detector.board.PYNQ_Z1 | detector.board.PYNQ_Z2)
print("Is this a Rock Pi board?", detector.board.any_rock_pi_board)
print("Is this a NanoPi board?", detector.board.any_nanopi)
print("Is this a Clockwork Pi board?", detector.board.any_clockwork_pi_board)
print("Is this an embedded Linux system?", detector.board.any_embedded_linux)
print("Is this a generic Linux PC?", detector.board.GENERIC_LINUX_PC)
print("Is this a UDOO Bolt?", detector.board.UDOO_BOLT)
print("Is this an ASUS Tinker Board?", detector.board.ASUS_TINKER_BOARD)
print("Is this an STM32MP1 Board?", detector.board.any_stm32mp1)
Example #3
0
"""A module that uses Adafruit-PlatformDetect for detecting hardware and OS conditions.
This module will contain the following information:

    * ON_WINDOWS (`bool`) `True` if Windows OS is detected, otherwise `False`
    * ON_RASPI (`bool`) `True` if raspberry pi is detected, otherwise `False`
    * ON_JETSON (`bool`) `True` if nVidia Jetson is detected, otherwise `False`

We could add more here. For a complete list of names for devices that CircuitPython will
aggree with (not Windows), the following commands in a Python REPR:

.. code-block:: python

    >>> import adafruit_platformdetect
    >>> dir(adafruit_platformdetect.board)
    ['BEAGLEBONE', 'BEAGLEBONE_AIR', 'BEAGLEBONE_BLACK', 'BEAGLEBONE_BLACK_INDUSTRIAL', 'BEAGLEBONE_BLACK_WIRELESS', 'BEAGLEBONE_BLUE', 'BEAGLEBONE_ENHANCED', 'BEAGLEBONE_GREEN', 'BEAGLEBONE_GREEN_WIRELESS', 'BEAGLEBONE_POCKETBEAGLE', 'BEAGLEBONE_POCKETBONE', 'BEAGLEBONE_USOMIQ', 'BEAGLELOGIC_STANDALONE', 'Board', 'CORAL_EDGE_TPU_DEV', 'DRAGONBOARD_410C', 'FEATHER_HUZZAH', 'FEATHER_M0_EXPRESS', 'FTDI_FT232H', 'GENERIC_LINUX_PC', 'GIANT_BOARD', 'JETSON_NANO', 'JETSON_TX1', 'JETSON_TX2', 'JETSON_XAVIER', 'NODEMCU', 'ODROID_C1', 'ODROID_C1_PLUS', 'ODROID_C2', 'ODROID_N2', 'ORANGE_PI_PC', 'ORANGE_PI_R1', 'ORANGE_PI_ZERO', 'OSD3358_DEV_BOARD', 'OSD3358_SM_RED', 'PYBOARD', 'RASPBERRY_PI_2B', 'RASPBERRY_PI_3A_PLUS', 'RASPBERRY_PI_3B', 'RASPBERRY_PI_3B_PLUS', 'RASPBERRY_PI_4B', 'RASPBERRY_PI_A', 'RASPBERRY_PI_A_PLUS', 'RASPBERRY_PI_B_PLUS', 'RASPBERRY_PI_B_REV1', 'RASPBERRY_PI_B_REV2', 'RASPBERRY_PI_CM1', 'RASPBERRY_PI_CM3', 'RASPBERRY_PI_CM3_PLUS', 'RASPBERRY_PI_ZERO', 'RASPBERRY_PI_ZERO_W', 'SIFIVE_UNLEASHED', '_BEAGLEBONE_BOARD_IDS', '_BEAGLEBONE_IDS', '_CORAL_IDS', '_JETSON_IDS', '_LINARO_96BOARDS_IDS', '_ODROID_40_PIN_IDS', '_ORANGE_PI_IDS', '_PI_REV_CODES', '_RASPBERRY_PI_40_PIN_IDS', '_RASPBERRY_PI_CM_IDS', '_SIFIVE_IDS', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'ap_chip', 'os']

"""
import adafruit_platformdetect as pfdetect

ON_WINDOWS = pfdetect.platform.platform(aliased=1,
                                        terse=1).startswith('Windows')

DETECT = pfdetect.Detector()  # object used to detect various information
MODEL = DETECT.board.id  # returns `None` on Windows

ON_RASPI = False if MODEL is None else MODEL.startswith('RASPBERRY_PI')
ON_JETSON = False if MODEL is None else MODEL.startswith('JETSON')
Example #4
0
def validateGPIO(
    id: str,
    name: str,
    count: int,
    leds_per_pixel: int,
    color_order: str,
    fps: int,
    init_brightness: int,
    array_config: t.Dict[str, t.Any],
) -> t.Union[baseArray, None]:
    """
    Validate GPIO pin and return array instance if valid.
    """
    try:
        import adafruit_platformdetect
        import adafruit_platformdetect.constants.boards as boards
    except ImportError:
        raise ImportError(
            "MQTTany's LED module requires 'Adafruit-PlatformDetect' to be installed, "
            "please see the wiki for instructions on how to install requirements"
        )

    detector = adafruit_platformdetect.Detector()
    board_id = detector.board.id

    if detector.board.any_raspberry_pi:
        pin_ok = False

        if array_config[CONF_KEY_RPI][CONF_KEY_GPIO] in [
                12, 18
        ] and board_id in [
                boards.RASPBERRY_PI_B_PLUS,
                boards.RASPBERRY_PI_2B,
                boards.RASPBERRY_PI_3B,
                boards.RASPBERRY_PI_3B_PLUS,
        ]:
            pin_ok = True  # PWM0

        elif array_config[CONF_KEY_RPI][CONF_KEY_GPIO] in [
                13
        ] and board_id in [
                boards.RASPBERRY_PI_B_PLUS,
                boards.RASPBERRY_PI_2B,
                boards.RASPBERRY_PI_3B,
                boards.RASPBERRY_PI_3B_PLUS,
                boards.RASPBERRY_PI_ZERO,
                boards.RASPBERRY_PI_ZERO_W,
        ]:
            pin_ok = True  # PWM1

        elif array_config[CONF_KEY_RPI][CONF_KEY_GPIO] in [
                21
        ] and board_id in [
                boards.RASPBERRY_PI_B_PLUS,
                boards.RASPBERRY_PI_2B,
                boards.RASPBERRY_PI_3B,
                boards.RASPBERRY_PI_3B_PLUS,
                boards.RASPBERRY_PI_ZERO,
                boards.RASPBERRY_PI_ZERO_W,
        ]:
            pin_ok = True  # PCM_DOUT

        elif array_config[CONF_KEY_RPI][CONF_KEY_GPIO] in [10]:
            pin_ok = True  # SPI0-MOSI

        if not pin_ok:
            logger.get_logger("led.rpi").error(
                "GPIO%02d cannot be used for LED control on %s",
                array_config[CONF_KEY_RPI][CONF_KEY_GPIO],
                board_id,
            )
            return None
        else:
            return rpiArray(
                id,
                name,
                count,
                leds_per_pixel,
                color_order,
                fps,
                init_brightness,
                array_config,
            )

    else:
        log = logger.get_logger("led.rpi")
        log.error(
            "This module only supports GPIO output on certain Raspberry Pi boards"
        )
        log.error("Please see the documentation for supported boards")