Skip audio output if DAC not attached

This commit is contained in:
RetiredWizard 2025-08-04 11:12:30 -04:00
parent d7302ea2a7
commit 235ed6018b

View file

@ -20,18 +20,28 @@ display = supervisor.runtime.display
display.auto_refresh = False display.auto_refresh = False
i2c = board.I2C() i2c = board.I2C()
dac = adafruit_tlv320.TLV320DAC3100(i2c) # Check if DAC is connected
while not i2c.try_lock():
time.sleep(0.01)
if 0x18 in i2c.scan():
ltv320_present = True
else:
ltv320_present = False
i2c.unlock()
# set sample rate & bit depth if ltv320_present:
dac.configure_clocks(sample_rate=11030, bit_depth=16) dac = adafruit_tlv320.TLV320DAC3100(i2c)
# use headphones # set sample rate & bit depth
dac.headphone_output = True dac.configure_clocks(sample_rate=11030, bit_depth=16)
dac.headphone_volume = -15 # dB
wave_file = open("/boot_animation/ada_fruitjam_boot_jingle.wav", "rb") # use headphones
wave = WaveFile(wave_file) dac.headphone_output = True
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN) dac.headphone_volume = -15 # dB
wave_file = open("/boot_animation/ada_fruitjam_boot_jingle.wav", "rb")
wave = WaveFile(wave_file)
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)
class OvershootAnimator: class OvershootAnimator:
@ -621,7 +631,8 @@ display.root_group = main_group
start_time = time.monotonic() start_time = time.monotonic()
audio.play(wave) if ltv320_present:
audio.play(wave)
while True: while True:
now = time.monotonic() now = time.monotonic()
@ -668,8 +679,9 @@ while True:
if not still_going: if not still_going:
break break
while audio.playing: if ltv320_present:
pass while audio.playing:
pass
supervisor.set_next_code_file("code.py") supervisor.set_next_code_file("code.py")
supervisor.reload() supervisor.reload()