raspberrypinixie.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:raspberrypinixie 作者: sroaj 项目源码 文件源码
def _int_to_bcd(value):
    # type: (Optional[int]) -> Tuple[bool, bool, bool, bool]
    """Converts an integer to a tuple representing the input bits to a BCD.

    If the input value is None, an all high output will be produced. This will
    typically make the BCD to turn its corresponding output off.

    Args:
        value: The value to be converted.

    Returns:
        tuple of bool corresponding to the BCD representation of the
        inputted value.
    """
    if value is None:
        output = (GPIO.HIGH,) * 4
    elif 0 <= value <= 9:
        output = tuple(int(digit, 2) for digit in "{:04b}".format(value))
        assert len(output) == 4
    else:
        raise ValueError("Specified input must be either None or between "
                         "0 and 9. Input was: {!r}.".format(value))
    logger.debug("Converted %s to %s", value, output)
    return output
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号