From 006c10cce0543ea3a860dea06a6d99277f7df7a1 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 8 Feb 2016 08:26:34 +0000 Subject: [PATCH] Miscellaneous minor changes for 1.1 --- Makefile | 2 +- docs/api_output.rst | 2 +- gpiozero/output_devices.py | 31 +++++++++++++++++++++++-------- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index e9843cd..3c3d3e1 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,7 @@ release: $(PY_SOURCES) $(DOC_SOURCES) $(DEB_SOURCES) dch --newversion $(VER)$(DEB_SUFFIX) --controlmaint # commit the changes and add a new tag git commit debian/changelog -m "Updated changelog for release $(VER)" - git tag -s release-$(VER) -m "Release $(VER)" + git tag -s v$(VER) -m "Release v$(VER)" # update the package's registration on PyPI (in case any metadata's changed) $(PYTHON) $(PYFLAGS) setup.py register diff --git a/docs/api_output.rst b/docs/api_output.rst index b1cf48e..3c8857f 100644 --- a/docs/api_output.rst +++ b/docs/api_output.rst @@ -35,7 +35,7 @@ RGBLED ====== .. autoclass:: RGBLED(red, green, blue, active_high=True) - :members: on, off, blink, red, green, blue, value + :members: on, off, toggle, blink, red, green, blue, color Motor ===== diff --git a/gpiozero/output_devices.py b/gpiozero/output_devices.py index 075ac34..208dca7 100644 --- a/gpiozero/output_devices.py +++ b/gpiozero/output_devices.py @@ -520,17 +520,22 @@ class RGBLED(SourceMixin, CompositeDevice): The GPIO pin that controls the blue component of the RGB LED. :param bool active_high: - If ``True`` (the default), the :meth:`on` method will set the GPIOs to - HIGH. If ``False``, the :meth:`on` method will set the GPIOs to LOW - (the :meth:`off` method always does the opposite). + Set to ``True`` (the default) for common cathode RGB LEDs. If you are + using a common anode RGB LED, set this to ``False``. + + :param bool initial_value: + The initial color for the LED. Defaults to black ``(0, 0, 0)``. """ - def __init__(self, red=None, green=None, blue=None, active_high=True): + def __init__( + self, red=None, green=None, blue=None, active_high=True, + initial_value=(0, 0, 0)): self._leds = () self._blink_thread = None if not all([red, green, blue]): raise OutputDeviceError('red, green, and blue pins must be provided') super(RGBLED, self).__init__() self._leds = tuple(PWMLED(pin, active_high) for pin in (red, green, blue)) + self.value = initial_value red = _led_property(0) green = _led_property(1) @@ -563,18 +568,28 @@ class RGBLED(SourceMixin, CompositeDevice): def on(self): """ - Turn the device on. This equivalent to setting the device color to - white ``(1, 1, 1)``. + Turn the LED on. This equivalent to setting the LED color to white + ``(1, 1, 1)``. """ self.value = (1, 1, 1) def off(self): """ - Turn the device off. This is equivalent to setting the device color - to black ``(0, 0, 0)``. + Turn the LED off. This is equivalent to setting the LED color to black + ``(0, 0, 0)``. """ self.value = (0, 0, 0) + def toggle(self): + """ + Toggle the state of the device. If the device is currently off + (:attr:`value` is ``(0, 0, 0)``), this changes it to "fully" on + (:attr:`value` is ``(1, 1, 1)``). If the device has a specific color, + this method inverts the color. + """ + r, g, b = self.value + self.value = (1 - r, 1 - g, 1 - b) + def close(self): self._stop_blink() for led in self._leds: