Beispiel #1
0
def set_pixel_color_matrix(row, column, color="", timeout=0.1):
    num_of_pixel = get_led_number(row, column)
    if Serial2.baud == 0:
        setup()
    command = "x{} {}\n".format(num_of_pixel, color)
    Serial2.write(command)
    itime = time.time()
    icommand = ""
    while (icommand.count(command) == 0 and time.time() < itime + 0.1):
        ichar = Serial2.read()
        if ichar != "\r":
            icommand += ichar
    if icommand.count(command) > 0:
        return True
    else:
        return False
def test(count=12):
    #ser = serial.Serial('/dev/ttyACM3', 115200, timeout=0.1)
    setup()
    #time.sleep(1)
    #print ser.readlines()
    for b in range(1,count + 1):
        for i in range(135):
            command = "x" + str(i) + " " + hex((b % 4 == 1) * 255 + (b % 4 == 2) * 256 * 255 + (b % 4 == 3) * 256 * 256 * 255)[2:]
            #x = ser.write(prikaz + "\n")
            Serial2.write(command + "\n")
            itime = time.time()
            icommand = ""
            while(icommand.count(command)==0 and time.time() < itime + 0.1):
                icommand += Serial2.read()
            #print icommand
    return #ser
Beispiel #3
0
def oldtest1(count=1000):
    """test of writing into panel video memory"""
    r = 0.5
    g = 0
    b = 0
    data_pattern = '\x00\x00\x00\x10\x10\x10   @@@'
    count_of_pixels = 40
    begin_time = time.time()
    for change_number in range(count):
        for memblock in range(4):
            command = "m{} {}".format(memblock * count_of_pixels, \
                    count_of_pixels)
            Serial2.write(command + "\n")
            itime = time.time()
            icommand = ""
            while (icommand.count(command) == 0 and time.time() < itime + 0.1):
                icommand += Serial2.read()
            # apply rgb modifying
            r = max(math.sin(change_number / 50.), 0)
            g = max(math.sin(change_number / 50. + math.pi * 2 / 3), 0)
            b = max(math.sin(change_number / 50. + math.pi * 4 / 3), 0)
            modif_data_pattern = ""
            for i in range(len(data_pattern)):
                modif_data_pattern += chr(int(ord(data_pattern[i]) * \
                    (r * (i % 3 == 0) + g * (i % 3 == 1) + b * (i % 3 == 2))))
            # data writing
            data = rotate(modif_data_pattern, (change_number * 3) % \
                    len(data_pattern)) * (count_of_pixels * 3 / \
                    len(data_pattern))
            Serial2.write(data)
            itime = time.time()
            icommand = ""
            while(icommand.count("OK")==0 and icommand.count("KO")==0 and \
                    time.time() < itime + 0.1):
                icommand += Serial2.read()
        command = "show"
        Serial2.write(command + "\n")
        itime = time.time()
        icommand = ""
        while (icommand.count(command) == 0 and time.time() < itime + 0.1):
            icommand += Serial2.read()
        #print icommand

    end_time = time.time()
    print "{} changes".format(count)
    print "total time {} seconds".format(end_time - begin_time)
    print "one change period {} seconds".format(
        (end_time - begin_time) / count)
    return  #ser
Beispiel #4
0
def send_to_panel(command, answer=None, timeout=0.1):
    """send command to panel
    command - command for sending
    answer - expected answer"""
    if Serial2.baud == 0:
        setup()
    if answer is None:
        answer = command
    Serial2.write(command)
    itime = time.time()
    icommand = ""
    while (icommand.count(answer) == 0 and time.time() < itime + timeout):
        ichar = Serial2.read()
        if ichar != "\r":
            icommand += ichar
    if icommand.count(answer) > 0:
        return True
    else:
        return False
