Ejemplo n.º 1
0
def test_display():
    device = ili9341(serial, gpio=Mock())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [{
        'command': [0x2a]
    }, {
        'data': [0x00, 0x00, 0x01, 0x3f]
    }, {
        'command': [0x2b]
    }, {
        'data': [0x00, 0x00, 0x00, 0xef]
    }, {
        'command': [0x2c]
    }, {
        'data': bytearray(get_reference_data('demo_ili9341'))
    }]
Ejemplo n.º 2
0
def test_display():
    device = st7789(serial, gpio=Mock(), framebuffer=full_frame())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.extend(data)

    def command(*cmd):
        recordings.extend(['command', list(cmd)[0], 'data', *list(cmd)[1:]])

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    # To regenerate test data, uncomment the following (remember not to commit though)
    # ================================================================================
    # from baseline_data import save_reference_data
    # save_reference_data("demo_st7789", recordings)

    assert recordings == get_reference_data('demo_st7789')
Ejemplo n.º 3
0
def test_monochrome_display():
    """
    SSD1322 OLED screen can draw and display a monochrome image.
    """
    device = ssd1322(serial, mode="1", framebuffer=full_frame())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    # To regenerate test data, uncomment the following (remember not to commit though)
    # ================================================================================
    # from baseline_data import save_reference_data
    # save_reference_data("demo_ssd1322_monochrome", recordings)

    assert recordings == get_reference_data('demo_ssd1322_monochrome')
Ejemplo n.º 4
0
def test_display():
    """
    UC1701X LCD screen can draw and display an image.
    """
    device = uc1701x(serial, gpio=Mock())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command = Mock(side_effect=command, unsafe=True)
    serial.data = Mock(side_effect=data, unsafe=True)

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    serial.data.assert_called()
    serial.command.assert_called()

    # To regenerate test data, uncomment the following (remember not to commit though)
    # ================================================================================
    # from baseline_data import save_reference_data
    # save_reference_data("demo_uc1701x", recordings)

    assert recordings == get_reference_data('demo_uc1701x')
Ejemplo n.º 5
0
def test_16bit_rgb_packing(bit, expected_16_bit_color):
    """
    Checks that 8 bit red component is packed into first 5 bits
    Checks that 8 bit green component is packed into next 6 bits
    Checks that 8 bit blue component is packed into remaining 5 bits
    """
    device = ssd1351(serial)
    serial.reset_mock()

    rgb_color = (2 ** bit,) * 3
    expected = expected_16_bit_color * device.width * device.height
    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline=rgb_color, fill=rgb_color)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [21]}, {'data': [0, 127]},
        {'command': [117]}, {'data': [0, 127]},
        {'command': [92]}, {'data': expected}
    ]
Ejemplo n.º 6
0
def test_display():
    """
    SH1106 OLED screen can draw and display an image.
    """
    device = sh1106(serial)
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command = Mock(side_effect=command, unsafe=True)
    serial.data = Mock(side_effect=data, unsafe=True)

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    serial.data.assert_called()
    serial.command.assert_called()

    assert recordings == get_json_data('demo_sh1106')
def test_alpha_blending():
    device = unicornhathd(serial)
    serial.reset_mock()
    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline=(255, 128, 64, 32))
    serial.data.assert_called_once_with(
        [0x72] + get_json_data('demo_unicornhathd_alphablend'))
def test_display():
    device = unicornhathd(serial)
    serial.reset_mock()
    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")
    serial.data.assert_called_once_with([0x72] +
                                        get_json_data('demo_unicornhathd'))
Ejemplo n.º 9
0
def test_greyscale_display():
    """
    SSD1322 OLED screen can draw and display a greyscale image.
    """
    device = ssd1322(serial, mode="RGB")
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        baseline_data.primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [21]}, {'data': [28, 91]},
        {'command': [117]}, {'data': [0, 63]},
        {'command': [92]}, {'data': baseline_data.demo_ssd1322_greyscale}
    ]
