Skip to content

Commit 7001278

Browse files
authored
Merge pull request #37 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents faeb1a7 + c13f9f5 commit 7001278

19 files changed

+553
-362
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_epd/epd.py

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@
3434
__version__ = "0.0.0-auto.0"
3535
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git"
3636

37-
class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-public-methods
37+
38+
class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-public-methods
3839
"""Base class for EPD displays
3940
"""
41+
4042
BLACK = const(0)
4143
WHITE = const(1)
4244
INVERSE = const(2)
4345
RED = const(3)
4446
DARK = const(4)
4547
LIGHT = const(5)
4648

47-
48-
def __init__(self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin): # pylint: disable=too-many-arguments
49+
def __init__(
50+
self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
51+
): # pylint: disable=too-many-arguments
4952
self._width = width
5053
self._height = height
5154

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

7982
self._spibuf = bytearray(1)
@@ -101,16 +104,16 @@ def display(self): # pylint: disable=too-many-branches
101104
while not self.spi_device.try_lock():
102105
time.sleep(0.01)
103106
self.sram.cs_pin.value = False
104-
#send read command
107+
# send read command
105108
self._buf[0] = mcp_sram.Adafruit_MCP_SRAM.SRAM_READ
106-
#send start address
109+
# send start address
107110
self._buf[1] = 0
108111
self._buf[2] = 0
109112
self.spi_device.write(self._buf, end=3)
110113
self.spi_device.unlock()
111114

112-
#first data byte from SRAM will be transfered in at the
113-
#same time as the EPD command is transferred out
115+
# first data byte from SRAM will be transfered in at the
116+
# same time as the EPD command is transferred out
114117
databyte = self.write_ram(0)
115118

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

128131
self._cs.value = True
129132
self.spi_device.unlock()
130-
time.sleep(.002)
133+
time.sleep(0.002)
131134

132135
if self.sram:
133136
while not self.spi_device.try_lock():
134137
time.sleep(0.01)
135138
self.sram.cs_pin.value = False
136-
#send read command
139+
# send read command
137140
self._buf[0] = mcp_sram.Adafruit_MCP_SRAM.SRAM_READ
138-
#send start address
141+
# send start address
139142
self._buf[1] = (self._buffer1_size >> 8) & 0xFF
140143
self._buf[2] = self._buffer1_size & 0xFF
141144
self.spi_device.write(self._buf, end=3)
142145
self.spi_device.unlock()
143146

144147
if self._buffer2_size != 0:
145-
#first data byte from SRAM will be transfered in at the
146-
#same time as the EPD command is transferred out
148+
# first data byte from SRAM will be transfered in at the
149+
# same time as the EPD command is transferred out
147150
databyte = self.write_ram(1)
148151

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

167170
self.update()
168171

169-
170172
def hardware_reset(self):
171173
"""If we have a reset pin, do a hardware reset by toggling it"""
172174
if self._rst:
@@ -251,15 +253,15 @@ def set_color_buffer(self, index, inverted):
251253
def _color_dup(self, func, args, color):
252254
black = getattr(self._blackframebuf, func)
253255
red = getattr(self._colorframebuf, func)
254-
if self._blackframebuf is self._colorframebuf: # monochrome
256+
if self._blackframebuf is self._colorframebuf: # monochrome
255257
black(*args, color=(color != Adafruit_EPD.WHITE) != self._black_inverted)
256258
else:
257259
black(*args, color=(color == Adafruit_EPD.BLACK) != self._black_inverted)
258260
red(*args, color=(color == Adafruit_EPD.RED) != self._color_inverted)
259261

260262
def pixel(self, x, y, color):
261263
"""draw a single pixel in the display buffer"""
262-
self._color_dup('pixel', (x, y), color)
264+
self._color_dup("pixel", (x, y), color)
263265

264266
def fill(self, color):
265267
"""fill the screen with the passed color"""
@@ -273,28 +275,45 @@ def fill(self, color):
273275
self._blackframebuf.fill(black_fill)
274276
self._colorframebuf.fill(red_fill)
275277

276-
def rect(self, x, y, width, height, color): # pylint: disable=too-many-arguments
278+
def rect(self, x, y, width, height, color): # pylint: disable=too-many-arguments
277279
"""draw a rectangle"""
278-
self._color_dup('rect', (x, y, width, height), color)
280+
self._color_dup("rect", (x, y, width, height), color)
279281

280-
def fill_rect(self, x, y, width, height, color): # pylint: disable=too-many-arguments
282+
def fill_rect(
283+
self, x, y, width, height, color
284+
): # pylint: disable=too-many-arguments
281285
"""fill a rectangle with the passed color"""
282-
self._color_dup('fill_rect', (x, y, width, height), color)
286+
self._color_dup("fill_rect", (x, y, width, height), color)
283287

