minor improvements
This commit is contained in:
parent
39e8da6388
commit
3b3c42cec7
@ -4,88 +4,94 @@
|
|||||||
Inky-Calendar epaper functions
|
Inky-Calendar epaper functions
|
||||||
Copyright by aceisace
|
Copyright by aceisace
|
||||||
"""
|
"""
|
||||||
|
from importlib import import_module
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
class Display:
|
class Display:
|
||||||
"""Display class for inkycal
|
"""Display class for inkycal
|
||||||
Handles rendering on display"""
|
Handles rendering on display"""
|
||||||
|
|
||||||
_allowed_models = []
|
def __init__(self, epaper_model):
|
||||||
|
|
||||||
def __init__(self, epaper_model, supports_colour = False):
|
|
||||||
"""Load the drivers for this epaper model"""
|
"""Load the drivers for this epaper model"""
|
||||||
|
if 'colour' in epaper_model:
|
||||||
|
self.supports_colour = True
|
||||||
|
else:
|
||||||
|
self.supports_colour = False
|
||||||
|
|
||||||
self.supports_colour = supports_colour
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
importer = 'from inkycal.display.drivers import {} as driver'.format(
|
driver_path = 'inkycal.display.drivers.{}'.format(epaper_model)
|
||||||
epaper_model)
|
driver = import_module(driver_path)
|
||||||
exec(importer)
|
self._epaper = driver.EPD()
|
||||||
|
|
||||||
except ModuleNotFoundError:
|
except ImportError:
|
||||||
raise Exception('This module is not supported. Check your spellings?')
|
raise Exception('This module is not supported. Check your spellings?')
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise Exception('SPI could not be found. Please check if SPI is enabled')
|
raise Exception('SPI could not be found. Please check if SPI is enabled')
|
||||||
|
|
||||||
self._epaper = driver.EPD()
|
self._epaper.init()
|
||||||
|
self._epaper.sleep()
|
||||||
def render(self, im_black, im_colour = None):
|
|
||||||
"""Render an image on the epaper
|
|
||||||
im_colour is required for three-colour epapers"""
|
|
||||||
|
|
||||||
epaper = self._epaper
|
def render(self, im_black, im_colour = None):
|
||||||
|
"""Render an image on the epaper
|
||||||
if self.supports_colour == False:
|
im_colour is required for three-colour epapers"""
|
||||||
print('Initialising..', end = '')
|
|
||||||
epaper.init()
|
|
||||||
print('Updating display......', end = '')
|
|
||||||
epaper.display(epaper.getbuffer(im_black))
|
|
||||||
print('Done')
|
|
||||||
|
|
||||||
elif self.supports_colour == True:
|
|
||||||
if not im_colour:
|
|
||||||
raise Exception('im_colour is required for coloured epaper displays')
|
|
||||||
print('Initialising..', end = '')
|
|
||||||
epaper.init()
|
|
||||||
print('Updating display......', end = '')
|
|
||||||
epaper.display(epaper.getbuffer(im_black))
|
|
||||||
print('Done')
|
|
||||||
|
|
||||||
print('Sending E-Paper to deep sleep...', end = '')
|
epaper = self._epaper
|
||||||
epaper.sleep()
|
|
||||||
|
if self.supports_colour == False:
|
||||||
|
print('Initialising..', end = '')
|
||||||
|
epaper.init()
|
||||||
|
print('Updating display......', end = '')
|
||||||
|
epaper.display(epaper.getbuffer(im_black))
|
||||||
print('Done')
|
print('Done')
|
||||||
|
|
||||||
def calibrate(self, cycles=3):
|
elif self.supports_colour == True:
|
||||||
"""Flush display with single colour to prevent burn-ins (ghosting)
|
if not im_colour:
|
||||||
cycles -> int. How many times should each colour be flushed?
|
raise Exception('im_colour is required for coloured epaper displays')
|
||||||
recommended cycles = 3"""
|
print('Initialising..', end = '')
|
||||||
|
|
||||||
epaper = self._epaper
|
|
||||||
epaper.init()
|
epaper.init()
|
||||||
|
print('Updating display......', end = '')
|
||||||
|
epaper.display(epaper.getbuffer(im_black), epaper.getbuffer(im_colour))
|
||||||
|
print('Done')
|
||||||
|
|
||||||
white = Image.new('1', (display_width, display_height), 'white')
|
print('Sending E-Paper to deep sleep...', end = '')
|
||||||
black = Image.new('1', (display_width, display_height), 'black')
|
epaper.sleep()
|
||||||
|
print('Done')
|
||||||
|
|
||||||
print('----------Started calibration of ePaper display----------')
|
def calibrate(self, cycles=3):
|
||||||
if self.supports_colour == True:
|
"""Flush display with single colour to prevent burn-ins (ghosting)
|
||||||
for _ in range(cycles):
|
cycles -> int. How many times should each colour be flushed?
|
||||||
print('Calibrating...', end= ' ')
|
recommended cycles = 3"""
|
||||||
print('black...', end= ' ')
|
|
||||||
epaper.display(epaper.getbuffer(black), epaper.getbuffer(white))
|
|
||||||
print('colour...', end = ' ')
|
|
||||||
epaper.display(epaper.getbuffer(white), epaper.getbuffer(black))
|
|
||||||
print('white...')
|
|
||||||
epaper.display(epaper.getbuffer(white), epaper.getbuffer(white))
|
|
||||||
print('Cycle {0} of {1} complete'.format(_+1, no_of_cycles))
|
|
||||||
if self.supports_colour == False:
|
|
||||||
for _ in range(no_of_cycles):
|
|
||||||
print('Calibrating...', end= ' ')
|
|
||||||
print('black...', end = ' ')
|
|
||||||
epaper.display(epaper.getbuffer(black))
|
|
||||||
print('white...')
|
|
||||||
epaper.display(epaper.getbuffer(white)),
|
|
||||||
print('Cycle {0} of {1} complete'.format(_+1, no_of_cycles))
|
|
||||||
|
|
||||||
print('-----------Calibration complete----------')
|
epaper = self._epaper
|
||||||
epaper.sleep()
|
epaper.init()
|
||||||
|
|
||||||
|
white = Image.new('1', (epaper.width, epaper.height), 'white')
|
||||||
|
black = Image.new('1', (epaper.width, epaper.height), 'black')
|
||||||
|
|
||||||
|
print('----------Started calibration of ePaper display----------')
|
||||||
|
if self.supports_colour == True:
|
||||||
|
for _ in range(cycles):
|
||||||
|
print('Calibrating...', end= ' ')
|
||||||
|
print('black...', end= ' ')
|
||||||
|
epaper.display(epaper.getbuffer(black), epaper.getbuffer(white))
|
||||||
|
print('colour...', end = ' ')
|
||||||
|
epaper.display(epaper.getbuffer(white), epaper.getbuffer(black))
|
||||||
|
print('white...')
|
||||||
|
epaper.display(epaper.getbuffer(white), epaper.getbuffer(white))
|
||||||
|
print('Cycle {0} of {1} complete'.format(_+1, cycles))
|
||||||
|
|
||||||
|
if self.supports_colour == False:
|
||||||
|
for _ in range(cycles):
|
||||||
|
print('Calibrating...', end= ' ')
|
||||||
|
print('black...', end = ' ')
|
||||||
|
epaper.display(epaper.getbuffer(black))
|
||||||
|
print('white...')
|
||||||
|
epaper.display(epaper.getbuffer(white)),
|
||||||
|
print('Cycle {0} of {1} complete'.format(_+1, cycles))
|
||||||
|
|
||||||
|
print('-----------Calibration complete----------')
|
||||||
|
epaper.sleep()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user