event_queue = eventGenerator.generateEvents() for event in event_queue: if event.get('type', None) == 'pour': # cup_color, light_rod, type light_rod = event.get('light_rod', None) if event.get('cup_color', None) == "red": c = Color(rgb=(0.0, 0.0, 1.0)) elif event.get('cup_color', None) == 'green': c = Color(rgb=(0.0, 1.0, 0.0)) elif event.get('cup_color', None) == 'blue': c = Color(rgb=(1.0, 0.0, 0.0)) if light_rod == 0: sendingColorBuffer.insertAndPop(c) sendingColorBuffer.send(data_receiver_color_key="COLORS", reverse=True) if light_rod == 1: sendingColorBuffer1.insertAndPop(c) sendingColorBuffer1.send(data_receiver_color_key="COLOR1", reverse=True) if light_rod == 2: sendingColorBuffer2.insertAndPop(c) sendingColorBuffer2.send(data_receiver_color_key="COLOR2", reverse=True) if light_rod == 3: sendingColorBuffer3.insertAndPop(c) sendingColorBuffer3.send(data_receiver_color_key="COLOR3", reverse=True) if light_rod == 4: sendingColorBuffer4.insertAndPop(c) sendingColorBuffer4.send(data_receiver_color_key="COLOR4", reverse=True) eventGenerator.reset()
# Put some known colors at the beginning. for c in Sequences.GetSentinels(): sendingColorBuffer.insertAndPop(c) for c in colorSequence: t = time.time() # Insert the next color into one end of the strip (and # pop the oldest color from the other end). sendingColorBuffer.insertAndPop(c) """ insertAndPop, see Buffer.py Insert the given Color into the beginning (index 0) of the color list, and pop a Color from the end (maintaining size). """ # Send the updated colors to the Arduino. sendingColorBuffer.send(data_receiver_color_key="COLOR2") sendingColorBuffer.send(data_receiver_color_key="COLORS") sys.stdout.write('.') sys.stdout.flush() sender.readAndPrint() dt += time.time() - t print 'Elapsed per %d updates: %.2fs' % (TRIALS, dt) print 'Updates per second: %.2f' % (TRIALS / dt)
# For simulating, TurtleBuffer subclasses SendingBuffer and # draws to the screen using Turtle Graphics as well. if DRAW: sendingColorBuffer = TurtleBuffer(sender=sender) else: sendingColorBuffer = SendingBuffer(sender=sender) # Put some known colors at the beginning. for c in Sequences.GetSentinels(): sendingColorBuffer.insertAndPop(c) for c in colorSequence: t = time.time() # Insert the next color into one end of the strip (and # pop the oldest color from the other end). sendingColorBuffer.insertAndPop(c) # Send the updated colors to the Arduino. sendingColorBuffer.send() sys.stdout.write('.') sys.stdout.flush() sender.readAndPrint() dt += time.time() - t print 'Elapsed per %d updates: %.2fs' % (TRIALS, dt) print 'Updates per second: %.2f' % (TRIALS / dt)