diff options
Diffstat (limited to 'sound_card_init/src/main.rs')
-rw-r--r-- | sound_card_init/src/main.rs | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/sound_card_init/src/main.rs b/sound_card_init/src/main.rs index 3f49ed97..806b7d53 100644 --- a/sound_card_init/src/main.rs +++ b/sound_card_init/src/main.rs @@ -14,9 +14,6 @@ use std::env; use std::error; use std::fmt; -use std::fs; -use std::io; -use std::path::PathBuf; use std::process; use std::string::String; @@ -24,24 +21,22 @@ use getopts::Options; use remain::sorted; use sys_util::{error, info, syslog}; -use max98390d::run_max98390d; -use utils::run_time; +use amp::AmpBuilder; +use dsm::utils::run_time; type Result<T> = std::result::Result<T, Error>; -const CONF_DIR: &str = "/etc/sound_card_init"; #[derive(Default)] struct Args { pub sound_card_id: String, + pub conf: String, } #[sorted] #[derive(Debug)] enum Error { MissingOption(String), - OpenConfigFailed(String, io::Error), ParseArgsFailed(getopts::Fail), - UnsupportedSoundCard(String), } impl error::Error for Error {} @@ -51,9 +46,7 @@ impl fmt::Display for Error { use Error::*; match self { MissingOption(option) => write!(f, "missing required option: {}", option), - OpenConfigFailed(file, e) => write!(f, "failed to open file {}: {}", file, e), ParseArgsFailed(e) => write!(f, "parse_args failed: {}", e), - UnsupportedSoundCard(name) => write!(f, "unsupported sound card: {}", name), } } } @@ -66,6 +59,12 @@ fn print_usage(opts: &Options) { fn parse_args() -> Result<Args> { let mut opts = Options::new(); opts.optopt("", "id", "sound card id", "ID"); + opts.optopt( + "", + "conf", + "the config file name. It should be $(cros_config /audio/main sound-card-init-conf)", + "CONFIG_NAME", + ); opts.optflag("h", "help", "print help menu"); let matches = opts .parse(&env::args().collect::<Vec<_>>()[1..]) @@ -87,31 +86,28 @@ fn parse_args() -> Result<Args> { e })?; - Ok(Args { sound_card_id }) -} - -fn get_config(args: &Args) -> Result<String> { - let config_path = PathBuf::from(CONF_DIR) - .join(&args.sound_card_id) - .with_extension("yaml"); + let conf = matches + .opt_str("conf") + .ok_or_else(|| Error::MissingOption("conf".to_owned())) + .map_err(|e| { + print_usage(&opts); + e + })?; - fs::read_to_string(&config_path) - .map_err(|e| Error::OpenConfigFailed(config_path.to_string_lossy().to_string(), e)) + Ok(Args { + sound_card_id, + conf, + }) } -/// Parses the CONF_DIR/<sound_card_id>.yaml and starts sound card initialization. +/// Parses the CONF_DIR/${args.conf}.yaml and starts the boot time calibration. fn sound_card_init(args: &Args) -> std::result::Result<(), Box<dyn error::Error>> { - info!("sound_card_id: {}", args.sound_card_id); - let conf = get_config(args)?; - - match args.sound_card_id.as_str() { - "sofcmlmax98390d" => { - run_max98390d(&args.sound_card_id, &conf)?; - info!("run_max98390d() finished successfully."); - Ok(()) - } - _ => Err(Error::UnsupportedSoundCard(args.sound_card_id.clone()).into()), - } + info!("sound_card_id: {}, conf:{}", args.sound_card_id, args.conf); + AmpBuilder::new(&args.sound_card_id, &args.conf) + .build()? + .boot_time_calibration()?; + + Ok(()) } fn main() { @@ -124,8 +120,9 @@ fn main() { } }; - if let Err(e) = sound_card_init(&args) { - error!("sound_card_init: {}", e); + match sound_card_init(&args) { + Ok(_) => info!("sound_card_init finished successfully."), + Err(e) => error!("sound_card_init: {}", e), } if let Err(e) = run_time::now_to_file(&args.sound_card_id) { |