def HyperLeaf(my_panels): PanelIDs = my_panels[1:-1] lower_panel = my_panels[0] upper_panel = my_panels[len(my_panels) - 1] first_panel = PanelIDs[0] last_panel = PanelIDs[len(PanelIDs) - 1] print(my_panels) print(lower_panel) print(first_panel) print(upper_panel) print(last_panel) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) my_aurora = Aurora(IPstring, tokenString) # IP address and key for nanoleaf Aurora my_aurora.on = True #Turn nanoleaf on my_aurora.brightness = 50 #set brightness sleep(1) strm = my_aurora.effect_stream( ) #set nanoleaf to streaming mode, this only works with bharat's fork of nanoleaf LOG.info(strm.addr) while True: data = sock.recvfrom( 21 ) # hyperion sends 3 bytes (R,G,B) for each configured light (3*7=21) now = datetime.datetime.now() # retrieve time for debuging new = bytearray(data[0]) # retrieve hyperion byte array RGBList = list(new) # great R-G-B list # print(RGBList) # for debuging only PanelCount = 0 # initial condition for Panel in PanelIDs: # itterate through the configured PanleID's above firstByteIndex = PanelCount * 3 # Red Index secondByteIndex = firstByteIndex + 1 # Green Index thirdByteIndex = secondByteIndex + 1 # Blue Index intPanelID = PanelIDs[ PanelCount] # This Panel ID ***could this not just be "Panel" intRedValue = RGBList[firstByteIndex] intGreenValue = RGBList[secondByteIndex] intBlueValue = RGBList[thirdByteIndex] # print(str(intPanelID) + " " + str(intRedValue) + " " + str(intGreenValue) + " " + str(intBlueValue)) if intPanelID == lower_panel or intPanelID == first_panel: # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well strm.panel_set(lower_panel, intRedValue, intGreenValue, intBlueValue) strm.panel_set(first_panel, intRedValue, intGreenValue, intBlueValue) else: if intPanelID == upper_panel or intPanelID == last_panel: # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well strm.panel_set(upper_panel, intRedValue, intGreenValue, intBlueValue) strm.panel_set(last_panel, intRedValue, intGreenValue, intBlueValue) else: strm.panel_set(intPanelID, intRedValue, intGreenValue, intBlueValue) # set the current panel color PanelCount += 1 # next panel
def do_cinema_mode(self, my_id, terminate): addr = self.get_ifaces() if len(addr) == 0: LOG.info("no UDP network connection detected") elif len(addr) == 1: iface, my_ip = addr.popitem() LOG.info("UDP network connection found") self.UDP_IP = my_ip LOG.info("Starting Nanoleaf Cinema Mode: " + str(my_id)) all_panels = self.get_panels() panel_ids = all_panels[1:-1] lower_panel = all_panels[0] upper_panel = all_panels[len(all_panels) - 1] first_panel = panel_ids[0] last_panel = panel_ids[len(panel_ids) - 1] try: LOG.info('Attempting to open the socket connection') sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP sock.bind((self.UDP_IP, self.UDP_PORT)) sock.settimeout(5) socket_open = True except Exception as e: LOG.error(e) LOG.info('Socket Connection Failed') socket_open = False LOG.info('Connecting to Aurora at: ' + self.IPstring + " : " + self.tokenString) my_aurora = Aurora( self.IPstring, self.tokenString) # IP address and key for nanoleaf Aurora my_aurora.on = True # Turn nanoleaf on my_aurora.brightness = 50 # set brightness sleep(1) LOG.info('Attempting to switch to cinema mode') try: strm = my_aurora.effect_stream() # set nanoleaf to streaming mode LOG.info('Aurora Successfully switched to cinema mode') LOG.info('waiting for udp data') while True: if not socket_open: break try: raw_data = sock.recvfrom( 21 ) # hyperion sends 3 bytes (R,G,B) for each configured light (3*7=21) byte_data = bytearray( raw_data[0]) # retrieve hyperion byte array rgb_list = list(byte_data) # great R-G-B list # LOG.info(rgb_list) # for debuging only panel_count = 0 # initial condition for each_panel in panel_ids: # itterate through the configured PanleID's above # Todo - Determine if I can use Panel instead of PanelID's # Todo - If we can use Panel then the PanelCount should not be required # LOG.info('Panel: ' + str(each_panel) + " - Panel ID:" + str(panel_ids[panel_count])) first_byte_index = panel_count * 3 # Red Index second_byte_index = first_byte_index + 1 # Green Index third_byte_index = second_byte_index + 1 # Blue Index int_panel_id = panel_ids[ panel_count] # This Panel ID ***could this not just be "Panel" # int_panel_id = each_panel int_red_value = rgb_list[first_byte_index] int_green_value = rgb_list[second_byte_index] int_blue_value = rgb_list[third_byte_index] if int_panel_id == lower_panel or int_panel_id == first_panel: # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well strm.panel_set(lower_panel, int_red_value, int_green_value, int_blue_value) strm.panel_set(first_panel, int_red_value, int_green_value, int_blue_value) else: if int_panel_id == upper_panel or int_panel_id == last_panel: # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well strm.panel_set(upper_panel, int_red_value, int_green_value, int_blue_value) strm.panel_set(last_panel, int_red_value, int_green_value, int_blue_value) else: strm.panel_set(int_panel_id, int_red_value, int_green_value, int_blue_value ) # set the current panel color panel_count += 1 # next panel except Exception as e: LOG.error(e) LOG.info('Socket Timeout Error - No Data Received') break if terminate(): LOG.info('Stop Signal Received') break except Exception as e: LOG.error(e) LOG.info('Aurora Failed to launch cinema mode') my_aurora.on = False # Turn nanoleaf off try: sock.close() LOG.info('Socket Closed') except Exception as e: LOG.error(e) LOG.info('Socket Closure Failed!') LOG.info("Nanoleaf Cinema Mode Ended: " + str(my_id))
def TestPanel(panel_id): MyPanelID = panel_id MyPanels = Aurora(IPstring, tokenString) Mystrm = MyPanels.effect_stream() Mystrm.panel_set(MyPanelID, 0, 0, 0)