Make mixer element names configurable

Doesn't really matter for us since all machines we plan to use so far
have the same chip, but might matter in the future.

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2023-10-14 10:15:55 +09:00
parent 7e8d634f64
commit 8fb7c31f88
4 changed files with 39 additions and 8 deletions

View file

@ -6,6 +6,12 @@ t_hysteresis = 10
channels = 12
period = 4096
[Controls]
vsense = VSENSE Switch
isense = ISENSE Switch
amp_gain = Amp Gain Volume
volume = Speaker Volume
[Speaker/Left Woofer 1]
group = 1
tr_coil = 28.09

View file

@ -6,6 +6,12 @@ t_hysteresis = 10
channels = 8
period = 4096
[Controls]
vsense = VSENSE Switch
isense = ISENSE Switch
amp_gain = Amp Gain Volume
volume = Speaker Volume
[Speaker/Left Woofer]
group = 1
tr_coil = 32.1

View file

@ -85,6 +85,17 @@ pub fn parse_float(config: &Ini, section: &str, key: &str) -> f32 {
val
}
/**
Wrapper around configparser::ini::Ini.getfloat()
to safely unwrap the Result<Option<f64>, E> returned by
it.
*/
pub fn parse_string(config: &Ini, section: &str, key: &str) -> String {
config
.get(section, key)
.expect(&format!("{}/{}: Missing key", section, key))
}
/**
Wrapper around alsa::ctl::ElemValue::new(). Lets us bail on errors and
pass in the Bytes type for V/ISENSE

View file

@ -78,9 +78,9 @@ struct Mixer {
impl Mixer {
// TODO: implement turning on V/ISENSE
fn new(name: &str, card: &Ctl) -> Mixer {
fn new(name: &str, card: &Ctl, globals: &Globals) -> Mixer {
let mut vs = Elem::new(
name.to_owned() + " VSENSE Switch",
name.to_owned() + " " + &globals.ctl_vsense,
card,
alsa::ctl::ElemType::Boolean,
);
@ -91,7 +91,7 @@ impl Mixer {
assert!(vs.val.get_boolean(0).unwrap());
let mut is = Elem::new(
name.to_owned() + " ISENSE Switch",
name.to_owned() + " " + &globals.ctl_isense,
card,
alsa::ctl::ElemType::Boolean,
);
@ -104,12 +104,12 @@ impl Mixer {
Mixer {
drv: name.to_owned(),
level: Elem::new(
name.to_owned() + " Speaker Volume",
name.to_owned() + " " + &globals.ctl_volume,
card,
alsa::ctl::ElemType::Integer,
),
amp_gain: Elem::new(
name.to_owned() + " Amp Gain Volume",
name.to_owned() + " " + &globals.ctl_amp_gain,
card,
alsa::ctl::ElemType::Integer,
),
@ -158,7 +158,7 @@ impl Mixer {
}
}
#[derive(Copy, Clone)]
#[derive(Clone)]
pub struct Globals {
pub visense_pcm: usize,
pub channels: usize,
@ -166,6 +166,10 @@ pub struct Globals {
pub t_ambient: f32,
pub t_safe_max: f32,
pub t_hysteresis: f32,
pub ctl_vsense: String,
pub ctl_isense: String,
pub ctl_amp_gain: String,
pub ctl_volume: String,
}
impl Globals {
@ -177,6 +181,10 @@ impl Globals {
t_ambient: helpers::parse_float(config, "Globals", "t_ambient"),
t_safe_max: helpers::parse_float(config, "Globals", "t_safe_max"),
t_hysteresis: helpers::parse_float(config, "Globals", "t_hysteresis"),
ctl_vsense: helpers::parse_string(config, "Controls", "vsense"),
ctl_isense: helpers::parse_string(config, "Controls", "isense"),
ctl_amp_gain: helpers::parse_string(config, "Controls", "amp_gain"),
ctl_volume: helpers::parse_string(config, "Controls", "volume"),
}
}
}
@ -235,7 +243,7 @@ impl Speaker {
let section = "Speaker/".to_owned() + name;
let mut new_speaker: Speaker = Speaker {
name: name.to_string(),
alsa_iface: Mixer::new(&name, ctl),
alsa_iface: Mixer::new(&name, ctl, globals),
group: helpers::parse_int(config, &section, "group"),
tau_coil: helpers::parse_float(config, &section, "tau_coil"),
tau_magnet: helpers::parse_float(config, &section, "tau_magnet"),
@ -248,7 +256,7 @@ impl Speaker {
vs_scale: helpers::parse_float(config, &section, "vs_scale"),
is_chan: helpers::parse_int(config, &section, "is_chan"),
vs_chan: helpers::parse_int(config, &section, "vs_chan"),
g: *globals,
g: globals.clone(),
s: Default::default(),
};