284-
def line(self, x_0, y_0, x_1, y_1, color): # pylint: disable=too-many-arguments
288+
def line(self, x_0, y_0, x_1, y_1, color): # pylint: disable=too-many-arguments
285289
"""Draw a line from (x_0, y_0) to (x_1, y_1) in passed color"""
286-
self._color_dup('line', (x_0, y_0, x_1, y_1), color)
290+
self._color_dup("line", (x_0, y_0, x_1, y_1), color)
287291

288292
def text(self, string, x, y, color, *, font_name="font5x8.bin"):
289293
"""Write text string at location (x, y) in given color, using font file"""
290-
if self._blackframebuf is self._colorframebuf: # monochrome
291-
self._blackframebuf.text(string, x, y, font_name=font_name,
292-
color=(color != Adafruit_EPD.WHITE) != self._black_inverted)
294+
if self._blackframebuf is self._colorframebuf: # monochrome
295+
self._blackframebuf.text(
296+
string,
297+
x,
298+
y,
299+
font_name=font_name,
300+
color=(color != Adafruit_EPD.WHITE) != self._black_inverted,
301+
)
293302
else:
294-
self._blackframebuf.text(string, x, y, font_name=font_name,
295-
color=(color == Adafruit_EPD.BLACK) != self._black_inverted)
296-
self._colorframebuf.text(string, x, y, font_name=font_name,
297-
color=(color == Adafruit_EPD.RED) != self._color_inverted)
303+
self._blackframebuf.text(
304+
string,
305+
x,
306+
y,
307+
font_name=font_name,
308+
color=(color == Adafruit_EPD.BLACK) != self._black_inverted,
309+
)
310+
self._colorframebuf.text(
311+
string,
312+
x,
313+
y,
314+
font_name=font_name,
315+
color=(color == Adafruit_EPD.RED) != self._color_inverted,
316+
)
298317

299318
@property
300319
def width(self):
@@ -329,17 +348,19 @@ def vline(self, x, y, height, color):
329348
"""draw a vertical line"""
330349
self.fill_rect(x, y, 1, height, color)
331350

332-
333351
def image(self, image):
334352
"""Set buffer to value of Python Imaging Library image. The image should
335353
be in RGB mode and a size equal to the display size.
336354
"""
337-
if image.mode != 'RGB':
338-
raise ValueError('Image must be in mode RGB.')
355+
if image.mode != "RGB":
356+
raise ValueError("Image must be in mode RGB.")
339357
imwidth, imheight = image.size
340358
if imwidth != self.width or imheight != self.height:
341-
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
342-
.format(self.width, self.height))
359+
raise ValueError(
360+
"Image must be same dimensions as display ({0}x{1}).".format(
361+
self.width, self.height
362+
)
363+
)
343364
if self.sram:
344365
raise RuntimeError("PIL image is not for use with SRAM assist")
345366
# Grab all the pixels from the image, faster than getpixel.
@@ -350,7 +371,7 @@ def image(self, image):
350371
for y in range(image.size[1]):
351372
for x in range(image.size[0]):
352373
pixel = pix[x, y]
353-
if (pixel[0] >= 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
374+
if (pixel[1] < 0x80 <= pixel[0]) and (pixel[2] < 0x80):
354375
# reddish
355376
self.pixel(x, y, Adafruit_EPD.RED)
356377
elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):

adafruit_epd/il0373.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@
5959
_IL0373_RESOLUTION = const(0x61)
6060
_IL0373_VCM_DC_SETTING = const(0x82)
6161

62+
6263
class Adafruit_IL0373(Adafruit_EPD):
6364
"""driver class for Adafruit IL0373 ePaper display breakouts"""
65+
6466
# pylint: disable=too-many-arguments
65-
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
66-
super(Adafruit_IL0373, self).__init__(width, height, spi, cs_pin, dc_pin,
67-
sramcs_pin, rst_pin, busy_pin)
67+
def __init__(
68+
self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
69+
):
70+
super(Adafruit_IL0373, self).__init__(
71+
width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
72+
)
6873

6974
self._buffer1_size = int(width * height / 8)
7075
self._buffer2_size = int(width * height / 8)
@@ -77,10 +82,12 @@ def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, b
7782
self._buffer2 = bytearray((width * height) // 8)
7883
# since we have *two* framebuffers - one for red and one for black
7984
# we dont subclass but manage manually
80-
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
81-
buf_format=adafruit_framebuf.MHMSB)
82-
self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height,
83-
buf_format=adafruit_framebuf.MHMSB)
85+
self._framebuf1 = adafruit_framebuf.FrameBuffer(
86+
self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB
87+
)
88+
self._framebuf2 = adafruit_framebuf.FrameBuffer(
89+
self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB
90+
)
8491
self.set_black_buffer(0, True)
8592
self.set_color_buffer(1, True)
8693
# pylint: enable=too-many-arguments
@@ -105,7 +112,7 @@ def power_up(self):
105112
self.hardware_reset()
106113
self.busy_wait()
107114

108-
self.command(_IL0373_POWER_SETTING, bytearray([0x03, 0x00, 0x2b, 0x2b, 0x09]))
115+
self.command(_IL0373_POWER_SETTING, bytearray([0x03, 0x00, 0x2B, 0x2B, 0x09]))
109116
self.command(_IL0373_BOOSTER_SOFT_START, bytearray([0x17, 0x17, 0x17]))
110117
self.command(_IL0373_POWER_ON)
111118

@@ -134,7 +141,7 @@ def update(self):
134141
time.sleep(0.1)
135142
self.busy_wait()
136143
if not self._busy:
137-
time.sleep(15) # wait 15 seconds
144+
time.sleep(15) # wait 15 seconds
138145

139146
def write_ram(self, index):
140147
"""Send the one byte command for starting the RAM write process. Returns
@@ -146,7 +153,7 @@ def write_ram(self, index):
146153
return self.command(_IL0373_DTM2, end=False)
147154
raise RuntimeError("RAM index must be 0 or 1")
148155

149-
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
156+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
150157
"""Set the RAM address location, not used on this chipset but required by
151158
the superclass"""
152-
return # on this chip it does nothing
159+
return # on this chip it does nothing

adafruit_epd/il0398.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@
6060
_IL0398_GETSTATUS = const(0x71)
6161
_IL0398_VCM_DC_SETTING = const(0x82)
6262

63+
6364
class Adafruit_IL0398(Adafruit_EPD):
6465
"""driver class for Adafruit IL0373 ePaper display breakouts"""
66+
6567
# pylint: disable=too-many-arguments
66-
def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin):
67-
super(Adafruit_IL0398, self).__init__(width, height, spi, cs_pin, dc_pin,
68-
sramcs_pin, rst_pin, busy_pin)
68+
def __init__(
69+
self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
70+
):
71+
super(Adafruit_IL0398, self).__init__(
72+
width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
73+
)
6974

7075
self._buffer1_size = int(width * height / 8)
7176
self._buffer2_size = int(width * height / 8)
@@ -78,10 +83,12 @@ def __init__(self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, b
7883
self._buffer2 = bytearray((width * height) // 8)
7984
# since we have *two* framebuffers - one for red and one for black
8085
# we dont subclass but manage manually
81-
self._framebuf1 = adafruit_framebuf.FrameBuffer(self._buffer1, width, height,
82-
buf_format=adafruit_framebuf.MHMSB)
83-
self._framebuf2 = adafruit_framebuf.FrameBuffer(self._buffer2, width, height,
84-
buf_format=adafruit_framebuf.MHMSB)
86+
self._framebuf1 = adafruit_framebuf.FrameBuffer(
87+
self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB
88+
)
89+
self._framebuf2 = adafruit_framebuf.FrameBuffer(
90+
self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB
91+
)
8592
self.set_black_buffer(0, True)
8693
self.set_color_buffer(1, True)
8794
# pylint: enable=too-many-arguments
@@ -97,7 +104,7 @@ def busy_wait(self):
97104
busy pin, or pausing"""
98105
if self._busy:
99106
while not self._busy.value:
100-
#self.command(_IL0398_GETSTATUS)
107+
# self.command(_IL0398_GETSTATUS)
101108
time.sleep(0.01)
102109
else:
103110
time.sleep(0.5)
@@ -134,7 +141,7 @@ def update(self):
134141
time.sleep(0.1)
135142
self.busy_wait()
136143
if not self._busy:
137-
time.sleep(15) # wait 15 seconds
144+
time.sleep(15) # wait 15 seconds
138145

139146
def write_ram(self, index):
140147
"""Send the one byte command for starting the RAM write process. Returns
@@ -146,7 +153,7 @@ def write_ram(self, index):
146153
return self.command(_IL0398_DTM2, end=False)
147154
raise RuntimeError("RAM index must be 0 or 1")
148155

149-
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
156+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
150157
"""Set the RAM address location, not used on this chipset but required by
151158
the superclass"""
152-
return # on this chip it does nothing
159+
return # on this chip it does nothing

0 commit comments

Comments
 (0)