Merge pull request #40 from RetiredWizard/fruitjamaudio

Skip audio output if DAC not attached
This commit is contained in:
foamyguy 2025-08-04 10:37:44 -05:00 committed by GitHub
commit f3e9e23c47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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,7 +679,8 @@ while True:
if not still_going: if not still_going:
break break
while audio.playing: if ltv320_present:
while audio.playing:
pass pass
supervisor.set_next_code_file("code.py") supervisor.set_next_code_file("code.py")