diff --git a/Calendar/Epd7in5Adapter.py b/Calendar/Epd7in5Adapter.py index 2852625..5157d83 100644 --- a/Calendar/Epd7in5Adapter.py +++ b/Calendar/Epd7in5Adapter.py @@ -31,32 +31,32 @@ class Epd7in5Adapter (EpdAdapter): self.wait_until_idle() def get_frame_buffer (self, image): - buf = [0x00] * int(self.width * self.height / 8) + buf = [0x00] * int(self.height * self.width / 8) # Set buffer to value of Python Imaging Library image. # Image must be in mode 1. image_monocolor = image.convert('1') #with ot withour dithering? imwidth, imheight = image_monocolor.size - if imwidth != self.width or imheight != self.height: + if imwidth != self.height or imheight != self.width: raise ValueError('Image must be same dimensions as display \ - ({0}x{1}).' .format(self.width, self.height)) + ({0}x{1}).' .format(self.height, self.width)) pixels = image_monocolor.load() - for y in range(self.height): - for x in range(self.width): + for y in range(self.width): + for x in range(self.height): # 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) + buf[int((x + y * self.height) / 8)] |= 0x80 >> (x % 8) return buf - def calibrate (self): + def calibrate (self): for _ in range(2): self.init_render() - black = Image.new('1', (self.width, self.height), 'black') + black = Image.new('1', (self.height, self.width), 'black') print('calibrating black...') ImageDraw.Draw(black) self.display_frame(self.get_frame_buffer(black)) - white = Image.new('1', (self.width, self.height), 'white') + white = Image.new('1', (self.height, self.width), 'white') ImageDraw.Draw(white) print('calibrating white...') self.display_frame(self.get_frame_buffer(white)) diff --git a/Calendar/Epd7in5bAdapter.py b/Calendar/Epd7in5bAdapter.py index 531272d..50c3dfd 100644 --- a/Calendar/Epd7in5bAdapter.py +++ b/Calendar/Epd7in5bAdapter.py @@ -8,7 +8,7 @@ class Epd7in5bAdapter (EpdAdapter): def display_frame (self, frame_buffer): self.send_command(DATA_START_TRANSMISSION_1) - for i in range(0, int(self.width / 4 * self.height)): + for i in range(0, int(self.height / 4 * self.width)): #the above line had to be modified due to python2 -> python3 #the issue lies in division, which returns integers in python2 #but floats in python3 @@ -38,44 +38,44 @@ 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.height * self.width / 4) # Set buffer to value of Python Imaging Library image. # Image must be in mode L. image_grayscale = image.convert('L', dither=None) imwidth, imheight = image_grayscale.size - if imwidth != self.width or imheight != self.height: + if imwidth != self.height or imheight != self.width: raise ValueError('Image must be same dimensions as display \ - ({0}x{1}).' .format(self.width, self.height)) + ({0}x{1}).' .format(self.height, self.width)) pixels = image_grayscale.load() - for y in range(self.height): - for x in range(self.width): + for y in range(self.width): + for x in range(self.height): # 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)) + buf[int((x + y * self.height) / 4)] &= ~(0xC0 >> (x % 4 * 2)) 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) + buf[int((x + y * self.height) / 4)] &= ~(0xC0 >> (x % 4 * 2)) + buf[int((x + y * self.height) / 4)] |= 0x40 >> (x % 4 * 2) else: # white - buf[int((x + y * self.width) / 4)] |= 0xC0 >> (x % 4 * 2) + buf[int((x + y * self.height) / 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') + black = Image.new('1', (self.height, self.width), 'black') print('calibrating black...') ImageDraw.Draw(black) self.display_frame(self.get_frame_buffer(black)) - red = Image.new('L', (self.width, self.height), 'red') + red = Image.new('L', (self.height, self.width), 'red') ImageDraw.Draw(red) print('calibrating red...') self.display_frame(self.get_frame_buffer(red)) - white = Image.new('1', (self.width, self.height), 'white') + white = Image.new('1', (self.height, self.width), 'white') ImageDraw.Draw(white) print('calibrating white...') self.display_frame(self.get_frame_buffer(white))