From eb4391fb1a57fb51eb74be957922e26cd18e18d8 Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 10:41:32 +0200 Subject: [PATCH 1/2] 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 @@ from micropython import const 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 @@ class Adafruit_SSD1680(Adafruit_EPD): 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 @@ class Adafruit_SSD1680(Adafruit_EPD): 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 @@ class Adafruit_SSD1680(Adafruit_EPD): 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 @@ class Adafruit_SSD1680(Adafruit_EPD): 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 @@ class Adafruit_SSD1680(Adafruit_EPD): 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 077dd7029479c38bb312d5a7a32bc5c061c6812c Mon Sep 17 00:00:00 2001 From: sdomoszlai13 Date: Wed, 10 May 2023 10:53:25 +0200 Subject: [PATCH 2/2] 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 @@ try: 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"