Skip to content

Commit 83d33d6

Browse files
committed
eliminate app dictionay, use only root config file and fix tlv320 variable name
1 parent 5c59c04 commit 83d33d6

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

Fruit_Jam/Larsio_Paint_Music/sound_manager.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,8 @@ def __init__(self, audio_output="pwm", seconds_per_eighth=0.25):
6666
self.audio = audiopwmio.PWMAudioOut(board.D10)
6767
else: # i2s
6868
# optional configuration file for speaker/headphone setting
69-
# check current directory first and then root directory
7069
launcher_config = {}
71-
if pathlib.Path("launcher.conf.json").exists():
72-
with open("launcher.conf.json", "r") as f:
73-
launcher_config = json.load(f)
74-
elif pathlib.Path("/launcher.conf.json").exists():
70+
if pathlib.Path("/launcher.conf.json").exists():
7571
with open("/launcher.conf.json", "r") as f:
7672
launcher_config = json.load(f)
7773

@@ -110,23 +106,24 @@ def __init__(self, audio_output="pwm", seconds_per_eighth=0.25):
110106

111107
# Initialize TLV320
112108
self.tlv = adafruit_tlv320.TLV320DAC3100(i2c)
109+
self.tlv.reset()
113110

114111
# set sample rate & bit depth
115112
self.tlv.configure_clocks(sample_rate=11025, bit_depth=16)
116113

117-
if "sound" in launcher_config:
118-
if launcher_config["sound"] == "speaker":
114+
if "tlv320" in launcher_config:
115+
if launcher_config["tlv320"].get("output") == "speaker":
119116
# use speaker
120117
self.tlv.speaker_output = True
121-
self.tlv.speaker_volume = -60
118+
self.tlv.dac_volume = launcher_config["tlv320"].get("volume",5) # dB
122119
else:
123120
# use headphones
124121
self.tlv.headphone_output = True
125-
self.tlv.headphone_volume = -15 # dB
122+
self.tlv.dac_volume = launcher_config["tlv320"].get("volume",0) # dB
126123
else:
127124
# default to headphones
128125
self.tlv.headphone_output = True
129-
self.tlv.headphone_volume = -15 # dB
126+
self.tlv.dac_volume = 0 # dB
130127

131128
# Setup I2S audio output - important to do this AFTER configuring the DAC
132129
self.audio = audiobusio.I2SOut(

Metro/Metro_RP2350_Chips_Challenge/definitions.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
import adafruit_pathlib as pathlib
99
import adafruit_tlv320
1010

11-
# optional configuration file for speaker/headphone setting, check current and root directory
11+
# optional configuration file for speaker/headphone setting
1212
launcher_config = {}
13-
if pathlib.Path("launcher.conf.json").exists():
14-
with open("launcher.conf.json", "r") as f:
15-
launcher_config = json.load(f)
16-
elif pathlib.Path("/launcher.conf.json").exists():
13+
if pathlib.Path("/launcher.conf.json").exists():
1714
with open("/launcher.conf.json", "r") as f:
1815
launcher_config = json.load(f)
1916

@@ -25,40 +22,41 @@
2522
break
2623
time.sleep(0.01)
2724
if 0x18 in i2c.scan():
28-
ltv320_present = True
25+
tlv320_present = True
2926
else:
30-
ltv320_present = False
27+
tlv320_present = False
3128
i2c.unlock()
3229
else:
33-
ltv320_present = False
30+
tlv320_present = False
3431

35-
if ltv320_present:
32+
if tlv320_present:
3633
dac = adafruit_tlv320.TLV320DAC3100(i2c)
34+
dac.reset()
3735

3836
# set sample rate & bit depth
3937
dac.configure_clocks(sample_rate=44100, bit_depth=16)
4038

41-
if "sound" in launcher_config:
42-
if launcher_config["sound"] == "speaker":
39+
if "tlv320" in launcher_config:
40+
if launcher_config["tlv320"].get("output") == "speaker":
4341
# use speaker
4442
dac.speaker_output = True
45-
dac.speaker_volume = -40
46-
elif launcher_config["sound"] != "mute":
43+
dac.dac_volume = launcher_config["tlv320"].get("volume",5) # dB
44+
else:
4745
# use headphones
4846
dac.headphone_output = True
49-
dac.headphone_volume = -15 # dB
47+
dac.dac_volume = launcher_config["tlv320"].get("volume",0) # dB
5048
else:
5149
# default to headphones
5250
dac.headphone_output = True
53-
dac.headphone_volume = -15 # dB
51+
dac.dac_volume = 0 # dB
5452

55-
if ltv320_present:
53+
if tlv320_present:
5654
_default_play_sounds = True
5755
else:
5856
_default_play_sounds = False
5957

6058
if "sound" in launcher_config:
61-
if launcher_config["sound"] == "mute":
59+
if launcher_config["tlv320"].get("output") == "mute":
6260
_default_play_sounds = False
6361

6462
# Settings

0 commit comments

Comments
 (0)