Skip to content

Commit

Permalink
Test uc8159
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Nov 5, 2020
1 parent fbe16fa commit 327db1e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
16 changes: 13 additions & 3 deletions library/inky/inky_uc8159.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import time
import struct

from PIL import Image
try:
from PIL import Image
except ImportError:
Image = None

from . import eeprom

try:
Expand Down Expand Up @@ -47,7 +51,7 @@

MOSI_PIN = 10
SCLK_PIN = 11
CS0_PIN = 0
CS0_PIN = 8

UC8159_PSR = 0x00
UC8159_PWR = 0x01
Expand Down Expand Up @@ -154,6 +158,10 @@ def __init__(self, resolution=(600, 448), colour='multi', cs_pin=CS0_PIN, dc_pin
self.reset_pin = reset_pin
self.busy_pin = busy_pin
self.cs_pin = cs_pin
try:
self.cs_channel = [8, 7].index(cs_pin)
except ValueError:
self.cs_channel = 0
self.h_flip = h_flip
self.v_flip = v_flip

Expand Down Expand Up @@ -197,7 +205,7 @@ def setup(self):
import spidev
self._spi_bus = spidev.SpiDev()

self._spi_bus.open(0, self.cs_pin)
self._spi_bus.open(0, self.cs_channel)
self._spi_bus.max_speed_hz = 3000000

self._gpio_setup = True
Expand Down Expand Up @@ -361,6 +369,8 @@ def set_image(self, image, saturation=0.5):
if not image.size == (self.width, self.height):
raise ValueError("Image must be ({}x{}) pixels!".format(self.width, self.height))
if not image.mode == "P":
if Image is None:
raise RuntimeError("PIL is required for converting images: sudo apt install python-pil python3-pil")
palette = self._palette_blend(saturation)
# Image size doesn't matter since it's just the palette we're using
palette_image = Image.new("P", (1, 1))
Expand Down
33 changes: 33 additions & 0 deletions library/tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,36 @@ def test_init_what_setup(spidev, smbus2, GPIO):

# Check API will been opened
spidev.SpiDev().open.assert_called_with(0, inky.cs_channel)


def test_init_7colour_setup(spidev, smbus2, GPIO):
"""Test initialisation and setup of 7-colour Inky.
Verify our expectations for GPIO setup in order to catch regressions.
"""
from inky.inky_uc8159 import Inky

# TODO: _busy_wait should timeout after N seconds
GPIO.input.return_value = GPIO.LOW

inky = Inky()
inky.setup()

# Check GPIO setup
GPIO.setwarnings.assert_called_with(False)
GPIO.setmode.assert_called_with(GPIO.BCM)
GPIO.setup.assert_has_calls([
mock.call(inky.dc_pin, GPIO.OUT, initial=GPIO.LOW, pull_up_down=GPIO.PUD_OFF),
mock.call(inky.reset_pin, GPIO.OUT, initial=GPIO.HIGH, pull_up_down=GPIO.PUD_OFF),
mock.call(inky.busy_pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
])

# Check device will been reset
GPIO.output.assert_has_calls([
mock.call(inky.reset_pin, GPIO.LOW),
mock.call(inky.reset_pin, GPIO.HIGH)
])

# Check API will been opened
spidev.SpiDev().open.assert_called_with(0, inky.cs_channel)
1 change: 0 additions & 1 deletion library/tests/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class InkyMockFAIL(InkyMock):
def _simulate(self, region):
pass


with pytest.raises(ValueError):
InkyMockFAIL('black')

Expand Down

0 comments on commit 327db1e

Please sign in to comment.