mirror of
https://github.com/kxgx/2.13-Ink-screen-clock.git
synced 2026-03-15 07:03:16 +08:00
更新微雪墨水屏的所有驱动
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
# * | Function : Electronic paper driver
|
||||
# * | Info :
|
||||
# *----------------
|
||||
# * | This version: V2.0
|
||||
# * | Date : 2019-06-20
|
||||
# * | This version: V2.1
|
||||
# * | Date : 2022-08-10
|
||||
# # | Info : python demo
|
||||
# -----------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@@ -30,6 +30,7 @@
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
from distutils.command.build_scripts import build_scripts
|
||||
import logging
|
||||
from . import epdconfig
|
||||
from PIL import Image
|
||||
@@ -39,6 +40,8 @@ import RPi.GPIO as GPIO
|
||||
EPD_WIDTH = 128
|
||||
EPD_HEIGHT = 296
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class EPD:
|
||||
def __init__(self):
|
||||
self.reset_pin = epdconfig.RST_PIN
|
||||
@@ -127,13 +130,20 @@ class EPD:
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte([data])
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
# send a lot of data
|
||||
def send_data2(self, data):
|
||||
epdconfig.digital_write(self.dc_pin, 1)
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte2(data)
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
def ReadBusy(self):
|
||||
logging.debug("e-Paper busy")
|
||||
logger.debug("e-Paper busy")
|
||||
while(epdconfig.digital_read(self.busy_pin) == 0): # 0: idle, 1: busy
|
||||
self.send_command(0x71)
|
||||
epdconfig.delay_ms(10)
|
||||
logging.debug("e-Paper busy release")
|
||||
logger.debug("e-Paper busy release")
|
||||
|
||||
def TurnOnDisplay(self):
|
||||
self.send_command(0x12)
|
||||
@@ -197,37 +207,32 @@ class EPD:
|
||||
self.send_data(0x97)
|
||||
|
||||
self.send_command(0x20) # vcom
|
||||
for count in range(0, 44):
|
||||
self.send_data(self.lut_vcom1[count])
|
||||
self.send_data2(self.lut_vcom1)
|
||||
self.send_command(0x21) # ww --
|
||||
for count in range(0, 42):
|
||||
self.send_data(self.lut_ww1[count])
|
||||
self.send_data2(self.lut_ww1)
|
||||
self.send_command(0x22) # bw r
|
||||
for count in range(0, 42):
|
||||
self.send_data(self.lut_bw1[count])
|
||||
self.send_data2(self.lut_bw1)
|
||||
self.send_command(0x23) # wb w
|
||||
for count in range(0, 42):
|
||||
self.send_data(self.lut_wb1[count])
|
||||
self.send_data2(self.lut_wb1)
|
||||
self.send_command(0x24) # bb b
|
||||
for count in range(0, 42):
|
||||
self.send_data(self.lut_bb1[count])
|
||||
self.send_data2(self.lut_bb1)
|
||||
|
||||
def getbuffer(self, image):
|
||||
# logging.debug("bufsiz = ",int(self.width/8) * self.height)
|
||||
# logger.debug("bufsiz = ",int(self.width/8) * self.height)
|
||||
buf = [0xFF] * (int(self.width/8) * self.height)
|
||||
image_monocolor = image.convert('1')
|
||||
imwidth, imheight = image_monocolor.size
|
||||
pixels = image_monocolor.load()
|
||||
# logging.debug("imwidth = %d, imheight = %d",imwidth,imheight)
|
||||
# logger.debug("imwidth = %d, imheight = %d",imwidth,imheight)
|
||||
if(imwidth == self.width and imheight == self.height):
|
||||
logging.debug("Vertical")
|
||||
logger.debug("Vertical")
|
||||
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):
|
||||
logging.debug("Horizontal")
|
||||
logger.debug("Horizontal")
|
||||
for y in range(imheight):
|
||||
for x in range(imwidth):
|
||||
newx = y
|
||||
@@ -238,13 +243,11 @@ class EPD:
|
||||
|
||||
def display(self, image):
|
||||
self.send_command(0x10)
|
||||
for i in range(0, int(self.width * self.height / 8)):
|
||||
self.send_data(0x00)
|
||||
self.send_data2([0x00] * int(self.width * self.height / 8))
|
||||
epdconfig.delay_ms(10)
|
||||
|
||||
self.send_command(0x13)
|
||||
for i in range(0, int(self.width * self.height / 8)):
|
||||
self.send_data(image[i])
|
||||
self.send_data2(image)
|
||||
epdconfig.delay_ms(10)
|
||||
|
||||
self.TurnOnDisplay()
|
||||
@@ -261,28 +264,28 @@ class EPD:
|
||||
self.send_data(int(self.height / 256))
|
||||
self.send_data(self.height % 256 - 1)
|
||||
self.send_data(0x28)
|
||||
|
||||
self.send_command(0x10)
|
||||
|
||||
|
||||
buf = [0x00] * int(self.width * self.height / 8)
|
||||
for i in range(0, int(self.width * self.height / 8)):
|
||||
self.send_data(image[i])
|
||||
buf[i] = ~image[i]
|
||||
self.send_command(0x10)
|
||||
self.send_data2(image)
|
||||
epdconfig.delay_ms(10)
|
||||
|
||||
self.send_command(0x13)
|
||||
for i in range(0, int(self.width * self.height / 8)):
|
||||
self.send_data(~image[i])
|
||||
self.send_data2(buf)
|
||||
epdconfig.delay_ms(10)
|
||||
|
||||
self.TurnOnDisplay()
|
||||
|
||||
def Clear(self, color):
|
||||
def Clear(self):
|
||||
self.send_command(0x10)
|
||||
for i in range(0, int(self.width * self.height / 8)):
|
||||
self.send_data(0x00)
|
||||
self.send_data2([0x00] * int(self.width * self.height / 8))
|
||||
epdconfig.delay_ms(10)
|
||||
|
||||
self.send_command(0x13)
|
||||
for i in range(0, int(self.width * self.height / 8)):
|
||||
self.send_data(0xFF)
|
||||
self.send_data2([0xFF] * int(self.width * self.height / 8))
|
||||
epdconfig.delay_ms(10)
|
||||
|
||||
self.TurnOnDisplay()
|
||||
|
||||
Reference in New Issue
Block a user