Skip to content

Commit 9d57d91

Browse files
authored
Add files via upload
1 parent 4d8d709 commit 9d57d91

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SPDX-FileCopyrightText: 2023 Anne Barela for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#
5+
# Play Multiple GIF files on a n ESP32-S2 Feather TFT
6+
# Requires CircuitPython 8.1.0-beta.1 or later
7+
# Updated 4/4/2023
8+
import os
9+
import struct
10+
import board
11+
import gifio
12+
import digitalio
13+
import time
14+
import gc
15+
16+
# Get a dictionary of GIF filenames at the passed base directory
17+
def get_files(base):
18+
files = os.listdir(base)
19+
file_names = []
20+
for j, filetext in enumerate(files):
21+
if not filetext.startswith("."):
22+
if filetext not in ('boot_out.txt', 'System Volume Information'):
23+
if filetext.endswith(".gif"):
24+
file_names.append(filetext)
25+
return file_names
26+
27+
# Set BOOT button on ESP32-S2 Feather TFT to advance to next GIF
28+
button = digitalio.DigitalInOut(board.BUTTON)
29+
button.switch_to_input(pull=digitalio.Pull.UP)
30+
31+
display = board.DISPLAY
32+
33+
# Take over display to drive directly
34+
display.auto_refresh = False
35+
display_bus = display.bus
36+
37+
files = get_files("/")
38+
for i in range(len(files)):
39+
40+
odg = gifio.OnDiskGif(files[i])
41+
# Skip PyPortal GIFs if put on ESP32-S2 Feather TFT
42+
if odg.width != board.DISPLAY.width:
43+
print("File "+files[i]+" not right width, skipping\n")
44+
pass
45+
46+
start = time.monotonic()
47+
next_delay = odg.next_frame() # Load the first frame
48+
end = time.monotonic()
49+
call_delay = end - start
50+
51+
# Display GIF file frames until screen touched (for PyPortal)
52+
while True:
53+
sleeptime = max(0, next_delay - call_delay)
54+
time.sleep(sleeptime)
55+
# If the BOOT button is pressed, advance to next GIF file
56+
if button.value is False:
57+
print("Button Press, Advance\n")
58+
break
59+
next_delay = odg.next_frame()
60+
display_bus.send(42, struct.pack(">hh", 0, odg.bitmap.width - 1))
61+
display_bus.send(43, struct.pack(">hh", 0, odg.bitmap.height - 1))
62+
display_bus.send(44, odg.bitmap)
63+
# End while
64+
# Clean up memory
65+
odg.deinit()
66+
odg = None
67+
gc.collect()
68+
# End for
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2023 Anne Barela for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#
5+
# Play a single animated GIF file (display_bus "fast" method)
6+
#
7+
# Documentation:
8+
# https://docs.circuitpython.org/en/latest/shared-bindings/gifio/
9+
# Updated 4/5/2023
10+
import board
11+
import gifio
12+
import digitalio
13+
import displayio
14+
import time
15+
import gc
16+
17+
display = board.DISPLAY
18+
splash = displayio.Group()
19+
display.root_group = splash
20+
21+
# Set BOOT button on ESP32-S2 Feather TFT to stop GIF
22+
button = digitalio.DigitalInOut(board.BUTTON)
23+
button.switch_to_input(pull=digitalio.Pull.UP)
24+
25+
# Open GIF file sample.gif
26+
odg = gifio.OnDiskGif('/sample.gif')
27+
28+
start = time.monotonic()
29+
next_delay = odg.next_frame() # Load the first frame
30+
end = time.monotonic()
31+
overhead = end - start
32+
33+
face = displayio.TileGrid(
34+
odg.bitmap,
35+
pixel_shader=displayio.ColorConverter(
36+
input_colorspace=displayio.Colorspace.RGB565_SWAPPED
37+
),
38+
)
39+
splash.append(face)
40+
board.DISPLAY.refresh()
41+
42+
# Display repeatedly & directly.
43+
while True:
44+
# Sleep for the frame delay specified by the GIF,
45+
# minus the overhead measured to advance between frames.
46+
time.sleep(max(0, next_delay - overhead))
47+
# If the BOOT button is pressed, stop the GIF
48+
if button.value is False:
49+
print("Button Press, Stop\n")
50+
break
51+
next_delay = odg.next_frame()
52+
# End While - cleanup memory
53+
odg.deinit()
54+
odg = None
55+
gc.collect()
Loading
Loading

0 commit comments

Comments
 (0)