From 2495e903df84660ade46d77c9860b77d2b5546a2 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Mon, 22 Feb 2016 02:46:19 +0000 Subject: [PATCH] RPIOPin fixups ...as discovered using the new real_pins unit-tests. --- gpiozero/pins/rpio.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gpiozero/pins/rpio.py b/gpiozero/pins/rpio.py index ed7bb24..05831ac 100644 --- a/gpiozero/pins/rpio.py +++ b/gpiozero/pins/rpio.py @@ -11,12 +11,14 @@ from threading import Lock import RPIO import RPIO.PWM +from RPIO.Exceptions import InvalidChannelException from . import Pin, PINS_CLEANUP from ..exc import ( PinInvalidFunction, PinSetInput, PinFixedPull, + PinInvalidPull, ) @@ -81,7 +83,10 @@ class RPIOPin(Pin): self._bounce = None self._when_changed = None self._edges = 'both' - RPIO.setup(self._number, RPIO.IN, self.GPIO_PULL_UPS[self._pull]) + try: + RPIO.setup(self._number, RPIO.IN, self.GPIO_PULL_UPS[self._pull]) + except InvalidChannelException as e: + raise ValueError(e) return self def __repr__(self): @@ -148,7 +153,10 @@ class RPIOPin(Pin): raise PinInvalidPull('invalid pull "%s" for pin %r' % (value, self)) def _get_frequency(self): - return 100 + if self._pwm: + return 100 + else: + return None def _set_frequency(self, value): if value is not None and value != 100: