fix image(), working now. blinka demo improvements
This commit is contained in:
parent
30434cc6c3
commit
432dacf019
2 changed files with 28 additions and 28 deletions
|
|
@ -340,24 +340,19 @@ class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-pub
|
||||||
if imwidth != self.width or imheight != self.height:
|
if imwidth != self.width or imheight != self.height:
|
||||||
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
|
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
|
||||||
.format(self.width, self.height))
|
.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.
|
# Grab all the pixels from the image, faster than getpixel.
|
||||||
pix = image.load()
|
pix = image.load()
|
||||||
|
# clear out any display buffers
|
||||||
for y in iter(range(image.size[1])):
|
self.fill(Adafruit_EPD.WHITE)
|
||||||
for x in iter(range(image.size[0])):
|
|
||||||
if x == 0:
|
for y in range(image.size[1]):
|
||||||
x = 1
|
for x in range(image.size[0]):
|
||||||
pixel = pix[x, y]
|
pixel = pix[x, y]
|
||||||
|
if (pixel[0] >= 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
|
||||||
addr = int(((self._width - x) * self._height + y)/8)
|
# reddish
|
||||||
|
self.pixel(x, y, Adafruit_EPD.RED)
|
||||||
if pixel == (0xFF, 0, 0):
|
elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
|
||||||
addr = addr + self._buffer1_size
|
# dark
|
||||||
current = self.sram.read8(addr)
|
self.pixel(x, y, Adafruit_EPD.BLACK)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,14 @@ from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-impo
|
||||||
# create the spi device and pins we will need
|
# create the spi device and pins we will need
|
||||||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
||||||
|
|
||||||
ecs = digitalio.DigitalInOut(board.D22)
|
# create the spi device and pins we will need
|
||||||
dc = digitalio.DigitalInOut(board.D13)
|
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
||||||
srcs = digitalio.DigitalInOut(board.D6)
|
ecs = digitalio.DigitalInOut(board.D4)
|
||||||
rst = digitalio.DigitalInOut(board.D19)
|
dc = digitalio.DigitalInOut(board.D5)
|
||||||
busy = digitalio.DigitalInOut(board.D26)
|
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
|
# 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,
|
cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs,
|
||||||
rst_pin=rst, busy_pin=busy)
|
rst_pin=rst, busy_pin=busy)
|
||||||
|
|
||||||
|
display.rotation = 3
|
||||||
# Create blank image for drawing.
|
# Create blank image for drawing.
|
||||||
# Make sure to create image with mode '1' for 1-bit color.
|
# Make sure to create image with mode '1' for 1-bit color.
|
||||||
width = display.width
|
width = display.width
|
||||||
|
|
@ -50,13 +53,15 @@ display.fill(Adafruit_EPD.WHITE)
|
||||||
|
|
||||||
# Get drawing object to draw on image.
|
# Get drawing object to draw on image.
|
||||||
draw = ImageDraw.Draw(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 an outline box
|
||||||
draw.rectangle((0,0,width,height), outline=BLACK, fill=WHITE)
|
draw.rectangle((1, 1, width-2, height-2), outline=BLACK, fill=WHITE)
|
||||||
|
|
||||||
# Draw some shapes.
|
# Draw some shapes.
|
||||||
# First define some constants to allow easy resizing of shapes.
|
# First define some constants to allow easy resizing of shapes.
|
||||||
padding = 2
|
padding = 5
|
||||||
shape_width = 30
|
shape_width = 30
|
||||||
top = padding
|
top = padding
|
||||||
bottom = height-padding
|
bottom = height-padding
|
||||||
|
|
@ -78,7 +83,7 @@ draw.line((x, top, x+shape_width, bottom), fill=RED)
|
||||||
x += shape_width+padding
|
x += shape_width+padding
|
||||||
|
|
||||||
# Load default font.
|
# 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
|
# Alternatively load a TTF font. Make sure the .ttf font
|
||||||
# file is in the same directory as the python script!
|
# file is in the same directory as the python script!
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue