From 742ca8987474d7b6d0a9dae886966f7405732fdc Mon Sep 17 00:00:00 2001 From: James Carr Date: Fri, 6 Aug 2021 18:24:41 +0100 Subject: [PATCH] Update OnDiskBitmap code to take a filename string with CP7. --- CircuitPython_RGBMatrix/fruit.py | 13 +++++++++++-- CircuitPython_RGBMatrix/tiled.py | 25 +++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CircuitPython_RGBMatrix/fruit.py b/CircuitPython_RGBMatrix/fruit.py index 697f4a1be..c1293fad1 100644 --- a/CircuitPython_RGBMatrix/fruit.py +++ b/CircuitPython_RGBMatrix/fruit.py @@ -18,8 +18,17 @@ # This bitmap contains the emoji we're going to use. It is assumed # to contain 20 icons, each 20x24 pixels. This fits nicely on the 64x32 # RGB matrix display. -bitmap_file = open("emoji.bmp", 'rb') + +filename = "emoji.bmp" + +# CircuitPython 6 & 7 compatible +bitmap_file = open(filename, 'rb') bitmap = displayio.OnDiskBitmap(bitmap_file) +pixel_shader = getattr(bitmap, 'pixel_shader', displayio.ColorConverter()) + +# # CircuitPython 7+ compatible +# bitmap = displayio.OnDiskBitmap(filename) +# pixel_shader = bitmap.pixel_shader # Each wheel can be in one of three states: STOPPED, RUNNING, BRAKING = range(3) @@ -35,7 +44,7 @@ def shuffled(seq): class Wheel(displayio.TileGrid): def __init__(self): # Portions of up to 3 tiles are visible. - super().__init__(bitmap=bitmap, pixel_shader=getattr(bitmap, 'pixel_shader', displayio.ColorConverter()), + super().__init__(bitmap=bitmap, pixel_shader=pixel_shader, width=1, height=3, tile_width=20, tile_height=24) self.order = shuffled(range(20)) self.state = STOPPED diff --git a/CircuitPython_RGBMatrix/tiled.py b/CircuitPython_RGBMatrix/tiled.py index c8a725be0..36d7b9d89 100755 --- a/CircuitPython_RGBMatrix/tiled.py +++ b/CircuitPython_RGBMatrix/tiled.py @@ -40,15 +40,28 @@ rotation=0) # Load BMP image, create Group and TileGrid to hold it -BITMAP = displayio.OnDiskBitmap(open('wales.bmp', 'rb')) -GROUP = displayio.Group() -GROUP.append(displayio.TileGrid( +FILENAME = "wales.bmp" + +# CircuitPython 6 & 7 compatible +BITMAP = displayio.OnDiskBitmap(open(FILENAME, "rb")) +TILEGRID = displayio.TileGrid( BITMAP, pixel_shader=getattr(BITMAP, 'pixel_shader', displayio.ColorConverter()), - width=1, - height=1, tile_width=BITMAP.width, - tile_height=BITMAP.height)) + tile_height=BITMAP.height +) + +# # CircuitPython 7+ compatible +# BITMAP = displayio.OnDiskBitmap(FILENAME) +# TILEGRID = displayio.TileGrid( +# BITMAP, +# pixel_shader=BITMAP.pixel_shader, +# tile_width=BITMAP.width, +# tile_height=BITMAP.height +# ) + +GROUP = displayio.Group() +GROUP.append(TILEGRID) DISPLAY.show(GROUP) DISPLAY.refresh()