def ring_image(led_count, ledOn): # Create a new driver config driver_config_proto = driver_pb2.DriverConfig() # Create an empty Everloop image image = [] # Set individual LED value for led in range(led_count): if led in ledOn: ledValue = io_pb2.LedValue( ) # Protocol buffer custom type for Matrix Voice ledValue.blue = ledOn[led]["blue"] ledValue.red = ledOn[led]["red"] ledValue.green = ledOn[led]["green"] ledValue.white = ledOn[led]["white"] image.append(ledValue) else: ledValue = io_pb2.LedValue() ledValue.blue = 0 ledValue.red = 0 ledValue.green = 0 ledValue.white = 0 image.append(ledValue) # Store the Everloop image in driver configuration driver_config_proto.image.led.extend(image) return driver_config_proto.SerializeToString()
def _newArray(self): ledValue = io_pb2.LedValue() ledValue.blue = 0 ledValue.red = 0 ledValue.green = 0 ledValue.white = 0 self._colors = [ledValue] * self._numLeds
def set_everloop_intensity(intensity): """Sets all of the LEDS to a given rgbw value""" # grab zmq context context = zmq.Context() # get socket for config config_socket = context.socket(zmq.PUSH) config_socket.connect('tcp://{0}:{1}'.format(creator_ip, creator_everloop_base_port)) # create a new driver config strut config = driver_pb2.DriverConfig() # initialize an empty list for the "image" or LEDS image = [] # iterate over all 35 LEDS and set the rgbw value of each # then append it to the end of the list/image thing for led in range(35): ledValue = io_pb2.LedValue() ledValue.blue = 0 ledValue.red = 0 ledValue.green = intensity ledValue.white = 0 image.append(ledValue) # add the "image" to the config driver config.image.led.extend(image) # send a serialized string of the driver config # to the config socket config_socket.send(config.SerializeToString())
def setPixel(self, ledNum, red, green, blue, white): ledValue = io_pb2.LedValue() ledValue.red = red ledValue.green = green ledValue.blue = blue ledValue.white = white self._colors[ledNum] = ledValue
def config_socket(ledCount): # Define zmq socket context = zmq.Context() # Create a Pusher socket socket = context.socket(zmq.PUSH) # Connect Pusher to configuration socket socket.connect('tcp://{0}:{1}'.format(matrix_ip, everloop_port)) # Loop forever while True: # Create a new driver config driver_config_proto = driver_pb2.DriverConfig() # Create an empty Everloop image image = [] # For each device LED for led in range(ledCount): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = randint(0, 50) ledValue.red = randint(0, 200) ledValue.green = randint(0, 255) ledValue.white = 0 image.append(ledValue) # Store the Everloop image in driver configuration driver_config_proto.image.led.extend(image) # Send driver configuration through ZMQ socket socket.send(driver_config_proto.SerializeToString()) #Wait before restarting loop time.sleep(0.05)
def get_led(**args): ledValue = io_pb2.LedValue() ledValue.red = args.get('red', 0) ledValue.green = args.get('green', 0) ledValue.blue = args.get('blue', 0) ledValue.white = args.get('white', 0) return ledValue
def updateLedCount(self, data): self._numLeds = io_pb2.LedValue().FromString(data[0]).green self._logger.info('{0} LEDs counted'.format(self._numLeds)) if self._numLeds > 0: self._logger.info( 'LED count obtained. Disconnecting from data publisher {0}'. format(self._everloopPort + 3)) ioloop.IOLoop.instance().stop()
def updateLedCount(data): # Extract data and pass into led_count global variable global led_count led_count = io_pb2.LedValue().FromString(data[0]).green # Log LEDs print('{0} LEDs counted'.format(led_count)) # If LED count obtained if led_count > 0: # Close Data Update Port connection ioloop.IOLoop.instance().stop() print('LED count obtained. Disconnecting from data publisher {0}'.format(everloop_port+3))
def setPixel(self, ledNum, red, green, blue, white): ledValue = io_pb2.LedValue() ledValue.red = red ledValue.green = green ledValue.blue = blue ledValue.white = white if ledNum < self._numLeds: self._colors[ledNum] = ledValue else: self._logger.warning( "Led number missmatch ({}/{}), aborting".format( ledNum, self._numLeds))
def ledSpin(lit_led): # Create an empty Everloop image image = [] if led_count == lit_led: lit_led = 1 else: lit_led = lit_led + 1 for led in range(0, lit_led): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 0 ledValue.red = 0 ledValue.green = 0 ledValue.white = 0 image.append(ledValue) for led in range(lit_led, lit_led+1): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 0 ledValue.red = 100 ledValue.green = 0 ledValue.white = 0 image.append(ledValue) for led in range(lit_led +1, led_count): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 0 ledValue.red = 0 ledValue.green = 0 ledValue.white = 0 image.append(ledValue) #reset led counter return [image, lit_led]
def setEverloopColor(red=0, green=0, blue=0, white=0): config = driver_pb2.DriverConfig() image = [] for led in range(35): ledValue = io_pb2.LedValue() ledValue.blue = blue ledValue.red = red ledValue.green = green ledValue.white = white image.append(ledValue) config.image.led.extend(image) config_socket.send(config.SerializeToString())
def speaking_leds(): driver_config_proto = driver_pb2.DriverConfig() everloop_image = [] for i in range(0, 35): led_value = io_pb2.LedValue() # set red brightness to 100 led_value.white = 20 # append that led configuration to led container everloop_image.append(led_value) # put the image into driver driver_config_proto.image.led.extend(everloop_image) # send the configuration to the driver socket.send(driver_config_proto.SerializeToString()) return None
def configSocket(self, ledCount): self._socket.connect('tcp://{0}:{1}'.format(self._matrixIp, self._everloopPort)) while True: image = [] # For each device LED for led in range(ledCount): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = randint(0, 50) ledValue.red = randint(0, 200) ledValue.green = randint(0, 255) ledValue.white = 0 image.append(ledValue) self._driver.image.led.extend(image) self._socket.send(self._driver.SerializeToString()) time.sleep(0.05)
def set_everloop_color(red=0, green=0, blue=0, white=0): """Submit a R,G,B,W value between 0-255""" # or local ip of MATRIX creator creator_ip = '127.0.0.1' # port for everloop driver creator_everloop_base_port = 20013 + 8 # grab zmq context context = zmq.Context() # get socket for config config_socket = context.socket(zmq.PUSH) config_socket.connect('tcp://{0}:{1}'.format(creator_ip, creator_everloop_base_port)) # create a new driver config strut config = driver_pb2.DriverConfig() # initialize an empty list for the "image" or LEDS image = [] # iterate over all 35 LEDS and set the rgbw value of each # then append it to the end of the list/image thing for led in range(35): ledValue = io_pb2.LedValue() ledValue.blue = blue ledValue.red = red ledValue.green = green ledValue.white = white image.append(ledValue) # add the "image" to the config driver config.image.led.extend(image) # send a serialized string of the driver config # to the config socket config_socket.send(config.SerializeToString())
def _create_everloop_colors(led_count, *led_colors_array): if len(led_colors_array) > led_count: _LOGGER.warn( "To many led colors given for everloop. Given: {}. Number of leds: {}" .format(len(led_colors_array), led_count)) # initialize an empty list for the "image" or LEDS image = [] for led_idx in range(led_count): color_count = len(led_colors_array) color_idx = math.floor(((led_idx / color_count) / (led_count / color_count)) * color_count) led_color = led_colors_array[color_idx] ledValue = io_pb2.LedValue() ledValue.red = led_color[0] ledValue.green = led_color[1] ledValue.blue = led_color[2] ledValue.white = led_color[3] image.append(ledValue) return image
def config_socket(ledCount): global flag global Color # Define zmq socket context = zmq.Context() # Create a Pusher socket socket = context.socket(zmq.PUSH) # Connect Pusher to configuration socket socket.connect('tcp://{0}:{1}'.format(matrix_ip, everloop_port)) rc = 0 driver_config_proto = driver_pb2.DriverConfig() # Create an empty Everloop image image = [] # For each device LED for led in range(ledCount): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 10 ledValue.red = 10 ledValue.green = 10 ledValue.white = 0 image.append(ledValue) # Store the Everloop image in driver configuration driver_config_proto.image.led.extend(image) # Send driver configuration through ZMQ socket socket.send(driver_config_proto.SerializeToString()) client = mqtt.Client() client.connect("raspberrypi.local", 1883) client.subscribe("hermes/nlu/intentParsed") client.subscribe("esp/test") client.on_message = on_message client.on_connect = on_connect client.on_publish = on_publish client.on_subscribe = on_subscribe client.on_log = on_log while rc == 0: rc = client.loop() if (flag): # Create a new driver config driver_config_proto = driver_pb2.DriverConfig() # Create an empty Everloop image image = [] # For each device LED if (Color == "red"): for led in range(ledCount): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 0 ledValue.red = 100 ledValue.green = 0 ledValue.white = 0 image.append(ledValue) elif (Color == "blue"): for led in range(ledCount): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 100 ledValue.red = 0 ledValue.green = 0 ledValue.white = 0 image.append(ledValue) elif (Color == "green"): client.publish("esp/lock", "Hello") for led in range(ledCount): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 0 ledValue.red = 0 ledValue.green = 100 ledValue.white = 0 image.append(ledValue) else: for led in range(ledCount): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 10 ledValue.red = 10 ledValue.green = 10 ledValue.white = 0 image.append(ledValue) # Store the Everloop image in driver configuration driver_config_proto.image.led.extend(image) # Send driver configuration through ZMQ socket socket.send(driver_config_proto.SerializeToString()) #Wait before restarting loop time.sleep(10) # Create a new driver config driver_config_proto = driver_pb2.DriverConfig() # Create an empty Everloop image image = [] # For each device LED for led in range(ledCount): # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = 10 ledValue.red = 10 ledValue.green = 10 ledValue.white = 0 image.append(ledValue) # Store the Everloop image in driver configuration driver_config_proto.image.led.extend(image) # Send driver configuration through ZMQ socket socket.send(driver_config_proto.SerializeToString()) flag = False
# Paint Goal for i_led, v_led in enumerate(goal.rgb_out()): img.set_led(int(goal.pos + i_led), int(v_led[0]), int(v_led[1]), int(v_led[2]), int(v_led[3]) ) # Paint Hero img.set_led(int(hero.pos), int(hero.r),int(hero.g),int(hero.b),int(hero.w)) ##################################################################### leds = img.out image = [] # For each device LED for led in leds: # Set individual LED value ledValue = io_pb2.LedValue() ledValue.blue = int(led[2]) ledValue.red = int(led[0]) ledValue.green = int(led[1]) ledValue.white = int(led[3]) image.append(ledValue) # Store the Everloop image in driver configuration driver_config_proto.image.led.extend(image) # Send driver configuration through ZMQ socket socket.send(driver_config_proto.SerializeToString()) # Wait before restarting loop loop_time = 0.1 time.sleep(loop_time) frame += 1
def _newArray(self): ledValue = io_pb2.LedValue() return [ledValue] * self._numLeds