Update OnDiskBitmap code to take a filename string with CP7.
This commit is contained in:
parent
a7e689287d
commit
195e66a2a2
1 changed files with 16 additions and 5 deletions
|
|
@ -2,24 +2,35 @@ import os
|
|||
import time
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import displayio
|
||||
|
||||
import mount_sd
|
||||
|
||||
display = board.DISPLAY
|
||||
|
||||
# The bmp files on the sd card will be shown in alphabetical order
|
||||
bmpfiles = sorted("/sd/" + filename for filename in os.listdir("/sd")
|
||||
if filename.lower().endswith("bmp"))
|
||||
bmpfiles = sorted("/sd/" + fn for fn in os.listdir("/sd") if fn.lower().endswith("bmp"))
|
||||
|
||||
while True:
|
||||
if len(bmpfiles) == 0:
|
||||
print("No BMP files found")
|
||||
break
|
||||
|
||||
for filename in bmpfiles:
|
||||
print("showing", filename)
|
||||
|
||||
# CircuitPython 6 & 7 compatible
|
||||
bitmap_file = open(filename, "rb")
|
||||
bitmap = displayio.OnDiskBitmap(bitmap_file)
|
||||
tile_grid = displayio.TileGrid(bitmap,
|
||||
pixel_shader=getattr(bitmap, 'pixel_shader', displayio.ColorConverter()))
|
||||
tile_grid = displayio.TileGrid(
|
||||
bitmap,
|
||||
pixel_shader=getattr(bitmap, 'pixel_shader', displayio.ColorConverter())
|
||||
)
|
||||
|
||||
# # CircuitPython 7+ compatible
|
||||
# bitmap = displayio.OnDiskBitmap(filename)
|
||||
# tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)
|
||||
|
||||
group = displayio.Group()
|
||||
group.append(tile_grid)
|
||||
display.show(group)
|
||||
|
|
|
|||
Loading…
Reference in a new issue