From c2d345dea012f2112585730e98878891b114f80b Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Tue, 19 Feb 2019 21:49:50 +0100 Subject: [PATCH] Implemented calibration --- Calendar/Epd7in5Adapter.py | 19 ++++++++++++++++++- Calendar/Epd7in5bAdapter.py | 33 ++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Calendar/Epd7in5Adapter.py b/Calendar/Epd7in5Adapter.py index aa53bfd..9a28f4e 100644 --- a/Calendar/Epd7in5Adapter.py +++ b/Calendar/Epd7in5Adapter.py @@ -1,4 +1,6 @@ from EpdAdapter import EpdAdapter, DISPLAY_REFRESH, DATA_START_TRANSMISSION_1 +from settings import display_colours +from PIL import Image, ImageDraw class Epd7in5Adapter (EpdAdapter): def __init__ (): @@ -44,4 +46,19 @@ class Epd7in5Adapter (EpdAdapter): # 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) - return buf \ No newline at end of file + return buf + + def calibrate (self): + for _ in range(2): + self.init_render() + black = Image.new('1', (self.width, self.height), 'black') + print('calibrating black...') + ImageDraw.Draw(black) + self.display_frame(self.get_frame_buffer(black)) + + white = Image.new('1', (self.width, self.height), 'white') + ImageDraw.Draw(white) + print('calibrating white...') + self.display_frame(self.get_frame_buffer(white)) + self.sleep() + print('Calibration complete') \ No newline at end of file diff --git a/Calendar/Epd7in5bAdapter.py b/Calendar/Epd7in5bAdapter.py index f2311a2..e3c1cc8 100644 --- a/Calendar/Epd7in5bAdapter.py +++ b/Calendar/Epd7in5bAdapter.py @@ -1,4 +1,6 @@ from EpdAdapter import EpdAdapter, DISPLAY_REFRESH, DATA_START_TRANSMISSION_1 +from settings import display_colours +from PIL import Image, ImageDraw class Epd7in5bAdapter (EpdAdapter): def __init__ (): @@ -36,7 +38,7 @@ class Epd7in5bAdapter (EpdAdapter): self.wait_until_idle() def get_frame_buffer (self, image): - buf = [0x00] * int(self.width * self.height / 4) + buf = [ 0x00 ] * int(self.width * self.height / 4) # Set buffer to value of Python Imaging Library image. # Image must be in mode L. image_grayscale = image.convert('L', dither=None) @@ -48,13 +50,34 @@ class Epd7in5bAdapter (EpdAdapter): pixels = image_grayscale.load() for y in range(self.height): for x in range(self.width): - # Set the bits for the column of pixels at the current position. - if pixels[x, y] < 75: #was 64 # black + # Set the bits for the column of pixels at the current + # position. + if pixels[x, y] < 75: #was 64 # black buf[int((x + y * self.width) / 4)] &= ~(0xC0 >> (x % 4 * 2)) - elif pixels[x, y] < 110: #was 192 # convert gray to red + elif pixels[x, y] < 110: #was 192 # convert gray to red buf[int((x + y * self.width) / 4)] &= ~(0xC0 >> (x % 4 * 2)) buf[int((x + y * self.width) / 4)] |= 0x40 >> (x % 4 * 2) else: # white buf[int((x + y * self.width) / 4)] |= 0xC0 >> (x % 4 * 2) return buf #due to python2 -> python3, int had to be added in 'get_frame - #_buffer \ No newline at end of file + #_buffer + + def calibrate (self): + for _ in range(2): + self.init_render() + black = Image.new('1', (self.width, self.height), 'black') + print('calibrating black...') + ImageDraw.Draw(black) + self.display_frame(self.get_frame_buffer(black)) + + red = Image.new('L', (self.width, self.height), 'red') + ImageDraw.Draw(red) + print('calibrating red...') + self.display_frame(self.get_frame_buffer(red)) + + white = Image.new('1', (self.width, self.height), 'white') + ImageDraw.Draw(white) + print('calibrating white...') + self.display_frame(self.get_frame_buffer(white)) + self.sleep() + print('Calibration complete') \ No newline at end of file