From ee82f4176f16205bc8ce37d290fe4e71ee987544 Mon Sep 17 00:00:00 2001 From: Garrett Berg Date: Thu, 19 Mar 2015 10:20:32 -0600 Subject: [PATCH] gpio: more compatible with rpio --- gpio.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/gpio.py b/gpio.py index f9a9b52..7c6fe4f 100644 --- a/gpio.py +++ b/gpio.py @@ -68,23 +68,40 @@ def wrapped(pin, *args, **kwargs): return wrapped +def cleanup(pin): + if pin not in _open: + return + files = _open[pin] + files['value'].close() + files['direction'].close() + files['drive'].close() + if os.path.exists(gpiopath(pin)): + log.debug("Unexporting pin {}".format(pin)) + with _export_lock: + with open(pjoin(gpio_root, 'unexport'), 'w') as f: + _write(f, pin) + + @_verify -def setup(pin, mode, value=False): +def setup(pin, mode, pullup=None, initial=False): '''Setup pin with mode IN or OUT. Args: pin (int): mode (str): use either gpio.OUT or gpio.IN - value (bool, optional): Initial pin value + pullup (None): rpio compatibility. If anything but None, raises + value Error + pullup (bool, optional): Initial pin value. Default is False ''' - + if pullup is not None: + raise ValueError("sysfs does not support pullups") if mode not in {IN, OUT, LOW, HIGH}: raise ValueError(mode) log.debug("Setup {}: {}".format(pin, mode)) f = _open[pin]['direction'] if mode == 'OUT': - if value: + if initial: mode = LOW else: mode = HIGH @@ -134,3 +151,16 @@ def input(pin): def output(pin, value): '''set the pin. Same as set''' return set(pin) + + +def setwarnings(value): + '''exists for rpio compatibility''' + pass + + +def setmode(value): + '''exists for rpio compatibility''' + pass + + +BCM = None # rpio compatibility