def send_to_panel(command, answer=None, timeout=0.1): 
    """send command to panel
    command - command for sending
    answer - expected answer"""
    if Serial2.baud == 0: 
        setup()
    if answer is None: 
        answer = command
    Serial2.write(command)
    itime = time.time()
    icommand = ""
    while(icommand.count(answer)==0 and time.time() < itime + timeout):
        ichar = Serial2.read()
        if ichar != "\r": 
            icommand += ichar
    if icommand.count(answer) > 0: 
        return True
    else: 
        return False
def oldtest1(count=1000):
    """test of writing into panel video memory"""
    r = 0.5
    g = 0
    b = 0
    data_pattern = '\x00\x00\x00\x10\x10\x10   @@@'
    count_of_pixels = 40
    begin_time = time.time()
    for change_number in range(count):
        for memblock in range(4):
            command = "m{} {}".format(memblock * count_of_pixels, \
                    count_of_pixels)
            Serial2.write(command + "\n")
            itime = time.time()
            icommand = ""
            while(icommand.count(command)==0 and time.time() < itime + 0.1):
                icommand += Serial2.read()
            # apply rgb modifying
            r = max(math.sin(change_number/50.), 0)
            g = max(math.sin(change_number/50. + math.pi * 2 / 3), 0)
            b = max(math.sin(change_number/50. + math.pi * 4 / 3), 0)
            modif_data_pattern = ""
            for i in range(len(data_pattern)):
                modif_data_pattern += chr(int(ord(data_pattern[i]) * \
                    (r * (i % 3 == 0) + g * (i % 3 == 1) + b * (i % 3 == 2))))
            # data writing
            data = rotate(modif_data_pattern, (change_number * 3) % \
                    len(data_pattern)) * (count_of_pixels * 3 / \
                    len(data_pattern))
            Serial2.write(data)
            itime = time.time()
            icommand = ""
            while(icommand.count("OK")==0 and icommand.count("KO")==0 and \
                    time.time() < itime + 0.1):
                icommand += Serial2.read()
        command = "show"
        Serial2.write(command + "\n")
        itime = time.time()
        icommand = ""
        while(icommand.count(command)==0 and time.time() < itime + 0.1):
            icommand += Serial2.read()
        #print icommand
 
    end_time = time.time()
    print "{} changes".format(count)
    print "total time {} seconds".format(end_time - begin_time)
    print "one change period {} seconds".format((end_time - begin_time) / count)
    return #ser
Beispiel #7
0
def read():
    """read and return all data from input serial buffer"""
    data = ""
    while Serial2.available():
        data += Serial2.read()
    return data
Beispiel #8
0
def setup(speed=115200):
    # Start Serial2 at speed baud:
    Serial2.begin(speed)
Beispiel #9
0
def test1(count=1000):
    """writing into video memory"""

    #ser = serial.Serial('/dev/ttyACM3', 115200, timeout=0.1)
    # time.sleep(1)
    r = 0.5
    g = 0
    b = 0
    #j = ser.readlines()
    j = nacti()
    data_pattern = '\x00\x00\x00\x10\x10\x10   @@@'
    count_of_pixels = 40
    begin_time = time.time()
    for change_number in range(count):
        for memblock in range(4):
            command = "m{} {}".format(memblock * count_of_pixels,
                                      count_of_pixels)
            #print command
            #m = ser.write(prikaz + "\n")
            #while ser.inWaiting() < len(prikaz) + 2:
            #    pass
            #j = ser.read(len(prikaz) + 2)
            Serial2.write(command + "\n")
            itime = time.time()
            icommand = ""
            while (icommand.count(command) == 0 and time.time() < itime + 0.1):
                icommand += Serial2.read()
            #print icommand

            # apply rgb modifying
            r = max(math.sin(change_number / 50.), 0)
            g = max(math.sin(change_number / 50. + math.pi * 2 / 3), 0)
            b = max(math.sin(change_number / 50. + math.pi * 4 / 3), 0)
            modif_data_pattern = ""
            for i in range(len(data_pattern)):
                modif_data_pattern += chr(int(ord(data_pattern[i]) * \
                    (r * (i % 3 == 0) + g * (i % 3 == 1) + b * (i % 3 == 2))))
            # data writing
            data = rotate(modif_data_pattern, (change_number * 3) % len(data_pattern)) \
                   * (count_of_pixels * 3 / len(data_pattern))

            print data

            #print len(data)
            #print data
            #m = ser.write(data)
            Serial2.write(data)
            # answer is OK or KO
            #while ser.inWaiting() < 2 + 2:
            #    pass
            #j = ser.read(2 + 2)
            itime = time.time()
            icommand = ""
            while (icommand.count("OK") == 0 and icommand.count("KO") == 0
                   and time.time() < itime + 0.1):
                icommand += Serial2.read()
            #print icommand

        command = "show"
        Serial2.write(command + "\n")
        itime = time.time()
        icommand = ""
        while (icommand.count(command) == 0 and time.time() < itime + 0.1):
            icommand += Serial2.read()
        #print icommand

    end_time = time.time()
    print "{} changes".format(count)
    print "total time {} seconds".format(end_time - begin_time)
    print "one change period {} seconds".format(
        (end_time - begin_time) / count)

    return  #ser
