Merge pull request #29 from waveform80/output-toggle

Fix #23
This commit is contained in:
Ben Nuttall
2015-09-23 13:50:01 +01:00

View File

@@ -1,5 +1,7 @@
from RPi import GPIO
from time import sleep from time import sleep
from threading import Lock
from RPi import GPIO
from .devices import GPIODeviceError, GPIODevice, GPIOThread from .devices import GPIODeviceError, GPIODevice, GPIOThread
@@ -24,6 +26,7 @@ class LED(OutputDevice):
def __init__(self, pin=None): def __init__(self, pin=None):
super(LED, self).__init__(pin) super(LED, self).__init__(pin)
self._blink_thread = None self._blink_thread = None
self._lock = Lock()
def blink(self, on_time=1, off_time=1): def blink(self, on_time=1, off_time=1):
self._stop_blink() self._stop_blink()
@@ -54,6 +57,13 @@ class LED(OutputDevice):
self._stop_blink() self._stop_blink()
super(LED, self).off() super(LED, self).off()
def toggle(self):
with self._lock:
if self.is_active:
self.off()
else:
self.on()
class Buzzer(OutputDevice): class Buzzer(OutputDevice):
pass pass