From 17ea37d5b775289acc1f7dcaa3ae7938a5f8c338 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Tue, 7 May 2024 21:24:32 +0100 Subject: [PATCH] Set aeps and eps correctly Signed-off-by: Sean Young --- src/bin/cir.rs | 16 +++++++------- src/bin/commands/config.rs | 8 ++++++- src/bin/commands/decode.rs | 43 +++++++++++++++++++------------------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/bin/cir.rs b/src/bin/cir.rs index 9d6ac24..76a6d84 100644 --- a/src/bin/cir.rs +++ b/src/bin/cir.rs @@ -101,44 +101,42 @@ struct DecodeOptions { long = "absolute-tolerance", value_parser = value_parser!(u32).range(0..100000), global = true, - default_value_t = 100, name = "AEPS", help_heading = "DECODING" )] - aeps: u32, + aeps: Option, /// Relative tolerance in % #[arg( long = "relative-tolerance", value_parser = value_parser!(u32).range(0..1000), global = true, - default_value_t = 3, name = "EPS", help_heading = "DECODING" )] - eps: u32, + eps: Option, /// Save the NFA - #[arg(long = "save-nfa", global = true, help_heading = "DECODING")] + #[arg(long = "save-nfa", global = true, help_heading = "ADVANCED")] save_nfa: bool, /// Save the DFA - #[arg(long = "save-dfa", global = true, help_heading = "DECODING")] + #[arg(long = "save-dfa", global = true, help_heading = "ADVANCED")] save_dfa: bool, } #[derive(Args)] struct BpfDecodeOptions { /// Save the LLVM IR - #[arg(long = "save-llvm-ir", help_heading = "DECODING")] + #[arg(long = "save-llvm-ir", help_heading = "ADVANCED")] save_llvm_ir: bool, /// Save the Assembly - #[arg(long = "save-asm", help_heading = "DECODING")] + #[arg(long = "save-asm", help_heading = "ADVANCED")] save_assembly: bool, /// Save the Object - #[arg(long = "save-object", help_heading = "DECODING")] + #[arg(long = "save-object", help_heading = "ADVANCED")] save_object: bool, } diff --git a/src/bin/commands/config.rs b/src/bin/commands/config.rs index ac2ffe2..35114eb 100644 --- a/src/bin/commands/config.rs +++ b/src/bin/commands/config.rs @@ -317,6 +317,8 @@ fn load_keymap( if let Some(decode) = &decode_options { options.nfa = decode.save_nfa; options.dfa = decode.save_dfa; + options.aeps = decode.aeps.unwrap_or(100); + options.eps = decode.eps.unwrap_or(3); } if let Some(decode) = &bpf_decode_options { @@ -384,7 +386,11 @@ fn load_lircd( max_gap = dev_max_gap; } - let mut options = remote.default_options(None, None, max_gap); + let mut options = remote.default_options( + decode_options.and_then(|decode| decode.aeps), + decode_options.and_then(|decode| decode.eps), + max_gap, + ); options.repeat_mask = remote.repeat_mask; diff --git a/src/bin/commands/decode.rs b/src/bin/commands/decode.rs index 0c16e10..6ac0145 100644 --- a/src/bin/commands/decode.rs +++ b/src/bin/commands/decode.rs @@ -13,8 +13,8 @@ use std::{ pub fn decode_irp(decode: &crate::Decode, irp_str: &String) { #[allow(unused_mut)] - let mut abs_tolerance = decode.options.aeps; - let rel_tolerance = decode.options.eps; + let mut abs_tolerance = decode.options.aeps.unwrap_or(100); + let rel_tolerance = decode.options.eps.unwrap_or(3); #[allow(unused_mut)] let mut max_gap = 100000; @@ -29,7 +29,7 @@ pub fn decode_irp(decode: &crate::Decode, irp_str: &String) { let input_on_cli = !decode.file.is_empty() || !decode.rawir.is_empty(); #[cfg(target_os = "linux")] - let lircdev = open_lirc(input_on_cli, decode, &mut abs_tolerance, &mut max_gap); + let lircdev = open_lirc(input_on_cli, decode, Some(&mut abs_tolerance), &mut max_gap); #[cfg(not(target_os = "linux"))] if !input_on_cli { @@ -161,7 +161,7 @@ pub fn decode_irp(decode: &crate::Decode, irp_str: &String) { fn open_lirc( input_on_cli: bool, decode: &crate::Decode, - abs_tolerance: &mut u32, + abs_tolerance: Option<&mut u32>, max_gap: &mut u32, ) -> Option { if input_on_cli { @@ -210,17 +210,19 @@ fn open_lirc( } if lircdev.can_receive_raw() { - if let Ok(resolution) = lircdev.receiver_resolution() { - if resolution > *abs_tolerance { - log::info!( - "{} resolution is {}, using absolute tolerance {} rather than {}", - lircdev, - resolution, - resolution, - abs_tolerance - ); - - *abs_tolerance = resolution; + if let Some(abs_tolerance) = abs_tolerance { + if let Ok(resolution) = lircdev.receiver_resolution() { + if resolution > *abs_tolerance { + log::info!( + "{} resolution is {}, using absolute tolerance {} rather than {}", + lircdev, + resolution, + resolution, + abs_tolerance + ); + + *abs_tolerance = resolution; + } } } @@ -249,8 +251,8 @@ fn open_lirc( pub fn decode_keymap(decode: &crate::Decode, path: &Path) { #[allow(unused_mut)] - let mut abs_tolerance = decode.options.aeps; - let rel_tolerance = decode.options.eps; + let mut abs_tolerance = decode.options.aeps.unwrap_or(100); + let rel_tolerance = decode.options.eps.unwrap_or(3); #[allow(unused_mut)] let mut max_gap = 100000; @@ -265,7 +267,7 @@ pub fn decode_keymap(decode: &crate::Decode, path: &Path) { let input_on_cli = !decode.file.is_empty() || !decode.rawir.is_empty(); #[cfg(target_os = "linux")] - let lircdev = open_lirc(input_on_cli, decode, &mut abs_tolerance, &mut max_gap); + let lircdev = open_lirc(input_on_cli, decode, Some(&mut abs_tolerance), &mut max_gap); #[cfg(not(target_os = "linux"))] if !input_on_cli { @@ -406,7 +408,7 @@ pub fn decode_lircd(decode: &crate::Decode, conf: &PathBuf) { let input_on_cli = !decode.file.is_empty() || !decode.rawir.is_empty(); #[cfg(target_os = "linux")] - let lircdev = open_lirc(input_on_cli, decode, &mut abs_tolerance, &mut max_gap); + let lircdev = open_lirc(input_on_cli, decode, abs_tolerance.as_mut(), &mut max_gap); #[cfg(not(target_os = "linux"))] if !input_on_cli { @@ -417,8 +419,7 @@ pub fn decode_lircd(decode: &crate::Decode, conf: &PathBuf) { let mut decoders = remotes .iter() .map(|remote| { - let mut options = - remote.default_options(Some(abs_tolerance), Some(rel_tolerance), max_gap); + let mut options = remote.default_options(abs_tolerance, rel_tolerance, max_gap); options.nfa = decode.options.save_nfa; options.dfa = decode.options.save_dfa;