Ejemplo n.º 10
0
def test_contrast():
    device = unicornhathd(serial)
    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white", fill="white")
    serial.reset_mock()
    device.contrast(0x6B)
    serial.data.assert_called_once_with([0x72] + [0x6B] * 256 * 3)
def test_contrast():
    device = unicornhathd(serial)
    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white", fill="white")
    serial.reset_mock()
    device.contrast(0x6B)
    serial.data.assert_called_once_with([0x72] + [0x6B] * 256 * 3)
Ejemplo n.º 12
0
def test_display():
    device = st7735(serial, gpio=Mock())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [{
        'command': [42]
    }, {
        'data': [0, 0, 0, 159]
    }, {
        'command': [43]
    }, {
        'data': [0, 0, 0, 127]
    }, {
        'command': [44]
    }, {
        'data': get_reference_data('demo_st7735')
    }]
Ejemplo n.º 13
0
def test_display():
    device = st7567(serial, gpio=Mock())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    # To regenerate test data, uncomment the following (remember not to commit though)
    # ================================================================================
    # from baseline_data import save_reference_data
    # save_reference_data("demo_st7567", recordings)

    assert recordings == get_reference_data('demo_st7567')
Ejemplo n.º 14
0
def test_display():
    """
    UC1701X LCD screen can draw and display an image.
    """
    device = uc1701x(serial, gpio=Mock())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command = Mock(side_effect=command, unsafe=True)
    serial.data = Mock(side_effect=data, unsafe=True)

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    serial.data.assert_called()
    serial.command.assert_called()

    assert recordings == get_reference_data('demo_uc1701x')
Ejemplo n.º 15
0
def test_display():
    """
    SH1106 OLED screen can draw and display an image.
    """
    device = sh1106(serial)
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command = Mock(side_effect=command, unsafe=True)
    serial.data = Mock(side_effect=data, unsafe=True)

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    serial.data.assert_called()
    serial.command.assert_called()

    assert recordings == get_json_data('demo_sh1106')
Ejemplo n.º 16
0
def test_display():
    """
    SSD1351 OLED screen can draw and display a color image.
    """
    device = ssd1351(serial)
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [21]}, {'data': [0, 127]},
        {'command': [117]}, {'data': [0, 127]},
        {'command': [92]}, {'data': get_json_data('demo_ssd1351')}
    ]
Ejemplo n.º 17
0
def test_greyscale_display():
    """
    SSD1322_NHD OLED screen can draw and display a greyscale image.
    """
    device = ssd1322_nhd(serial, mode="RGB")
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [21]}, {'data': [28, 91]},
        {'command': [117]}, {'data': [0, 63]},
        {'command': [92]}, {'data': get_json_data('demo_ssd1322_nhd_greyscale')}
    ]
Ejemplo n.º 18
0
def test_contrast():
    device = apa102(serial, cascaded=6)
    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="red")
    serial.reset_mock()
    device.contrast(0x6B)
    serial.data.assert_called_with(
        padding(6) + [0xE6, 0, 0, 0xFF] * 6 + padding(6))
Ejemplo n.º 19
0
def test_hide():
    """
    SSD1351 OLED screen content can be hidden.
    """
    device = ssd1351(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
Ejemplo n.º 20
0
def test_hide():
    """
    SSD1309 OLED screen content can be hidden.
    """
    device = ssd1309(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
Ejemplo n.º 21
0
def test_hide():
    """
    SSD1331 OLED screen content can be hidden.
    """
    device = ssd1331(serial, framebuffer=full_frame())
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
Ejemplo n.º 22
0
def test_show():
    """
    SSD1331 OLED screen content can be displayed.
    """
    device = ssd1331(serial, framebuffer=full_frame())
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
Ejemplo n.º 23
0
def test_show():
    """
    SSD1309 OLED screen content can be displayed.
    """
    device = ssd1309(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
Ejemplo n.º 24
0
def test_show():
    """
    SSD1351 OLED screen content can be displayed.
    """
    device = ssd1351(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
Ejemplo n.º 25
0
def test_display():
    device = apa102(serial, width=4, height=1)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline=(0x11, 0x22, 0x33, 0x44))

    serial.data.assert_called_with(
        padding(4) + [0xE4, 0x33, 0x22, 0x11] * 4 + padding(4))
Ejemplo n.º 26
0
def test_display():
    device = pcd8544(serial)
    serial.reset_mock()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    # Initial command to reset the display
    serial.command.assert_called_once_with(32, 128, 64)

    # Next 1024 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_reference_data('demo_pcd8544'))
Ejemplo n.º 27
0
def test_display():
    device = pcd8544(serial, gpio=Mock())
    serial.reset_mock()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    # Initial command to reset the display
    serial.command.assert_called_once_with(32, 128, 64)

    # Next 1024 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_reference_data('demo_pcd8544'))
Ejemplo n.º 28
0
def test_monochrome_display():
    """
    SSD1327 OLED screen can draw and display a monochrome image.
    """
    device = ssd1327(serial, mode="1")
    serial.reset_mock()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    # Initial command to reset the display
    serial.command.assert_called_once_with(21, 0, 63, 117, 0, 127)

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1327_monochrome'))
Ejemplo n.º 29
0
def test_display():
    """
    SSD1331 OLED screen can draw and display an image.
    """
    device = ssd1331(serial)
    serial.reset_mock()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    # Initial command to reset the display
    serial.command.assert_called_once_with(21, 0, 95, 117, 0, 63)

    # Next 12288 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1331'))
Ejemplo n.º 30
0
def test_16bit_rgb_packing(bit, expected_16_bit_color):
    """
    Checks that 8 bit red component is packed into first 5 bits
    Checks that 8 bit green component is packed into next 6 bits
    Checks that 8 bit blue component is packed into remaining 5 bits
    """
    device = ssd1331(serial)
    serial.reset_mock()

    rgb_color = (2 ** bit,) * 3
    expected = expected_16_bit_color * device.width * device.height

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline=rgb_color, fill=rgb_color)

    serial.data.assert_called_once_with(expected)
Ejemplo n.º 31
0
def test_16bit_rgb_packing(bit, expected_16_bit_color):
    """
    Checks that 8 bit red component is packed into first 5 bits
    Checks that 8 bit green component is packed into next 6 bits
    Checks that 8 bit blue component is packed into remaining 5 bits
    """
    device = ssd1331(serial)
    serial.reset_mock()

    rgb_color = (2**bit, ) * 3
    expected = expected_16_bit_color * device.width * device.height

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline=rgb_color, fill=rgb_color)

    serial.data.assert_called_once_with(expected)
Ejemplo n.º 32
0
def test_greyscale_display():
    """
    SSD1362 OLED screen can draw and display a greyscale image.
    """
    device = ssd1362(serial, mode="RGB")
    serial.reset_mock()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    # Initial command to reset the display
    serial.command.assert_called_once_with(21, 0, 127, 117, 0, 63)

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1362_greyscale'))
Ejemplo n.º 33
0
def test_display():
    """
    SSD1309 OLED screen can draw and display an image.
    """
    device = ssd1309(serial)
    serial.reset_mock()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    # Initial command to reset the display
    serial.command.assert_called_once_with(33, 0, 127, 34, 0, 7)

    # Next 1024 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1309'))
Ejemplo n.º 34
0
def test_monochrome_display():
    """
    SSD1325 OLED screen can draw and display a monochrome image.
    """
    device = ssd1325(serial, mode="1")
    serial.reset_mock()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        baseline_data.primitives(device, draw)

    # Initial command to reset the display
    serial.command.assert_called_once_with(21, 0, 127, 117, 0, 63)

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(baseline_data.demo_ssd1325_monochrome)
Ejemplo n.º 35
0
def test_display():
    """
    SSD1306 OLED screen can draw and display an image.
    """
    device = ssd1306(serial)
    serial.reset_mock()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        baseline_data.primitives(device, draw)

    # Initial command to reset the display
    serial.command.assert_called_once_with(33, 0, 127, 34, 0, 7)

    # Next 1024 bytes are data representing the drawn image
    serial.data.assert_called_once_with(baseline_data.demo_ssd1306)
Ejemplo n.º 36
0
def test_block_realignment_plus180():
    device = max7219(serial, cascaded=2, block_orientation=180)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 0xF0, 1, 0x90]),
        call([2, 0x90, 2, 0x90]),
        call([3, 0x90, 3, 0x90]),
        call([4, 0x90, 4, 0x90]),
        call([5, 0x90, 5, 0x90]),
        call([6, 0x90, 6, 0x90]),
        call([7, 0x90, 7, 0x90]),
        call([8, 0x90, 8, 0xF0])
    ])
