34
34
__version__ = "0.0.0-auto.0"
35
35
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git"
36
36
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
38
39
"""Base class for EPD displays
39
40
"""
41
+
40
42
BLACK = const (0 )
41
43
WHITE = const (1 )
42
44
INVERSE = const (2 )
43
45
RED = const (3 )
44
46
DARK = const (4 )
45
47
LIGHT = const (5 )
46
48
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
49
52
self ._width = width
50
53
self ._height = height
51
54
@@ -73,7 +76,7 @@ def __init__(self, width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy
73
76
self .spi_device = spi
74
77
while not self .spi_device .try_lock ():
75
78
time .sleep (0.01 )
76
- self .spi_device .configure (baudrate = 1000000 ) # 1 Mhz
79
+ self .spi_device .configure (baudrate = 1000000 ) # 1 Mhz
77
80
self .spi_device .unlock ()
78
81
79
82
self ._spibuf = bytearray (1 )
@@ -101,16 +104,16 @@ def display(self): # pylint: disable=too-many-branches
101
104
while not self .spi_device .try_lock ():
102
105
time .sleep (0.01 )
103
106
self .sram .cs_pin .value = False
104
- #send read command
107
+ # send read command
105
108
self ._buf [0 ] = mcp_sram .Adafruit_MCP_SRAM .SRAM_READ
106
- #send start address
109
+ # send start address
107
110
self ._buf [1 ] = 0
108
111
self ._buf [2 ] = 0
109
112
self .spi_device .write (self ._buf , end = 3 )
110
113
self .spi_device .unlock ()
111
114
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
114
117
databyte = self .write_ram (0 )
115
118
116
119
while not self .spi_device .try_lock ():
@@ -127,23 +130,23 @@ def display(self): # pylint: disable=too-many-branches
127
130
128
131
self ._cs .value = True
129
132
self .spi_device .unlock ()
130
- time .sleep (.002 )
133
+ time .sleep (0 .002 )
131
134
132
135
if self .sram :
133
136
while not self .spi_device .try_lock ():
134
137
time .sleep (0.01 )
135
138
self .sram .cs_pin .value = False
136
- #send read command
139
+ # send read command
137
140
self ._buf [0 ] = mcp_sram .Adafruit_MCP_SRAM .SRAM_READ
138
- #send start address
141
+ # send start address
139
142
self ._buf [1 ] = (self ._buffer1_size >> 8 ) & 0xFF
140
143
self ._buf [2 ] = self ._buffer1_size & 0xFF
141
144
self .spi_device .write (self ._buf , end = 3 )
142
145
self .spi_device .unlock ()
143
146
144
147
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
147
150
databyte = self .write_ram (1 )
148
151
149
152
while not self .spi_device .try_lock ():
@@ -166,7 +169,6 @@ def display(self): # pylint: disable=too-many-branches
166
169
167
170
self .update ()
168
171
169
-
170
172
def hardware_reset (self ):
171
173
"""If we have a reset pin, do a hardware reset by toggling it"""
172
174
if self ._rst :
@@ -251,15 +253,15 @@ def set_color_buffer(self, index, inverted):
251
253
def _color_dup (self , func , args , color ):
252
254
black = getattr (self ._blackframebuf , func )
253
255
red = getattr (self ._colorframebuf , func )
254
- if self ._blackframebuf is self ._colorframebuf : # monochrome
256
+ if self ._blackframebuf is self ._colorframebuf : # monochrome
255
257
black (* args , color = (color != Adafruit_EPD .WHITE ) != self ._black_inverted )
256
258
else :
257
259
black (* args , color = (color == Adafruit_EPD .BLACK ) != self ._black_inverted )
258
260
red (* args , color = (color == Adafruit_EPD .RED ) != self ._color_inverted )
259
261
260
262
def pixel (self , x , y , color ):
261
263
"""draw a single pixel in the display buffer"""
262
- self ._color_dup (' pixel' , (x , y ), color )
264
+ self ._color_dup (" pixel" , (x , y ), color )
263
265
264
266
def fill (self , color ):
265
267
"""fill the screen with the passed color"""
@@ -273,28 +275,45 @@ def fill(self, color):
273
275
self ._blackframebuf .fill (black_fill )
274
276
self ._colorframebuf .fill (red_fill )
275
277
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
277
279
"""draw a rectangle"""
278
- self ._color_dup (' rect' , (x , y , width , height ), color )
280
+ self ._color_dup (" rect" , (x , y , width , height ), color )
279
281
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
281
285
"""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 )
283
287
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
285
289
"""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 )
287
291
288
292
def text (self , string , x , y , color , * , font_name = "font5x8.bin" ):
289
293
"""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
+ )
293
302
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
+ )
298
317
299
318
@property
300
319
def width (self ):
@@ -329,17 +348,19 @@ def vline(self, x, y, height, color):
329
348
"""draw a vertical line"""
330
349
self .fill_rect (x , y , 1 , height , color )
331
350
332
-
333
351
def image (self , image ):
334
352
"""Set buffer to value of Python Imaging Library image. The image should
335
353
be in RGB mode and a size equal to the display size.
336
354
"""
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." )
339
357
imwidth , imheight = image .size
340
358
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
+ )
343
364
if self .sram :
344
365
raise RuntimeError ("PIL image is not for use with SRAM assist" )
345
366
# Grab all the pixels from the image, faster than getpixel.
@@ -350,7 +371,7 @@ def image(self, image):
350
371
for y in range (image .size [1 ]):
351
372
for x in range (image .size [0 ]):
352
373
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 ):
354
375
# reddish
355
376
self .pixel (x , y , Adafruit_EPD .RED )
356
377
elif (pixel [0 ] < 0x80 ) and (pixel [1 ] < 0x80 ) and (pixel [2 ] < 0x80 ):
0 commit comments