From 54cb04071c1499e8adc9e3c312fbce97720b1a99 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Sat, 18 May 2024 22:02:57 +0100 Subject: [PATCH] Remove cir decode subcommands Signed-off-by: Sean Young --- README.md | 18 ++++++-------- cir/src/bin/cir.rs | 51 ++++++++++++++------------------------- cir/tests/decode_tests.rs | 16 ++++++------ 3 files changed, 34 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 11632cc..3adb75a 100644 --- a/README.md +++ b/README.md @@ -107,21 +107,21 @@ Use this if have a `.lircd.conf` file or `.toml` keymap, and want to decode the any configation. ```bash -cir decode keymap foo.lircd.conf +cir decode --keymap foo.lircd.conf ``` This will infrared from the first lirc device. You can also decode IR on the command line or a file. ```bash -cir decode keymap foo.lircd.conf -r '+9000 -4500 +560' +cir decode --keymap foo.lircd.conf -r '+9000 -4500 +560' ``` or ```bash -cir decode keymap foo.lircd.conf -f input-file +cir decode --keymap foo.lircd.conf -f input-file ``` If you wish to decode using IRP Notation that is possible too: ```bash -cir decode irp '{40k,600}<1,-1|2,-1>(4,-1,F:8,^45m)[F:0..255]' +cir decode --irp '{40k,600}<1,-1|2,-1>(4,-1,F:8,^45m)[F:0..255]' ``` Like above the input can be from a lirc device (optionally specify the device with `-d /dev/lirc1` or `-s rc`), on the command line (`-r '+100 -200 +100'`) or a file (`-f filename`). @@ -132,20 +132,18 @@ This is the cir equivalent of `ir-keytable -w`, however cir can not just load ke also load `.lircd.conf` files. ```bash -cir load -s rc0 foo.lircd.conf +cir keymap -s rc0 foo.lircd.conf ``` This will generate a BPF decoder for `foo.lircd.conf` and load it. On startup, `ir-keytable -a -s rc0` read the correct keymap from `/etc/rc_maps.cfg`. ```bash -cir auto -s rc0 +cir keymap -s rc0 ``` -## Configuration (cir config) - -`cir config` is usually not needed, this for tweaking things like auto-repeat or lirc timeout. For example: +Setting the auto-repeat parameters. ```bash -cir config -P 125 -D 500 +cir keymap -P 125 -D 500 ``` ## Test configuration (cir test) diff --git a/cir/src/bin/cir.rs b/cir/src/bin/cir.rs index 04d13fe..88ab351 100644 --- a/cir/src/bin/cir.rs +++ b/cir/src/bin/cir.rs @@ -81,11 +81,16 @@ struct Decode { )] rawir: Vec, + /// IRP Notation + #[arg(long = "irp", short = 'i', required_unless_present = "keymap")] + irp: Option, + + /// Keymap or lircd.conf file + #[arg(long = "keymap", short = 'k')] + keymap: Option, + #[clap(flatten)] options: DecodeOptions, - - #[command(subcommand)] - commands: DecodeCommands, } #[derive(Args)] @@ -134,27 +139,6 @@ struct BpfDecodeOptions { save_object: bool, } -#[derive(Subcommand)] -enum DecodeCommands { - #[command(about = "Decode using IRP Notation")] - Irp(DecodeIrp), - - #[command(about = "Decode using keymap or lircd.conf file")] - Keymap(DecodeKeymap), -} - -#[derive(Args)] -struct DecodeIrp { - /// IRP Notation - irp: String, -} - -#[derive(Args)] -struct DecodeKeymap { - /// Keymap or lircd.conf file - keymap: PathBuf, -} - #[cfg(target_os = "linux")] #[derive(Args)] struct RcDevice { @@ -587,18 +571,19 @@ fn main() { log::set_max_level(level); match &args.command { - Commands::Decode(decode) => match &decode.commands { - DecodeCommands::Irp(irp) => { - commands::decode::decode_irp(decode, &irp.irp); - } - DecodeCommands::Keymap(keymap) => { - if keymap.keymap.to_string_lossy().ends_with(".lircd.conf") { - commands::decode::decode_lircd(decode, &keymap.keymap); + Commands::Decode(decode) => { + if let Some(irp) = &decode.irp { + commands::decode::decode_irp(decode, irp) + } else { + let keymap = decode.keymap.as_ref().unwrap(); + + if keymap.to_string_lossy().ends_with(".lircd.conf") { + commands::decode::decode_lircd(decode, keymap); } else { - commands::decode::decode_keymap(decode, &keymap.keymap); + commands::decode::decode_keymap(decode, keymap); } } - }, + } Commands::Transmit(args) => commands::transmit::transmit(args), #[cfg(target_os = "linux")] Commands::List(args) => commands::list::list(args), diff --git a/cir/tests/decode_tests.rs b/cir/tests/decode_tests.rs index bf591fe..57a6933 100644 --- a/cir/tests/decode_tests.rs +++ b/cir/tests/decode_tests.rs @@ -6,7 +6,7 @@ fn toggle_bit_mask() { let assert = cmd .args([ - "decode", "keymap", "../testdata/lircd_conf/d-link/DSM-10.lircd.conf", "-q", "-r", + "decode", "--keymap", "../testdata/lircd_conf/d-link/DSM-10.lircd.conf", "-q", "-r", "+9132 -4396 +664 -460 +664 -460 +664 -460 +664 -1592 +664 -460 +664 -460 +664 -460 +664 -460 +664 -460 +664 -1592 +664 -1592 +664 -460 +664 -460 +664 -1592 +664 -1592 +664 -1592 +664 -460 +664 -460 +664 -1592 +664 -460 +664 -1592 +664 -460 +664 -460 +664 -460 +664 -1592 +664 -1592 +664 -460 +664 -1592 +664 -460 +664 -1592 +664 -1592 +664 -1592 +671 -42232 +9128 -2143 +671 -96305" ]) .assert(); @@ -33,7 +33,7 @@ fn ignore_mask() { let assert = cmd .args([ - "decode", "keymap", "../testdata/lircd_conf/apple/A1156.lircd.conf", "-q", "-r", + "decode", "--keymap", "../testdata/lircd_conf/apple/A1156.lircd.conf", "-q", "-r", "+9065 -4484 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -547 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -547 +574 -1668 +567 -37600 +9031 -2242 +567 -37600" ]) .assert(); @@ -56,7 +56,7 @@ decoded: remote:Apple_A1156 code:KEY_PLAY let assert = cmd .args([ - "decode", "keymap", "../testdata/lircd_conf/apple/A1156.lircd.conf", "-q", "-r", + "decode", "--keymap", "../testdata/lircd_conf/apple/A1156.lircd.conf", "-q", "-r", "+9065 -4484 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -547 +574 -1668 +574 -1668 +574 -547 +574 -547 +574 -547 +574 -547 +574 -547 +574 -547 +574 -547 +574 -1668 +574 -1668 +574 -1668 +574 -547 +574 -1668 +574 -547 +567 -37600 +9031 -2242 +567 -37600" ]) .assert(); @@ -82,7 +82,7 @@ fn keymap() { let assert = cmd .args([ - "decode", "keymap", "../testdata/rc_keymaps/sony.toml", "-v", "-r", + "decode", "--keymap", "../testdata/rc_keymaps/sony.toml", "-v", "-r", "+2400 -600 +600 -600 +600 -600 +600 -600 +600 -600 +600 -600 +1200 -600 +1200 -600 +600 -600 +600 -600 +600 -600 +600 -600 +1200 -26400" ]) .assert(); @@ -119,7 +119,7 @@ debug: scancode 0x100060 let assert = cmd .args([ - "decode", "keymap", "../testdata/rc_keymaps/sony-12.toml", "-r", + "decode", "--keymap", "../testdata/rc_keymaps/sony-12.toml", "-r", "+2400 -600 +1200 -600 +600 -600 +1200 -600 +600 -600 +1200 -600 +600 -600 +600 -600 +600 -600 +600 -600 +600 -600 +600 -600 +600 -26400" ]) .assert(); @@ -144,7 +144,7 @@ debug: scancode 0x100060 let assert = cmd .args([ - "decode", "keymap", "../testdata/rc_keymaps/dish_network.toml", "-q", "-r", + "decode", "--keymap", "../testdata/rc_keymaps/dish_network.toml", "-q", "-r", "+525 -6045 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +440 -1645 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +440 -2780 +450 -40000" ]) .assert(); @@ -166,7 +166,7 @@ debug: scancode 0x100060 let assert = cmd .args([ - "decode", "keymap", "../testdata/rc_keymaps/rc6_mce.toml", "-q", "-r", + "decode", "--keymap", "../testdata/rc_keymaps/rc6_mce.toml", "-q", "-r", "+2664 -888 +444 -444 +444 -444 +444 -888 +444 -888 +1332 -888 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +444 -444 +888 -444 +444 -444 +444 -444 +444 -888 +444 -444 +444 -444 +444 -444 +444 -444 +888 -888 +444 -444 +444 -444 +888 -888 +888 -444 +444 -444 +444 -888 +444 -444 +444 -67704" ]) .assert(); @@ -188,7 +188,7 @@ debug: scancode 0x100060 let assert = cmd .args([ - "decode", "keymap", "../testdata/rc_keymaps/RM-786.toml", "-r", + "decode", "--keymap", "../testdata/rc_keymaps/RM-786.toml", "-r", "+2465 -569 +620 -582 +618 -584 +1242 -581 +618 -585 +620 -583 +620 -585 +1242 -607 +622 -575 +1243 -584 +1243 -578 +621 -579 +619 -20000" ]) .assert();