Ejemplo n.º 37
0
def test_normal_alignment():
    device = max7219(serial, cascaded=2, block_orientation=0)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 0x09, 1, 0x0F]),
        call([2, 0x09, 2, 0x09]),
        call([3, 0x09, 3, 0x09]),
        call([4, 0x09, 4, 0x09]),
        call([5, 0x09, 5, 0x09]),
        call([6, 0x09, 6, 0x09]),
        call([7, 0x09, 7, 0x09]),
        call([8, 0x0F, 8, 0x09])
    ])
Ejemplo n.º 38
0
def test_block_realignment_plus180():
    device = max7219(serial, cascaded=2, block_orientation=180)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 0xF0, 1, 0x90]),
        call([2, 0x90, 2, 0x90]),
        call([3, 0x90, 3, 0x90]),
        call([4, 0x90, 4, 0x90]),
        call([5, 0x90, 5, 0x90]),
        call([6, 0x90, 6, 0x90]),
        call([7, 0x90, 7, 0x90]),
        call([8, 0x90, 8, 0xF0])
    ])
Ejemplo n.º 39
0
def test_display_16x8():
    device = max7219(serial, cascaded=2)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")

    serial.data.assert_has_calls([
        call([1, 0x81, 1, 0xFF]),
        call([2, 0x81, 2, 0x81]),
        call([3, 0x81, 3, 0x81]),
        call([4, 0x81, 4, 0x81]),
        call([5, 0x81, 5, 0x81]),
        call([6, 0x81, 6, 0x81]),
        call([7, 0x81, 7, 0x81]),
        call([8, 0xFF, 8, 0x81])
    ])
Ejemplo n.º 40
0
def test_display_16x16():
    device = max7219(serial, width=16, height=16)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")

    serial.data.assert_has_calls([
        call([1, 0x80, 1, 0xFF, 1, 0x01, 1, 0xFF]),
        call([2, 0x80, 2, 0x80, 2, 0x01, 2, 0x01]),
        call([3, 0x80, 3, 0x80, 3, 0x01, 3, 0x01]),
        call([4, 0x80, 4, 0x80, 4, 0x01, 4, 0x01]),
        call([5, 0x80, 5, 0x80, 5, 0x01, 5, 0x01]),
        call([6, 0x80, 6, 0x80, 6, 0x01, 6, 0x01]),
        call([7, 0x80, 7, 0x80, 7, 0x01, 7, 0x01]),
        call([8, 0xFF, 8, 0x80, 8, 0xFF, 8, 0x01])
    ])
Ejemplo n.º 41
0
def test_reversed_max7219():
    device = max7219(serial, cascaded=4, blocks_arranged_in_reverse_order=True)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 15, 1, 9, 1, 0, 1, 0]),
        call([2, 9, 2, 9, 2, 0, 2, 0]),
        call([3, 9, 3, 9, 3, 0, 3, 0]),
        call([4, 9, 4, 9, 4, 0, 4, 0]),
        call([5, 9, 5, 9, 5, 0, 5, 0]),
        call([6, 9, 6, 9, 6, 0, 6, 0]),
        call([7, 9, 7, 9, 7, 0, 7, 0]),
        call([8, 9, 8, 15, 8, 0, 8, 0])
    ])
