Skip to content

Commit

Permalink
test transmit when toggle_bit_mask is set
Browse files Browse the repository at this point in the history
clearing toggle_bit_mask_state makes the behaviour of lircd much more
sane: no xoring happens and we can mostly ignore this option. Note the
comment in liblircd on this behaviour.

Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed Mar 10, 2024
1 parent ed5402a commit 1438f87
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
10 changes: 9 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ not define D/F/C. So, decoder has to look at down part, see if it does not
define all required vars, and if not, add one iteration of repeat to
down decoder: very messy.

See also https://github.com/bengtmartensson/IrpTransmogrifier/issues/229
See also https://github.com/bengtmartensson/IrpTransmogrifier/issues/229

ENCODING ISSUES:
- toggle_bit_mask not used when popcount > 1

DECODING ISSUES:
- raw not supported
- toggle_bit_mask with more than 1 bit not supported
- pcmak leading gap not decoded
6 changes: 6 additions & 0 deletions liblircd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ impl<'a> Code<'a> {
}
}

if unsafe { (*self.1 .0).toggle_bit_mask } != 0 {
unsafe {
(*self.1 .0).toggle_bit_mask_state = 0;
}
}

let res = unsafe { send_buffer_put(self.1 .0, self.0) };
if res != 1 {
return None;
Expand Down
58 changes: 29 additions & 29 deletions src/lircd_conf/irp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Remote {

struct Builder<'a> {
remote: &'a Remote,
encoding: bool,
min_repeat: u64,
irp: String,
}
Expand All @@ -45,6 +46,7 @@ impl<'a> Builder<'a> {

Builder {
remote,
encoding,
min_repeat,
irp: String::new(),
}
Expand Down Expand Up @@ -285,7 +287,12 @@ impl<'a> Builder<'a> {
}

let toggle_bit_mask = if self.remote.toggle_bit_mask.count_ones() == 1 {
self.remote.toggle_bit_mask
// FIXME: lircd rcmm transmit does not encode toggle bit
if self.encoding && self.remote.flags.contains(Flags::RCMM) {
0
} else {
self.remote.toggle_bit_mask
}
} else {
0
};
Expand Down Expand Up @@ -382,15 +389,6 @@ impl<'a> Builder<'a> {
.unwrap();
}

if self.remote.toggle_bit_mask.count_ones() > 1 {
write!(
&mut self.irp,
"CODE=CODE^{:#x},",
self.remote.toggle_bit_mask >> self.remote.post_data_bits
)
.unwrap();
}

if self.toggle_pre_data() {
write!(
&mut self.irp,
Expand Down Expand Up @@ -489,28 +487,30 @@ impl<'a> Builder<'a> {
};

let bit_count = highest_bit - bit;
let offset = bit;

match stream {
Stream::Constant(v) => {
let v = (v >> offset) & gen_mask(bit_count);

if v <= 9 {
if bit_count > 0 {
let offset = bit;

match stream {
Stream::Constant(v) => {
let v = (v >> offset) & gen_mask(bit_count);

if v <= 9 {
write!(&mut self.irp, "{v}:{bit_count},").unwrap();
} else {
write!(&mut self.irp, "0x{v:x}:{bit_count},").unwrap();
}
}
Stream::Expression(v) if offset == 0 => {
write!(&mut self.irp, "{v}:{bit_count},").unwrap();
} else {
write!(&mut self.irp, "0x{v:x}:{bit_count},").unwrap();
}
}
Stream::Expression(v) if offset == 0 => {
write!(&mut self.irp, "{v}:{bit_count},").unwrap();
}
Stream::Expression(v) => {
write!(&mut self.irp, "{v}:{bit_count}:{offset},").unwrap();
}
Stream::Toggle => {
assert_eq!(bit_count, 1);
Stream::Expression(v) => {
write!(&mut self.irp, "{v}:{bit_count}:{offset},").unwrap();
}
Stream::Toggle => {
assert_eq!(bit_count, 1);

self.irp.push_str("T:1,");
self.irp.push_str("T:1,");
}
}
}

Expand Down
9 changes: 0 additions & 9 deletions tests/lircd_conf_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ fn lircd_encode(path: &Path) {

let our_remote = our_conf.next().unwrap();

if lircd_remote.toggle_bit_mask() != 0 && lircd_remote.toggle_bit() == 0 {
// TODO: fix either cir or lircd
println!(
"SKIP: {} because lircd does weird things",
lircd_remote.name()
);
continue;
}

if lircd_remote.is_raw() {
for (our_code, lircd_code) in our_remote.raw_codes.iter().zip(lircd_remote.codes_iter())
{
Expand Down

0 comments on commit 1438f87

Please sign in to comment.