Skip to content

added typing for image, scs, and, reverse_bit num #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 28, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions adafruit_sharpmemorydisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@

"""
# pylint: enable=line-too-long
from __future__ import annotations

import adafruit_framebuf
from adafruit_bus_device.spi_device import SPIDevice
from micropython import const

try:
from PIL import Image
import numpy
from digitalio import DigitalInOut
except ImportError:
numpy = None

Expand All @@ -45,7 +48,7 @@
_SHARPMEM_BIT_CLEAR = const(0x20) # in lsb


def reverse_bit(num):
def reverse_bit(num: float):
"""Turn an LSB byte to an MSB byte, and vice versa. Used for SPI as
it is LSB for the SHARP, but 99% of SPI implementations are MSB only!"""
result = 0
Expand All @@ -62,7 +65,15 @@ class SharpMemoryDisplay(adafruit_framebuf.FrameBuffer):

# pylint: disable=too-many-instance-attributes,abstract-method

def __init__(self, spi, scs_pin, width, height, *, baudrate=2000000):
def __init__(
self,
spi: SPIDevice,
scs_pin: DigitalInOut,
width: float,
height: float,
*,
baudrate=2000000,
):
scs_pin.switch_to_output(value=True)
self.spi_device = SPIDevice(
spi, scs_pin, cs_active_value=True, baudrate=baudrate
Expand Down Expand Up @@ -105,7 +116,7 @@ def show(self):
image_buffer.extend(self._buf)
spi.write(image_buffer)

def image(self, img):
def image(self, img: Image):
"""Set buffer to value of Python Imaging Library image. The image should
be in 1 bit mode and a size equal to the display size."""
# determine our effective width/height, taking rotation into account
Expand Down