Migrate MCP and utilities to CircuitPython, including color GIF and volume fixes
This commit is contained in:
@@ -10,7 +10,7 @@ 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):
|
||||
def play(self, filename, *, loops=1, x=40, y=0, threshold=1, clear_between_frames=False, max_frames=-1):
|
||||
"""Decode a GIF from disk and push frames to the reflective LCD.
|
||||
|
||||
CircuitPython gifio currently supports GIFs up to 320 pixels wide, so
|
||||
@@ -23,14 +23,21 @@ class GIFPlayer:
|
||||
try:
|
||||
count = 0
|
||||
while loops < 0 or count < loops:
|
||||
frame_count = 0
|
||||
while True:
|
||||
if max_frames > 0 and frame_count >= max_frames:
|
||||
break
|
||||
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()
|
||||
if hasattr(self.display, "draw_bitmap_color"):
|
||||
self.display.draw_bitmap_color(gif.bitmap, gif.palette, x, y)
|
||||
else:
|
||||
self.display.draw_bitmap_threshold(gif.bitmap, x, y, threshold=threshold)
|
||||
self.display.show()
|
||||
frame_count += 1
|
||||
# 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))
|
||||
|
||||
Reference in New Issue
Block a user