From f8cab129153bd5d10540b40675e6370c58965cf8 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Tue, 2 May 2023 23:45:48 +0200 Subject: [PATCH 01/17] Added type annotations. --- adafruit_epd/mcp_sram.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/adafruit_epd/mcp_sram.py b/adafruit_epd/mcp_sram.py index d3895b5..2ad963e 100644 --- a/adafruit_epd/mcp_sram.py +++ b/adafruit_epd/mcp_sram.py @@ -11,6 +11,13 @@ from micropython import const from adafruit_bus_device import spi_device +from digitalio import DigitalInOut # Needed for type annotation +from busio import SPI # Needed for type annotation + +try: + from typing import Any, List +except ImportError: + pass __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -21,15 +28,15 @@ class Adafruit_MCP_SRAM_View: """A interface class that turns an SRAM chip into something like a memoryview""" - def __init__(self, sram, offset): + def __init__(self, sram: int, offset: int) -> None: self._sram = sram self._offset = offset self._buf = [0] - def __getitem__(self, i): + def __getitem__(self, i: int) -> Any: return self._sram.read(self._offset + i, 1)[0] - def __setitem__(self, i, val): + def __setitem__(self, i: int, val: Any) -> None: self._buf[0] = val self._sram.write(self._offset + i, self._buf) @@ -43,7 +50,7 @@ class Adafruit_MCP_SRAM: SRAM_RDSR = 0x05 SRAM_WRSR = 0x01 - def __init__(self, cs_pin, spi): + def __init__(self, cs_pin: DigitalInOut, spi: SPI): # Handle hardware SPI self._spi = spi_device.SPIDevice(spi, cs_pin, baudrate=8000000) self.spi_device = spi @@ -54,11 +61,11 @@ def __init__(self, cs_pin, spi): with self._spi as spidev: spidev.write(self._buf, end=2) # pylint: disable=no-member - def get_view(self, offset): + def get_view(self, offset: int) -> Adafruit_MCP_SRAM_View: """Create an object that can be used as a memoryview, with a given offset""" return Adafruit_MCP_SRAM_View(self, offset) - def write(self, addr, buf, reg=SRAM_WRITE): + def write(self, addr: int, buf: List, reg=SRAM_WRITE): """write the passed buffer to the passed address""" self._buf[0] = reg self._buf[1] = (addr >> 8) & 0xFF @@ -68,7 +75,7 @@ def write(self, addr, buf, reg=SRAM_WRITE): spi.write(self._buf, end=3) # pylint: disable=no-member spi.write(bytearray(buf)) # pylint: disable=no-member - def read(self, addr, length, reg=SRAM_READ): + def read(self, addr: int, length: int, reg: int = SRAM_READ): """read passed number of bytes at the passed address""" self._buf[0] = reg self._buf[1] = (addr >> 8) & 0xFF @@ -80,24 +87,24 @@ def read(self, addr, length, reg=SRAM_READ): spi.readinto(buf) # pylint: disable=no-member return buf - def read8(self, addr, reg=SRAM_READ): + def read8(self, addr: int, reg: int = SRAM_READ): """read a single byte at the passed address""" return self.read(addr, 1, reg)[0] - def read16(self, addr, reg=SRAM_READ): + def read16(self, addr: int, reg: int = SRAM_READ): """read 2 bytes at the passed address""" buf = self.read(addr, 2, reg) return buf[0] << 8 | buf[1] - def write8(self, addr, value, reg=SRAM_WRITE): + def write8(self, addr: int, value: Any, reg: int = SRAM_WRITE): """write a single byte at the passed address""" self.write(addr, [value], reg) - def write16(self, addr, value, reg=SRAM_WRITE): + def write16(self, addr: int, value: Any, reg: int = SRAM_WRITE): """write 2 bytes at the passed address""" self.write(addr, [value >> 8, value], reg) - def erase(self, addr, length, value): + def erase(self, addr: int, length: int, value: Any): """erase the passed number of bytes starting at the passed address""" self._buf[0] = Adafruit_MCP_SRAM.SRAM_WRITE self._buf[1] = (addr >> 8) & 0xFF From 3f7e3d753b6000900ec62b297fb0a49f95d0eea5 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Tue, 9 May 2023 15:45:12 +0200 Subject: [PATCH 02/17] Fixed type annotations in accordance with code review. --- adafruit_epd/mcp_sram.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/adafruit_epd/mcp_sram.py b/adafruit_epd/mcp_sram.py index 2ad963e..0cf8c2a 100644 --- a/adafruit_epd/mcp_sram.py +++ b/adafruit_epd/mcp_sram.py @@ -11,11 +11,13 @@ from micropython import const from adafruit_bus_device import spi_device -from digitalio import DigitalInOut # Needed for type annotation -from busio import SPI # Needed for type annotation + try: + """Needed for type annotations""" from typing import Any, List + from digitalio import DigitalInOut + from busio import SPI except ImportError: pass @@ -96,11 +98,11 @@ def read16(self, addr: int, reg: int = SRAM_READ): buf = self.read(addr, 2, reg) return buf[0] << 8 | buf[1] - def write8(self, addr: int, value: Any, reg: int = SRAM_WRITE): + def write8(self, addr: int, value: int, reg: int = SRAM_WRITE): """write a single byte at the passed address""" self.write(addr, [value], reg) - def write16(self, addr: int, value: Any, reg: int = SRAM_WRITE): + def write16(self, addr: int, value: int, reg: int = SRAM_WRITE): """write 2 bytes at the passed address""" self.write(addr, [value >> 8, value], reg) From e4f301f833c571a6cb19031a93e6c89cf1db4af2 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Tue, 9 May 2023 23:59:28 +0200 Subject: [PATCH 03/17] Added requested type annotations. --- adafruit_epd/epd.py | 104 ++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 29 deletions(-) diff --git a/adafruit_epd/epd.py b/adafruit_epd/epd.py index fcccc26..4023271 100644 --- a/adafruit_epd/epd.py +++ b/adafruit_epd/epd.py @@ -11,9 +11,17 @@ import time from micropython import const -from digitalio import Direction +from digitalio import Direction, DigitalInOut from adafruit_epd import mcp_sram +try: + """Needed for type annotations""" + from typing import Any, Union, Callable + from busio import SPI + from PIL.Image import Image +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -29,8 +37,16 @@ class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-pu LIGHT = const(5) def __init__( - self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): # pylint: disable=too-many-arguments + self, + width: int, + height: int, + spi: SPI, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut, + ) -> None: # pylint: disable=too-many-arguments self._width = width self._height = height @@ -76,7 +92,7 @@ def __init__( self._black_inverted = self._color_inverted = True self.hardware_reset() - def display(self): # pylint: disable=too-many-branches + def display(self) -> None: # pylint: disable=too-many-branches """show the contents of the display buffer""" self.power_up() @@ -149,7 +165,7 @@ def display(self): # pylint: disable=too-many-branches self.update() - def hardware_reset(self): + def hardware_reset(self) -> None: """If we have a reset pin, do a hardware reset by toggling it""" if self._rst: self._rst.value = False @@ -157,7 +173,7 @@ def hardware_reset(self): self._rst.value = True time.sleep(0.1) - def command(self, cmd, data=None, end=True): + def command(self, cmd: Any, data: Any = None, end: bool = True) -> Any: """Send command byte to display.""" self._cs.value = True self._dc.value = False @@ -176,7 +192,7 @@ def command(self, cmd, data=None, end=True): return ret - def _spi_transfer(self, data): + def _spi_transfer(self, data: Any) -> Any: """Transfer one byte or bytearray, toggling the cs pin if required by the EPD chipset""" if isinstance(data, int): # single byte! self._spibuf[0] = data @@ -203,30 +219,30 @@ def _spi_transfer(self, data): self._spi_transfer(x) return None - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating. must be implemented in subclass""" raise NotImplementedError() - def power_down(self): + def power_down(self) -> None: """Power down the display, must be implemented in subclass""" raise NotImplementedError() - def update(self): + def update(self) -> None: """Update the display from internal memory, must be implemented in subclass""" raise NotImplementedError() - def write_ram(self, index): + def write_ram(self, index: int) -> None: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays. must be implemented in subclass""" raise NotImplementedError() - def set_ram_address(self, x, y): + def set_ram_address(self, x: int, y: int) -> None: """Set the RAM address location, must be implemented in subclass""" raise NotImplementedError() - def set_black_buffer(self, index, inverted): + def set_black_buffer(self, index: Union[0, 1], inverted: bool) -> None: """Set the index for the black buffer data (0 or 1) and whether its inverted""" if index == 0: self._blackframebuf = self._framebuf1 @@ -236,7 +252,7 @@ def set_black_buffer(self, index, inverted): raise RuntimeError("Buffer index must be 0 or 1") self._black_inverted = inverted - def set_color_buffer(self, index, inverted): + def set_color_buffer(self, index: Union[0, 1], inverted: bool) -> None: """Set the index for the color buffer data (0 or 1) and whether its inverted""" if index == 0: self._colorframebuf = self._framebuf1 @@ -246,7 +262,12 @@ def set_color_buffer(self, index, inverted): raise RuntimeError("Buffer index must be 0 or 1") self._color_inverted = inverted - def _color_dup(self, func, args, color): + def _color_dup( + self, + func: Callable, + args: Any, + color: Union[0, 1, 2, 3, 4, 5], + ) -> None: black = getattr(self._blackframebuf, func) red = getattr(self._colorframebuf, func) if self._blackframebuf is self._colorframebuf: # monochrome @@ -255,11 +276,11 @@ def _color_dup(self, func, args, color): black(*args, color=(color == Adafruit_EPD.BLACK) != self._black_inverted) red(*args, color=(color == Adafruit_EPD.RED) != self._color_inverted) - def pixel(self, x, y, color): + def pixel(self, x: int, y: int, color: int) -> None: """draw a single pixel in the display buffer""" self._color_dup("pixel", (x, y), color) - def fill(self, color): + def fill(self, color: int) -> None: """fill the screen with the passed color""" red_fill = ((color == Adafruit_EPD.RED) != self._color_inverted) * 0xFF black_fill = ((color == Adafruit_EPD.BLACK) != self._black_inverted) * 0xFF @@ -271,21 +292,34 @@ def fill(self, color): self._blackframebuf.fill(black_fill) self._colorframebuf.fill(red_fill) - def rect(self, x, y, width, height, color): # pylint: disable=too-many-arguments + def rect( + self, x: int, y: int, width: int, height: int, color: int + ) -> None: # pylint: disable=too-many-arguments """draw a rectangle""" self._color_dup("rect", (x, y, width, height), color) def fill_rect( - self, x, y, width, height, color - ): # pylint: disable=too-many-arguments + self, x: int, y: int, width: int, height: int, color: int + ) -> None: # pylint: disable=too-many-arguments """fill a rectangle with the passed color""" self._color_dup("fill_rect", (x, y, width, height), color) - def line(self, x_0, y_0, x_1, y_1, color): # pylint: disable=too-many-arguments + def line( + self, x_0: int, y_0: int, x_1: int, y_1: int, color: int + ) -> None: # pylint: disable=too-many-arguments """Draw a line from (x_0, y_0) to (x_1, y_1) in passed color""" self._color_dup("line", (x_0, y_0, x_1, y_1), color) - def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1): + def text( + self, + string: str, + x: int, + y: int, + color: int, + *, + font_name: str = "font5x8.bin", + size: int = 1 + ) -> None: """Write text string at location (x, y) in given color, using font file""" if self._blackframebuf is self._colorframebuf: # monochrome self._blackframebuf.text( @@ -315,39 +349,51 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1): ) @property - def width(self): + def width(self) -> int: """The width of the display, accounting for rotation""" if self.rotation in (0, 2): return self._width return self._height @property - def height(self): + def height(self) -> int: """The height of the display, accounting for rotation""" if self.rotation in (0, 2): return self._height return self._width @property - def rotation(self): + def rotation(self) -> Union[0, 1, 2, 3]: """The rotation of the display, can be one of (0, 1, 2, 3)""" return self._framebuf1.rotation @rotation.setter - def rotation(self, val): + def rotation(self, val: int) -> None: self._framebuf1.rotation = val if self._framebuf2: self._framebuf2.rotation = val - def hline(self, x, y, width, color): + def hline( + self, + x: int, + y: int, + width: int, + color: int, + ) -> None: """draw a horizontal line""" self.fill_rect(x, y, width, 1, color) - def vline(self, x, y, height, color): + def vline( + self, + x: int, + y: int, + height: int, + color: int, + ) -> None: """draw a vertical line""" self.fill_rect(x, y, 1, height, color) - def image(self, image): + def image(self, image: Image) -> None: """Set buffer to value of Python Imaging Library image. The image should be in RGB mode and a size equal to the display size. """ From 507f7862fb3977ee2db98246ac0981cf5e5b4678 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 10:03:32 +0200 Subject: [PATCH 04/17] Added requested type annotations to uc8151d.py --- adafruit_epd/uc8151d.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/adafruit_epd/uc8151d.py b/adafruit_epd/uc8151d.py index 1d4ed83..76d6c6e 100644 --- a/adafruit_epd/uc8151d.py +++ b/adafruit_epd/uc8151d.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -63,8 +72,17 @@ class Adafruit_UC8151D(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) @@ -90,13 +108,13 @@ def __init__( self.set_color_buffer(1, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -105,7 +123,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -119,14 +137,14 @@ def power_up(self): self.command(_UC8151D_CDI, bytearray([0x97])) time.sleep(0.05) - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_UC8151D_CDI, bytearray([0xF7])) self.command(_UC8151D_POWER_OFF) self.busy_wait() self.command(_UC8151D_DEEP_SLEEP, bytearray([0xA5])) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_UC8151D_DISPLAY_REFRESH) time.sleep(0.1) @@ -134,7 +152,7 @@ def update(self): if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0, 1]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -144,7 +162,9 @@ def write_ram(self, index): return self.command(_UC8151D_DTM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" return # on this chip it does nothing From f0e34c2cddde2b88a0bd4bb7497595586945d987 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 10:29:53 +0200 Subject: [PATCH 05/17] Added requested type annotations to ssd1681.py --- adafruit_epd/ssd1681.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/adafruit_epd/ssd1681.py b/adafruit_epd/ssd1681.py index 9482b01..38e7e36 100644 --- a/adafruit_epd/ssd1681.py +++ b/adafruit_epd/ssd1681.py @@ -14,6 +14,14 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -72,8 +80,17 @@ class Adafruit_SSD1681(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) @@ -101,13 +118,13 @@ def __init__( self.set_color_buffer(1, False) # pylint: enable=too-many-arguments - def begin(self, reset=True): + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -116,7 +133,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -143,12 +160,12 @@ def power_up(self): self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1681_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1681_DISP_CTRL2, bytearray([0xF7])) self.command(_SSD1681_MASTER_ACTIVATE) @@ -156,7 +173,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0, 1]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -166,7 +183,9 @@ def write_ram(self, index): return self.command(_SSD1681_WRITE_REDRAM, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" # Set RAM X address counter From eb4391fb1a57fb51eb74be957922e26cd18e18d8 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 10:41:32 +0200 Subject: [PATCH 06/17] Added requested type annotations to ssd1680.py. --- adafruit_epd/ssd1680.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index 7c5f553..58045e6 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -14,6 +14,12 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -72,8 +78,10 @@ class Adafruit_SSD1680(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + self, width: int, height: int, spi: SPI, *, cs_pin: DigitalInOut, + dc_pin: DigitalInOut, sramcs_pin: DigitalInOut, rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) @@ -110,13 +118,13 @@ def __init__( self.set_color_buffer(1, False) # pylint: enable=too-many-arguments - def begin(self, reset=True): + def begin(self, reset: bool=True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -125,7 +133,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -160,12 +168,12 @@ def power_up(self): self.command(_SSD1680_SET_RAMYCOUNT, bytearray([self._height - 1, 0])) self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1680_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1680_DISP_CTRL2, bytearray([0xF4])) self.command(_SSD1680_MASTER_ACTIVATE) @@ -173,7 +181,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0, 1]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -183,7 +191,7 @@ def write_ram(self, index): return self.command(_SSD1680_WRITE_REDRAM, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address(self, x: int, y: int) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" # Set RAM X address counter From 3b7e9b47f3042b71765d66a48504f883ef6c1bf6 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 10:49:16 +0200 Subject: [PATCH 07/17] Added requested type annotations to ssd1675b.py. --- adafruit_epd/ssd1675b.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/adafruit_epd/ssd1675b.py b/adafruit_epd/ssd1675b.py index 81b2dfe..eb27f15 100644 --- a/adafruit_epd/ssd1675b.py +++ b/adafruit_epd/ssd1675b.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -77,8 +86,17 @@ class Adafruit_SSD1675B(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) @@ -115,13 +133,13 @@ def __init__( self.set_color_buffer(0, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -130,7 +148,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() time.sleep(0.1) @@ -189,12 +207,12 @@ def power_up(self): self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1675B_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1675B_DISP_CTRL2, bytearray([0xC7])) self.command(_SSD1675B_MASTER_ACTIVATE) @@ -202,7 +220,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0, 1]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -212,7 +230,9 @@ def write_ram(self, index): return self.command(_SSD1675B_WRITE_RAM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" self.command(_SSD1675B_SET_RAMXCOUNT, bytearray([x])) From 077dd7029479c38bb312d5a7a32bc5c061c6812c Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 10:53:25 +0200 Subject: [PATCH 08/17] Added except clause. --- adafruit_epd/ssd1680.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index 58045e6..b04aee4 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -20,6 +20,9 @@ from busio import SPI from digitalio import DigitalInOut +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" From 8342c3fd4272ceb35f758957f093125d039de1e0 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 11:09:38 +0200 Subject: [PATCH 09/17] Added requested type annotations to ssd1675.py. --- adafruit_epd/ssd1675.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/adafruit_epd/ssd1675.py b/adafruit_epd/ssd1675.py index c86e4cf..bb36316 100644 --- a/adafruit_epd/ssd1675.py +++ b/adafruit_epd/ssd1675.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -51,7 +60,16 @@ class Adafruit_SSD1675(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut ): super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin @@ -89,13 +107,13 @@ def __init__( self.set_color_buffer(0, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -104,7 +122,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() time.sleep(0.1) @@ -147,12 +165,12 @@ def power_up(self): self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1675_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1675_DISP_CTRL2, bytearray([0xC7])) self.command(_SSD1675_MASTER_ACTIVATE) @@ -160,7 +178,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0, 1]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -170,7 +188,9 @@ def write_ram(self, index): return self.command(_SSD1675_WRITE_RAM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" self.command(_SSD1675_SET_RAMXCOUNT, bytearray([x])) From f732181a3e8ebce69ea26cebac42432bab8517f9 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 11:10:33 +0200 Subject: [PATCH 10/17] Automatic formatting for ssd1680.py. --- adafruit_epd/ssd1680.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index b04aee4..f65008e 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -81,8 +81,15 @@ class Adafruit_SSD1680(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width: int, height: int, spi: SPI, *, cs_pin: DigitalInOut, - dc_pin: DigitalInOut, sramcs_pin: DigitalInOut, rst_pin: DigitalInOut, + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, busy_pin: DigitalInOut ) -> None: super().__init__( @@ -121,7 +128,7 @@ def __init__( self.set_color_buffer(1, False) # pylint: enable=too-many-arguments - def begin(self, reset: bool=True) -> None: + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() @@ -194,7 +201,9 @@ def write_ram(self, index: Union[0, 1]) -> Any: return self.command(_SSD1680_WRITE_REDRAM, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x: int, y: int) -> None: # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" # Set RAM X address counter From 22eeabb28fc3c583d5a6ca8550af6a824f6946de Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 11:18:23 +0200 Subject: [PATCH 11/17] Added requested type annotations for ssd1608.py. --- adafruit_epd/ssd1608.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/adafruit_epd/ssd1608.py b/adafruit_epd/ssd1608.py index 0bb4b7b..0ad6e26 100644 --- a/adafruit_epd/ssd1608.py +++ b/adafruit_epd/ssd1608.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -57,8 +66,17 @@ class Adafruit_SSD1608(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) @@ -80,13 +98,13 @@ def __init__( self.set_color_buffer(0, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -95,7 +113,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -125,12 +143,12 @@ def power_up(self): self.command(_SSD1608_WRITE_LUT, _LUT_DATA) self.busy_wait() - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_SSD1608_DEEP_SLEEP, bytearray([0x01])) time.sleep(0.1) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_SSD1608_DISP_CTRL2, bytearray([0xC7])) self.command(_SSD1608_MASTER_ACTIVATE) @@ -138,7 +156,7 @@ def update(self): if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -146,7 +164,9 @@ def write_ram(self, index): return self.command(_SSD1608_WRITE_RAM, end=False) raise RuntimeError("RAM index must be 0") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" # Set RAM X address counter From 61d59ad16235b00b8e54ab353d751d5744843765 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 11:25:11 +0200 Subject: [PATCH 12/17] Added requested type annotations for il0398.py. --- adafruit_epd/il0398.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/adafruit_epd/il0398.py b/adafruit_epd/il0398.py index 039cca4..298e709 100644 --- a/adafruit_epd/il0398.py +++ b/adafruit_epd/il0398.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -49,8 +58,17 @@ class Adafruit_IL0398(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) @@ -76,13 +94,13 @@ def __init__( self.set_color_buffer(1, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -92,7 +110,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -111,14 +129,14 @@ def power_up(self): self.command(_IL0398_RESOLUTION, bytearray([_b0, _b1, _b2, _b3])) time.sleep(0.05) - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_IL0398_CDI, bytearray([0xF7])) self.command(_IL0398_POWER_OFF) self.busy_wait() self.command(_IL0398_DEEP_SLEEP, bytearray([0xA5])) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_IL0398_DISPLAY_REFRESH) time.sleep(0.1) @@ -126,7 +144,7 @@ def update(self): if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0, 1]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -136,7 +154,9 @@ def write_ram(self, index): return self.command(_IL0398_DTM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" return # on this chip it does nothing From 207ba7e691ce3e05522514b29e24e2714a7f3280 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 11:31:04 +0200 Subject: [PATCH 13/17] Added requested type annotations to il91874.py. --- adafruit_epd/il91874.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/adafruit_epd/il91874.py b/adafruit_epd/il91874.py index 910b01b..738d19d 100644 --- a/adafruit_epd/il91874.py +++ b/adafruit_epd/il91874.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + "Needed for type annotations" + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -56,8 +65,17 @@ class Adafruit_IL91874(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) @@ -83,14 +101,14 @@ def __init__( self.set_color_buffer(1, False) self._single_byte_tx = True - def begin(self, reset=True): + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -99,7 +117,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() time.sleep(0.2) @@ -134,7 +152,7 @@ def power_up(self): self.command(_IL91874_RESOLUTION, bytearray([_b0, _b1, _b2, _b3])) self.command(_IL91874_PDRF, bytearray([0x00])) - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_IL91874_POWER_OFF, bytearray([0x17])) self.busy_wait() @@ -142,14 +160,14 @@ def power_down(self): if self._rst: # Only deep sleep if we can get out of it self.command(_IL91874_DEEP_SLEEP, bytearray([0xA5])) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_IL91874_DISPLAY_REFRESH) self.busy_wait() if not self._busy: time.sleep(16) # wait 16 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0, 1]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -159,7 +177,9 @@ def write_ram(self, index): return self.command(_IL91874_DTM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" return # on this chip it does nothing From 3b02f34a5f8d62863488e1b2d4d3f32a7de4943b Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 11:39:11 +0200 Subject: [PATCH 14/17] Added requested type annotations to il0373.py. --- adafruit_epd/il0373.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/adafruit_epd/il0373.py b/adafruit_epd/il0373.py index 27e11ef..ceb5c5d 100644 --- a/adafruit_epd/il0373.py +++ b/adafruit_epd/il0373.py @@ -14,6 +14,15 @@ import adafruit_framebuf from adafruit_epd.epd import Adafruit_EPD +try: + """Needed for type annotations""" + from typing import Union, Any + from busio import SPI + from digitalio import DigitalInOut + +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" @@ -48,8 +57,17 @@ class Adafruit_IL0373(Adafruit_EPD): # pylint: disable=too-many-arguments def __init__( - self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin - ): + self, + width: int, + height: int, + spi: SPI, + *, + cs_pin: DigitalInOut, + dc_pin: DigitalInOut, + sramcs_pin: DigitalInOut, + rst_pin: DigitalInOut, + busy_pin: DigitalInOut + ) -> None: super().__init__( width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin ) @@ -75,13 +93,13 @@ def __init__( self.set_color_buffer(1, True) # pylint: enable=too-many-arguments - def begin(self, reset=True): + def begin(self, reset: bool = True) -> None: """Begin communication with the display and set basic settings""" if reset: self.hardware_reset() self.power_down() - def busy_wait(self): + def busy_wait(self) -> None: """Wait for display to be done with current task, either by polling the busy pin, or pausing""" if self._busy: @@ -90,7 +108,7 @@ def busy_wait(self): else: time.sleep(0.5) - def power_up(self): + def power_up(self) -> None: """Power up the display in preparation for writing RAM and updating""" self.hardware_reset() self.busy_wait() @@ -112,13 +130,13 @@ def power_up(self): self.command(_IL0373_VCM_DC_SETTING, bytearray([0x0A])) time.sleep(0.05) - def power_down(self): + def power_down(self) -> None: """Power down the display - required when not actively displaying!""" self.command(_IL0373_CDI, bytearray([0x17])) self.command(_IL0373_VCM_DC_SETTING, bytearray([0x00])) self.command(_IL0373_POWER_OFF) - def update(self): + def update(self) -> None: """Update the display from internal memory""" self.command(_IL0373_DISPLAY_REFRESH) time.sleep(0.1) @@ -126,7 +144,7 @@ def update(self): if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index): + def write_ram(self, index: Union[0, 1]) -> Any: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" @@ -136,7 +154,9 @@ def write_ram(self, index): return self.command(_IL0373_DTM2, end=False) raise RuntimeError("RAM index must be 0 or 1") - def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + def set_ram_address( + self, x: int, y: int + ) -> None: # pylint: disable=unused-argument, no-self-use """Set the RAM address location, not used on this chipset but required by the superclass""" return # on this chip it does nothing From 95758b357f6ec304cb23238796f31f7d1a2ed780 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Thu, 18 May 2023 21:13:17 +0200 Subject: [PATCH 15/17] Added changes requested by @FoamyGuy. --- adafruit_epd/epd.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/adafruit_epd/epd.py b/adafruit_epd/epd.py index 4023271..a6f583d 100644 --- a/adafruit_epd/epd.py +++ b/adafruit_epd/epd.py @@ -11,14 +11,15 @@ import time from micropython import const -from digitalio import Direction, DigitalInOut from adafruit_epd import mcp_sram try: """Needed for type annotations""" - from typing import Any, Union, Callable + from typing import Any, Union, Callable, Optional from busio import SPI + from digitalio import Direction, DigitalInOut from PIL.Image import Image + except ImportError: pass @@ -26,7 +27,7 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" -class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-public-methods +class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-public-methods, too-many-arguments """Base class for EPD displays""" BLACK = const(0) @@ -173,7 +174,9 @@ def hardware_reset(self) -> None: self._rst.value = True time.sleep(0.1) - def command(self, cmd: Any, data: Any = None, end: bool = True) -> Any: + def command( + self, cmd: int, data: Optional[bytearray] = None, end: bool = True + ) -> int: """Send command byte to display.""" self._cs.value = True self._dc.value = False @@ -192,7 +195,7 @@ def command(self, cmd: Any, data: Any = None, end: bool = True) -> Any: return ret - def _spi_transfer(self, data: Any) -> Any: + def _spi_transfer(self, data: Union[int, bytearray]) -> int: """Transfer one byte or bytearray, toggling the cs pin if required by the EPD chipset""" if isinstance(data, int): # single byte! self._spibuf[0] = data From 3a6375d54a2d8bea2865881f218b760c25329219 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Sat, 20 May 2023 19:18:51 +0200 Subject: [PATCH 16/17] Implemented changes requested by @FoamyGuy. --- adafruit_epd/epd.py | 4 ++-- adafruit_epd/il0373.py | 4 ++-- adafruit_epd/il0398.py | 4 ++-- adafruit_epd/il91874.py | 4 ++-- adafruit_epd/ssd1608.py | 4 ++-- adafruit_epd/ssd1675.py | 4 ++-- adafruit_epd/ssd1675b.py | 4 ++-- adafruit_epd/ssd1680.py | 4 ++-- adafruit_epd/ssd1681.py | 4 ++-- adafruit_epd/uc8151d.py | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/adafruit_epd/epd.py b/adafruit_epd/epd.py index a6f583d..13f1d64 100644 --- a/adafruit_epd/epd.py +++ b/adafruit_epd/epd.py @@ -18,7 +18,7 @@ from typing import Any, Union, Callable, Optional from busio import SPI from digitalio import Direction, DigitalInOut - from PIL.Image import Image + from circuitpython_typing.pil import Image except ImportError: pass @@ -195,7 +195,7 @@ def command( return ret - def _spi_transfer(self, data: Union[int, bytearray]) -> int: + def _spi_transfer(self, data: Union[int, bytearray]) -> Optional[int]: """Transfer one byte or bytearray, toggling the cs pin if required by the EPD chipset""" if isinstance(data, int): # single byte! self._spibuf[0] = data diff --git a/adafruit_epd/il0373.py b/adafruit_epd/il0373.py index ceb5c5d..ac83270 100644 --- a/adafruit_epd/il0373.py +++ b/adafruit_epd/il0373.py @@ -16,7 +16,7 @@ try: """Needed for type annotations""" - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -144,7 +144,7 @@ def update(self) -> None: if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index: Union[0, 1]) -> Any: + def write_ram(self, index: Union[0, 1]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" diff --git a/adafruit_epd/il0398.py b/adafruit_epd/il0398.py index 298e709..5b8fcac 100644 --- a/adafruit_epd/il0398.py +++ b/adafruit_epd/il0398.py @@ -16,7 +16,7 @@ try: """Needed for type annotations""" - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -144,7 +144,7 @@ def update(self) -> None: if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index: Union[0, 1]) -> Any: + def write_ram(self, index: Union[0, 1]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" diff --git a/adafruit_epd/il91874.py b/adafruit_epd/il91874.py index 738d19d..ac9472d 100644 --- a/adafruit_epd/il91874.py +++ b/adafruit_epd/il91874.py @@ -16,7 +16,7 @@ try: "Needed for type annotations" - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -167,7 +167,7 @@ def update(self) -> None: if not self._busy: time.sleep(16) # wait 16 seconds - def write_ram(self, index: Union[0, 1]) -> Any: + def write_ram(self, index: Union[0, 1]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" diff --git a/adafruit_epd/ssd1608.py b/adafruit_epd/ssd1608.py index 0ad6e26..2792c0c 100644 --- a/adafruit_epd/ssd1608.py +++ b/adafruit_epd/ssd1608.py @@ -16,7 +16,7 @@ try: """Needed for type annotations""" - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -156,7 +156,7 @@ def update(self) -> None: if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index: Union[0]) -> Any: + def write_ram(self, index: Union[0]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" diff --git a/adafruit_epd/ssd1675.py b/adafruit_epd/ssd1675.py index bb36316..6c72efa 100644 --- a/adafruit_epd/ssd1675.py +++ b/adafruit_epd/ssd1675.py @@ -16,7 +16,7 @@ try: """Needed for type annotations""" - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -178,7 +178,7 @@ def update(self) -> None: if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index: Union[0, 1]) -> Any: + def write_ram(self, index: Union[0, 1]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" diff --git a/adafruit_epd/ssd1675b.py b/adafruit_epd/ssd1675b.py index eb27f15..2542ce4 100644 --- a/adafruit_epd/ssd1675b.py +++ b/adafruit_epd/ssd1675b.py @@ -16,7 +16,7 @@ try: """Needed for type annotations""" - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -220,7 +220,7 @@ def update(self) -> None: if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index: Union[0, 1]) -> Any: + def write_ram(self, index: Union[0, 1]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" diff --git a/adafruit_epd/ssd1680.py b/adafruit_epd/ssd1680.py index f65008e..5f4e89c 100644 --- a/adafruit_epd/ssd1680.py +++ b/adafruit_epd/ssd1680.py @@ -16,7 +16,7 @@ try: """Needed for type annotations""" - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -191,7 +191,7 @@ def update(self) -> None: if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index: Union[0, 1]) -> Any: + def write_ram(self, index: Union[0, 1]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" diff --git a/adafruit_epd/ssd1681.py b/adafruit_epd/ssd1681.py index 38e7e36..15b3944 100644 --- a/adafruit_epd/ssd1681.py +++ b/adafruit_epd/ssd1681.py @@ -15,7 +15,7 @@ from adafruit_epd.epd import Adafruit_EPD try: - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -173,7 +173,7 @@ def update(self) -> None: if not self._busy: time.sleep(3) # wait 3 seconds - def write_ram(self, index: Union[0, 1]) -> Any: + def write_ram(self, index: Union[0, 1]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" diff --git a/adafruit_epd/uc8151d.py b/adafruit_epd/uc8151d.py index 76d6c6e..4cbdb73 100644 --- a/adafruit_epd/uc8151d.py +++ b/adafruit_epd/uc8151d.py @@ -16,7 +16,7 @@ try: """Needed for type annotations""" - from typing import Union, Any + from typing import Union from busio import SPI from digitalio import DigitalInOut @@ -152,7 +152,7 @@ def update(self) -> None: if not self._busy: time.sleep(15) # wait 15 seconds - def write_ram(self, index: Union[0, 1]) -> Any: + def write_ram(self, index: Union[0, 1]) -> int: """Send the one byte command for starting the RAM write process. Returns the byte read at the same time over SPI. index is the RAM buffer, can be 0 or 1 for tri-color displays.""" From 148c744668d0fb5d6b33637b7536c6b09ca786f5 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 22 May 2023 15:55:54 -0500 Subject: [PATCH 17/17] Import Direction at runtime --- adafruit_epd/epd.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_epd/epd.py b/adafruit_epd/epd.py index 13f1d64..6e61e1f 100644 --- a/adafruit_epd/epd.py +++ b/adafruit_epd/epd.py @@ -8,16 +8,18 @@ CircuitPython driver for Adafruit ePaper display breakouts * Author(s): Dean Miller """ +# pylint: disable=ungrouped-imports import time from micropython import const +from digitalio import Direction from adafruit_epd import mcp_sram try: """Needed for type annotations""" from typing import Any, Union, Callable, Optional from busio import SPI - from digitalio import Direction, DigitalInOut + from digitalio import DigitalInOut from circuitpython_typing.pil import Image except ImportError: