mirror of
https://github.com/ivabus/speakersafetyd
synced 2024-11-10 02:15:16 +03:00
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:
parent
7e8d634f64
commit
8fb7c31f88
|
@ -6,6 +6,12 @@ t_hysteresis = 10
|
||||||
channels = 12
|
channels = 12
|
||||||
period = 4096
|
period = 4096
|
||||||
|
|
||||||
|
[Controls]
|
||||||
|
vsense = VSENSE Switch
|
||||||
|
isense = ISENSE Switch
|
||||||
|
amp_gain = Amp Gain Volume
|
||||||
|
volume = Speaker Volume
|
||||||
|
|
||||||
[Speaker/Left Woofer 1]
|
[Speaker/Left Woofer 1]
|
||||||
group = 1
|
group = 1
|
||||||
tr_coil = 28.09
|
tr_coil = 28.09
|
||||||
|
|
|
@ -6,6 +6,12 @@ t_hysteresis = 10
|
||||||
channels = 8
|
channels = 8
|
||||||
period = 4096
|
period = 4096
|
||||||
|
|
||||||
|
[Controls]
|
||||||
|
vsense = VSENSE Switch
|
||||||
|
isense = ISENSE Switch
|
||||||
|
amp_gain = Amp Gain Volume
|
||||||
|
volume = Speaker Volume
|
||||||
|
|
||||||
[Speaker/Left Woofer]
|
[Speaker/Left Woofer]
|
||||||
group = 1
|
group = 1
|
||||||
tr_coil = 32.1
|
tr_coil = 32.1
|
||||||
|
|
|
@ -85,6 +85,17 @@ pub fn parse_float(config: &Ini, section: &str, key: &str) -> f32 {
|
||||||
val
|
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
|
Wrapper around alsa::ctl::ElemValue::new(). Lets us bail on errors and
|
||||||
pass in the Bytes type for V/ISENSE
|
pass in the Bytes type for V/ISENSE
|
||||||
|
|
24
src/types.rs
24
src/types.rs
|
@ -78,9 +78,9 @@ struct Mixer {
|
||||||
|
|
||||||
impl Mixer {
|
impl Mixer {
|
||||||
// TODO: implement turning on V/ISENSE
|
// 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(
|
let mut vs = Elem::new(
|
||||||
name.to_owned() + " VSENSE Switch",
|
name.to_owned() + " " + &globals.ctl_vsense,
|
||||||
card,
|
card,
|
||||||
alsa::ctl::ElemType::Boolean,
|
alsa::ctl::ElemType::Boolean,
|
||||||
);
|
);
|
||||||
|
@ -91,7 +91,7 @@ impl Mixer {
|
||||||
assert!(vs.val.get_boolean(0).unwrap());
|
assert!(vs.val.get_boolean(0).unwrap());
|
||||||
|
|
||||||
let mut is = Elem::new(
|
let mut is = Elem::new(
|
||||||
name.to_owned() + " ISENSE Switch",
|
name.to_owned() + " " + &globals.ctl_isense,
|
||||||
card,
|
card,
|
||||||
alsa::ctl::ElemType::Boolean,
|
alsa::ctl::ElemType::Boolean,
|
||||||
);
|
);
|
||||||
|
@ -104,12 +104,12 @@ impl Mixer {
|
||||||
Mixer {
|
Mixer {
|
||||||
drv: name.to_owned(),
|
drv: name.to_owned(),
|
||||||
level: Elem::new(
|
level: Elem::new(
|
||||||
name.to_owned() + " Speaker Volume",
|
name.to_owned() + " " + &globals.ctl_volume,
|
||||||
card,
|
card,
|
||||||
alsa::ctl::ElemType::Integer,
|
alsa::ctl::ElemType::Integer,
|
||||||
),
|
),
|
||||||
amp_gain: Elem::new(
|
amp_gain: Elem::new(
|
||||||
name.to_owned() + " Amp Gain Volume",
|
name.to_owned() + " " + &globals.ctl_amp_gain,
|
||||||
card,
|
card,
|
||||||
alsa::ctl::ElemType::Integer,
|
alsa::ctl::ElemType::Integer,
|
||||||
),
|
),
|
||||||
|
@ -158,7 +158,7 @@ impl Mixer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Globals {
|
pub struct Globals {
|
||||||
pub visense_pcm: usize,
|
pub visense_pcm: usize,
|
||||||
pub channels: usize,
|
pub channels: usize,
|
||||||
|
@ -166,6 +166,10 @@ pub struct Globals {
|
||||||
pub t_ambient: f32,
|
pub t_ambient: f32,
|
||||||
pub t_safe_max: f32,
|
pub t_safe_max: f32,
|
||||||
pub t_hysteresis: f32,
|
pub t_hysteresis: f32,
|
||||||
|
pub ctl_vsense: String,
|
||||||
|
pub ctl_isense: String,
|
||||||
|
pub ctl_amp_gain: String,
|
||||||
|
pub ctl_volume: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Globals {
|
impl Globals {
|
||||||
|
@ -177,6 +181,10 @@ impl Globals {
|
||||||
t_ambient: helpers::parse_float(config, "Globals", "t_ambient"),
|
t_ambient: helpers::parse_float(config, "Globals", "t_ambient"),
|
||||||
t_safe_max: helpers::parse_float(config, "Globals", "t_safe_max"),
|
t_safe_max: helpers::parse_float(config, "Globals", "t_safe_max"),
|
||||||
t_hysteresis: helpers::parse_float(config, "Globals", "t_hysteresis"),
|
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 section = "Speaker/".to_owned() + name;
|
||||||
let mut new_speaker: Speaker = Speaker {
|
let mut new_speaker: Speaker = Speaker {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
alsa_iface: Mixer::new(&name, ctl),
|
alsa_iface: Mixer::new(&name, ctl, globals),
|
||||||
group: helpers::parse_int(config, §ion, "group"),
|
group: helpers::parse_int(config, §ion, "group"),
|
||||||
tau_coil: helpers::parse_float(config, §ion, "tau_coil"),
|
tau_coil: helpers::parse_float(config, §ion, "tau_coil"),
|
||||||
tau_magnet: helpers::parse_float(config, §ion, "tau_magnet"),
|
tau_magnet: helpers::parse_float(config, §ion, "tau_magnet"),
|
||||||
|
@ -248,7 +256,7 @@ impl Speaker {
|
||||||
vs_scale: helpers::parse_float(config, §ion, "vs_scale"),
|
vs_scale: helpers::parse_float(config, §ion, "vs_scale"),
|
||||||
is_chan: helpers::parse_int(config, §ion, "is_chan"),
|
is_chan: helpers::parse_int(config, §ion, "is_chan"),
|
||||||
vs_chan: helpers::parse_int(config, §ion, "vs_chan"),
|
vs_chan: helpers::parse_int(config, §ion, "vs_chan"),
|
||||||
g: *globals,
|
g: globals.clone(),
|
||||||
s: Default::default(),
|
s: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue