Skip to content

Commit

Permalink
Teach cir decode to decode using all linux kernel protocols
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed May 23, 2024
1 parent 1631dd0 commit 898450b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
8 changes: 6 additions & 2 deletions cir/src/bin/cir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ struct Decode {
)]
rawir: Vec<String>,

/// IRP Notation
/// Decode using IRP Notation
#[arg(long = "irp", short = 'i')]
irp: Vec<String>,

/// Keymap or lircd.conf file
/// Decode using Keymap or lircd.conf file
#[arg(long = "keymap", short = 'k')]
keymap: Vec<PathBuf>,

/// Decode using all Linux Kernel Protocols
#[arg(long = "builtin-kernel-protocols", short = 'b')]
linux_kernel: bool,

#[clap(flatten)]
options: DecodeOptions,
}
Expand Down
27 changes: 24 additions & 3 deletions cir/src/bin/commands/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use super::keymap::{find_devices, Purpose};
use crate::get_irp_protocols;
#[cfg(target_os = "linux")]
use cir::lirc::Lirc;
use cir::{keymap::Keymap, lircd_conf::parse};
use cir::{
keymap::{Keymap, LINUX_PROTOCOLS},
lircd_conf::parse,
};
use irp::{Decoder, InfraredData, Irp, Message, Options};
use itertools::Itertools;
use log::{error, info};
Expand All @@ -20,7 +23,7 @@ pub fn decode(global: &crate::App, decode: &crate::Decode) {

let mut lircd_remotes = Vec::new();
let mut rc_keymaps = Vec::new();
let mut irps = Vec::new();
let mut irps: Vec<(&str, &str, Irp)> = Vec::new();

for irp_arg in &decode.irp {
match get_irp_protocols(&global.irp_protocols) {
Expand Down Expand Up @@ -70,7 +73,25 @@ pub fn decode(global: &crate::App, decode: &crate::Decode) {
}
}

if decode.irp.is_empty() && decode.keymap.is_empty() {
if decode.linux_kernel {
for protocol in LINUX_PROTOCOLS {
if let Some(irp_notation) = protocol.irp {
log::debug!("decoding kernel {}: {}", protocol.name, irp_notation);

let irp = match Irp::parse(irp_notation) {
Ok(m) => m,
Err(s) => {
eprintln!("unable to parse irp ‘{}’: {s}", irp_notation);
std::process::exit(2);
}
};

irps.push((protocol.name, irp_notation, irp));
}
}
}

if !decode.linux_kernel && decode.irp.is_empty() && decode.keymap.is_empty() {
match get_irp_protocols(&global.irp_protocols) {
Ok(res) => {
irp_protocols_xml = res;
Expand Down
1 change: 1 addition & 0 deletions cir/src/keymap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod parse;
mod protocol;

pub use encode::encode;
pub use protocol::LINUX_PROTOCOLS;

/// A Linux keymap, either toml or text format used by ir-keytable
#[derive(PartialEq, Debug, Default)]
Expand Down
2 changes: 1 addition & 1 deletion cir/src/keymap/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl LinuxProtocol {
}
}

const LINUX_PROTOCOLS: &[LinuxProtocol] = &[
pub const LINUX_PROTOCOLS: &[LinuxProtocol] = &[
LinuxProtocol {
name: "rc5",
decoder: "rc-5",
Expand Down

0 comments on commit 898450b

Please sign in to comment.