69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
import epaper
|
|
import microbmp
|
|
import time
|
|
import gc
|
|
|
|
colormap = [
|
|
[0x00, 0x00, 0x00], # black
|
|
[0xff, 0xff, 0xff], # white
|
|
[0x00, 0xdd, 0x00], # green
|
|
[0x00, 0x00, 0xee], # blue
|
|
[0x00, 0xdd, 0x00], # red
|
|
[0xff, 0xdd, 0x00], # yellow
|
|
[0xff, 0x88, 0x00], # orange
|
|
]
|
|
|
|
images = ["lambo.bmp", "fallout.bmp", "nasa.bmp"]
|
|
|
|
gc.enable()
|
|
|
|
def init_display():
|
|
#print("ePaper init ", str(time.localtime()))
|
|
epd = epaper.EPD_5in65()
|
|
epd.fill(epd.White)
|
|
return epd
|
|
|
|
def draw_image(filename):
|
|
global epd
|
|
global colormap
|
|
def color_distance(c1, c2):
|
|
def dist(a, b):
|
|
return abs(a - b)
|
|
return dist(c1[0], c2[0]) + dist(c1[1], c2[1]) + dist(c1[2], c2[2])
|
|
def callback(x, y, color):
|
|
global epd
|
|
global colormap
|
|
best_index = 0
|
|
best_score = 256
|
|
for index in range(len(colormap)):
|
|
c = colormap[index]
|
|
score = color_distance(c, color)
|
|
if score < best_score:
|
|
best_score = score
|
|
best_index = index
|
|
pixel = best_index
|
|
#print("PXL ", str([color, r,g,b, pixel]))
|
|
epd.pixel(x, y, pixel)
|
|
|
|
#print("BMP ", filename, " loading ", str(time.localtime()))
|
|
epd.fill(epd.White)
|
|
microbmp.MicroBMP(data_callback=callback).load(filename)
|
|
#print("BMP loaded ", str(time.localtime()))
|
|
epd.EPD_5IN65F_Display(epd.buffer)
|
|
#print("ePaper printed ", str(time.localtime()))
|
|
|
|
|
|
# MAIN
|
|
|
|
epd = init_display()
|
|
|
|
while True:
|
|
for filename in images:
|
|
epd.EPD_5IN65F_Init()
|
|
print("TV loading image ", filename)
|
|
draw_image(filename)
|
|
epd.Sleep()
|
|
print("TV showing ", filename)
|
|
gc.collect()
|
|
epd.delay_ms(10000)
|