Ejemplo n.º 1
0
def test_NexSlider(port):
    nexSerial = PySerialNex(port)

    nexSlider = NexSlider(nexSerial, "h0", cid=4)

    nexSerial.send("page pg_slider")
    time.sleep(0.1)

    nexSlider.value = 43691  # 0-65535

    time.sleep(1)

    # nexSlider.cursor.color = Colour.GRAY
    nexSlider.forecolor = Colour.GRAY

    time.sleep(1)

    w = 10
    nexSlider.cursor.width = w
    assert nexSlider.cursor.width == w

    time.sleep(1)

    h = 13
    nexSlider.cursor.height = h
    assert nexSlider.cursor.height == h

    time.sleep(1)

    nexSerial.close()
Ejemplo n.º 2
0
def test_NexCheckbox(port):
    nexSerial = PySerialNex(port)

    nexCheckbox0 = NexCheckbox(nexSerial, "c0", cid=4)
    nexCheckbox1 = NexCheckbox(nexSerial, "c1", cid=5)
    nexCheckbox2 = NexCheckbox(nexSerial, "c2", cid=7)

    nexSerial.send("page pg_dsb_chk_rad")

    nexCheckbox0.value = False
    nexCheckbox1.value = False
    nexCheckbox2.value = False

    assert not nexCheckbox0.value

    time.sleep(1)

    nexCheckbox0.value = True

    assert nexCheckbox0.value

    time.sleep(1)

    nexCheckbox0.value = False

    assert not nexCheckbox0.value

    time.sleep(1)

    nexSerial.close()
Ejemplo n.º 3
0
def test_NexQRCode(port):
    nexSerial = PySerialNex(port)

    nexQRcode = NexQRcode(nexSerial, "qr0", cid=1)
    nexText = NexText(nexSerial, "t1", cid=3)

    nexSerial.send("page pg_qr")

    time.sleep(1)

    text = "Hello"
    nexQRcode.text = text
    nexText.text = text

    time.sleep(2)

    # text = "https://github.com/scls19fr/pynextion"
    text = "http://bit.ly/2vWS75r"
    nexText.text = text
    # nexQRcode.textmaxlength = len(text)
    # nexQRcode.textmaxlength = 50
    # time.sleep(1)
    nexQRcode.text = text

    assert nexText.text == text
    assert nexQRcode.text == text

    nexSerial.close()
Ejemplo n.º 4
0
def test_NexRadio(port):
    nexSerial = PySerialNex(port)

    nexRadio0 = NexRadio(nexSerial, "r0", cid=8)
    nexRadio1 = NexRadio(nexSerial, "r1", cid=9)
    nexRadio2 = NexRadio(nexSerial, "r2", cid=10)

    nexSerial.send("page pg_dsb_chk_rad")

    nexRadio0.value = False
    nexRadio1.value = False
    nexRadio2.value = False

    assert not nexRadio0.value

    time.sleep(1)

    nexRadio0.value = True

    assert nexRadio0.value

    time.sleep(1)

    nexRadio0.value = False

    assert not nexRadio0.value

    time.sleep(1)

    nexSerial.close()
Ejemplo n.º 5
0
def test_NexPicture(port):
    nexSerial = PySerialNex(port)

    nexPicture = NexPicture(nexSerial, "p0", cid=1)

    nexSerial.send("page pg_pic")

    for i in range(1, 5):
        time.sleep(1)
        # nexPicture.picture = i
        nexPicture.picture = Picture(i)
        # assert nexPicture.picture == Picture(i)  # ToDo

    nexSerial.close()
Ejemplo n.º 6
0
def test_NexNumber(port):
    nexSerial = PySerialNex(port)

    nexNumber = NexNumber(nexSerial, "n0", cid=1)

    nexSerial.send("page pg_num")

    time.sleep(1)
    nexNumber.value = 1
    time.sleep(1)
    nexNumber.value = 2
    nexNumber.backcolor = Colour.RED
    nexNumber.forecolor = Colour.WHITE

    time.sleep(1)
    assert nexNumber.value == 2
    time.sleep(1)
    nexNumber.value = 3
    nexNumber.backcolor = Colour.WHITE
    nexNumber.forecolor = Colour.RED
    time.sleep(1)
    """
    n = typemax(Int32)
    # how to get max and min val of C integers (from Python)
    # see also https://stackoverflow.com/questions/9860588/maximum-value-for-long-integer/9860812

    nexNumber.value = n
    time.sleep(1)
    assert nexNumber.value == n
    """
    """
    n = typemin(Int32)
    nexNumber.value = n
    time.sleep(1)
    assert nexNumber.value == n
    """

    n = -2
    nexNumber.value = n
    time.sleep(1)
    assert nexNumber.value == n

    nexSerial.close()
