mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-12-08 20:39:01 +00:00
@@ -27,7 +27,6 @@ from .exc import (
|
|||||||
OutputDeviceError,
|
OutputDeviceError,
|
||||||
OutputDeviceBadValue,
|
OutputDeviceBadValue,
|
||||||
PinError,
|
PinError,
|
||||||
PinFixedFunction,
|
|
||||||
PinInvalidFunction,
|
PinInvalidFunction,
|
||||||
PinInvalidState,
|
PinInvalidState,
|
||||||
PinInvalidPull,
|
PinInvalidPull,
|
||||||
|
|||||||
@@ -64,9 +64,6 @@ class OutputDeviceBadValue(OutputDeviceError, ValueError):
|
|||||||
class PinError(GPIOZeroError):
|
class PinError(GPIOZeroError):
|
||||||
"Base class for errors related to pin implementations"
|
"Base class for errors related to pin implementations"
|
||||||
|
|
||||||
class PinFixedFunction(PinError, AttributeError):
|
|
||||||
"Error raised when attempting to change the function of a fixed type pin"
|
|
||||||
|
|
||||||
class PinInvalidFunction(PinError, ValueError):
|
class PinInvalidFunction(PinError, ValueError):
|
||||||
"Error raised when attempting to change the function of a pin to an invalid value"
|
"Error raised when attempting to change the function of a pin to an invalid value"
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ class InputDevice(GPIODevice):
|
|||||||
def __init__(self, pin=None, pull_up=False):
|
def __init__(self, pin=None, pull_up=False):
|
||||||
super(InputDevice, self).__init__(pin)
|
super(InputDevice, self).__init__(pin)
|
||||||
try:
|
try:
|
||||||
if self.pin.function != 'input':
|
self.pin.function = 'input'
|
||||||
self.pin.function = 'input'
|
|
||||||
pull = 'up' if pull_up else 'down'
|
pull = 'up' if pull_up else 'down'
|
||||||
if self.pin.pull != pull:
|
if self.pin.pull != pull:
|
||||||
self.pin.pull = pull
|
self.pin.pull = pull
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from __future__ import (
|
|||||||
str = type('')
|
str = type('')
|
||||||
|
|
||||||
from ..exc import (
|
from ..exc import (
|
||||||
PinFixedFunction,
|
PinInvalidFunction,
|
||||||
PinSetInput,
|
PinSetInput,
|
||||||
PinFixedPull,
|
PinFixedPull,
|
||||||
PinPWMUnsupported,
|
PinPWMUnsupported,
|
||||||
@@ -30,12 +30,12 @@ class Pin(object):
|
|||||||
overridden:
|
overridden:
|
||||||
|
|
||||||
* :meth:`_get_function`
|
* :meth:`_get_function`
|
||||||
|
* :meth:`_set_function`
|
||||||
* :meth:`_get_state`
|
* :meth:`_get_state`
|
||||||
|
|
||||||
The following functions *may* be overridden if applicable:
|
The following functions *may* be overridden if applicable:
|
||||||
|
|
||||||
* :meth:`close`
|
* :meth:`close`
|
||||||
* :meth:`_set_function`
|
|
||||||
* :meth:`_set_state`
|
* :meth:`_set_state`
|
||||||
* :meth:`_get_frequency`
|
* :meth:`_get_frequency`
|
||||||
* :meth:`_set_frequency`
|
* :meth:`_set_frequency`
|
||||||
@@ -105,7 +105,9 @@ class Pin(object):
|
|||||||
return "input"
|
return "input"
|
||||||
|
|
||||||
def _set_function(self, value):
|
def _set_function(self, value):
|
||||||
raise PinFixedFunction("Cannot set the function of pin %r" % self)
|
if value != "input":
|
||||||
|
raise PinInvalidFunction(
|
||||||
|
"Cannot set the function of pin %r to %s" % (self, value))
|
||||||
|
|
||||||
function = property(
|
function = property(
|
||||||
lambda self: self._get_function(),
|
lambda self: self._get_function(),
|
||||||
@@ -119,8 +121,7 @@ class Pin(object):
|
|||||||
With certain pin types (e.g. GPIO pins), this attribute can be changed
|
With certain pin types (e.g. GPIO pins), this attribute can be changed
|
||||||
to configure the function of a pin. If an invalid function is
|
to configure the function of a pin. If an invalid function is
|
||||||
specified, for this attribute, :exc:`PinInvalidFunction` will be
|
specified, for this attribute, :exc:`PinInvalidFunction` will be
|
||||||
raised. If this pin is fixed function and an attempt is made to set
|
raised.
|
||||||
this attribute, :exc:`PinFixedFunction` will be raised.
|
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def _get_state(self):
|
def _get_state(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user