Skip to content

Commit

Permalink
Fix remaining lircd nfa decoding issues
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed Mar 25, 2024
1 parent 1387b5a commit d0469bd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
4 changes: 3 additions & 1 deletion irp/src/build_nfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,9 @@ impl<'a> Builder<'a> {
self.add_entry_action(Action::Set {
var: var.to_owned(),
expr: self.const_folding(expr),
})
});

self.set(var, !0);
}
_ => return Err(format!("expression {expr} not supported")),
}
Expand Down
51 changes: 33 additions & 18 deletions src/lircd_conf/irp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ enum Stream {

impl<'a> Builder<'a> {
fn new(remote: &'a Remote, encoding: bool) -> Self {
let min_repeat = if encoding {
remote.min_repeat
} else {
remote.min_code_repeat
};
let min_repeat = if encoding { remote.min_repeat } else { 0 };

Builder {
remote,
Expand Down Expand Up @@ -212,10 +208,14 @@ impl<'a> Builder<'a> {
}
} else {
self.irp.pop();
if self.min_repeat > 0 {
write!(&mut self.irp, "){}+", self.min_repeat + 1).unwrap();
if self.encoding {
if self.min_repeat > 0 {
write!(&mut self.irp, "){}+", self.min_repeat + 1).unwrap();
} else {
self.irp.push_str(")+");
}
} else {
self.irp.push_str(")+");
self.irp.push_str(")*");
}
}

Expand Down Expand Up @@ -246,7 +246,16 @@ impl<'a> Builder<'a> {
self.irp.push('}');
}

write!(&mut self.irp, " [CODE:0..{}", gen_mask(self.remote.bits)).unwrap();
write!(
&mut self.irp,
" [CODE:0..{}",
if self.remote.bits == 0 {
1
} else {
gen_mask(self.remote.bits)
}
)
.unwrap();

if self.remote.toggle_bit_mask.count_ones() == 1 {
self.irp.push_str(",T@:0..1=0");
Expand Down Expand Up @@ -330,12 +339,18 @@ impl<'a> Builder<'a> {
"CODE".into()
};

self.add_bit_stream(
Stream::Expression(code),
self.remote.bits,
toggle_bit_mask >> self.remote.post_data_bits,
self.remote.rc6_mask >> self.remote.post_data_bits,
);
if self.remote.bits == 0 {
if !self.encoding {
self.irp.push_str("CODE=0,");
}
} else {
self.add_bit_stream(
Stream::Expression(code),
self.remote.bits,
toggle_bit_mask >> self.remote.post_data_bits,
self.remote.rc6_mask >> self.remote.post_data_bits,
);
}

if self.remote.post_data_bits != 0 {
let stream = if self.toggle_post_data() {
Expand Down Expand Up @@ -379,7 +394,7 @@ impl<'a> Builder<'a> {

self.add_gap(repeat);

if self.remote.toggle_mask != 0 {
if self.encoding && self.remote.toggle_mask != 0 {
write!(
&mut self.irp,
"CODE=CODE^{:#x},",
Expand All @@ -389,7 +404,7 @@ impl<'a> Builder<'a> {
.unwrap();
}

if self.toggle_pre_data() {
if self.encoding && self.toggle_pre_data() {
write!(
&mut self.irp,
"PRE=PRE^{:#x},",
Expand All @@ -399,7 +414,7 @@ impl<'a> Builder<'a> {
.unwrap();
}

if self.toggle_post_data() {
if self.encoding && self.toggle_post_data() {
write!(
&mut self.irp,
"POST=POST^{:#x},",
Expand Down
4 changes: 2 additions & 2 deletions tests/lircd_conf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn lircd_encode_decode(path: &Path) {
});
}

if decoded != expect {
if decoded != expect && !expect.is_empty() {
// is decoded and expected all the same value?
let all_the_same = if !decoded.is_empty() && !expect.is_empty() {
decoded
Expand All @@ -224,7 +224,7 @@ fn lircd_encode_decode(path: &Path) {
if !all_the_same {
println!("{}", message.print_rawir());
println!("irp: {}", our_remote.decode_irp());
println!(
panic!(
"DECODE MISMATCH got: {decoded:#x?} expected: {:#x?}",
expect
);
Expand Down

0 comments on commit d0469bd

Please sign in to comment.