mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Add active_high parameter to LEDBarGraph's constructor
Also adds an active_high property to LEDCollection, and fixes up some of the LEDBoard docstrings
This commit is contained in:
@@ -122,6 +122,10 @@ class LEDCollection(CompositeOutputDevice):
|
|||||||
else:
|
else:
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
@property
|
||||||
|
def active_high(self):
|
||||||
|
return self[0].active_high
|
||||||
|
|
||||||
|
|
||||||
class LEDBoard(LEDCollection):
|
class LEDBoard(LEDCollection):
|
||||||
"""
|
"""
|
||||||
@@ -148,21 +152,23 @@ class LEDBoard(LEDCollection):
|
|||||||
|
|
||||||
:param bool active_high:
|
:param bool active_high:
|
||||||
If ``True`` (the default), the :meth:`on` method will set all the
|
If ``True`` (the default), the :meth:`on` method will set all the
|
||||||
associates pins to HIGH. If ``False``, the :meth:`on` method will set
|
associated pins to HIGH. If ``False``, the :meth:`on` method will set
|
||||||
all pins to LOW (the :meth:`off` method always does the opposite).
|
all pins to LOW (the :meth:`off` method always does the opposite). This
|
||||||
|
parameter can only be specified as a keyword parameter.
|
||||||
|
|
||||||
:param bool initial_value:
|
:param bool initial_value:
|
||||||
If ``False`` (the default), all LEDs will be off initially. If
|
If ``False`` (the default), all LEDs will be off initially. If
|
||||||
``None``, each device will be left in whatever state the pin is found
|
``None``, each device will be left in whatever state the pin is found
|
||||||
in when configured for output (warning: this can be on). If ``True``,
|
in when configured for output (warning: this can be on). If ``True``,
|
||||||
the device will be switched on initially.
|
the device will be switched on initially. This parameter can only be
|
||||||
|
specified as a keyword parameter.
|
||||||
|
|
||||||
:param \*\*named_pins:
|
:param \*\*named_pins:
|
||||||
Sepcify GPIO pins that LEDs of the board are attached to, associated
|
Specify GPIO pins that LEDs of the board are attached to, associating
|
||||||
each LED with a property name. You can designate as many pins as
|
each LED with a property name. You can designate as many pins as
|
||||||
necessary and any name provided it's not already in use by something
|
necessary and use any names, provided they're not already in use by
|
||||||
else. You can also specify :class:`LEDBoard` instances to create
|
something else. You can also specify :class:`LEDBoard` instances to
|
||||||
trees of LEDs.
|
create trees of LEDs.
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self._blink_leds = []
|
self._blink_leds = []
|
||||||
@@ -345,15 +351,21 @@ class LEDBarGraph(LEDCollection):
|
|||||||
Specify the GPIO pins that the LEDs of the bar graph are attached to.
|
Specify the GPIO pins that the LEDs of the bar graph are attached to.
|
||||||
You can designate as many pins as necessary.
|
You can designate as many pins as necessary.
|
||||||
|
|
||||||
:param float initial_value:
|
|
||||||
The initial :attr:`value` of the graph given as a float between -1 and
|
|
||||||
+1. Defaults to 0.0. This parameter can only be specified as a keyword
|
|
||||||
parameter.
|
|
||||||
|
|
||||||
:param bool pwm:
|
:param bool pwm:
|
||||||
If ``True``, construct :class:`PWMLED` instances for each pin. If
|
If ``True``, construct :class:`PWMLED` instances for each pin. If
|
||||||
``False`` (the default), construct regular :class:`LED` instances. This
|
``False`` (the default), construct regular :class:`LED` instances. This
|
||||||
parameter can only be specified as a keyword parameter.
|
parameter can only be specified as a keyword parameter.
|
||||||
|
|
||||||
|
:param bool active_high:
|
||||||
|
If ``True`` (the default), the :meth:`on` method will set all the
|
||||||
|
associated pins to HIGH. If ``False``, the :meth:`on` method will set
|
||||||
|
all pins to LOW (the :meth:`off` method always does the opposite). This
|
||||||
|
parameter can only be specified as a keyword parameter.
|
||||||
|
|
||||||
|
:param float initial_value:
|
||||||
|
The initial :attr:`value` of the graph given as a float between -1 and
|
||||||
|
+1. Defaults to 0.0. This parameter can only be specified as a keyword
|
||||||
|
parameter.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *pins, **kwargs):
|
def __init__(self, *pins, **kwargs):
|
||||||
@@ -361,10 +373,11 @@ class LEDBarGraph(LEDCollection):
|
|||||||
for pin in pins:
|
for pin in pins:
|
||||||
assert not isinstance(pin, LEDCollection)
|
assert not isinstance(pin, LEDCollection)
|
||||||
pwm = kwargs.pop('pwm', False)
|
pwm = kwargs.pop('pwm', False)
|
||||||
|
active_high = kwargs.pop('active_high', True)
|
||||||
initial_value = kwargs.pop('initial_value', 0)
|
initial_value = kwargs.pop('initial_value', 0)
|
||||||
if kwargs:
|
if kwargs:
|
||||||
raise TypeError('unexpected keyword argument: %s' % kwargs.popitem()[0])
|
raise TypeError('unexpected keyword argument: %s' % kwargs.popitem()[0])
|
||||||
super(LEDBarGraph, self).__init__(*pins, pwm=pwm)
|
super(LEDBarGraph, self).__init__(*pins, pwm=pwm, active_high=active_high)
|
||||||
try:
|
try:
|
||||||
self.value = initial_value
|
self.value = initial_value
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user