Skip to content

Commit

Permalink
Set aeps and eps correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed May 7, 2024
1 parent d2772ab commit 17ea37d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
16 changes: 7 additions & 9 deletions src/bin/cir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,

/// 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<u32>,

/// 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,
}

Expand Down
8 changes: 7 additions & 1 deletion src/bin/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
43 changes: 22 additions & 21 deletions src/bin/commands/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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<Lirc> {
if input_on_cli {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 17ea37d

Please sign in to comment.