Ejemplo n.º 7
0
def test_waveform(port, delay):
    nexSerial = PySerialNex(port)

    nexPage = NexPage(nexSerial, "pg_waveform", pid=12)

    nexWaveform = NexWaveform(nexSerial, "s0", cid=2)

    nexSerial.send("cls WHITE")
    nexPage.show()

    nexWaveform.grid.width = 20
    nexWaveform.grid.height = 20
    nexWaveform.grid.color = NamedColor.GRAY

    time.sleep(1)

    # send(nexSerial, "s0.pco0=65535")

    # nb_channels = len(nexWaveform.channels)
    # @test nb_channels == 4
    nb_channels = 4

    channel = nexWaveform.channels[2]  # 0, 1, 2, 3
    channel.color = NamedColor.RED

    # channel.append(123)  # values in 0:255 (add cid,chid,val)
    # channel.append(133)  # values in 0:255 (add)
    # channel.append(143)  # values in 0:255 (add)
    # channel.append(153)  # values in 0:255 (add)

    # channel.append([123, 133, 143, 153, 163, 173, 183])  # (addt)

    vals = [51 * x for x in range(1, 5)]
    dt_start = datetime.datetime.utcnow()
    while True:
        for ch in range(nb_channels):
            channel = nexWaveform.channels[ch]
            val = vals[ch]
            channel.append(val)
            vals[ch] = int(vals[ch] + 2 * random.uniform(-1, 1))
        if datetime.datetime.utcnow() - dt_start > datetime.timedelta(seconds=delay):
            break
        time.sleep(0.01)
Ejemplo n.º 8
0
def test_pages(port):
    nexSerial = PySerialNex(port)

    nexButtonPlus = NexButton(nexSerial, "b0", cid=1)
    nexNumber0 = NexNumber(nexSerial, "n0", cid=2)
    nexButtonMinus = NexButton(nexSerial, "b1", cid=3)
    nexButtonEnter = NexButton(nexSerial, "b2", cid=4)  # noqa: F841

    nexSerial.send("page pg_but")

    nexButtonPlus.backcolor = Colour.GREEN
    nexButtonMinus.backcolor = Colour.RED

    # nexNumber0.value = value
    value = nexNumber0.value
    while True:
        time.sleep(0.2)
        new_value = nexNumber0.value
        if new_value != value:
            value = new_value
            print(value)

    nexSerial.close()
Ejemplo n.º 9
0
def test_pages(port):
    nexserial = PySerialNex(port)
    nexWaveform = NexWaveform(nexserial, "s0", cid=2)

    nexserial.send("cls WHITE")
    nexserial.send("page pg_waveform")

    nexWaveform.grid.width = 20
    nexWaveform.grid.height = 20
    nexWaveform.grid.color = Colour.GRAY

    time.sleep(1)

    # send(nexSerial, "s0.pco0=65535")

    # nb_channels = len(nexWaveform.channels)
    # @test nb_channels == 4
    nb_channels = 4

    channel = nexWaveform.channels[2]  # 0, 1, 2, 3
    channel.color = Colour.RED

    # channel.append(123)  # values in 0:255 (add cid,chid,val)
    # channel.append(133)  # values in 0:255 (add)
    # channel.append(143)  # values in 0:255 (add)
    # channel.append(153)  # values in 0:255 (add)

    # channel.append([123, 133, 143, 153, 163, 173, 183])  # (addt)

    vals = [51 * x for x in range(1, 5)]
    while True:
        for ch in range(nb_channels):
            channel = nexWaveform.channels[ch]
            val = vals[ch]
            channel.append(val)
            vals[ch] = int(vals[ch] + 2 * random.uniform(-1, 1))
        time.sleep(0.01)
