add lock to blinkenlight
This commit is contained in:
parent
1ea3761089
commit
2fef89ff7b
|
@ -3,7 +3,7 @@ Controls an LED using a GPIO pin
|
||||||
'''
|
'''
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import time, logging
|
import time, logging
|
||||||
from threading import Event
|
from threading import Event, Lock
|
||||||
from exceptionThreading import ExceptionThread
|
from exceptionThreading import ExceptionThread
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
|
@ -12,9 +12,11 @@ logger = logging.getLogger(__name__)
|
||||||
class Blinkenlights(ExceptionThread):
|
class Blinkenlights(ExceptionThread):
|
||||||
def __init__(self, pin, cyclePeriod=2):
|
def __init__(self, pin, cyclePeriod=2):
|
||||||
self._stopper = Event()
|
self._stopper = Event()
|
||||||
|
self._blink = Event()
|
||||||
|
self._lock = Lock()
|
||||||
|
|
||||||
self._pin = pin
|
self._pin = pin
|
||||||
|
|
||||||
self._blink = Event()
|
|
||||||
self.setCyclePeriod(cyclePeriod) #cyclePeriod is length of one blink cycle in seconds
|
self.setCyclePeriod(cyclePeriod) #cyclePeriod is length of one blink cycle in seconds
|
||||||
|
|
||||||
GPIO.setup(pin, GPIO.OUT)
|
GPIO.setup(pin, GPIO.OUT)
|
||||||
|
@ -45,6 +47,7 @@ class Blinkenlights(ExceptionThread):
|
||||||
logger.debug('Stopping LED on pin %s', self._pin)
|
logger.debug('Stopping LED on pin %s', self._pin)
|
||||||
|
|
||||||
def setCyclePeriod(self, cyclePeriod):
|
def setCyclePeriod(self, cyclePeriod):
|
||||||
|
with self._lock:
|
||||||
self._sleeptime = cyclePeriod/20/2
|
self._sleeptime = cyclePeriod/20/2
|
||||||
|
|
||||||
def setBlink(self, toggle):
|
def setBlink(self, toggle):
|
||||||
|
|
Loading…
Reference in New Issue