10
10
from threading import Lock
11
11
from itertools import repeat , cycle , chain
12
12
13
- from .exc import OutputDeviceError , GPIODeviceError , GPIODeviceClosed
13
+ from .exc import OutputDeviceBadValue , GPIOPinMissing , GPIODeviceClosed
14
14
from .devices import GPIODevice , GPIOThread , CompositeDevice , SourceMixin
15
15
16
16
@@ -24,7 +24,7 @@ class OutputDevice(SourceMixin, GPIODevice):
24
24
25
25
:param int pin:
26
26
The GPIO pin (in BCM numbering) that the device is connected to. If
27
- this is ``None`` a :exc:`GPIODeviceError ` will be raised.
27
+ this is ``None`` a :exc:`GPIOPinMissing ` will be raised.
28
28
29
29
:param bool active_high:
30
30
If ``True`` (the default), the :meth:`on` method will set the GPIO to
@@ -54,7 +54,7 @@ def _write(self, value):
54
54
value = not value
55
55
try :
56
56
self .pin .state = bool (value )
57
- except ValueError :
57
+ except AttributeError :
58
58
self ._check_open ()
59
59
raise
60
60
@@ -269,7 +269,7 @@ class PWMOutputDevice(OutputDevice):
269
269
def __init__ (self , pin = None , active_high = True , initial_value = 0 , frequency = 100 ):
270
270
self ._blink_thread = None
271
271
if not 0 <= initial_value <= 1 :
272
- raise OutputDeviceError ("initial_value must be between 0 and 1" )
272
+ raise OutputDeviceBadValue ("initial_value must be between 0 and 1" )
273
273
super (PWMOutputDevice , self ).__init__ (pin , active_high )
274
274
try :
275
275
# XXX need a way of setting these together
@@ -299,7 +299,7 @@ def _write(self, value):
299
299
if not self .active_high :
300
300
value = 1 - value
301
301
if not 0 <= value <= 1 :
302
- raise OutputDeviceError ("PWM value must be between 0 and 1" )
302
+ raise OutputDeviceBadValue ("PWM value must be between 0 and 1" )
303
303
try :
304
304
self .pin .state = value
305
305
except AttributeError :
@@ -505,7 +505,7 @@ def __init__(
505
505
self ._leds = ()
506
506
self ._blink_thread = None
507
507
if not all ([red , green , blue ]):
508
- raise OutputDeviceError ('red, green, and blue pins must be provided' )
508
+ raise GPIOPinMissing ('red, green, and blue pins must be provided' )
509
509
super (RGBLED , self ).__init__ ()
510
510
self ._leds = tuple (PWMLED (pin , active_high ) for pin in (red , green , blue ))
511
511
self .value = initial_value
@@ -680,7 +680,7 @@ class Motor(SourceMixin, CompositeDevice):
680
680
"""
681
681
def __init__ (self , forward = None , backward = None ):
682
682
if not all ([forward , backward ]):
683
- raise OutputDeviceError (
683
+ raise GPIOPinMissing (
684
684
'forward and backward pins must be provided'
685
685
)
686
686
super (Motor , self ).__init__ ()
@@ -722,7 +722,7 @@ def value(self):
722
722
@value .setter
723
723
def value (self , value ):
724
724
if not - 1 <= value <= 1 :
725
- raise OutputDeviceError ("Motor value must be between -1 and 1" )
725
+ raise OutputDeviceBadValue ("Motor value must be between -1 and 1" )
726
726
if value > 0 :
727
727
self .forward (value )
728
728
elif value < 0 :
0 commit comments