Add CircuitPython RLCD migration prototype
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
"""GIF playback helper for the custom RLCD CircuitPython driver."""
|
||||
|
||||
import gc
|
||||
import time
|
||||
|
||||
import gifio
|
||||
|
||||
|
||||
class GIFPlayer:
|
||||
def __init__(self, display):
|
||||
self.display = display
|
||||
|
||||
def play(self, filename, *, loops=1, x=40, y=0, threshold=1, clear_between_frames=False):
|
||||
"""Decode a GIF from disk and push frames to the reflective LCD.
|
||||
|
||||
CircuitPython gifio currently supports GIFs up to 320 pixels wide, so
|
||||
x defaults to 40 to center a 320-wide GIF on this 400-wide display.
|
||||
The ST7305/RLCD display is monochrome in this project, so frames are
|
||||
thresholded from palette indexes: palette index 0 is white; any index
|
||||
>= threshold is black.
|
||||
"""
|
||||
gif = gifio.OnDiskGif(filename)
|
||||
try:
|
||||
count = 0
|
||||
while loops < 0 or count < loops:
|
||||
while True:
|
||||
delay = gif.next_frame()
|
||||
if delay is None:
|
||||
break
|
||||
if clear_between_frames:
|
||||
self.display.clear(0)
|
||||
self.display.draw_bitmap_threshold(gif.bitmap, x, y, threshold=threshold)
|
||||
self.display.show()
|
||||
# gifio delay is seconds in modern CircuitPython builds. If
|
||||
# an older build plays 100x too slowly, divide by 100 here.
|
||||
time.sleep(max(0.0, delay))
|
||||
count += 1
|
||||
if loops < 0 or count < loops:
|
||||
# OnDiskGif has no reliable seek/rewind API; reopen to loop.
|
||||
gif.deinit()
|
||||
gc.collect()
|
||||
gif = gifio.OnDiskGif(filename)
|
||||
finally:
|
||||
try:
|
||||
gif.deinit()
|
||||
except AttributeError:
|
||||
pass
|
||||
gc.collect()
|
||||
Reference in New Issue
Block a user