DM: adding blinka support

This commit is contained in:
dean 2018-08-21 17:12:23 -04:00
parent c2a05b64ab
commit 02e70fa8bf
2 changed files with 108 additions and 0 deletions

View file

@ -166,6 +166,37 @@ class Adafruit_IL0373(Adafruit_EPD):
self.update()
def image(self, image):
"""Set buffer to value of Python Imaging Library image. The image should
be in RGB mode and a size equal to the display size.
"""
if image.mode != 'RGB':
raise ValueError('Image must be in mode RGB.')
imwidth, imheight = image.size
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))
# Grab all the pixels from the image, faster than getpixel.
pix = image.load()
for y in xrange(image.size[1]):
for x in xrange(image.size[0]):
if x == 0:
x = 1
p = pix[x, y]
addr = int(((self.width - x) * self.height + y)/8)
if color == Adafruit_EPD.RED:
addr = addr + self.bw_bufsize
current = self.sram.read8(addr)
if p 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)
def draw_pixel(self, x, y, color):
"""draw a single pixel in the display buffer"""
if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height):

77
examples/epd_blinka.py Normal file
View file

@ -0,0 +1,77 @@
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import digitalio
import busio
import board
from adafruit_epd.epd import Adafruit_EPD
from adafruit_epd.il0373 import Adafruit_IL0373
# 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.D8)
rst = digitalio.DigitalInOut(board.D19)
busy = digitalio.DigitalInOut(board.D26)
# give them all to our driver
display = Adafruit_IL0373(152, 152, rst, dc, busy, srcs, ecs, spi)
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('RGB', (width, height))
WHITE = (0xFF, 0xFF, 0xFF)
RED = (0xFF, 0x00, 0x00)
BLACK = (0x00, 0x00, 0x00)
GRAY = (0x7F, 0x7F, 0x7F)
# clear the buffer
display.clear_buffer()
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Draw a white filled box to clear the image.
draw.rectangle((0,0,width,height), outline=BLACK, fill=WHITE)
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = 2
shape_width = 30
top = padding
bottom = height-padding
# Move left to right keeping track of the current x position for drawing shapes.
x = padding
# Draw an ellipse.
draw.ellipse((x, top , x+shape_width, bottom), outline=RED, fill=GRAY)
x += shape_width+padding
# Draw a rectangle.
draw.rectangle((x, top, x+shape_width, bottom), outline=RED, fill=BLACK)
x += shape_width+padding
# Draw a triangle.
draw.polygon([(x, bottom), (x+shape_width/2, top), (x+shape_width, bottom)], outline=BLACK, fill=RED)
x += shape_width+padding
# Draw an X.
draw.line((x, bottom, x+shape_width, top), fill=RED)
draw.line((x, top, x+shape_width, bottom), fill=RED)
x += shape_width+padding
# Load default font.
font = ImageFont.load_default()
# Alternatively load a TTF font. Make sure the .ttf font file is in the same directory as the python script!
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
#font = ImageFont.truetype('Minecraftia.ttf', 8)
# Write two lines of text.
draw.text((x, top), 'Hello', font=font, fill=RED)
draw.text((x, top+20), 'World!', font=font, fill=RED)
# Display image.
display.image(image)
display.display()