场景是这样的-
定义一个-
input_pin = 21-
GPIO.setmode(GPIO.BOARD)-
GPIO.setup(input_pin, GPIO.IN,pull_up_down=GPIO.HIGH)-
value = GPIO.input(input_pin)-
预期在没有输入的情况下,预期这里的value 应该是 GPIO.HIGH-
但是事实上,却不是,pull_up_down 选项没有工作-
查看github上的代码-
https://github.com/D-Robotics/x5-hobot-io/blob/4ebc8dff6bd14b4012ae88ba63051552d9582004/hb\_gpio\_py/hobot-gpio/lib/python/Hobot/GPIO/gpio.py#L198-
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)-
这里的 pull_up_down 除了 用于 if direction == OUT and pull_up_down:
raise RuntimeError("Pull-up and pull-down are not "
“supported in output mode”)-
之外根本没有,用于后续操作,全局搜索 pull_up_down 也没有相关操作了