def blinkytape_artnet_receiver():
    print(("Listening in {0}:{1}").format(UDP_IP, UDP_PORT))

    sock = socket(AF_INET, SOCK_DGRAM)  # UDP
    sock.bind((UDP_IP, UDP_PORT))

    bt = blinkytape.BlinkyTape(BLINKYTAPE_DEVICE, BLINKYTAPE_LENGTH)

    lastSequence = 0

    packetCount = 0
    lastTime = time.time()

    datas = []

    while True:
        try:
            data, addr = sock.recvfrom(1024)
            packet = ArtnetPacket.unpack_raw_artnet_packet(data)

            if packet != None:
                # print("Sequence=%i universe=%i"%(packet.sequence,packet.universe))
                packetCount += 1

                while len(datas) < packet.universe + 1:
                    print("adding new universe %i" % (packet.universe))
                    datas.append('')

                datas[packet.universe] = bytearray(packet.data)

                # Send an update to the tape when a new sequence is received on the last universe
                # and lastSequence != packet.sequence: some artnet doesn't provide sequence updates
                if packet.universe == (len(datas)-1):
                    outputData = bytearray()

                    for data in datas:
                        if len(data) > PIXELS_PER_UNIVERSE*BYTES_PER_PIXEL:
                            data = data[0:PIXELS_PER_UNIVERSE*BYTES_PER_PIXEL]

                        if len(data) < PIXELS_PER_UNIVERSE*BYTES_PER_PIXEL:
                            data = data + \
                                ('\x00' * (PIXELS_PER_UNIVERSE *
                                           BYTES_PER_PIXEL - len(data)))

                        outputData.extend(data)

                    outputDataStr = ""
                    for b in outputData:
                        outputDataStr += chr(b)
                    bt.sendData(outputDataStr)
                    lastSequence = packet.sequence

            if time.time() > lastTime+1:
                print("Packets per second: %i" % (packetCount))
                packetCount = 0
                lastTime = time.time()

        except KeyboardInterrupt:
            sock.close()
            sys.exit()
Пример #2
0
def connect(port):

    if not port:
        sys.exit("Could not locate a BlinkyTape.")

    print("BlinkyTape found at: %s" % port)

    bt = blinkytape.BlinkyTape(port)
    bt.displayColor(0, 0, 0)
    return bt
Пример #3
0
            data += makePixel(r, g, b)

        self.j += .3
        self.f += .3
        self.k += .5

        return data


if __name__ == "__main__":

    import blinkytape
    import time

    animation = colorloop(14 * 3, 1, 1, 1)
    bt = blinkytape.BlinkyTape()

    i = 0
    while True:
        data = animation.getData()

        for pixel in range(0, 14 * 3):
            bt.sendPixel(ord(data[pixel * 3 + 0]), ord(data[pixel * 3 + 1]),
                         ord(data[pixel * 3 + 2]))
        bt.show()

        i += 1
        if i > 985:
            animation = colorloop(14 * 3, 1, 1, 1)
            i = 0
Пример #4
0
 def __init__(self, port):
     super(BlinkyTape, self).__init__()
     self.btape = blinkytape.BlinkyTape(port)
     self.c_color = (0, 0, 0)
     self.set_color(RGB_OFF)