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 settings import display_colours
from PIL import Image, ImageDraw
class Epd7in5Adapter (EpdAdapter):
def __init__ ():
@ -45,3 +47,18 @@ class Epd7in5Adapter (EpdAdapter):
if pixels[x, y] != 0:
buf[int((x + y * self.width) / 8)] |= 0x80 >> (x % 8)
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 settings import display_colours
from PIL import Image, ImageDraw
class Epd7in5bAdapter (EpdAdapter):
def __init__ ():
@ -48,7 +50,8 @@ 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.
# 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
@ -58,3 +61,23 @@ class Epd7in5bAdapter (EpdAdapter):
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
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')