From 432dacf019f9d4d06ff2c9db1c69e60813a4092b Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 28 Sep 2019 00:12:52 -0400 Subject: [PATCH] fix image(), working now. blinka demo improvements --- adafruit_epd/epd.py | 31 +++++++++++++------------------ examples/epd_blinka.py | 25 +++++++++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/adafruit_epd/epd.py b/adafruit_epd/epd.py index 39afa09..0f96511 100644 --- a/adafruit_epd/epd.py +++ b/adafruit_epd/epd.py @@ -340,24 +340,19 @@ class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-pub 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)) + if self.sram: + raise RuntimeError("PIL image is not for use with SRAM assist") # Grab all the pixels from the image, faster than getpixel. pix = image.load() - - for y in iter(range(image.size[1])): - for x in iter(range(image.size[0])): - if x == 0: - x = 1 + # clear out any display buffers + self.fill(Adafruit_EPD.WHITE) + + for y in range(image.size[1]): + for x in range(image.size[0]): pixel = pix[x, y] - - addr = int(((self._width - x) * self._height + y)/8) - - if pixel == (0xFF, 0, 0): - addr = addr + self._buffer1_size - current = self.sram.read8(addr) - - if pixel in ((0xFF, 0, 0), (0, 0, 0)): - current = current & ~(1 << (7 - y%8)) - else: - current = current | (1 << (7 - y%8)) - - self.sram.write8(addr, current) + if (pixel[0] >= 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80): + # reddish + self.pixel(x, y, Adafruit_EPD.RED) + elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80): + # dark + self.pixel(x, y, Adafruit_EPD.BLACK) diff --git a/examples/epd_blinka.py b/examples/epd_blinka.py index a6b592c..33dc719 100644 --- a/examples/epd_blinka.py +++ b/examples/epd_blinka.py @@ -15,11 +15,14 @@ from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-impo # create the spi device and pins we will need spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) -ecs = digitalio.DigitalInOut(board.D22) -dc = digitalio.DigitalInOut(board.D13) -srcs = digitalio.DigitalInOut(board.D6) -rst = digitalio.DigitalInOut(board.D19) -busy = digitalio.DigitalInOut(board.D26) +# create the spi device and pins we will need +spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) +ecs = digitalio.DigitalInOut(board.D4) +dc = digitalio.DigitalInOut(board.D5) +srcs = None +rst = digitalio.DigitalInOut(board.D6) # can be None to not use this pin +busy = digitalio.DigitalInOut(board.D7) # can be None to not use this pin + # give them all to our driver @@ -34,7 +37,7 @@ display = Adafruit_IL0373(104, 212, spi, # 2.13" Tri-color display cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs, rst_pin=rst, busy_pin=busy) - +display.rotation = 3 # Create blank image for drawing. # Make sure to create image with mode '1' for 1-bit color. width = display.width @@ -50,13 +53,15 @@ display.fill(Adafruit_EPD.WHITE) # Get drawing object to draw on image. draw = ImageDraw.Draw(image) +# empty it +draw.rectangle((0, 0, width, height), fill=WHITE) -# Draw a white filled box to clear the image. -draw.rectangle((0,0,width,height), outline=BLACK, fill=WHITE) +# Draw an outline box +draw.rectangle((1, 1, width-2, height-2), outline=BLACK, fill=WHITE) # Draw some shapes. # First define some constants to allow easy resizing of shapes. -padding = 2 +padding = 5 shape_width = 30 top = padding bottom = height-padding @@ -78,7 +83,7 @@ draw.line((x, top, x+shape_width, bottom), fill=RED) x += shape_width+padding # Load default font. -font = ImageFont.load_default() +font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 20) # Alternatively load a TTF font. Make sure the .ttf font # file is in the same directory as the python script!