Skip to content

Commit

Permalink
Bug fixes for old versions of Python and more
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2tds committed Jun 4, 2015
1 parent 2bed57a commit c3be81d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def except_hook(exctype, value, tb):
pjoin = os.path.join

gpio_root = '/sys/class/gpio'
gpiopath = lambda pin: os.path.join(gpio_root, 'gpio{}'.format(pin))
gpiopath = lambda pin: os.path.join(gpio_root, 'gpio{0}'.format(pin))
_export_lock = threading.Lock()

_pyset = set
Expand All @@ -37,13 +37,13 @@ def except_hook(exctype, value, tb):


def _write(f, v):
log.debug("writing: {}: {}".format(f, v))
log.debug("writing: {0}: {1}".format(f, v))
f.write(str(v))
f.flush()


def _read(f):
log.debug("Reading: {}".format(f))
log.debug("Reading: {0}".format(f))
f.seek(0)
return f.read().strip()

Expand All @@ -56,7 +56,7 @@ def wrapped(pin, *args, **kwargs):
if pin not in _open:
ppath = gpiopath(pin)
if not os.path.exists(ppath):
log.debug("Creating Pin {}".format(pin))
log.debug("Creating Pin {0}".format(pin))
with _export_lock:
with open(pjoin(gpio_root, 'export'), 'w') as f:
_write(f, pin)
Expand All @@ -77,7 +77,7 @@ def cleanup(pin):
files['direction'].close()
files['drive'].close()
if os.path.exists(gpiopath(pin)):
log.debug("Unexporting pin {}".format(pin))
log.debug("Unexporting pin {0}".format(pin))
with _export_lock:
with open(pjoin(gpio_root, 'unexport'), 'w') as f:
_write(f, pin)
Expand All @@ -97,9 +97,9 @@ def setup(pin, mode, pullup=None, initial=False):
if pullup is not None:
raise ValueError("sysfs does not support pullups")

if mode not in {IN, OUT, LOW, HIGH}:
if mode not in (IN, OUT, LOW, HIGH):
raise ValueError(mode)
log.debug("Setup {}: {}".format(pin, mode))
log.debug("Setup {0}: {1}".format(pin, mode))
f = _open[pin]['direction']
_write(f, mode)
if mode == OUT:
Expand Down Expand Up @@ -129,15 +129,15 @@ def read(pin):
'''
f = _open[pin]['value']
out = int(_read(f))
log.debug("Read {}: {}".format(pin, out))
log.debug("Read {0}: {1}".format(pin, out))
return out


@_verify
def set(pin, value):
'''set the pin value to 0 or 1'''
value = int(bool(value))
log.debug("Write {}: {}".format(pin, value))
log.debug("Write {0}: {1}".format(pin, value))
f = _open[pin]['value']
_write(f, value)

Expand All @@ -151,7 +151,7 @@ def input(pin):
@_verify
def output(pin, value):
'''set the pin. Same as set'''
return set(pin)
return set(pin, value)


def setwarnings(value):
Expand Down

0 comments on commit c3be81d

Please sign in to comment.