Consolidate repeated functions

This commit is contained in:
missionfloyd 2021-02-24 22:31:05 -07:00
commit c586f8d0f7
38 changed files with 2001 additions and 2881 deletions

View file

@ -36,33 +36,9 @@ EPD_HEIGHT = 480
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)
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)
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)
def ReadBusy(self):
logging.debug("e-Paper busy")
@ -71,7 +47,7 @@ class EPD:
logging.debug("e-Paper busy release")
def TurnOnDisplay(self):
self.send_command(0x12); #POWER ON
epdconfig.send_command(0x12); #POWER ON
epdconfig.delay_ms(100)
self.ReadBusy();
@ -79,36 +55,36 @@ class EPD:
if (epdconfig.module_init() != 0):
return -1
# EPD hardware init start
self.reset()
epdconfig.reset(200, 2, 200)
self.send_command(0x01) #POWER SETTING
self.send_data (0x07)
self.send_data (0x07) #VGH=20V,VGL=-20V
self.send_data (0x3f) #VDH=15V
self.send_data (0x3f) #VDL=-15V
epdconfig.send_command(0x01) #POWER SETTING
epdconfig.send_data (0x07)
epdconfig.send_data (0x07) #VGH=20V,VGL=-20V
epdconfig.send_data (0x3f) #VDH=15V
epdconfig.send_data (0x3f) #VDL=-15V
self.send_command(0x04) #POWER ON
epdconfig.send_command(0x04) #POWER ON
epdconfig.delay_ms(100)
self.ReadBusy() #waiting for the electronic paper IC to release the idle signal
self.send_command(0X00) #PANNEL SETTING
self.send_data(0x1F) #KW-3f KWR-2F BWROTP 0f BWOTP 1f
epdconfig.send_command(0X00) #PANNEL SETTING
epdconfig.send_data(0x1F) #KW-3f KWR-2F BWROTP 0f BWOTP 1f
self.send_command(0x61) #tres
self.send_data (0x02) #source 648
self.send_data (0x88)
self.send_data (0x01) #gate 480
self.send_data (0xE0)
epdconfig.send_command(0x61) #tres
epdconfig.send_data (0x02) #source 648
epdconfig.send_data (0x88)
epdconfig.send_data (0x01) #gate 480
epdconfig.send_data (0xE0)
self.send_command(0X15)
self.send_data(0x00)
epdconfig.send_command(0X15)
epdconfig.send_data(0x00)
self.send_command(0X50) #VCOM AND DATA INTERVAL SETTING
self.send_data(0x10)
self.send_data(0x07)
epdconfig.send_command(0X50) #VCOM AND DATA INTERVAL SETTING
epdconfig.send_data(0x10)
epdconfig.send_data(0x07)
self.send_command(0X60) #TCON SETTING
self.send_data(0x22)
epdconfig.send_command(0X60) #TCON SETTING
epdconfig.send_data(0x22)
# EPD hardware init end
return 0
@ -138,28 +114,28 @@ class EPD:
return buf
def display(self, image):
self.send_command(0x10)
epdconfig.send_command(0x10)
for i in range(0, int(self.width * self.height / 8)):
self.send_data(0x00)
self.send_command(0x13)
epdconfig.send_data(0x00)
epdconfig.send_command(0x13)
for i in range(0, int(self.width * self.height / 8)):
self.send_data(~image[i])
epdconfig.send_data(~image[i])
self.TurnOnDisplay()
def Clear(self):
self.send_command(0x10)
epdconfig.send_command(0x10)
for i in range(0, int(self.width * self.height / 8)):
self.send_data(0x00)
self.send_command(0x13)
epdconfig.send_data(0x00)
epdconfig.send_command(0x13)
for i in range(0, int(self.width * self.height / 8)):
self.send_data(0x00)
epdconfig.send_data(0x00)
self.TurnOnDisplay()
def sleep(self):
self.send_command(0x02) # POWER_OFF
epdconfig.send_command(0x02) # POWER_OFF
self.ReadBusy()
self.send_command(0x07) # DEEP_SLEEP
self.send_data(0XA5)
epdconfig.send_command(0x07) # DEEP_SLEEP
epdconfig.send_data(0XA5)
epdconfig.delay_ms(2000)
epdconfig.module_exit()