Skip to content

Commit

Permalink
Merge pull request #37 from adafruit/pylint-update
Browse files Browse the repository at this point in the history
Ran black, updated to pylint 2.x
  • Loading branch information
kattni committed Mar 17, 2020
2 parents faeb1a7 + c13f9f5 commit 7001278
Show file tree
Hide file tree
Showing 19 changed files with 553 additions and 362 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
91 changes: 56 additions & 35 deletions adafruit_epd/epd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@
__version__ = "0.0.0-auto.0"
__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
"""Base class for EPD displays
"""

BLACK = const(0)
WHITE = const(1)
INVERSE = const(2)
RED = const(3)
DARK = const(4)
LIGHT = const(5)


def __init__(self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): # pylint: disable=too-many-arguments
def __init__(
self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
): # pylint: disable=too-many-arguments
self._width = width
self._height = height

Expand Down Expand Up @@ -73,7 +76,7 @@ def __init__(self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy
self.spi_device = spi
while not self.spi_device.try_lock():
time.sleep(0.01)
self.spi_device.configure(baudrate=1000000) # 1 Mhz
self.spi_device.configure(baudrate=1000000) # 1 Mhz
self.spi_device.unlock()

self._spibuf = bytearray(1)
Expand Down Expand Up @@ -101,16 +104,16 @@ def display(self): # pylint: disable=too-many-branches
while not self.spi_device.try_lock():
time.sleep(0.01)
self.sram.cs_pin.value = False
#send read command
# send read command
self._buf[0] = mcp_sram.Adafruit_MCP_SRAM.SRAM_READ
#send start address
# send start address
self._buf[1] = 0
self._buf[2] = 0
self.spi_device.write(self._buf, end=3)
self.spi_device.unlock()

#first data byte from SRAM will be transfered in at the
#same time as the EPD command is transferred out
# first data byte from SRAM will be transfered in at the
# same time as the EPD command is transferred out
databyte = self.write_ram(0)

while not self.spi_device.try_lock():
Expand All @@ -127,23 +130,23 @@ def display(self): # pylint: disable=too-many-branches

self._cs.value = True
self.spi_device.unlock()
time.sleep(.002)
time.sleep(0.002)

if self.sram:
while not self.spi_device.try_lock():
time.sleep(0.01)
self.sram.cs_pin.value = False
#send read command
# send read command
self._buf[0] = mcp_sram.Adafruit_MCP_SRAM.SRAM_READ
#send start address
# send start address
self._buf[1] = (self._buffer1_size >> 8) & 0xFF
self._buf[2] = self._buffer1_size & 0xFF
self.spi_device.write(self._buf, end=3)
self.spi_device.unlock()

if self._buffer2_size != 0:
#first data byte from SRAM will be transfered in at the
#same time as the EPD command is transferred out
# first data byte from SRAM will be transfered in at the
# same time as the EPD command is transferred out
databyte = self.write_ram(1)

while not self.spi_device.try_lock():
Expand All @@ -166,7 +169,6 @@ def display(self): # pylint: disable=too-many-branches

self.update()


def hardware_reset(self):
"""If we have a reset pin, do a hardware reset by toggling it"""
if self._rst:
Expand Down Expand Up @@ -251,15 +253,15 @@ def set_color_buffer(self, index, inverted):
def _color_dup(self, func, args, color):
black = getattr(self._blackframebuf, func)
red = getattr(self._colorframebuf, func)
if self._blackframebuf is self._colorframebuf: # monochrome
if self._blackframebuf is self._colorframebuf: # monochrome
black(*args, color=(color != Adafruit_EPD.WHITE) != self._black_inverted)
else:
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):
"""draw a single pixel in the display buffer"""
self._color_dup('pixel', (x, y), color)
self._color_dup("pixel", (x, y), color)

def fill(self, color):
"""fill the screen with the passed color"""
Expand All @@ -273,28 +275,45 @@ 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, y, width, height, color): # pylint: disable=too-many-arguments
"""draw a rectangle"""
self._color_dup('rect', (x, y, width, height), color)
self._color_dup("rect", (x, y, width, height), color)

def fill_rect(self, x, y, width, height, color): # pylint: disable=too-many-arguments
def fill_rect(
self, x, y, width, height, color
): # pylint: disable=too-many-arguments
"""fill a rectangle with the passed color"""
self._color_dup('fill_rect', (x, y, width, height), 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, y_0, x_1, y_1, color): # 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)
self._color_dup("line", (x_0, y_0, x_1, y_1), color)

def text(self, string, x, y, color, *, font_name="font5x8.bin"):
"""Write text string at location (x, y) in given color, using font file"""
if self._blackframebuf is self._colorframebuf: # monochrome
self._blackframebuf.text(string, x, y, font_name=font_name,
color=(color != Adafruit_EPD.WHITE) != self._black_inverted)
if self._blackframebuf is self._colorframebuf: # monochrome
self._blackframebuf.text(
string,
x,
y,
font_name=font_name,
color=(color != Adafruit_EPD.WHITE) != self._black_inverted,
)
else:
self._blackframebuf.text(string, x, y, font_name=font_name,
color=(color == Adafruit_EPD.BLACK) != self._black_inverted)
self._colorframebuf.text(string, x, y, font_name=font_name,
color=(color == Adafruit_EPD.RED) != self._color_inverted)
self._blackframebuf.text(
string,
x,
y,
font_name=font_name,
color=(color == Adafruit_EPD.BLACK) != self._black_inverted,
)
self._colorframebuf.text(
string,
x,
y,
font_name=font_name,
color=(color == Adafruit_EPD.RED) != self._color_inverted,
)

