diff --git a/docs/api_boards.rst b/docs/api_boards.rst index 6b2604b..2db1d83 100644 --- a/docs/api_boards.rst +++ b/docs/api_boards.rst @@ -36,6 +36,13 @@ TrafficLights :inherited-members: :members: +LedBorg +======= + +.. autoclass:: LedBorg + :inherited-members: + :members: + PiLITEr ======= diff --git a/docs/images/output_device_hierarchy.dot b/docs/images/output_device_hierarchy.dot index 1cd5e02..6a92a52 100644 --- a/docs/images/output_device_hierarchy.dot +++ b/docs/images/output_device_hierarchy.dot @@ -21,5 +21,6 @@ digraph classes { PWMOutputDevice->OutputDevice; PWMLED->PWMOutputDevice; RGBLED->Device; + LedBorg->RGBLED; } diff --git a/docs/images/output_device_hierarchy.pdf b/docs/images/output_device_hierarchy.pdf index 91cb8c1..b7ffe95 100644 Binary files a/docs/images/output_device_hierarchy.pdf and b/docs/images/output_device_hierarchy.pdf differ diff --git a/docs/images/output_device_hierarchy.png b/docs/images/output_device_hierarchy.png index 61bf956..7afa368 100644 Binary files a/docs/images/output_device_hierarchy.png and b/docs/images/output_device_hierarchy.png differ diff --git a/docs/images/output_device_hierarchy.svg b/docs/images/output_device_hierarchy.svg index a2a922c..4f1cad2 100644 --- a/docs/images/output_device_hierarchy.svg +++ b/docs/images/output_device_hierarchy.svg @@ -11,18 +11,18 @@ Device - -Device + +Device GPIODevice - -GPIODevice + +GPIODevice GPIODevice->Device - - + + OutputDevice @@ -31,8 +31,8 @@ OutputDevice->GPIODevice - - + + DigitalOutputDevice @@ -86,13 +86,23 @@ RGBLED - -RGBLED + +RGBLED RGBLED->Device - - + + + + +LedBorg + +LedBorg + + +LedBorg->RGBLED + + diff --git a/gpiozero/__init__.py b/gpiozero/__init__.py index 63191c1..e2933be 100644 --- a/gpiozero/__init__.py +++ b/gpiozero/__init__.py @@ -106,6 +106,7 @@ from .boards import ( LEDCollection, LEDBoard, LEDBarGraph, + LedBorg, PiLiter, PiLiterBarGraph, TrafficLights, diff --git a/gpiozero/boards.py b/gpiozero/boards.py index e8bb0b9..31419a8 100644 --- a/gpiozero/boards.py +++ b/gpiozero/boards.py @@ -21,7 +21,14 @@ from .exc import ( OutputDeviceBadValue, ) from .input_devices import Button -from .output_devices import OutputDevice, LED, PWMLED, Buzzer, Motor +from .output_devices import ( + OutputDevice, + LED, + PWMLED, + RGBLED, + Buzzer, + Motor, + ) from .threads import GPIOThread from .devices import Device, CompositeDevice from .mixins import SharedMixin, SourceMixin @@ -431,6 +438,36 @@ class LEDBarGraph(LEDCollection): led.value = calc_value(index) +class LedBorg(RGBLED): + """ + Extends :class:`RGBLED` for the `PiBorg LedBorg`_: an add-on board + containing a very bright RGB LED. + + The LedBorg pins are fixed and therefore there's no need to specify them + when constructing this class. The following example turns the LedBorg + purple:: + + from gpiozero import LedBorg + + led = LedBorg() + led.color = (1, 0, 1) + + :param tuple initial_value: + The initial color for the LedBorg. Defaults to black ``(0, 0, 0)``. + + :param bool pwm: + If ``True`` (the default), construct :class:`PWMLED` instances for + each component of the LedBorg. If ``False``, construct regular + :class:`LED` instances, which prevents smooth color graduations. + + .. _PiBorg LedBorg: https://www.piborg.org/ledborg + """ + + def __init__(self, initial_value=(0, 0, 0), pwm=True): + super(LedBorg, self).__init__(red=17, green=27, blue=22, + initial_value=initial_value, pwm=pwm) + + class PiLiter(LEDBoard): """ Extends :class:`LEDBoard` for the `Ciseco Pi-LITEr`_: a strip of 8 very bright diff --git a/tests/test_boards.py b/tests/test_boards.py index ff324c9..1d519df 100644 --- a/tests/test_boards.py +++ b/tests/test_boards.py @@ -18,7 +18,7 @@ from gpiozero import * def setup_function(function): import gpiozero.devices # dirty, but it does the job - if function.__name__ in ('test_robot', 'test_ryanteck_robot', 'test_camjam_kit_robot'): + if function.__name__ in ('test_robot', 'test_ryanteck_robot', 'test_camjam_kit_robot', 'test_led_borg'): gpiozero.devices.pin_factory = MockPWMPin else: gpiozero.devices.pin_factory = MockPin @@ -524,6 +524,11 @@ def test_led_bar_graph_pwm_initial_value(): assert graph.value == -0.5 assert (pin1.state, pin2.state, pin3.state) == (0, 0.5, 1) +def test_led_borg(): + pins = [MockPWMPin(n) for n in (17, 27, 22)] + with LedBorg() as board: + assert [device.pin for device in board._leds] == pins + def test_pi_liter(): pins = [MockPin(n) for n in (4, 17, 27, 18, 22, 23, 24, 25)] with PiLiter() as board: