Merge branch 'master' into master

This commit is contained in:
missionfloyd 2021-03-05 17:40:46 -07:00 committed by GitHub
commit 8a513c81ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -89,47 +89,39 @@ class EPD:
return 0 return 0
def getbuffer(self, image): def getbuffer(self, image):
# logging.debug("bufsiz = ",int(self.width/8) * self.height) img = image
buf = [0xFF] * (int(self.width/8) * self.height) imwidth, imheight = img.size
image_monocolor = image.convert('1')
imwidth, imheight = image_monocolor.size
pixels = image_monocolor.load()
# logging.debug("imwidth = %d, imheight = %d",imwidth,imheight)
if(imwidth == self.width and imheight == self.height): if(imwidth == self.width and imheight == self.height):
logging.debug("Vertical") img = img.convert('1')
for y in range(imheight):
for x in range(imwidth):
# Set the bits for the column of pixels at the current position.
if pixels[x, y] == 0:
buf[int((x + y * self.width) / 8)] &= ~(0x80 >> (x % 8))
elif(imwidth == self.height and imheight == self.width): elif(imwidth == self.height and imheight == self.width):
logging.debug("Horizontal") # image has correct dimensions, but needs to be rotated
for y in range(imheight): img = img.rotate(90, expand=True).convert('1')
for x in range(imwidth): else:
newx = y logging.warning("Wrong image dimensions: must be " + str(self.width) + "x" + str(self.height))
newy = self.height - x - 1 # return a blank buffer
if pixels[x, y] == 0: return [0x00] * (int(self.width/8) * self.height)
buf[int((newx + newy*self.width) / 8)] &= ~(0x80 >> (y % 8))
buf = bytearray(img.tobytes('raw'))
# The bytes need to be inverted, because in the PIL world 0=black and 1=white, but
# in the e-paper world 0=white and 1=black.
for i in range(len(buf)):
buf[i] ^= 0xFF
return buf return buf
def display(self, image): def display(self, image):
epdconfig.send_command(0x13) epdconfig.send_command(0x13)
for i in range(0, int(self.width * self.height / 8)): epdconfig.send_data2(image)
epdconfig.send_data(~image[i])
epdconfig.send_command(0x12) epdconfig.send_command(0x12)
epdconfig.delay_ms(100) epdconfig.delay_ms(100)
self.ReadBusy() self.ReadBusy()
def Clear(self): def Clear(self):
buf = [0x00] * (int(self.width/8) * self.height)
epdconfig.send_command(0x10) epdconfig.send_command(0x10)
for i in range(0, int(self.width * self.height / 8)): epdconfig.send_data2(buf)
epdconfig.send_data(0x00)
epdconfig.send_command(0x13) epdconfig.send_command(0x13)
for i in range(0, int(self.width * self.height / 8)): epdconfig.send_data2(buf)
epdconfig.send_data(0x00)
epdconfig.send_command(0x12) epdconfig.send_command(0x12)
epdconfig.delay_ms(100) epdconfig.delay_ms(100)
self.ReadBusy() self.ReadBusy()