Image centering with limited height caption area
This commit is contained in:
parent
9b6632370d
commit
206f00e96d
14
epaper.py
14
epaper.py
@ -86,7 +86,7 @@ class EPD_5in65(framebuf.FrameBuffer):
|
||||
|
||||
def module_exit(self):
|
||||
self.digital_write(self.reset_pin, 0)
|
||||
print("ePaper exited")
|
||||
#print("ePaper exited")
|
||||
|
||||
# Hardware reset
|
||||
def reset(self):
|
||||
@ -161,7 +161,7 @@ class EPD_5in65(framebuf.FrameBuffer):
|
||||
self.delay_ms(100);
|
||||
self.send_command(0x50);
|
||||
self.send_data(0x37);
|
||||
print("ePaper inited")
|
||||
#print("ePaper inited")
|
||||
|
||||
def EPD_5IN65F_Clear(self,color):
|
||||
|
||||
@ -181,7 +181,7 @@ class EPD_5in65(framebuf.FrameBuffer):
|
||||
self.send_command(0x02) # 0x02
|
||||
self.BusyLow()
|
||||
self.delay_ms(500)
|
||||
print("ePaper cleared")
|
||||
#print("ePaper cleared")
|
||||
|
||||
def EPD_5IN65F_Display(self,image):
|
||||
|
||||
@ -202,7 +202,7 @@ class EPD_5in65(framebuf.FrameBuffer):
|
||||
self.send_command(0x02) # 0x02
|
||||
self.BusyLow()
|
||||
self.delay_ms(200)
|
||||
print("ePaper displayed image")
|
||||
#print("ePaper displayed image")
|
||||
|
||||
def EPD_5IN65F_Display_part(self,image,xstart,ystart,image_width,image_heigh):
|
||||
|
||||
@ -213,9 +213,9 @@ class EPD_5in65(framebuf.FrameBuffer):
|
||||
self.send_data(0xC0)
|
||||
self.send_command(0x10)
|
||||
for i in range(0, self.height):
|
||||
for j in range(0, int(self.width / 2)):
|
||||
if((i<(image_heigh+ystart)) & (i>(ystart-1) ) & (j<(image_width+xstart)/2) & (j>(xstart/2 - 1))):
|
||||
self.send_data(image[(j-xstart/2) + (image_width/2*(i-ystart))])
|
||||
for j in range(0, int(self.width // 2)):
|
||||
if((i<(image_heigh+ystart)) & (i>(ystart-1) ) & (j<(image_width+xstart)//2) & (j>(xstart//2 - 1))):
|
||||
self.send_data(image[(j-xstart//2) + (image_width//2*(i-ystart))])
|
||||
else:
|
||||
self.send_data(0x11)
|
||||
|
||||
|
60
test.py
60
test.py
@ -19,6 +19,7 @@ epd_colormap = [
|
||||
]
|
||||
|
||||
images = list(filter(lambda x : x.endswith(".bmp"), os.listdir()))
|
||||
max_free_height = 200
|
||||
|
||||
def init_display():
|
||||
#print("ePaper init ", str(time.localtime()))
|
||||
@ -29,17 +30,30 @@ def init_display():
|
||||
def draw_image(filename):
|
||||
global epd
|
||||
global epd_colormap
|
||||
global free_x, free_y, free_width, free_height
|
||||
offset_x = 0
|
||||
offset_y = 0
|
||||
free_x = 0
|
||||
free_y = 0
|
||||
free_width = 0
|
||||
free_height = 0
|
||||
color_map = {}
|
||||
def header_callback(header):
|
||||
#print("header callback: ", str(header))
|
||||
global epd_resolution
|
||||
global offset_x, offset_y
|
||||
global free_x, free_y, free_width, free_height
|
||||
global max_free_height
|
||||
w = header[0]
|
||||
h = header[1]
|
||||
offset_x = (epd_resolution[0] - w)//2
|
||||
offset_y = (epd_resolution[1] - h)//2
|
||||
rest_x = (epd_resolution[0] - w)
|
||||
rest_y = (epd_resolution[1] - h)
|
||||
free_x = 0
|
||||
free_y = max(h, epd_resolution[1] - max_free_height)
|
||||
free_width = epd_resolution[0]
|
||||
free_height = min(rest_y, max_free_height)
|
||||
offset_x = rest_x//2
|
||||
offset_y = max(0, rest_y - max_free_height)//2
|
||||
def pixel_callback(x, y, color):
|
||||
global epd
|
||||
global epd_colormap
|
||||
@ -79,11 +93,32 @@ def draw_image(filename):
|
||||
time_loaded = time.ticks_ms()
|
||||
print(" time to load: ", (time_loaded - time_start) / 1000, " s")
|
||||
#print(str(time.localtime()), " BMP loaded")
|
||||
epd.EPD_5IN65F_Display(epd.buffer)
|
||||
#epd.EPD_5IN65F_Display(epd.buffer)
|
||||
#print(str(time.localtime()), " ePaper printed")
|
||||
time_finished = time.ticks_ms()
|
||||
print(" time to render: ", (time_finished - time_loaded) / 1000, " s")
|
||||
return [free_x, free_y, free_width, free_height]
|
||||
|
||||
def draw_pattern():
|
||||
global epd
|
||||
global epd_resolution
|
||||
free_x = 0
|
||||
free_y = 400
|
||||
free_width = epd_resolution[0]
|
||||
free_height = epd_resolution[1] - free_y
|
||||
epd.fill_rect(0, 0, epd_resolution[0], free_y, random.randrange(2,7))
|
||||
return [free_x, free_y, free_width, free_height]
|
||||
|
||||
def print_text(text, region):
|
||||
global epd
|
||||
epd.text(text, region[0]+5, region[1]+5, epd.Black)
|
||||
|
||||
def draw_extra(region):
|
||||
fnt = 8
|
||||
if region[2] < fnt or region[3] < fnt:
|
||||
print("Not enough space for extra: ", str(region))
|
||||
return
|
||||
#epd.rect(region[0], region[1], region[2], region[3], epd.Black)
|
||||
#region[0] += random.randrange(50)
|
||||
print_text("Lorem ipsum: " + str(random.randrange(1000, 999999)), region)
|
||||
|
||||
# MAIN
|
||||
|
||||
@ -91,10 +126,19 @@ epd = init_display()
|
||||
|
||||
while True:
|
||||
epd.EPD_5IN65F_Init()
|
||||
epd.fill(epd.White)
|
||||
filename = random.choice(images)
|
||||
print("TV loading image ", filename)
|
||||
draw_image(filename)
|
||||
print("TV drawing image ", filename)
|
||||
free_space = draw_image(filename)
|
||||
#free_space = draw_pattern()
|
||||
draw_extra(free_space)
|
||||
time_render_start = time.ticks_ms()
|
||||
epd.EPD_5IN65F_Display(epd.buffer)
|
||||
time_render_stop = time.ticks_ms()
|
||||
print(" time to render: ", (time_render_stop - time_render_start) / 1000, " s")
|
||||
print("TV showing ", filename)
|
||||
epd.Sleep()
|
||||
|
||||
print("")
|
||||
gc.collect()
|
||||
epd.delay_ms(10000)
|
||||
epd.delay_ms(60000 * 1)
|
||||
|
Loading…
Reference in New Issue
Block a user