Beispiel #1
0
def test_unsupported_gpio_platform():
    try:
        gpio_cs_spi(spi=spidev, port=9, device=1, gpio_CS=23)
    except luma.core.error.UnsupportedPlatform as ex:
        assert str(ex) == 'GPIO access not available'
    except ImportError:
        pytest.skip(rpi_gpio_missing)
Beispiel #2
0
def test_init_invalid_bus_speed():
    with pytest.raises(AssertionError):
        gpio_cs_spi(gpio=gpio,
                    spi=spidev,
                    port=5,
                    device=2,
                    bus_speed_hz=942312,
                    gpio_CS=23)
Beispiel #3
0
def test_cleanup():
    serial = gpio_cs_spi(gpio=gpio, spi=spidev, port=9, device=1, gpio_CS=23)
    serial._managed = True
    serial.cleanup()
    verify_gpio_cs_spi_init(9, 1)
    spidev.close.assert_called_once_with()
    assert_only_cleans_whats_setup(gpio)
Beispiel #4
0
def test_init():
    port = 5
    device = 2
    bus_speed = 16000000
    dc = 17
    rst = 11
    cs = 23

    gpio_cs_spi(gpio=gpio,
                spi=spidev,
                port=port,
                device=device,
                bus_speed_hz=16000000,
                gpio_DC=dc,
                gpio_RST=rst,
                gpio_CS=cs)
    verify_gpio_cs_spi_init(port, device, bus_speed, dc, rst, cs)
    gpio.output.assert_has_calls([call(rst, gpio.LOW), call(rst, gpio.HIGH)])
Beispiel #5
0
def test_data():
    data = list(fib(100))
    serial = gpio_cs_spi(gpio=gpio, spi=spidev, port=9, device=1, gpio_CS=23)
    serial.data(data)
    verify_gpio_cs_spi_init(9, 1)
    gpio.output.assert_has_calls([
        call(25, gpio.HIGH),
        call(24, gpio.HIGH),
        call(23, gpio.LOW),
        call(23, gpio.HIGH)
    ])
    spidev.writebytes.assert_called_once_with(data)
Beispiel #6
0
def test_command():
    cmds = [3, 1, 4, 2]
    serial = gpio_cs_spi(gpio=gpio, spi=spidev, port=9, device=1, gpio_CS=23)
    serial.command(*cmds)
    verify_gpio_cs_spi_init(9, 1)
    gpio.output.assert_has_calls([
        call(25, gpio.HIGH),
        call(24, gpio.LOW),
        call(23, gpio.LOW),
        call(23, gpio.HIGH)
    ])
    spidev.writebytes.assert_called_once_with(cmds)
Beispiel #7
0
 def gpio_cs_spi(self):
     from luma.core.interface.serial import gpio_cs_spi
     GPIO = self.__init_alternative_GPIO()
     return gpio_cs_spi(port=self.opts.spi_port,
                        device=self.opts.spi_device,
                        bus_speed_hz=self.opts.spi_bus_speed,
                        cs_high=self.opts.spi_cs_high,
                        transfer_size=self.opts.spi_transfer_size,
                        reset_hold_time=self.opts.gpio_reset_hold_time,
                        reset_release_time=self.opts.gpio_reset_release_time,
                        gpio_DC=self.opts.gpio_data_command,
                        gpio_RST=self.opts.gpio_reset,
                        gpio_CS=self.opts.gpio_chip_select,
                        gpio=self.gpio or GPIO)
Beispiel #8
0
def test_init_device_not_found():
    spidev = get_spidev()
    port = 1234
    with pytest.raises(luma.core.error.DeviceNotFoundError) as ex:
        gpio_cs_spi(gpio=gpio, spi=spidev.SpiDev(), port=port, gpio_CS=23)
    assert str(ex.value) == 'SPI device not found'