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 ):
0 commit comments