Skip to content

Commit f3e9e23

Browse files
authored
Merge pull request #40 from RetiredWizard/fruitjamaudio
Skip audio output if DAC not attached
2 parents 42bb023 + 235ed60 commit f3e9e23

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/boot_animation.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,28 @@
2020
display.auto_refresh = False
2121

2222
i2c = board.I2C()
23-
dac = adafruit_tlv320.TLV320DAC3100(i2c)
23+
# Check if DAC is connected
24+
while not i2c.try_lock():
25+
time.sleep(0.01)
26+
if 0x18 in i2c.scan():
27+
ltv320_present = True
28+
else:
29+
ltv320_present = False
30+
i2c.unlock()
2431

25-
# set sample rate & bit depth
26-
dac.configure_clocks(sample_rate=11030, bit_depth=16)
32+
if ltv320_present:
33+
dac = adafruit_tlv320.TLV320DAC3100(i2c)
2734

28-
# use headphones
29-
dac.headphone_output = True
30-
dac.headphone_volume = -15 # dB
35+
# set sample rate & bit depth
36+
dac.configure_clocks(sample_rate=11030, bit_depth=16)
3137

32-
wave_file = open("/boot_animation/ada_fruitjam_boot_jingle.wav", "rb")
33-
wave = WaveFile(wave_file)
34-
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
38+
# use headphones
39+
dac.headphone_output = True
40+
dac.headphone_volume = -15 # dB
41+
42+
wave_file = open("/boot_animation/ada_fruitjam_boot_jingle.wav", "rb")
43+
wave = WaveFile(wave_file)
44+
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
3545

3646

3747
class OvershootAnimator:
@@ -621,7 +631,8 @@ def cancel(self):
621631

622632
start_time = time.monotonic()
623633

624-
audio.play(wave)
634+
if ltv320_present:
635+
audio.play(wave)
625636

626637
while True:
627638
now = time.monotonic()
@@ -668,8 +679,9 @@ def cancel(self):
668679
if not still_going:
669680
break
670681

671-
while audio.playing:
672-
pass
682+
if ltv320_present:
683+
while audio.playing:
684+
pass
673685

674686
supervisor.set_next_code_file("code.py")
675687
supervisor.reload()

0 commit comments

Comments
 (0)