Esempio n. 1
0
def sendout(args):
    # sendout function that sends out data to the networked devices and
    # also to the matrix screen simulator if enabled.
    # or only to the matrix simulator if netSilent enabled.
    try:
        for t in TARGETS:
            pattern = TARGETS[t]
            data = pattern.generate()
            # make sure matrixSim always displays
            # the data the right way.
            # can't have the matrixsimulator hang because there is not change..
            if args.matrixSim == "enabled":
                matrixscreen.handleinput()
            # if this is a simulation draw it to the matrixscreen
            if args.matrixSim == "enabled":
                    matrixscreen.process(data)
            # convert the data for the special matrix layout.
            if args.snakeMode == "enabled":
                data = convertSnakeModes(data)
            if args.byteMode == "enabled":
                data = convertByteMode(data, args.convertColor)
            # check if data generated is the same as before because then
            # just don't send it out
            change = True
            if args.soc == "enabled":
                previous_set = collections.Counter(sendout.data)
                current_set = collections.Counter(data)
                change = previous_set != current_set
            elif args.soc == "disabled":
                change = True
            if(change):
                sendout.data = data
                # send it out over the network.
                if not (args.netSilent == "enabled"):
                    try:
                        if (args.mapy == "enabled"):

                            for universe in range(0,matrix_height):
                                #print('send to universe:', universe)
                                sock.sendto(buildPacket(universe, data[matrix_width*universe:(matrix_width*(universe+1))]), (t, UDP_PORT))    
                        else:
                            #sock.sendto(buildPacket(0, data), (t, UDP_PORT))
                            #sock.sendto(buildPacket(1, data), (t, UDP_PORT))
                            #sock.sendto(buildPacket(2, data), (t, UDP_PORT))
                            sock.sendto(buildPacket(3, data), (t, UDP_PORT))
                            #sock.sendto(buildPacket(4, data), (t, UDP_PORT))
                            #sock.sendto(buildPacket(5, data), (t, UDP_PORT))
                    except Exception:
                        print("no good ip dest found: %s" % (t))
                        sys.exit(0)
    # matrix sim needs this because i am to lazy to press the x button.
    except KeyboardInterrupt:
        signal_handler(None, None)
    except SystemExit as error:
        signal_handler(error, None)
Esempio n. 2
0
 def run(self):
     try:
         self.matrix_widget.process()
         data = self.matrix_widget.get_data()
         if data:
             if self.args.snakeMode == "enabled":
                 data = convertSnakeModes(data)
             if self.args.byteMode == "enabled":
                 data = convertByteMode(data, self.args.convertColor)
             if self.args.netSilent == "disabled":
                 self.send_packets.sendout(data)
     except Exception as e:
         print >>self, e
     return True