Skip to content

Commit 5cabdec

Browse files
authored
Add files via upload
1 parent 9d57d91 commit 5cabdec

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-FileCopyrightText: 2023 Anne Barela for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#
5+
# Play Multiple GIF files on a PyPortal
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 time
13+
import adafruit_touchscreen
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+
display = board.DISPLAY
28+
29+
# Take over display to drive directly
30+
display.auto_refresh = False
31+
display_bus = display.bus
32+
33+
# Pyportal has a touchscreen, a touch advances to next GIF file
34+
WIDTH = board.DISPLAY.width
35+
HEIGHT = board.DISPLAY.height
36+
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
37+
board.TOUCH_YD, board.TOUCH_YU,
38+
calibration=((5200, 59000), (5800, 57000)),
39+
size=(WIDTH, HEIGHT))
40+
files = get_files("/")
41+
for i in range(len(files)):
42+
43+
odg = gifio.OnDiskGif(files[i])
44+
# Skip Feather GIFs if put on PyPortal
45+
if odg.width != WIDTH:
46+
print("File "+files[i]+" not right width, skipping\n")
47+
pass
48+
49+
start = time.monotonic()
50+
next_delay = odg.next_frame() # Load the first frame
51+
end = time.monotonic()
52+
call_delay = end - start
53+
54+
# Display GIF file frames until screen touched (for PyPortal)
55+
while True:
56+
sleeptime = max(0, next_delay - call_delay)
57+
time.sleep(sleeptime)
58+
if ts.touch_point is not None:
59+
break
60+
next_delay = odg.next_frame()
61+
display_bus.send(42, struct.pack(">hh", 0, odg.bitmap.width - 1))
62+
display_bus.send(43, struct.pack(">hh", 0, odg.bitmap.height - 1))
63+
display_bus.send(44, odg.bitmap)
64+
# End while
65+
# Clean up memory
66+
odg.deinit()
67+
odg = None
68+
gc.collect()
69+
# 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+
# gifio demo for the Adafruit PyPortal - single file
6+
#
7+
# Documentation:
8+
# https://docs.circuitpython.org/en/latest/shared-bindings/gifio/
9+
# Updated 4/5/2023
10+
#
11+
import board
12+
import gifio
13+
import displayio
14+
import time
15+
import adafruit_touchscreen
16+
import gc
17+
18+
display = board.DISPLAY
19+
splash = displayio.Group()
20+
display.root_group = splash
21+
22+
# Pyportal has a touchscreen, a touch stops the display
23+
WIDTH = board.DISPLAY.width
24+
HEIGHT = board.DISPLAY.height
25+
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
26+
board.TOUCH_YD, board.TOUCH_YU,
27+
calibration=((5200, 59000), (5800, 57000)),
28+
size=(WIDTH, HEIGHT))
29+
30+
odg = gifio.OnDiskGif('/sample.gif')
31+
32+
start = time.monotonic()
33+
next_delay = odg.next_frame() # Load the first frame
34+
end = time.monotonic()
35+
call_delay = end - start
36+
37+
# Depending on your display the next line may need Colorspace.RGB565
38+
# instead of Colorspace.RGB565_SWAPPED
39+
face = displayio.TileGrid(odg.bitmap,
40+
pixel_shader=displayio.ColorConverter
41+
(input_colorspace=displayio.Colorspace.RGB565_SWAPPED))
42+
splash.append(face)
43+
board.DISPLAY.refresh()
44+
45+
# Play the GIF file until screen is touched
46+
while True:
47+
time.sleep(max(0, next_delay - call_delay))
48+
next_delay = odg.next_frame()
49+
if ts.touch_point is not None:
50+
break
51+
# End while
52+
# Clean up memory
53+
odg.deinit()
54+
odg = None
55+
gc.collect()
Loading
Loading
Loading

0 commit comments

Comments
 (0)