Merging e-paper drivers for bw and bwr display
This commit is contained in:
parent
28c76b6d86
commit
a038818050
57
test.py
57
test.py
@ -1,6 +1,7 @@
|
|||||||
import epdif
|
import epdif
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
from settings import display_colours
|
||||||
|
|
||||||
# Display resolution
|
# Display resolution
|
||||||
EPD_WIDTH = 640
|
EPD_WIDTH = 640
|
||||||
@ -78,7 +79,6 @@ class EPD:
|
|||||||
if (epdif.epd_init() != 0):
|
if (epdif.epd_init() != 0):
|
||||||
return -1
|
return -1
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
self.send_command(POWER_SETTING)
|
self.send_command(POWER_SETTING)
|
||||||
self.send_data(0x37)
|
self.send_data(0x37)
|
||||||
self.send_data(0x00)
|
self.send_data(0x00)
|
||||||
@ -119,16 +119,36 @@ class EPD:
|
|||||||
self.digital_write(self.reset_pin, GPIO.HIGH)
|
self.digital_write(self.reset_pin, GPIO.HIGH)
|
||||||
self.delay_ms(200)
|
self.delay_ms(200)
|
||||||
|
|
||||||
|
|
||||||
def get_frame_buffer(self, image):
|
def get_frame_buffer(self, image):
|
||||||
|
if display_colours is 'bwr':
|
||||||
|
buf = [0x00] * int(self.width * self.height / 4)
|
||||||
|
image_grayscale = image.convert('L', dither=None)
|
||||||
|
imwidth, imheight = image_grayscale.size
|
||||||
|
if imwidth != self.width or imheight != self.height:
|
||||||
|
raise ValueError('Image must be same dimensions as display \
|
||||||
|
({0}x{1}).' .format(self.width, self.height))
|
||||||
|
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] == 0: # black
|
||||||
|
buf[int((x + y * self.width) / 4)] &= ~(0xC0 >> (x % 4 * 2))
|
||||||
|
elif pixels[x, y] == 76: # 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
|
||||||
|
|
||||||
|
if display_colours is 'bw':
|
||||||
buf = [0x00] * int(self.width * self.height / 8)
|
buf = [0x00] * int(self.width * self.height / 8)
|
||||||
# Set buffer to value of Python Imaging Library image.
|
image_monocolor = image.convert('1')
|
||||||
# Image must be in mode 1.
|
|
||||||
image_monocolor = image.convert('1') #with ot withour dithering?
|
|
||||||
imwidth, imheight = image_monocolor.size
|
imwidth, imheight = image_monocolor.size
|
||||||
if imwidth != self.width or imheight != self.height:
|
if imwidth != self.width or imheight != self.height:
|
||||||
raise ValueError('Image must be same dimensions as display \
|
raise ValueError('Image must be same dimensions as display \
|
||||||
({0}x{1}).' .format(self.width, self.height))
|
({0}x{1}).' .format(self.width, self.height))
|
||||||
|
|
||||||
pixels = image_monocolor.load()
|
pixels = image_monocolor.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):
|
||||||
@ -137,8 +157,33 @@ class EPD:
|
|||||||
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 display_frame(self, frame_buffer):
|
def display_frame(self, frame_buffer):
|
||||||
self.send_command(DATA_START_TRANSMISSION_1)
|
self.send_command(DATA_START_TRANSMISSION_1)
|
||||||
|
if display_colours is 'bwr':
|
||||||
|
for i in range(0, int(self.width / 4 * self.height)):
|
||||||
|
temp1 = frame_buffer[i]
|
||||||
|
j = 0
|
||||||
|
while (j < 4):
|
||||||
|
if ((temp1 & 0xC0) == 0xC0):
|
||||||
|
temp2 = 0x03
|
||||||
|
elif ((temp1 & 0xC0) == 0x00):
|
||||||
|
temp2 = 0x00
|
||||||
|
else:
|
||||||
|
temp2 = 0x04
|
||||||
|
temp2 = (temp2 << 4) & 0xFF
|
||||||
|
temp1 = (temp1 << 2) & 0xFF
|
||||||
|
j += 1
|
||||||
|
if((temp1 & 0xC0) == 0xC0):
|
||||||
|
temp2 |= 0x03
|
||||||
|
elif ((temp1 & 0xC0) == 0x00):
|
||||||
|
temp2 |= 0x00
|
||||||
|
else:
|
||||||
|
temp2 |= 0x04
|
||||||
|
temp1 = (temp1 << 2) & 0xFF
|
||||||
|
self.send_data(temp2)
|
||||||
|
j += 1
|
||||||
|
if display_colours is 'bw':
|
||||||
for i in range(0, 30720):
|
for i in range(0, 30720):
|
||||||
temp1 = frame_buffer[i]
|
temp1 = frame_buffer[i]
|
||||||
j = 0
|
j = 0
|
||||||
@ -166,5 +211,3 @@ class EPD:
|
|||||||
self.wait_until_idle()
|
self.wait_until_idle()
|
||||||
self.send_command(DEEP_SLEEP)
|
self.send_command(DEEP_SLEEP)
|
||||||
self.send_data(0xa5)
|
self.send_data(0xa5)
|
||||||
|
|
||||||
### END OF FILE ###
|
|
||||||
|
Loading…
Reference in New Issue
Block a user