Beispiel #10
0
def nacti():
    data = ""
    while Serial2.available():
        data += Serial2.read()
    return data
def test1(count=1000):
    """writing into video memory"""
    
    #ser = serial.Serial('/dev/ttyACM3', 115200, timeout=0.1)
    # time.sleep(1)
    r = 0.5
    g = 0
    b = 0
    #j = ser.readlines()
    j = nacti()
    data_pattern = '\x00\x00\x00\x10\x10\x10   @@@'
    count_of_pixels = 40
    begin_time = time.time()
    for change_number in range(count):
        for memblock in range(4):
            command = "m{} {}".format(memblock * count_of_pixels, count_of_pixels)
            #print command
            #m = ser.write(prikaz + "\n")
            #while ser.inWaiting() < len(prikaz) + 2:
            #    pass
            #j = ser.read(len(prikaz) + 2)
            Serial2.write(command + "\n")
            itime = time.time()
            icommand = ""
            while(icommand.count(command)==0 and time.time() < itime + 0.1):
                icommand += Serial2.read()
            #print icommand

            # apply rgb modifying
            r = max(math.sin(change_number/50.), 0)
            g = max(math.sin(change_number/50. + math.pi * 2 / 3), 0)
            b = max(math.sin(change_number/50. + math.pi * 4 / 3), 0)
            modif_data_pattern = ""
            for i in range(len(data_pattern)):
                modif_data_pattern += chr(int(ord(data_pattern[i]) * \
                    (r * (i % 3 == 0) + g * (i % 3 == 1) + b * (i % 3 == 2))))
            # data writing
            data = rotate(modif_data_pattern, (change_number * 3) % len(data_pattern)) \
                   * (count_of_pixels * 3 / len(data_pattern))

            print data
            
            #print len(data)
            #print data
            #m = ser.write(data)
            Serial2.write(data)
            # answer is OK or KO
            #while ser.inWaiting() < 2 + 2:
            #    pass
            #j = ser.read(2 + 2)
            itime = time.time()
            icommand = ""
            while(icommand.count("OK")==0 and icommand.count("KO")==0 and time.time() < itime + 0.1):
                icommand += Serial2.read()
            #print icommand

        command = "show"
        Serial2.write(command + "\n")
        itime = time.time()
        icommand = ""
        while(icommand.count(command)==0 and time.time() < itime + 0.1):
            icommand += Serial2.read()
        #print icommand
 
    end_time = time.time()
    print "{} changes".format(count)
    print "total time {} seconds".format(end_time - begin_time)
    print "one change period {} seconds".format((end_time - begin_time) / count)
        
    return #ser
def nacti():
    data = ""
    while Serial2.available():
        data += Serial2.read()
    return data
def setup(speed=115200):
  # Start Serial2 at speed baud:
  Serial2.begin(speed)
def read():
    """read and return all data from input serial buffer"""
    data = ""
    while Serial2.available():
        data += Serial2.read()
    return data