Choose random image from flash

This commit is contained in:
Dejvino 2023-04-20 06:12:41 +02:00
parent a5cc0634f6
commit 47f3038174

36
test.py
View File

@ -2,8 +2,11 @@ import epaper
import microbmp import microbmp
import time import time
import random import random
import os
import gc import gc
gc.enable()
epd_resolution = [600, 448] epd_resolution = [600, 448]
epd_colormap = [ epd_colormap = [
[0x00, 0x00, 0x00], # black [0x00, 0x00, 0x00], # black
@ -15,9 +18,7 @@ epd_colormap = [
[0xff, 0x77, 0x00], # orange [0xff, 0x77, 0x00], # orange
] ]
images = ["lambo.bmp", "fallout.bmp", "nasa.bmp"] images = list(filter(lambda x : x.endswith(".bmp"), os.listdir()))
gc.enable()
def init_display(): def init_display():
#print("ePaper init ", str(time.localtime())) #print("ePaper init ", str(time.localtime()))
@ -71,24 +72,29 @@ def draw_image(filename):
#for i in range(len(colors)): #for i in range(len(colors)):
# epd.pixel(offset_x + x + i, offset_y + y, color_to_index(colors[i])) # epd.pixel(offset_x + x + i, offset_y + y, color_to_index(colors[i]))
print(str(time.localtime()), " BMP ", filename, " loading") #print(str(time.localtime()), " BMP ", filename, " loading")
time_start = time.ticks_ms()
epd.fill(epd.White) epd.fill(epd.White)
microbmp.MicroBMP(header_callback=header_callback, data_callback=pixel_callback).load(filename) microbmp.MicroBMP(header_callback=header_callback, data_callback=pixel_callback).load(filename)
print(str(time.localtime()), " BMP loaded") 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") #print(str(time.localtime()), " ePaper printed")
time_finished = time.ticks_ms()
print(" time to render: ", (time_finished - time_loaded) / 1000, " s")
# MAIN # MAIN
epd = init_display() epd = init_display()
while True: while True:
for filename in images: epd.EPD_5IN65F_Init()
epd.EPD_5IN65F_Init() filename = random.choice(images)
print("TV loading image ", filename) print("TV loading image ", filename)
draw_image(filename) draw_image(filename)
epd.Sleep() print("TV showing ", filename)
print("TV showing ", filename) epd.Sleep()
gc.collect() gc.collect()
epd.delay_ms(10000) epd.delay_ms(10000)