Consolidate repeated functions
This commit is contained in:
parent
e51fcad444
commit
c586f8d0f7
38 changed files with 2001 additions and 2881 deletions
|
|
@ -37,36 +37,10 @@ EPD_HEIGHT = 264
|
|||
|
||||
class EPD:
|
||||
def __init__(self):
|
||||
self.reset_pin = epdconfig.RST_PIN
|
||||
self.dc_pin = epdconfig.DC_PIN
|
||||
self.busy_pin = epdconfig.BUSY_PIN
|
||||
self.cs_pin = epdconfig.CS_PIN
|
||||
self.width = EPD_WIDTH
|
||||
self.height = EPD_HEIGHT
|
||||
|
||||
# Hardware reset
|
||||
def reset(self):
|
||||
epdconfig.digital_write(self.reset_pin, 1)
|
||||
epdconfig.delay_ms(200)
|
||||
epdconfig.digital_write(self.reset_pin, 0)
|
||||
epdconfig.delay_ms(2)
|
||||
epdconfig.digital_write(self.reset_pin, 1)
|
||||
epdconfig.delay_ms(200)
|
||||
|
||||
# Send Command
|
||||
def send_command(self, command):
|
||||
epdconfig.digital_write(self.dc_pin, 0)
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte([command])
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
# Send Data
|
||||
def send_data(self, data):
|
||||
epdconfig.digital_write(self.dc_pin, 1)
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte([data])
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
|
||||
# Read Busy
|
||||
def ReadBusy(self):
|
||||
logging.debug("e-Paper busy")
|
||||
|
|
@ -76,42 +50,42 @@ class EPD:
|
|||
|
||||
# Setting the display window
|
||||
def SetWindows(self, Xstart, Ystart, Xend, Yend):
|
||||
self.send_command(0x44)
|
||||
self.send_data((Xstart >> 3) & 0xff)
|
||||
self.send_data((Xend >> 3) & 0xff)
|
||||
epdconfig.send_command(0x44)
|
||||
epdconfig.send_data((Xstart >> 3) & 0xff)
|
||||
epdconfig.send_data((Xend >> 3) & 0xff)
|
||||
|
||||
self.send_command(0x45)
|
||||
self.send_data(Ystart & 0xff)
|
||||
self.send_data((Ystart >> 8) & 0xff)
|
||||
self.send_data(Yend & 0xff)
|
||||
self.send_data((Yend >> 8) & 0xff)
|
||||
epdconfig.send_command(0x45)
|
||||
epdconfig.send_data(Ystart & 0xff)
|
||||
epdconfig.send_data((Ystart >> 8) & 0xff)
|
||||
epdconfig.send_data(Yend & 0xff)
|
||||
epdconfig.send_data((Yend >> 8) & 0xff)
|
||||
|
||||
# Set Cursor
|
||||
def SetCursor(self, Xstart, Ystart):
|
||||
self.send_command(0x4E)
|
||||
self.send_data(Xstart & 0xff)
|
||||
self.send_command(0x4F)
|
||||
self.send_data(Ystart & 0xff)
|
||||
self.send_data((Ystart >> 8) & 0xff)
|
||||
epdconfig.send_command(0x4E)
|
||||
epdconfig.send_data(Xstart & 0xff)
|
||||
epdconfig.send_command(0x4F)
|
||||
epdconfig.send_data(Ystart & 0xff)
|
||||
epdconfig.send_data((Ystart >> 8) & 0xff)
|
||||
|
||||
# Initialize the e-Paper register
|
||||
def init(self):
|
||||
if (epdconfig.module_init() != 0):
|
||||
return -1
|
||||
|
||||
self.reset()
|
||||
epdconfig.reset(200, 2, 200)
|
||||
|
||||
self.ReadBusy()
|
||||
self.send_command(0x12)
|
||||
epdconfig.send_command(0x12)
|
||||
self.ReadBusy()
|
||||
|
||||
self.send_command(0x00)
|
||||
self.send_data(0x27)
|
||||
self.send_data(0x01)
|
||||
self.send_data(0x00)
|
||||
epdconfig.send_command(0x00)
|
||||
epdconfig.send_data(0x27)
|
||||
epdconfig.send_data(0x01)
|
||||
epdconfig.send_data(0x00)
|
||||
|
||||
self.send_command(0x11)
|
||||
self.send_data(0x03)
|
||||
epdconfig.send_command(0x11)
|
||||
epdconfig.send_data(0x03)
|
||||
|
||||
self.SetWindows(0, 0, self.width-1, self.height-1)
|
||||
self.SetCursor(0, 0)
|
||||
|
|
@ -146,37 +120,37 @@ class EPD:
|
|||
Width = self.width / 8
|
||||
Height = self.height
|
||||
|
||||
self.send_command(0x24)
|
||||
epdconfig.send_command(0x24)
|
||||
for i in range(0, int(Width * Height)):
|
||||
self.send_data(imageblack[i])
|
||||
epdconfig.send_data(imageblack[i])
|
||||
|
||||
self.send_command(0x26)
|
||||
epdconfig.send_command(0x26)
|
||||
for i in range(0, int(Width * Height)):
|
||||
self.send_data(~imagered[i])
|
||||
epdconfig.send_data(~imagered[i])
|
||||
|
||||
self.TurnOnDisplay()
|
||||
|
||||
# Clear the screen
|
||||
def Clear(self):
|
||||
self.send_command(0x24)
|
||||
epdconfig.send_command(0x24)
|
||||
for i in range(0, int(self.width * self.height / 8)):
|
||||
self.send_data(0xff)
|
||||
epdconfig.send_data(0xff)
|
||||
|
||||
self.send_command(0x26)
|
||||
epdconfig.send_command(0x26)
|
||||
for i in range(0, int(self.width * self.height / 8)):
|
||||
self.send_data(0x00)
|
||||
epdconfig.send_data(0x00)
|
||||
|
||||
self.TurnOnDisplay()
|
||||
|
||||
# Turn on display
|
||||
def TurnOnDisplay(self):
|
||||
self.send_command(0x20)
|
||||
epdconfig.send_command(0x20)
|
||||
self.ReadBusy()
|
||||
|
||||
# Enter sleep mode
|
||||
def sleep(self):
|
||||
self.send_command(0x10)
|
||||
self.send_data(0x01)
|
||||
epdconfig.send_command(0x10)
|
||||
epdconfig.send_data(0x01)
|
||||
|
||||
epdconfig.delay_ms(2000)
|
||||
epdconfig.module_exit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue