Skip to content

Commit 432dacf

Browse files
committed
fix image(), working now. blinka demo improvements
1 parent 30434cc commit 432dacf

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

adafruit_epd/epd.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -340,24 +340,19 @@ def image(self, image):
340340
if imwidth != self.width or imheight != self.height:
341341
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
342342
.format(self.width, self.height))
343+
if self.sram:
344+
raise RuntimeError("PIL image is not for use with SRAM assist")
343345
# Grab all the pixels from the image, faster than getpixel.
344346
pix = image.load()
345-
346-
for y in iter(range(image.size[1])):
347-
for x in iter(range(image.size[0])):
348-
if x == 0:
349-
x = 1
347+
# clear out any display buffers
348+
self.fill(Adafruit_EPD.WHITE)
349+
350+
for y in range(image.size[1]):
351+
for x in range(image.size[0]):
350352
pixel = pix[x, y]
351-
352-
addr = int(((self._width - x) * self._height + y)/8)
353-
354-
if pixel == (0xFF, 0, 0):
355-
addr = addr + self._buffer1_size
356-
current = self.sram.read8(addr)
357-
358-
if pixel in ((0xFF, 0, 0), (0, 0, 0)):
359-
current = current & ~(1 << (7 - y%8))
360-
else:
361-
current = current | (1 << (7 - y%8))
362-
363-
self.sram.write8(addr, current)
353+
if (pixel[0] >= 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
354+
# reddish
355+
self.pixel(x, y, Adafruit_EPD.RED)
356+
elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
357+
# dark
358+
self.pixel(x, y, Adafruit_EPD.BLACK)

examples/epd_blinka.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
# create the spi device and pins we will need
1616
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
1717

18-
ecs = digitalio.DigitalInOut(board.D22)
19-
dc = digitalio.DigitalInOut(board.D13)
20-
srcs = digitalio.DigitalInOut(board.D6)
21-
rst = digitalio.DigitalInOut(board.D19)
22-
busy = digitalio.DigitalInOut(board.D26)
18+
# create the spi device and pins we will need
19+
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
20+
ecs = digitalio.DigitalInOut(board.D4)
21+
dc = digitalio.DigitalInOut(board.D5)
22+
srcs = None
23+
rst = digitalio.DigitalInOut(board.D6) # can be None to not use this pin
24+
busy = digitalio.DigitalInOut(board.D7) # can be None to not use this pin
25+
2326

2427

2528
# give them all to our driver
@@ -34,7 +37,7 @@
3437
cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs,
3538
rst_pin=rst, busy_pin=busy)
3639

37-
40+
display.rotation = 3
3841
# Create blank image for drawing.
3942
# Make sure to create image with mode '1' for 1-bit color.
4043
width = display.width
@@ -50,13 +53,15 @@
5053

5154
# Get drawing object to draw on image.
5255
draw = ImageDraw.Draw(image)
56+
# empty it
57+
draw.rectangle((0, 0, width, height), fill=WHITE)
5358

54-
# Draw a white filled box to clear the image.
55-
draw.rectangle((0,0,width,height), outline=BLACK, fill=WHITE)
59+
# Draw an outline box
60+
draw.rectangle((1, 1, width-2, height-2), outline=BLACK, fill=WHITE)
5661

5762
# Draw some shapes.
5863
# First define some constants to allow easy resizing of shapes.
59-
padding = 2
64+
padding = 5
6065
shape_width = 30
6166
top = padding
6267
bottom = height-padding
@@ -78,7 +83,7 @@
7883
x += shape_width+padding
7984

8085
# Load default font.
81-
font = ImageFont.load_default()
86+
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 20)
8287

8388
# Alternatively load a TTF font. Make sure the .ttf font
8489
# file is in the same directory as the python script!

0 commit comments

Comments
 (0)