no busy wait in blinkenlights

This commit is contained in:
petrucci4prez 2017-06-17 14:44:29 -04:00
parent 2fef89ff7b
commit c7814c39a7
1 changed files with 3 additions and 2 deletions

View File

@ -25,14 +25,14 @@ class Blinkenlights(ExceptionThread):
def blinkLights(): def blinkLights():
pwm.start(0) pwm.start(0)
while not self._stopper.isSet(): while not self._stopper.isSet():
t = self._sleeptime
if self._blink.is_set(): if self._blink.is_set():
t = self._sleeptime
for dc in chain(range(100, -1, -5), range(0, 101, 5)): for dc in chain(range(100, -1, -5), range(0, 101, 5)):
pwm.ChangeDutyCycle(dc) pwm.ChangeDutyCycle(dc)
time.sleep(t) time.sleep(t)
else: else:
pwm.ChangeDutyCycle(100) pwm.ChangeDutyCycle(100)
time.sleep(t) self._blink.wait()
pwm.stop() # required to avoid core dumps when process terminates pwm.stop() # required to avoid core dumps when process terminates
super().__init__(target=blinkLights, daemon=True) super().__init__(target=blinkLights, daemon=True)
@ -44,6 +44,7 @@ class Blinkenlights(ExceptionThread):
def stop(self): def stop(self):
if self.is_alive(): if self.is_alive():
self._stopper.set() self._stopper.set()
self._blink.set()
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):