Example #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'))
    }]
Example #2
0
def test_display_full_frame():
    device = ili9341(serial, gpio=Mock(), framebuffer=full_frame())
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': list(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_ili9341", recordings)

    assert recordings == get_reference_data('demo_ili9341')
Example #3
0
    def _init_display_device(self):
        # Init Device
        self.serial = spi(port=0,
                          device=0,
                          gpio_DC=24,
                          gpio_RST=25,
                          bus_speed_hz=32000000,
                          reset_hold_time=0.2,
                          reset_release_time=0.2)
        self.device = ili9341(self.serial,
                              active_low=False,
                              width=self.WIDTH,
                              height=self.HEIGHT,
                              gpio_LIGHT=5,
                              rotate=self.rotation)

        # Setup & Start Display Loop Thread
        display_thread = threading.Thread(target=self._display_loop)
        display_thread.start()
Example #4
0
def test_show():
    device = ili9341(serial, gpio=Mock())
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(41)
Example #5
0
def test_contrast():
    device = ili9341(serial, gpio=Mock())
    serial.reset_mock()
    with pytest.raises(AssertionError):
        device.contrast(300)
Example #6
0
def test_offsets():
    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

    ili9341(serial, gpio=Mock(), width=240, height=240, h_offset=2, v_offset=1)

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

    assert recordings == [
        {
            'command': [0xef]
        },
        {
            'data': [0x03, 0x80, 0x02]
        },
        {
            'command': [0xcf]
        },
        {
            'data': [0x00, 0xc1, 0x30]
        },
        {
            'command': [0xed]
        },
        {
            'data': [0x64, 0x03, 0x12, 0x81]
        },
        {
            'command': [0xe8]
        },
        {
            'data': [0x85, 0x00, 0x78]
        },
        {
            'command': [0xcb]
        },
        {
            'data': [0x39, 0x2c, 0x00, 0x34, 0x02]
        },
        {
            'command': [0xf7]
        },
        {
            'data': [0x20]
        },
        {
            'command': [0xea]
        },
        {
            'data': [0x00, 0x00]
        },
        {
            'command': [0xc0]
        },
        {
            'data': [0x23]
        },
        {
            'command': [0xc1]
        },
        {
            'data': [0x10]
        },
        {
            'command': [0xc5]
        },
        {
            'data': [0x3e, 0x28]
        },
        {
            'command': [0xc7]
        },
        {
            'data': [0x86]
        },
        {
            'command': [0x36]
        },
        {
            'data': [0x28]
        },
        {
            'command': [0x3a]
        },
        {
            'data': [0x46]
        },
        {
            'command': [0xb1]
        },
        {
            'data': [0x00, 0x18]
        },
        {
            'command': [0xb6]
        },
        {
            'data': [0x08, 0x82, 0x27]
        },
        {
            'command': [0xf2]
        },
        {
            'data': [0x00]
        },
        {
            'command': [0x26]
        },
        {
            'data': [0x01]
        },
        {
            'command': [0xe0]
        },
        {
            'data': [
                0x0f, 0x31, 0x2b, 0x0c, 0x0e, 0x08, 0x4e, 0xf1, 0x37, 0x07,
                0x10, 0x03, 0x0e, 0x09, 0x00
            ]
        },
        {
            'command': [0xe1]
        },
        {
            'data': [
                0x00, 0x0e, 0x14, 0x03, 0x11, 0x07, 0x31, 0xc1, 0x48, 0x08,
                0x0f, 0x0c, 0x31, 0x36, 0x0f
            ]
        },
        {
            'command': [0x11]
        },
        {
            'command': [0x2A]
        },
        {
            'data': [0x00, 0x02, 0x00, 0xef + 0x02]
        },
        {
            'command': [0x2B]
        },
        {
            'data': [0x00, 0x01, 0x00, 0xef + 0x01]
        },
        {
            'command': [0x2C]
        },
        {
            'data': bytearray([0x00] * (240 * 240 * 3))
        },
        {
            'command': [0x29]
        },
    ]
# of using sysfs directly for hardware PWM on an RPi (after loading
# the pwm-2chan overlay in the Pi's /boot/config.txt file).
#

serial = spi(port=0,
             device=0,
             gpio_DC=24,
             gpio_RST=25,
             reset_hold_time=0.2,
             reset_release_time=0.2)

if kodi_panel_display.USE_PWM:
    device = ili9341(serial,
                     active_low=False,
                     width=320,
                     height=240,
                     bus_speed_hz=32000000,
                     gpio_LIGHT=18,
                     pwm_frequency=PWM_FREQ)
else:
    device = ili9341(serial,
                     active_low=False,
                     width=320,
                     height=240,
                     bus_speed_hz=32000000,
                     gpio_LIGHT=18)

if __name__ == "__main__":

    # This section is definitely specific to the ILI9341 display
    if CHANGE_GAMMA:
Example #8
0
def test_init_320x240():
    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

    ili9341(serial, gpio=Mock(), framebuffer=full_frame())

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

    assert recordings == [
        {
            'command': [0xef]
        },
        {
            'data': [0x03, 0x80, 0x02]
        },
        {
            'command': [0xcf]
        },
        {
            'data': [0x00, 0xc1, 0x30]
        },
        {
            'command': [0xed]
        },
        {
            'data': [0x64, 0x03, 0x12, 0x81]
        },
        {
            'command': [0xe8]
        },
        {
            'data': [0x85, 0x00, 0x78]
        },
        {
            'command': [0xcb]
        },
        {
            'data': [0x39, 0x2c, 0x00, 0x34, 0x02]
        },
        {
            'command': [0xf7]
        },
        {
            'data': [0x20]
        },
        {
            'command': [0xea]
        },
        {
            'data': [0x00, 0x00]
        },
        {
            'command': [0xc0]
        },
        {
            'data': [0x23]
        },
        {
            'command': [0xc1]
        },
        {
            'data': [0x10]
        },
        {
            'command': [0xc5]
        },
        {
            'data': [0x3e, 0x28]
        },
        {
            'command': [0xc7]
        },
        {
            'data': [0x86]
        },
        {
            'command': [0x36]
        },
        {
            'data': [0x28]
        },
        {
            'command': [0x3a]
        },
        {
            'data': [0x46]
        },
        {
            'command': [0xb1]
        },
        {
            'data': [0x00, 0x18]
        },
        {
            'command': [0xb6]
        },
        {
            'data': [0x08, 0x82, 0x27]
        },
        {
            'command': [0xf2]
        },
        {
            'data': [0x00]
        },
        {
            'command': [0x26]
        },
        {
            'data': [0x01]
        },
        {
            'command': [0xe0]
        },
        {
            'data': [
                0x0f, 0x31, 0x2b, 0x0c, 0x0e, 0x08, 0x4e, 0xf1, 0x37, 0x07,
                0x10, 0x03, 0x0e, 0x09, 0x00
            ]
        },
        {
            'command': [0xe1]
        },
        {
            'data': [
                0x00, 0x0e, 0x14, 0x03, 0x11, 0x07, 0x31, 0xc1, 0x48, 0x08,
                0x0f, 0x0c, 0x31, 0x36, 0x0f
            ]
        },
        {
            'command': [0x11]
        },
        {
            'command': [0x2a]
        },
        {
            'data': [0x00, 0x00, 0x01, 0x3f]
        },
        {
            'command': [0x2b]
        },
        {
            'data': [0x00, 0x00, 0x00, 0xef]
        },
        {
            'command': [0x2c]
        },
        {
            'data': bytearray([0x00] * (320 * 240 * 3))
        },
        {
            'command': [0x29]
        },
    ]