diff options
Diffstat (limited to 'sound_card_init/amp/src/lib.rs')
-rw-r--r-- | sound_card_init/amp/src/lib.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/sound_card_init/amp/src/lib.rs b/sound_card_init/amp/src/lib.rs index 7486ff0a..7114233d 100644 --- a/sound_card_init/amp/src/lib.rs +++ b/sound_card_init/amp/src/lib.rs @@ -7,6 +7,7 @@ mod max98373d; mod max98390d; +use std::path::PathBuf; use dsm::Error; @@ -19,19 +20,32 @@ const CONF_DIR: &str = "/etc/sound_card_init"; /// It creates `Amp` object based on the sound card name. pub struct AmpBuilder<'a> { sound_card_id: &'a str, + config_path: PathBuf, } impl<'a> AmpBuilder<'a> { /// Creates an `AmpBuilder`. - pub fn new(sound_card_id: &'a str) -> Self { - AmpBuilder { sound_card_id } + /// # Arguments + /// + /// * `card_name` - card name. + /// * `conf_file` - config file name. + pub fn new(sound_card_id: &'a str, conf_file: &'a str) -> Self { + let config_path = PathBuf::from(CONF_DIR).join(conf_file); + AmpBuilder { + sound_card_id, + config_path, + } } /// Creates an `Amp` based on the sound card name. pub fn build(&self) -> Result<Box<dyn Amp>> { match self.sound_card_id { - "sofcmlmax98390d" => Ok(Box::new(Max98390::new(self.sound_card_id)?) as Box<dyn Amp>), - "sofrt5682" => Ok(Box::new(Max98373::new(self.sound_card_id)?) as Box<dyn Amp>), + "sofcmlmax98390d" => { + Ok(Box::new(Max98390::new(self.sound_card_id, &self.config_path)?) as Box<dyn Amp>) + } + "sofrt5682" => { + Ok(Box::new(Max98373::new(self.sound_card_id, &self.config_path)?) as Box<dyn Amp>) + } _ => Err(Error::UnsupportedSoundCard(self.sound_card_id.to_owned())), } } |