Skip to content

Commit

Permalink
Remove cir decode subcommands
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed May 20, 2024
1 parent 86c4fe4 commit 54cb040
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 51 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand All @@ -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)
Expand Down
51 changes: 18 additions & 33 deletions cir/src/bin/cir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ struct Decode {
)]
rawir: Vec<String>,

/// IRP Notation
#[arg(long = "irp", short = 'i', required_unless_present = "keymap")]
irp: Option<String>,

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

#[clap(flatten)]
options: DecodeOptions,

#[command(subcommand)]
commands: DecodeCommands,
}

#[derive(Args)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
16 changes: 8 additions & 8 deletions cir/tests/decode_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 54cb040

Please sign in to comment.