@property
def width(self):
Expand Down Expand Up @@ -329,17 +348,19 @@ def vline(self, x, y, height, color):
"""draw a vertical line"""
self.fill_rect(x, y, 1, height, color)


def image(self, image):
"""Set buffer to value of Python Imaging Library image. The image should
be in RGB mode and a size equal to the display size.
"""
if image.mode != 'RGB':
raise ValueError('Image must be in mode RGB.')
if image.mode != "RGB":
raise ValueError("Image must be in mode RGB.")
imwidth, imheight = image.size
if imwidth != self.width or imheight != self.height:
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
.format(self.width, self.height))
raise ValueError(
"Image must be same dimensions as display ({0}x{1}).".format(
self.width, self.height
)
)
if self.sram:
raise RuntimeError("PIL image is not for use with SRAM assist")
# Grab all the pixels from the image, faster than getpixel.
Expand All @@ -350,7 +371,7 @@ def image(self, image):
for y in range(image.size[1]):
for x in range(image.size[0]):
pixel = pix[x, y]
if (pixel[0] >= 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
if (pixel[1] < 0x80 <= pixel[0]) and (pixel[2] < 0x80):
# reddish
self.pixel(x, y, Adafruit_EPD.RED)
elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
Expand Down
29 changes: 18 additions & 11 deletions adafruit_epd/il0373.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@
_IL0373_RESOLUTION = const(0x61)
_IL0373_VCM_DC_SETTING = const(0x82)


class Adafruit_IL0373(Adafruit_EPD):
"""driver class for Adafruit IL0373 ePaper display breakouts"""

# pylint: disable=too-many-arguments
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
super(Adafruit_IL0373, self).__init__(width, height, spi, cs_pin, dc_pin,
sramcs_pin, rst_pin, busy_pin)
def __init__(
self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
):
super(Adafruit_IL0373, self).__init__(
width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
)

self._buffer1_size = int(width * height / 8)
self._buffer2_size = int(width * height / 8)
Expand All @@ -77,10 +82,12 @@ def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, b
self._buffer2 = bytearray((width * height) // 8)
# since we have *two* framebuffers - one for red and one for black
# we dont subclass but manage manually
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
buf_format=adafruit_framebuf.MHMSB)
self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height,
buf_format=adafruit_framebuf.MHMSB)
self._framebuf1 = adafruit_framebuf.FrameBuffer(
self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB
)
self._framebuf2 = adafruit_framebuf.FrameBuffer(
self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB
)
self.set_black_buffer(0, True)
self.set_color_buffer(1, True)
# pylint: enable=too-many-arguments
Expand All @@ -105,7 +112,7 @@ def power_up(self):
self.hardware_reset()
self.busy_wait()

self.command(_IL0373_POWER_SETTING, bytearray([0x03, 0x00, 0x2b, 0x2b, 0x09]))
self.command(_IL0373_POWER_SETTING, bytearray([0x03, 0x00, 0x2B, 0x2B, 0x09]))
self.command(_IL0373_BOOSTER_SOFT_START, bytearray([0x17, 0x17, 0x17]))
self.command(_IL0373_POWER_ON)

Expand Down Expand Up @@ -134,7 +141,7 @@ def update(self):
time.sleep(0.1)
self.busy_wait()
if not self._busy:
time.sleep(15) # wait 15 seconds
time.sleep(15) # wait 15 seconds

def write_ram(self, index):
"""Send the one byte command for starting the RAM write process. Returns
Expand All @@ -146,7 +153,7 @@ 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, y): # 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
return # on this chip it does nothing
29 changes: 18 additions & 11 deletions adafruit_epd/il0398.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@
_IL0398_GETSTATUS = const(0x71)
_IL0398_VCM_DC_SETTING = const(0x82)


class Adafruit_IL0398(Adafruit_EPD):
"""driver class for Adafruit IL0373 ePaper display breakouts"""

# pylint: disable=too-many-arguments
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
super(Adafruit_IL0398, self).__init__(width, height, spi, cs_pin, dc_pin,
sramcs_pin, rst_pin, busy_pin)
def __init__(
self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
):
super(Adafruit_IL0398, self).__init__(
width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
)

self._buffer1_size = int(width * height / 8)
self._buffer2_size = int(width * height / 8)
Expand All @@ -78,10 +83,12 @@ def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, b
self._buffer2 = bytearray((width * height) // 8)
# since we have *two* framebuffers - one for red and one for black
# we dont subclass but manage manually
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
buf_format=adafruit_framebuf.MHMSB)
self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height,
buf_format=adafruit_framebuf.MHMSB)
self._framebuf1 = adafruit_framebuf.FrameBuffer(
self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB
)
self._framebuf2 = adafruit_framebuf.FrameBuffer(
self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB
)
self.set_black_buffer(0, True)
self.set_color_buffer(1, True)
# pylint: enable=too-many-arguments
Expand All @@ -97,7 +104,7 @@ def busy_wait(self):
busy pin, or pausing"""
if self._busy:
while not self._busy.value:
#self.command(_IL0398_GETSTATUS)
# self.command(_IL0398_GETSTATUS)
time.sleep(0.01)
else:
time.sleep(0.5)
Expand Down Expand Up @@ -134,7 +141,7 @@ def update(self):
time.sleep(0.1)
self.busy_wait()
if not self._busy:
time.sleep(15) # wait 15 seconds
time.sleep(15) # wait 15 seconds

def write_ram(self, index):
"""Send the one byte command for starting the RAM write process. Returns
Expand All @@ -146,7 +153,7 @@ 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, y): # 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
return # on this chip it does nothing

0 comments on commit 7001278

Please sign in to comment.