Skip to content

Commit 66e82e7

Browse files
authored
Merge pull request #3059 from FoamyGuy/fruitjam_startups
fruitjam startup screens
2 parents cee73a1 + 054e7c4 commit 66e82e7

File tree

12 files changed

+195
-0
lines changed

12 files changed

+195
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
import time
4+
from audiocore import WaveFile
5+
import audiobusio
6+
import board
7+
from displayio import Group, TileGrid, Bitmap, Palette
8+
import supervisor
9+
import adafruit_imageload
10+
import adafruit_tlv320
11+
from adafruit_fruitjam.peripherals import request_display_config
12+
13+
14+
# how long between animation frames
15+
ANIMATE_INTERVAL = 1 / 45
16+
17+
background_color = 0xE1F7CE
18+
19+
i2c = board.I2C()
20+
dac = adafruit_tlv320.TLV320DAC3100(i2c)
21+
dac.configure_clocks(sample_rate=44100, bit_depth=16)
22+
# for headphone jack ouput
23+
dac.headphone_output = True
24+
dac.headphone_volume = -15 # dB
25+
# for speaker JST output
26+
# dac.speaker_output = True
27+
# dac.speaker_volume = -15 # dB
28+
29+
wave_file = open("gameboy_startup/gameboy_pling.wav", "rb")
30+
wave = WaveFile(wave_file)
31+
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
32+
33+
# display setup
34+
request_display_config(320, 240)
35+
display = supervisor.runtime.display
36+
37+
# group to hold all visual elements
38+
main_group = Group()
39+
40+
# Bitmap for background color
41+
bg_bmp = Bitmap(display.width // 20, display.height // 20, 1)
42+
bg_palette = Palette(1)
43+
bg_palette[0] = background_color
44+
bg_tg = TileGrid(bg_bmp, pixel_shader=bg_palette)
45+
46+
# group to scale the background bitmap up to display size
47+
bg_group = Group(scale=20)
48+
bg_group.append(bg_tg)
49+
main_group.append(bg_group)
50+
51+
# Bitmap for logo
52+
logo, palette = adafruit_imageload.load("gameboy_startup/gameboy_logo.bmp")
53+
logo_tg = TileGrid(logo, pixel_shader=palette)
54+
main_group.append(logo_tg)
55+
56+
# place it in the center horizontally and above the top of the display
57+
logo_tg.x = display.width // 2 - logo_tg.tile_width // 2
58+
logo_tg.y = -logo_tg.tile_height
59+
60+
# y pixel location to stop logo at
61+
STOP_Y = display.height * 0.4 - logo_tg.tile_height // 2
62+
63+
64+
display.root_group = main_group
65+
time.sleep(1.5)
66+
last_animate_time = time.monotonic()
67+
played_audio = False
68+
display.auto_refresh = False
69+
while True:
70+
now = time.monotonic()
71+
72+
# if it's time to animate and the logo isn't to the
73+
# stopping position yet
74+
if last_animate_time + ANIMATE_INTERVAL <= now and logo_tg.y < STOP_Y:
75+
76+
# update the timestamp
77+
last_animate_time = now
78+
# move the logo down by a pixel
79+
logo_tg.y += 1
80+
display.refresh()
81+
82+
# if the logo has reached the stop position
83+
if logo_tg.y >= STOP_Y and not played_audio:
84+
played_audio = True
85+
# play the audio pling
86+
audio.play(wave)
87+
while audio.playing:
88+
pass
Binary file not shown.
Binary file not shown.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
import time
4+
from audiocore import WaveFile
5+
import audiobusio
6+
import board
7+
import supervisor
8+
from displayio import Group, TileGrid, OnDiskBitmap
9+
import adafruit_tlv320
10+
from adafruit_fruitjam.peripherals import request_display_config
11+
from adafruit_progressbar.horizontalprogressbar import (
12+
HorizontalFillDirection,
13+
HorizontalProgressBar,
14+
)
15+
16+
# DAC setup
17+
i2c = board.I2C()
18+
dac = adafruit_tlv320.TLV320DAC3100(i2c)
19+
dac.configure_clocks(sample_rate=44100, bit_depth=16)
20+
21+
# for headphone jack ouput
22+
dac.headphone_output = True
23+
dac.headphone_volume = -15 # dB
24+
# for speaker JST output
25+
# dac.speaker_output = True
26+
# dac.speaker_volume = -15 # dB
27+
28+
# Chime audio setup
29+
wave_file = open("mac_startup/mac_chime.wav", "rb")
30+
wave = WaveFile(wave_file)
31+
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
32+
33+
# Display setup
34+
request_display_config(640, 480)
35+
display = supervisor.runtime.display
36+
display.auto_refresh = False
37+
38+
# group to hold visual all elements
39+
main_group = Group()
40+
display.root_group = main_group
41+
display.refresh()
42+
43+
# background image
44+
bg_bmp = OnDiskBitmap("mac_startup/mac_startup_bg.bmp")
45+
bg_tg = TileGrid(bg_bmp, pixel_shader=bg_bmp.pixel_shader)
46+
main_group.append(bg_tg)
47+
48+
# Icons for bottom left
49+
icons = []
50+
for i in range(6):
51+
odb = OnDiskBitmap("mac_startup/mac_startup_icon{0}.bmp".format(i))
52+
tg = TileGrid(odb, pixel_shader=odb.pixel_shader)
53+
icons.append(
54+
{
55+
"bmp": odb,
56+
"tg": tg,
57+
}
58+
)
59+
tg.x = 10 + ((33 + 8) * i)
60+
tg.y = display.height - tg.tile_height - 10
61+
tg.hidden = True
62+
if i < 5:
63+
odb.pixel_shader.make_transparent(0)
64+
main_group.append(tg)
65+
66+
# progress bar in the welcome box
67+
progress_bar = HorizontalProgressBar(
68+
(147, 138),
69+
(346, 7),
70+
direction=HorizontalFillDirection.LEFT_TO_RIGHT,
71+
min_value=0,
72+
max_value=800,
73+
fill_color=0xC7BEFD,
74+
outline_color=0x000000,
75+
bar_color=0x3F3F3F,
76+
margin_size=0,
77+
)
78+
main_group.append(progress_bar)
79+
80+
# play the chime sound
81+
audio.play(wave)
82+
while audio.playing:
83+
pass
84+
85+
# start drawing the visual elements
86+
display.auto_refresh = True
87+
time.sleep(1)
88+
start_time = time.monotonic()
89+
90+
while True:
91+
elapsed = time.monotonic() - start_time
92+
93+
# if we haven't reached the end yet
94+
if elapsed * 100 <= 800:
95+
# update the progress bar
96+
progress_bar.value = elapsed * 100
97+
98+
else: # reached the end animation
99+
# set progress bar to max value
100+
progress_bar.value = 800
101+
102+
# loop over all icons
103+
for index, icon in enumerate(icons):
104+
# if it's time for the current icon to show, and it's still hidden
105+
if (elapsed - 1) > index and icon["tg"].hidden:
106+
# make the current icon visible
107+
icon["tg"].hidden = False
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)