Ejemplo n.º 10
0
def test_draw(port):
    nexSerial = PySerialNex(port)

    nexSerial.send("page0")
    cls(nexSerial, DEFAULT_COLOUR)

    def print_several_lines(nexSerial,
                            lcd_width=LCD_WIDTH,
                            color1="WHITE",
                            color2="BLACK"):
        def swap(x, y):
            return y, x

        x, y = 0, 10
        w, h = lcd_width, 30
        font = Font(0)
        fontcolor = color1
        backcolor = color2
        xcenter = Alignment.Horizontal.CENTRE  # NONE/LEFT/CENTRE/RIGHT
        ycenter = Alignment.Vertical.CENTRE  # NONE/UP/CENTRE/DOWN
        sta = Background.SOLIDCOLOUR  # NONE/CROPIMAGE/SOLIDCOLOUR/IMAGE/NOBACKCOLOUR

        rows = [
            "Hello Python!", "", "This is Nextion", "",
            "I'm an intelligent display", "", "", "",
            "https://github.com/scls19fr", "/pynextion"
        ]
        for row in rows:
            print(nexSerial, row, x, y, w, h, font, fontcolor, backcolor,
                  xcenter, ycenter, sta)
            xstr(nexSerial, row, x, y, w, h, font, fontcolor, backcolor,
                 xcenter, ycenter, sta)
            y = y + h
            fontcolor, backcolor = swap(fontcolor, backcolor)

    def diagonal_line(nexSerial, lcd_width=LCD_WIDTH, lcd_height=LCD_HEIGHT):
        x1, y1 = 0, 0
        x2, y2 = lcd_width, lcd_height
        colour = Colour.BLUE
        line(nexSerial, x1, y1, x2, y2, colour)

    def circle_frame_fill(nexSerial,
                          lcd_width=LCD_WIDTH,
                          lcd_height=LCD_HEIGHT,
                          delay=1):
        x = int(round(lcd_width / 2))
        y = int(round(lcd_height / 2))
        r = 100
        colour = Colour.BLUE
        circle(nexSerial, x, y, r, colour)
        time.sleep(delay)
        circle(nexSerial, x, y, r, colour, Background.SOLIDCOLOUR)

    def clear_screen_color_france(nexSerial, delay=1):
        cls(nexSerial, Colour.BLUE)
        time.sleep(delay)
        cls(nexSerial, Colour.WHITE)
        time.sleep(delay)
        cls(nexSerial, Colour.RED)

    def france_flag(nexSerial, lcd_width=LCD_WIDTH, lcd_height=LCD_HEIGHT):
        w, h = int(round(lcd_width / 3)), lcd_height
        x1, y1 = 0, 0
        y2 = h
        x2 = x1 + w
        colour = Colour.BLUE
        rectangle(nexSerial, x1, y1, x2, y2, colour, Background.SOLIDCOLOUR)
        x1 = x1 + 2 * w
        x2 = x1 + w
        colour = Colour.RED
        rectangle(nexSerial, x1, y1, x2, y2, colour, Background.SOLIDCOLOUR)

    def rectangle_frame_fill(nexSerial,
                             lcd_width=LCD_WIDTH,
                             lcd_height=LCD_HEIGHT):
        w, h = 120, 80
        x1 = int(round((lcd_width - w) / 2))
        y1 = int(round((lcd_height - h) / 2))
        x2 = x1 + w
        y2 = y1 + h
        colour = Colour.RED
        rectangle(nexSerial, x1, y1, x2, y2, colour)
        time.sleep(1)
        rectangle(nexSerial, x1, y1, x2, y2, colour, Background.SOLIDCOLOUR)

    def picture_example(nexSerial,
                        lcd_width=LCD_WIDTH,
                        lcd_height=LCD_HEIGHT,
                        img_width=IMG_WIDTH,
                        img_height=IMG_HEIGHT,
                        delay=0.5):
        x = int(round((lcd_width - img_width) / 2))
        y = int(round((lcd_height - img_height) / 2))
        for picid in range(5):
            picture(nexSerial, x, y, Picture(picid))
            time.sleep(delay)

    cls(nexSerial)

    print_several_lines(nexSerial)
    time.sleep(2)

    cls(nexSerial, DEFAULT_COLOUR)
    diagonal_line(nexSerial)

    time.sleep(2)
    cls(nexSerial)

    circle_frame_fill(nexSerial)

    time.sleep(2)
    cls(nexSerial)

    clear_screen_color_france(nexSerial)

    time.sleep(2)
    cls(nexSerial)

    france_flag(nexSerial)

    time.sleep(2)
    cls(nexSerial)
    time.sleep(1)

    rectangle_frame_fill(nexSerial)

    time.sleep(2)
    cls(nexSerial)

    picture_example(nexSerial)

    nexSerial.close()
Ejemplo n.º 11
0
def test_NexSlider(port):
    nexSerial = PySerialNex(port)

    print("Init")
    nexSerial.init()

    print("Create objects")
    # nexText = NexText(nexSerial, "t1", pid=2, cid=1)
    # nexText = NexText(nexSerial, "t1")
    nexText = NexText(nexSerial, "t1", cid=1)

    print("Reset")
    nexSerial.reset()

    time.sleep(1)

    nexSerial.send("page pg_text")

    time.sleep(1)

    msg = "Hello"
    nexText.text = msg

    time.sleep(1)
    assert nexText.text == msg

    time.sleep(0.5)

    nexText.backcolor = Colour.BLUE
    nexText.text = "1"

    time.sleep(0.5)

    nexText.backcolor = Colour.WHITE
    nexText.text = "2"

    time.sleep(0.5)

    nexText.backcolor = Colour.RED
    nexText.text = "3"

    time.sleep(0.5)

    nexText.text = "Bye nexText"

    time.sleep(0.5)

    nexText.visible = False
    nexText.backcolor = Colour.WHITE

    time.sleep(2)

    nexText.visible = True

    time.sleep(0.5)

    nexText.alignment.horizontal = Alignment.Horizontal.RIGHT
    nexText.alignment.vertical = Alignment.Vertical.DOWN
    nexText.forecolor = Colour.BLUE

    # Change fontid from 0 to 1
    nexText.font = Font(1)

    # nexSerial.reset()
    # time.sleep(0.5)

    nexSerial.close()