From 7dc04ccb1dad7cc9e893e2d648761821e8da840d Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Thu, 12 Oct 2023 16:51:00 +0900 Subject: [PATCH] helpers: Add lock_el helper Signed-off-by: Hector Martin --- src/helpers.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/helpers.rs b/src/helpers.rs index d139701..c260298 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -150,6 +150,24 @@ pub fn write_ev(card: &alsa::ctl::Ctl, ev: &alsa::ctl::ElemValue, name: &str) { }; } +/** + Wrapper for alsa::ctl::Ctl::elem_read(). +*/ +pub fn lock_el(card: &alsa::ctl::Ctl, el: &alsa::ctl::ElemId, name: &str) { + let _val = match card.elem_lock(el) { + // alsa:Result<()> + Ok(val) => val, + Err(e) => { + println!( + "Could not lock elem {}. alsa-lib error: {:?}", + name, e + ); + fail(); + std::process::exit(1); + } + }; +} + pub fn int_to_db(card: &alsa::ctl::Ctl, id: &alsa::ctl::ElemId, val: i32) -> MilliBel { let db = match card.convert_to_db(id, val.into()) { Ok(inner) => inner,