From 2fef89ff7b60afde11409ca079816f18e0f85344 Mon Sep 17 00:00:00 2001 From: petrucci4prez Date: Sat, 17 Jun 2017 14:26:29 -0400 Subject: [PATCH] add lock to blinkenlight --- blinkenLights.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/blinkenLights.py b/blinkenLights.py index 8ea8f37..bcb2f85 100644 --- a/blinkenLights.py +++ b/blinkenLights.py @@ -3,7 +3,7 @@ Controls an LED using a GPIO pin ''' import RPi.GPIO as GPIO import time, logging -from threading import Event +from threading import Event, Lock from exceptionThreading import ExceptionThread from itertools import chain @@ -12,9 +12,11 @@ logger = logging.getLogger(__name__) class Blinkenlights(ExceptionThread): def __init__(self, pin, cyclePeriod=2): self._stopper = Event() + self._blink = Event() + self._lock = Lock() + self._pin = pin - self._blink = Event() self.setCyclePeriod(cyclePeriod) #cyclePeriod is length of one blink cycle in seconds GPIO.setup(pin, GPIO.OUT) @@ -45,7 +47,8 @@ class Blinkenlights(ExceptionThread): logger.debug('Stopping LED on pin %s', self._pin) def setCyclePeriod(self, cyclePeriod): - self._sleeptime = cyclePeriod/20/2 + with self._lock: + self._sleeptime = cyclePeriod/20/2 def setBlink(self, toggle): if toggle: