Hobot.GPIO gpio.py代码
def setup(channels, direction, pull_up_down=None, initial=None):
if not pin_mode:
raise RuntimeError(“No channel mode set”)
if direction not in DIRECTION_LIST:
raise ValueError(“Setup channel direction is invalid”)
if direction == OUT and pull_up_down:
raise RuntimeError("Pull-up and pull-down are not "
“supported in output mode”)
if type(channels) == list or type(channels) == tuple:
pin_names = copy.deepcopy(channels)
elif type(channels) == str or type(channels) == int:
pin_names =
pin_names.append(channels)
else:
raise TypeError(“The channel parameter is of the wrong type”)
for pin_name in pin_names:
if pin_info.__contains__(pin_name):
_cleanup_one(pin_name)
try:
pin_info[pin_name] = PinPro(pin_name)
except Exception as exc:
raise ValueError(“This channel was not found in this mode”)
_export_gpio(pin_name, direction)
if direction == OUT and initial:
output(pin_name, initial)