Ejemplo n.º 42
0
def test_normal_alignment():
    device = max7219(serial, cascaded=2, block_orientation=0)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 0x09, 1, 0x0F]),
        call([2, 0x09, 2, 0x09]),
        call([3, 0x09, 3, 0x09]),
        call([4, 0x09, 4, 0x09]),
        call([5, 0x09, 5, 0x09]),
        call([6, 0x09, 6, 0x09]),
        call([7, 0x09, 7, 0x09]),
        call([8, 0x0F, 8, 0x09])
    ])
Ejemplo n.º 43
0
def test_display_16x16():
    device = max7219(serial, width=16, height=16)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")

    serial.data.assert_has_calls([
        call([1, 0x80, 1, 0xFF, 1, 0x01, 1, 0xFF]),
        call([2, 0x80, 2, 0x80, 2, 0x01, 2, 0x01]),
        call([3, 0x80, 3, 0x80, 3, 0x01, 3, 0x01]),
        call([4, 0x80, 4, 0x80, 4, 0x01, 4, 0x01]),
        call([5, 0x80, 5, 0x80, 5, 0x01, 5, 0x01]),
        call([6, 0x80, 6, 0x80, 6, 0x01, 6, 0x01]),
        call([7, 0x80, 7, 0x80, 7, 0x01, 7, 0x01]),
        call([8, 0xFF, 8, 0x80, 8, 0xFF, 8, 0x01])
    ])
Ejemplo n.º 44
0
def test_display_16x8():
    device = max7219(serial, cascaded=2)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")

    serial.data.assert_has_calls([
        call([1, 0x81, 1, 0xFF]),
        call([2, 0x81, 2, 0x81]),
        call([3, 0x81, 3, 0x81]),
        call([4, 0x81, 4, 0x81]),
        call([5, 0x81, 5, 0x81]),
        call([6, 0x81, 6, 0x81]),
        call([7, 0x81, 7, 0x81]),
        call([8, 0xFF, 8, 0x81])
    ])
Ejemplo n.º 45
0
def test_display():
    device = st7567(serial)
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        primitives(device, draw)

    assert serial.data.called
    assert serial.command.called

    assert recordings == get_reference_data('demo_st7567')
Ejemplo n.º 46
0
def test_hide():
    device = pcd8544(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(8)
Ejemplo n.º 47
0
def test_show():
    device = pcd8544(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(12)
Ejemplo n.º 48
0
def test_hide():
    device = max7219(serial, cascaded=5)
    serial.reset_mock()
    device.hide()
    serial.data.assert_called_once_with([12, 0] * 5)
Ejemplo n.º 49
0
def test_show():
    device = max7219(serial, cascaded=3)
    serial.reset_mock()
    device.show()
    serial.data.assert_called_once_with([12, 1] * 3)
Ejemplo n.º 50
0
def test_contrast():
    device = max7219(serial, cascaded=6)
    serial.reset_mock()
    device.contrast(0x6B)
    serial.data.assert_called_once_with([10, 6] * 6)
Ejemplo n.º 51
0
def test_alpha_blending():
    device = unicornhathd(serial)
    serial.reset_mock()
    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline=(255, 128, 64, 32))
    serial.data.assert_called_once_with([0x72] + get_json_data('demo_unicornhathd_alphablend'))
Ejemplo n.º 52
0
def test_hide():
    device = unicornhathd(serial)
    serial.reset_mock()
    device.hide()
    serial.data.assert_called_once_with([0x72] + [0] * 256 * 3)
Ejemplo n.º 53
0
def test_contrast():
    device = st7567(serial)
    serial.reset_mock()
    with pytest.raises(AssertionError):
        device.contrast(300)
Ejemplo n.º 54
0
def test_display():
    device = unicornhathd(serial)
    serial.reset_mock()
    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")
    serial.data.assert_called_once_with([0x72] + get_json_data('demo_unicornhathd'))