From d09af7afd3c50ca9da44d14d9d67356c573e048e Mon Sep 17 00:00:00 2001 From: Ben Nuttall Date: Mon, 19 Sep 2016 13:41:00 +0100 Subject: [PATCH] Disable source when directly controlling DigitalOutputDevice, close #200 --- gpiozero/output_devices.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gpiozero/output_devices.py b/gpiozero/output_devices.py index 1b3c2e2..e516911 100644 --- a/gpiozero/output_devices.py +++ b/gpiozero/output_devices.py @@ -142,14 +142,17 @@ class DigitalOutputDevice(OutputDevice): def close(self): self._stop_blink() + self._stop_source() super(DigitalOutputDevice, self).close() def on(self): self._stop_blink() + self._stop_source() self._write(True) def off(self): self._stop_blink() + self._stop_source() self._write(False) def blink(self, on_time=1, off_time=1, n=None, background=True): @@ -172,6 +175,7 @@ class DigitalOutputDevice(OutputDevice): this method never returning). """ self._stop_blink() + self._stop_source() self._blink_thread = GPIOThread( target=self._blink_device, args=(on_time, off_time, n) ) @@ -180,6 +184,10 @@ class DigitalOutputDevice(OutputDevice): self._blink_thread.join() self._blink_thread = None + def _stop_source(self): + if self.source is not None: + self.source = None + def _stop_blink(self): if self._controller: self._controller._stop_blink(self) @@ -1207,4 +1215,3 @@ class AngularServo(Servo): self._value_range * ((value - self._min_angle) / self._angular_range) + self._min_value) -