minor improvements

This commit is contained in:
Ace 2020-05-30 00:48:12 +02:00
parent 39e8da6388
commit 3b3c42cec7

View File

@ -4,29 +4,34 @@
Inky-Calendar epaper functions
Copyright by aceisace
"""
from importlib import import_module
from PIL import Image
class Display:
"""Display class for inkycal
Handles rendering on display"""
_allowed_models = []
def __init__(self, epaper_model, supports_colour = False):
def __init__(self, epaper_model):
"""Load the drivers for this epaper model"""
self.supports_colour = supports_colour
if 'colour' in epaper_model:
self.supports_colour = True
else:
self.supports_colour = False
try:
importer = 'from inkycal.display.drivers import {} as driver'.format(
epaper_model)
exec(importer)
driver_path = 'inkycal.display.drivers.{}'.format(epaper_model)
driver = import_module(driver_path)
self._epaper = driver.EPD()
except ModuleNotFoundError:
except ImportError:
raise Exception('This module is not supported. Check your spellings?')
except FileNotFoundError:
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
@ -47,7 +52,7 @@ class Display:
print('Initialising..', end = '')
epaper.init()
print('Updating display......', end = '')
epaper.display(epaper.getbuffer(im_black))
epaper.display(epaper.getbuffer(im_black), epaper.getbuffer(im_colour))
print('Done')
print('Sending E-Paper to deep sleep...', end = '')
@ -62,8 +67,8 @@ class Display:
epaper = self._epaper
epaper.init()
white = Image.new('1', (display_width, display_height), 'white')
black = Image.new('1', (display_width, display_height), 'black')
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:
@ -75,15 +80,16 @@ class Display:
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))
print('Cycle {0} of {1} complete'.format(_+1, cycles))
if self.supports_colour == False:
for _ in range(no_of_cycles):
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, no_of_cycles))
print('Cycle {0} of {1} complete'.format(_+1, cycles))
print('-----------Calibration complete----------')
epaper.sleep()