Beispiel #1
0
def test_init_256x64():
    """
    SSD1362 OLED with a 256 x 64 resolution works correctly.
    """
    ssd1362(serial)
    serial.command.assert_has_calls([
        call(171, 1, 173, 158, 21, 0, 127, 117, 0, 63, 160, 67, 161, 0, 162, 0, 164, 168, 63, 177, 17, 179, 240, 185, 188, 4, 190, 5),
        call(129, 127),
        call(21, 0, 127, 117, 0, 63),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 64 / 2)
    serial.data.assert_called_once_with([0] * (256 * 64 // 2))
Beispiel #2
0
def test_show():
    """
    SSD1362 OLED screen content can be displayed.
    """
    device = ssd1362(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
Beispiel #3
0
def test_hide():
    """
    SSD1362 OLED screen content can be hidden.
    """
    device = ssd1362(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
Beispiel #4
0
def test_monochrome_display():
    """
    SSD1362 OLED screen can draw and display a monochrome image.
    """
    device = ssd1362(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, 127, 117, 0, 63)

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1362_monochrome'))
Beispiel #5
0
def test_monochrome_display():
    """
    SSD1362 OLED screen can draw and display a monochrome image.
    """
    device = ssd1362(serial, mode="1", framebuffer=full_frame())
    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)

    # To regenerate test data, uncomment the following (remember not to commit though)
    # ================================================================================
    # from baseline_data import save_reference_data
    # save_reference_data("demo_ssd1362_monochrome", serial.data.call_args.args[0])

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(
        get_reference_data('demo_ssd1362_monochrome'))
Beispiel #6
0
def connect_oled_i2c_spi(app, cfg):
    """connect to oled I2c SPI"""
    try:
        # OLED DISPLAY 2 SETUP
        app.devices = cfg.get('OLED DISPLAY 2 SETUP', 'oled_devices').strip('"')
        app.i2c_or_spi = cfg.get('OLED DISPLAY 2 SETUP', 'oled_i2c_or_spi').strip('"')
        app.spi_gpio_dc_pin = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_spi_gpio_dc_pin').strip('"'))
        app.spi_gpio_rst_pin = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_spi_gpio_rst_pin'))
        app.port_address = cfg.get('OLED DISPLAY 2 SETUP', 'oled_port_address').strip('"')
        app.spi_device_number = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_spi_device_number'))
        app.port = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_port').strip('"'))
        app.color_mode = cfg.get('OLED DISPLAY 2 SETUP', 'oled_color_mode').strip('"')
        app.screen_width = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_width').strip('"'))
        app.screen_height = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_height').strip('"'))
        app.rotate_screen = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_rotate').strip('"'))
        # Logo / States Images
        app.showlogo = cfg.get('OLED DISPLAY 2 TEXT', 'oled_showlogo').strip('"')
        app.logos = cfg.get('OLED DISPLAY 2 TEXT', 'oled_logos').strip('"')
        app.logo_path = cfg.get('OLED DISPLAY 2 TEXT', 'oled_logo_path').strip('"')
        app.states_pictures = cfg.get('OLED DISPLAY 2 TEXT', 'oled_states_pictures').strip('"')
        app.state_picture_path = cfg.get('OLED DISPLAY 2 TEXT', 'oled_state_picture_path').strip('"')
        # Text 1, Counter, Date-Time
        app.font_1 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_font_1').strip('"')
        app.counter_1 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_counter_type1').strip('"')
        app.text1_color = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text1_color').strip('"')
        app.text_1 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text_1').strip('"')
        app.size_1 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_size_1').strip('"'))
        app.right_1 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text1_right').strip('"'))
        app.down_1 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text1_down').strip('"'))
        # Text 2, Counter, Date-Time
        app.font_2 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_font_2').strip('"')
        app.counter_2 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_counter_type2').strip('"')
        app.text2_color = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text2_color').strip('"')
        app.text_2 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text_2').strip('"')
        app.size_2 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_size_2').strip('"'))
        app.right_2 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text2_right').strip('"'))
        app.down_2 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text2_down').strip('"'))
        # Text 3, Counter, Date-Time
        app.font_3 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_font_3').strip('"')
        app.counter_3 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_counter_type3').strip('"')
        app.text3_color = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text3_color').strip('"')
        app.text_3 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text_3').strip('"')
        app.size_3 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_size_3').strip('"'))
        app.right_3 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text3_right').strip('"'))
        app.down_3 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text3_down').strip('"'))
        # Text 4, Counter, Date-Time
        app.font_4 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_font_4').strip('"')
        app.counter_4 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_counter_type4').strip('"')
        app.text4_color = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text4_color').strip('"')
        app.text_4 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text_4').strip('"')
        app.size_4 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_size_4').strip('"'))
        app.right_4 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text4_right').strip('"'))
        app.down_4 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text4_down').strip('"'))
    except OSError:
        pass

    try:
        # Choose I2c or SPI connection
        i = app.i2c_or_spi.split()
        if "SPI" in i:
            app.serial = spi(device=app.spi_device_number, port=app.port, gpio_DC=app.spi_gpio_dc_pin, gpio_RST=app.spi_gpio_rst_pin)
        elif "I2c" in i:
            app.serial = i2c(port=app.port, address=app.port_address)
    except OSError:
        pass
        
    try:  # Connect to screen
        d = app.devices.split()
        if "sh1106" in d:
            app.device = sh1106(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1306" in d:
            app.device = ssd1306(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1309" in d:
            app.device = ssd1309(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1322" in d:
            app.device = ssd1322(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1325" in d:
            app.device = ssd1325(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1327" in d:
            app.device = ssd1327(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1331" in d:
            app.device = ssd1331(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1351" in d:
            app.device = ssd1351(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1362" in d:
            app.device = ssd1362(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
    except OSError:
        pass