From 9f6f88760d8d46b9e2fdc8f82bc0f24a98b4ba8b Mon Sep 17 00:00:00 2001 From: gcohen Date: Tue, 6 Jan 2015 01:48:45 -0800 Subject: Do no issue a new command for an LED if it hasn't ended it's last operation --- python/examples/futureHouse/futureHouse.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/python/examples/futureHouse/futureHouse.py b/python/examples/futureHouse/futureHouse.py index 318d759..0597b19 100644 --- a/python/examples/futureHouse/futureHouse.py +++ b/python/examples/futureHouse/futureHouse.py @@ -39,13 +39,13 @@ channel = 'futureChannel' # pulse lengths have a max of 4096 leds = [ - {'name': 'iceCaveLamp', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005}, - {'name': 'iceCaveCrystal', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005}, - {'name': 'fireplaceOrange', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005}, - {'name': 'campfire', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005}, - {'name': 'porchLight', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005}, - {'name': 'fireplaceRed', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005}, - {'name': 'stove', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005} + {'name': 'iceCaveLamp', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005, 'proc': False}, + {'name': 'iceCaveCrystal', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005, 'proc': False}, + {'name': 'fireplaceOrange', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005, 'proc': False}, + {'name': 'campfire', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005, 'proc': False}, + {'name': 'porchLight', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005, 'proc': False}, + {'name': 'fireplaceRed', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005, 'proc': False}, + {'name': 'stove', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005, 'proc': False} ] def pubMessage(message): @@ -201,23 +201,23 @@ pwm.setPWMFreq(60) # Set frequency to 60 Hz def cycleLEDs(x): + leds[x]['proc'] = True pwm.setPWM(x, 0, leds[x]['minPulseLength']) time.sleep(random.uniform(leds[x]['waitCeiling'], leds[x]['waitFloor'])) pwm.setPWM(x, 0, leds[x]['maxPulseLength']) time.sleep(random.uniform(leds[x]['waitCeiling'], leds[x]['waitFloor'])) + leds[x]['proc'] = False + def startCycling(): while (True): for x in range(0,7) : - # print str(x) + ": " + str(leds[x]['minPulseLength']) + " " + str(leds[x]['maxPulseLength']) + " " + str(leds[x]['waitFloor']) + " " + str(leds[x]['waitCeiling']) - # Change speed of continuous servo on channel O - try: - thread.start_new_thread( cycleLEDs, (x,) ) - except: - print "Error: unable to start LED thread" - - #cycleLEDs(x) + if (leds[x]['proc'] == False): + try: + thread.start_new_thread( cycleLEDs, (x,) ) + except: + print "Error: unable to start LED thread" startCycling() -- cgit v1.2.3