Implemented calibration

This commit is contained in:
Maximilian Giller 2019-02-19 21:49:50 +01:00
parent 7596b7703d
commit c2d345dea0
2 changed files with 46 additions and 6 deletions

View file

@ -1,4 +1,6 @@
from EpdAdapter import EpdAdapter, DISPLAY_REFRESH, DATA_START_TRANSMISSION_1 from EpdAdapter import EpdAdapter, DISPLAY_REFRESH, DATA_START_TRANSMISSION_1
from settings import display_colours
from PIL import Image, ImageDraw
class Epd7in5Adapter (EpdAdapter): class Epd7in5Adapter (EpdAdapter):
def __init__ (): def __init__ ():
@ -44,4 +46,19 @@ class Epd7in5Adapter (EpdAdapter):
# Set the bits for the column of pixels at the current position. # Set the bits for the column of pixels at the current position.
if pixels[x, y] != 0: if pixels[x, y] != 0:
buf[int((x + y * self.width) / 8)] |= 0x80 >> (x % 8) buf[int((x + y * self.width) / 8)] |= 0x80 >> (x % 8)
return buf 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')

View file

@ -1,4 +1,6 @@
from EpdAdapter import EpdAdapter, DISPLAY_REFRESH, DATA_START_TRANSMISSION_1 from EpdAdapter import EpdAdapter, DISPLAY_REFRESH, DATA_START_TRANSMISSION_1
from settings import display_colours
from PIL import Image, ImageDraw
class Epd7in5bAdapter (EpdAdapter): class Epd7in5bAdapter (EpdAdapter):
def __init__ (): def __init__ ():
@ -36,7 +38,7 @@ class Epd7in5bAdapter (EpdAdapter):
self.wait_until_idle() self.wait_until_idle()
def get_frame_buffer (self, image): 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. # Set buffer to value of Python Imaging Library image.
# Image must be in mode L. # Image must be in mode L.
image_grayscale = image.convert('L', dither=None) image_grayscale = image.convert('L', dither=None)
@ -48,13 +50,34 @@ class Epd7in5bAdapter (EpdAdapter):
pixels = image_grayscale.load() pixels = image_grayscale.load()
for y in range(self.height): for y in range(self.height):
for x in range(self.width): for x in range(self.width):
# Set the bits for the column of pixels at the current position. # Set the bits for the column of pixels at the current
if pixels[x, y] < 75: #was 64 # black # position.
if pixels[x, y] < 75: #was 64 # black
buf[int((x + y * self.width) / 4)] &= ~(0xC0 >> (x % 4 * 2)) 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)] &= ~(0xC0 >> (x % 4 * 2))
buf[int((x + y * self.width) / 4)] |= 0x40 >> (x % 4 * 2) buf[int((x + y * self.width) / 4)] |= 0x40 >> (x % 4 * 2)
else: # white else: # white
buf[int((x + y * self.width) / 4)] |= 0xC0 >> (x % 4 * 2) 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 return buf #due to python2 -> python3, int had to be added in 'get_frame
#_buffer #_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')