File tree Expand file tree Collapse file tree
CircuitPython_gifio/Single Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 method)
6+ #
7+ # Documentation:
8+ # https://docs.circuitpython.org/en/latest/shared-bindings/gifio/
9+ # Updated 3/29/2023
10+ import board
11+ import struct
12+ import gifio
13+ import time
14+
15+ display = board .DISPLAY
16+ # Take over display to drive directly
17+ display .auto_refresh = False
18+ display_bus = display .bus
19+
20+ try :
21+ odg = gifio .OnDiskGif ('/sample.gif' )
22+ except OSError : # pylint: disable=broad-except
23+ raise Exception ("sample.gif was not found\n " )
24+ start = time .monotonic ()
25+ next_delay = odg .next_frame () # Load the first frame
26+ end = time .monotonic ()
27+ overhead = end - start
28+
29+ # Display repeatedly & directly.
30+ while True :
31+ # Sleep for the frame delay specified by the GIF,
32+ # minus the overhead measured to advance between frames.
33+ time .sleep (max (0 , next_delay - overhead ))
34+ next_delay = odg .next_frame ()
35+
36+ display_bus .send (42 , struct .pack (">hh" , 0 , odg .bitmap .width - 1 ))
37+ display_bus .send (43 , struct .pack (">hh" , 0 , odg .bitmap .height - 1 ))
38+ display_bus .send (44 , odg .bitmap )
You can’t perform that action at this time.
0 commit comments