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
评论列表
文章目录