Exemple #1
0
def test_init():
    ssd1306(bus)
    assert len(bus.recordings) == 35
    # Bursts 0/1 are initialization commands
    cmds = [174, 213, 128, 168, 63, 211, 0, 64, 141, 20, 32, 0,
            160, 200, 218, 18, 129, 207, 217, 241, 219, 64, 164,
            166, 33, 0, 127, 34, 0, 7]
    assert bus.recordings[0].mode == 0
    assert bus.recordings[1].mode == 0
    assert bus.recordings[0].data + bus.recordings[1].data == cmds

    # Next 32 bursts are all data: zero's to clear the RAM
    # (32 * 32 = 1024 = 128 * 64 / 8)
    for i in range(32):
        assert bus.recordings[i + 2] == mock.recording(60, 64, [0] * 32)

    # Last burst is a command to show the screen
    assert bus.recordings[34] == mock.recording(60, 0, [175])
Exemple #2
0
def test_diplay():
    device = ssd1306(bus)
    bus.reset()

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

    assert len(bus.recordings) == 33

    # Initial command to reset the display
    assert bus.recordings[0] == mock.recording(60, 0, [33, 0, 127, 34, 0, 7])

    # Next 32 recordings are data representing the drawn image
    for i in range(32):
        assert bus.recordings[i + 1] == baseline_data.demo_ssd1306[i]
Exemple #3
0
def test_show():
    device = ssd1306(bus)
    bus.reset()
    device.show()
    assert len(bus.recordings) == 1
    assert bus.recordings[0] == mock.recording(60, 0, [175])
Exemple #4
0
def test_hide():
    device = ssd1306(bus)
    bus.reset()
    device.hide()
    assert len(bus.recordings) == 1
    assert bus.recordings[0] == mock.recording(60, 0, [174])
Exemple #5
0
    draw.ellipse((x, top, x + shape_width, bottom), outline=255, fill=0)
    x += shape_width + padding
    draw.rectangle((x, top, x + shape_width, bottom), outline=255, fill=0)
    x += shape_width + padding
    draw.polygon([(x, bottom), (x + shape_width / 2, top), (x + shape_width, bottom)], outline=255, fill=0)
    x += shape_width + padding
    draw.line((x, bottom, x + shape_width, top), fill=255)
    draw.line((x, top, x + shape_width, bottom), fill=255)
    x += shape_width + padding
    draw.text((x, top),    'Hello',  font=font, fill=255)
    draw.text((x, top + 20), 'World!', font=font, fill=255)


# These datasets are purely to prevent regression bugs from creeping in
demo_ssd1306 = [
    mock.recording(60, 64, [255, 1, 1, 1, 1, 1, 1, 1, 1, 129, 193, 65, 193, 129, 1, 1, 241, 241, 17, 17, 1, 1, 241, 241, 17, 17, 1, 129, 193, 65, 193, 129]),
    mock.recording(60, 64, [33, 225, 225, 129, 225, 225, 1, 13, 113, 129, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 129, 113, 13, 1, 1, 1, 1]),
    mock.recording(60, 64, [1, 1, 1, 1, 1, 1, 225, 29, 225, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 253, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]),
    mock.recording(60, 64, [5, 5, 5, 5, 5, 5, 5, 253, 1, 1, 1, 1, 1, 129, 97, 25, 9, 5, 5, 5, 5, 5, 9, 25, 97, 129, 1, 1, 1, 1, 1, 255]),
    mock.recording(60, 64, [255, 0, 0, 0, 0, 0, 0, 0, 0, 3, 7, 4, 7, 3, 4, 4, 7, 7, 4, 4, 4, 4, 7, 7, 4, 4, 0, 5, 5, 5, 7, 3]),
    mock.recording(60, 64, [4, 7, 7, 0, 7, 7, 0, 0, 0, 3, 28, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 28, 3, 0, 0, 0, 0, 0, 0]),
    mock.recording(60, 64, [0, 0, 0, 0, 0, 248, 7, 0, 7, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
    mock.recording(60, 64, [0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 240, 14, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 240, 0, 0, 0, 255]),
    mock.recording(60, 64, [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
    mock.recording(60, 64, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 56, 192, 0, 0, 0, 0, 0, 192, 56, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
    mock.recording(60, 64, [0, 0, 0, 128, 126, 1, 0, 0, 0, 1, 126, 128, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
    mock.recording(60, 64, [0, 0, 0, 0, 0, 0, 0, 255, 0, 192, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 192, 0, 255]),
    mock.recording(60, 64, [255, 0, 0, 0, 0, 94, 94, 0, 64, 127, 127, 69, 124, 56, 64, 64, 127, 127, 65, 65, 12, 4, 76, 120, 124, 68, 0, 56, 124, 68, 124, 56]),
    mock.recording(60, 64, [2, 30, 112, 62, 112, 30, 0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 112, 128, 112, 14, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
    mock.recording(60, 64, [0, 0, 224, 31, 0, 0, 0, 0, 0, 0, 0, 31, 224, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
    mock.recording(60, 64, [0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255]),