Skip to content

Commit

Permalink
Add irp for imon protocol
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed Jun 17, 2024
1 parent 4517cb2 commit 4250075
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 39 deletions.
7 changes: 4 additions & 3 deletions cir/src/keymap/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ pub const LINUX_PROTOCOLS: &[LinuxProtocol] = &[
LinuxProtocol {
name: "imon",
decoder: "imon",
// TODO: {416,38k,msb}<-1|1>(1,<P:1,1:1,(CHK=CHK>>1,P=CHK&1)|0:2,(CHK=CHK>>1,P=1)>(CODE:31),^106m){P=1,CHK=0x7efec2} [CODE:0..0x7fffffff],
irp: None,
scancode_mask: u32::MAX,
irp: Some("{416,38k,msb}<1|-1>(1,\
C:1:30,CODE:1:30,C:1:29,CODE:1:29,C:1:28,CODE:1:28,C:1:27,CODE:1:27,C:1:26,CODE:1:26,C:1:25,CODE:1:25,C:1:24,CODE:1:24,C:1:23,CODE:1:23,C:1:22,CODE:1:22,C:1:21,CODE:1:21,C:1:20,CODE:1:20,C:1:19,CODE:1:19,C:1:18,CODE:1:18,C:1:17,CODE:1:17,C:1:16,CODE:1:16,C:1:15,CODE:1:15,C:1:14,CODE:1:14,C:1:13,CODE:1:13,C:1:12,CODE:1:12,C:1:11,CODE:1:11,C:1:10,CODE:1:10,C:1:9,CODE:1:9,C:1:8,CODE:1:8,C:1:7,CODE:1:7,C:1:6,CODE:1:6,C:1:5,CODE:1:5,C:1:4,CODE:1:4,C:1:3,CODE:1:3,C:1:2,CODE:1:2,C:1:1,CODE:1:1,C:1,CODE:1,\
^106m) {C=CODE|(CODE>>1)|0xbc8081ff} [CODE:0..0x7fffffff]"),
scancode_mask: 0x7fffffff,
protocol_no: 23,
},
LinuxProtocol {
Expand Down
17 changes: 12 additions & 5 deletions cir/tests/kernel_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ fn kernel_scancode_encode() {
rc_proto::RC_PROTO_RCMM12,
rc_proto::RC_PROTO_RCMM24,
rc_proto::RC_PROTO_RCMM32,
rc_proto::RC_PROTO_IMON,
] {
let name = unsafe { CStr::from_ptr(libirctl::protocol_name(proto)) }
.to_str()
.unwrap();
let linux = LinuxProtocol::find(name).unwrap();

assert_eq!(linux.scancode_mask, unsafe {
libirctl::protocol_scancode_mask(proto)
});
let irctl_mask = unsafe { libirctl::protocol_scancode_mask(proto) };

assert_eq!(
linux.scancode_mask, irctl_mask,
"{:#x} != {:#x}",
linux.scancode_mask, irctl_mask
);
assert_eq!(linux.protocol_no, proto as u32);
let mut rng = rand::thread_rng();

Expand All @@ -46,7 +51,9 @@ fn kernel_scancode_encode() {

let mut kencoded = libkcodec::encode(proto, scancode);
// TODO: we're not comparing the trailing gap
kencoded.pop();
if kencoded.len() % 2 == 0 {
kencoded.pop();
}

let mut vars = Vartable::new();

Expand Down Expand Up @@ -75,7 +82,7 @@ fn kernel_scancode_encode() {
{
assert!(compare_with_rounding(&kencoded, &our.raw));
} else {
assert_eq!(kencoded, our.raw);
assert_eq!(kencoded, our.raw, "proto:{proto:?} scancode:{scancode:#x}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libkcodec/src/ir-imon-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static int ir_imon_decode(struct rc_dev *dev, struct ir_raw_event ev)
* -ENOBUFS if there isn't enough space in the array to fit the
* encoding. In this case all @max events will have been written.
*/
static int ir_imon_encode(enum rc_proto protocol, u32 scancode,
int ir_imon_encode(enum rc_proto protocol, u32 scancode,
struct ir_raw_event *events, unsigned int max)
{
struct ir_raw_event *e = events;
Expand Down
46 changes: 16 additions & 30 deletions libkcodec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {
fn ir_sanyo_encode(proto: rc_proto, scancode: u32, event: *mut ir_raw_event, max: u32) -> u32;
fn ir_sharp_encode(proto: rc_proto, scancode: u32, event: *mut ir_raw_event, max: u32) -> u32;
fn ir_rcmm_encode(proto: rc_proto, scancode: u32, event: *mut ir_raw_event, max: u32) -> u32;
fn ir_imon_encode(proto: rc_proto, scancode: u32, event: *mut ir_raw_event, max: u32) -> u32;
}

#[no_mangle]
Expand Down Expand Up @@ -40,57 +41,42 @@ struct ir_raw_event {
pub fn encode(proto: rc_proto, scancode: u32) -> Vec<u32> {
let mut raw = vec![ir_raw_event::default(); 1024];

match proto {
let len = match proto {
rc_proto::RC_PROTO_RC5 | rc_proto::RC_PROTO_RC5X_20 | rc_proto::RC_PROTO_RC5_SZ => {
let len = unsafe { ir_rc5_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) };

raw.truncate(len as usize);
unsafe { ir_rc5_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
rc_proto::RC_PROTO_JVC => {
let len = unsafe { ir_jvc_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) };

raw.truncate(len as usize);
unsafe { ir_jvc_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
rc_proto::RC_PROTO_SONY12 | rc_proto::RC_PROTO_SONY15 | rc_proto::RC_PROTO_SONY20 => {
let len =
unsafe { ir_sony_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) };

raw.truncate(len as usize);
unsafe { ir_sony_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
rc_proto::RC_PROTO_NEC | rc_proto::RC_PROTO_NECX | rc_proto::RC_PROTO_NEC32 => {
let len = unsafe { ir_nec_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) };

raw.truncate(len as usize);
unsafe { ir_nec_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
rc_proto::RC_PROTO_SHARP => {
let len =
unsafe { ir_sharp_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) };

raw.truncate(len as usize);
unsafe { ir_sharp_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
rc_proto::RC_PROTO_SANYO => {
let len =
unsafe { ir_sanyo_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) };

raw.truncate(len as usize);
unsafe { ir_sanyo_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
rc_proto::RC_PROTO_RC6_0
| rc_proto::RC_PROTO_RC6_6A_20
| rc_proto::RC_PROTO_RC6_6A_24
| rc_proto::RC_PROTO_RC6_6A_32
| rc_proto::RC_PROTO_RC6_MCE => {
let len = unsafe { ir_rc6_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) };

raw.truncate(len as usize);
unsafe { ir_rc6_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
rc_proto::RC_PROTO_RCMM12 | rc_proto::RC_PROTO_RCMM24 | rc_proto::RC_PROTO_RCMM32 => {
let len =
unsafe { ir_rcmm_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) };

raw.truncate(len as usize);
unsafe { ir_rcmm_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
rc_proto::RC_PROTO_IMON => {
unsafe { ir_imon_encode(proto, scancode, raw.as_mut_ptr(), raw.len() as u32) }
}
_ => panic!("proto {}", proto as u32),
}
};

raw.truncate(len as usize);

raw.iter().map(|raw| raw.duration).collect()
}

0 comments on commit 4250075

Please sign in to comment.