Skip to content

Commit

Permalink
Add list and load 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 7, 2024
1 parent 681038f commit d2772ab
Show file tree
Hide file tree
Showing 5 changed files with 530 additions and 340 deletions.
89 changes: 57 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,29 @@ express [any IR protocol](http://hifi-remote.com/wiki/index.php/DecodeIR).
We can parse IRP and compile a decoder to BPF using LLVM. So, any protocol can
be supported directly.

## Listing IR devices (cir config)
## List devices (cir list)

This is the cir equivalent of both `ir-keytable` with no arguments and `ir-ctl -f`.
This gives you a list of infrared and CEC devices on your Linux system. It is the cir equivalent of both
`ir-keytable` with no arguments combined with the lirc features from `ir-ctl -f`.

```bash
cir list
```
This gives you a list of the all the rc devices on the system.
```
rc0:
Device Name : Media Center Ed. eHome Infrared Remote Transceiver (1784:0008)
Driver : mceusb
Default Keymap : rc-rc6-mce
Input Device : /dev/input/event12
Input properties : Permission denied (os error 13)
LIRC Device : /dev/lirc0
LIRC Features : Permission denied (os error 13)
Supported Protocols : rc-5 nec rc-6 jvc sony rc-5-sz sanyo sharp mce_kbd xmp imon rc-mm
Enabled Protocols : rc-6
```
Not all information is available, unless you run it as root.
```
$ cir config
rc0:
Device Name : Media Center Ed. eHome Infrared Remote Transceiver (1784:0008)
Driver : mceusb
Expand Down Expand Up @@ -57,28 +74,29 @@ rc0:
If you have a `.lircd.conf` file or `.toml` keymap, you can transmit with the following
command:

```
$ cir transmit keymap RM-Y173.lircd.conf KEY_CHANNELUP
info: carrier: 38000Hz
info: rawir: +2485 -527 +656 -527 +656 -527 +656 -527 +656 -527 +1262 -527 +656 -527 +656 -527 +1262 -527 +656 -527 +656 -527 +656 -527 +656 -26274
```bash
cir transmit keymap RM-Y173.lircd.conf KEY_CHANNELUP
```
Alternatively, you can send raw IR directly like so:
```
$ cir transmit rawir '+9000 -4500 +560'
```bash
cir transmit rawir '+9000 -4500 +560'
```
You can also send files or linux kernel scancodes, using the same options like `ir-ctl`. This supports
mode2 files or raw IR files.
```
$ cir transmit rawir -s input-file -S nec:0xcafe
```bash
cir transmit rawir -s input-file -S nec:0xcafe
```
You can send pronto codes:
```
$ cir transmit pronto '5000 0073 0000 0001 0001 0001'
```bash
cir transmit pronto '5000 0073 0000 0001 0001 0001'
```
Lastly you use IRP notation and set the parameters. This is great for experimenting with IRP; use the `--dry-run` (`-n`)
to avoid sending.
```bash
cir transmit irp -n -fF=2 '{40k,600}<1,-1|2,-1>(4,-1,F:8,^45m)[F:0..255]'
```
This will give the following output:
```
$ cir transmit irp -n -fF=2 '{40k,600}<1,-1|2,-1>(4,-1,F:8,^45m)[F:0..255]'
info: carrier: 40000Hz
info: rawir: +2400 -600 +600 -600 +1200 -600 +600 -600 +600 -600 +600 -600 +600 -600 +600 -600 +600 -32400
```
Expand All @@ -88,47 +106,54 @@ info: rawir: +2400 -600 +600 -600 +1200 -600 +600 -600 +600 -600 +600 -600 +600
Use this if have a `.lircd.conf` file or `.toml` keymap, and want to decode the IR. This does not change
any configation.

```
$ cir decode keymap foo.lircd.conf
```bash
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.

```
$ cir decode keymap foo.lircd.conf -r '+9000 -4500 +560'
```bash
cir decode keymap foo.lircd.conf -r '+9000 -4500 +560'
```
or
```
$ cir decode keymap foo.lircd.conf -f input-file
```bash
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
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`).

## Configuration (cir config -w)
## Loading of keymaps

This is the cir equivalent of `ir-keytable -w`.
This is the cir equivalent of `ir-keytable -w`, however cir can not just load keymaps, it can
also load `.lircd.conf` files.

```
$ cir config -s rc0 -w foo.lircd.conf
```bash
cir load -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`.
On startup, `ir-keytable -a -s rc0` read the correct keymap from `/etc/rc_maps.cfg`.

```bash
cir auto -s rc0
```
$ cir auto -s rc0
## Configuration (cir config)

`cir config` is usually not needed, this for tweaking things like auto-repeat or lirc timeout. For example:
```bash
cir config -P 125 -D 500
```

## Test configuration (cir test)

This is the cir equivalent of `ir-keytable -t`

```
$ cir test
```bash
cir test
```

## Status
Expand All @@ -150,4 +175,4 @@ cargo install --git https://github.com/seanyoung/cir cir
- The IRP encoder and decoder is compared against IrpTransmogrifier with a large set of inputs.
- The parsing, encoding and decoding of lircd.conf files is compared against lirc (see liblircd)
- The encoding of linux protocols is compared against ir-ctl (see libirctl)
- There are more tests
- There are many more tests
85 changes: 68 additions & 17 deletions src/bin/cir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ enum Commands {
Transmit(Transmit),
#[cfg(target_os = "linux")]
#[command(about = "List IR and CEC devices")]
Config(Config),
List(List),
#[cfg(target_os = "linux")]
#[command(about = "Load keymaps or lircd.conf remotes")]
Load(Load),
#[cfg(target_os = "linux")]
#[command(about = "Receive IR and print to stdout")]
Test(Test),
#[cfg(target_os = "linux")]
#[command(about = "Configure IR and CEC devices")]
Config(Config),
#[cfg(target_os = "linux")]
#[command(about = "Auto-load keymaps based on configuration")]
Auto(Auto),
}
Expand Down Expand Up @@ -120,6 +126,22 @@ struct DecodeOptions {
#[arg(long = "save-dfa", global = true, help_heading = "DECODING")]
save_dfa: bool,
}

#[derive(Args)]
struct BpfDecodeOptions {
/// Save the LLVM IR
#[arg(long = "save-llvm-ir", help_heading = "DECODING")]
save_llvm_ir: bool,

/// Save the Assembly
#[arg(long = "save-asm", help_heading = "DECODING")]
save_assembly: bool,

/// Save the Object
#[arg(long = "save-object", help_heading = "DECODING")]
save_object: bool,
}

#[derive(Subcommand)]
enum DecodeCommands {
#[command(about = "Decode using IRP Notation")]
Expand Down Expand Up @@ -169,14 +191,52 @@ struct RcDevice {

#[cfg(target_os = "linux")]
#[derive(Args)]
struct Config {
struct Load {
#[cfg(target_os = "linux")]
#[clap(flatten)]
device: RcDevice,

/// Set receiving timeout
#[arg(long = "timeout", short = 't')]
timeout: Option<u32>,

/// Sets the delay before repeating a keystroke
#[arg(long = "delay", short = 'D', name = "DELAY")]
delay: Option<u32>,

/// Sets the period before repeating a keystroke
#[arg(long = "period", short = 'P', name = "PERIOD")]
period: Option<u32>,

/// Load toml or lircd.conf keymap
#[arg(name = "KEYMAP")]
keymaps: Vec<PathBuf>,

#[clap(flatten)]
options: DecodeOptions,

#[clap(flatten)]
bpf_options: BpfDecodeOptions,
}

#[cfg(target_os = "linux")]
#[derive(Args)]
struct List {
#[cfg(target_os = "linux")]
#[clap(flatten)]
device: RcDevice,

/// Display the scancode to keycode mapping
#[arg(long = "read-mapping", short = 'm')]
mapping: bool,
}

#[cfg(target_os = "linux")]
#[derive(Args)]
struct Config {
#[cfg(target_os = "linux")]
#[clap(flatten)]
device: RcDevice,

/// Clear existing configuration
#[arg(long = "clear", short = 'c')]
Expand All @@ -194,28 +254,15 @@ struct Config {
#[arg(long = "period", short = 'P', name = "PERIOD")]
period: Option<u32>,

/// Load toml or lircd.conf keymap
#[arg(long = "keymap", short = 'w', name = "KEYMAP")]
keymaps: Vec<PathBuf>,

// TODO:
// --irp '{}<>()[]'
// set scancode (like ir-keytable --set-key/-k)
// set protocol (like ir-keytabke -P)
#[clap(flatten)]
options: DecodeOptions,

/// Save the LLVM IR
#[arg(long = "save-llvm-ir", help_heading = "DECODING")]
save_llvm_ir: bool,

/// Save the Assembly
#[arg(long = "save-asm", help_heading = "DECODING")]
save_assembly: bool,

/// Save the Object
#[arg(long = "save-object", help_heading = "DECODING")]
save_object: bool,
#[clap(flatten)]
bpf_options: BpfDecodeOptions,
}

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -551,6 +598,10 @@ fn main() {
},
Commands::Transmit(transmit) => commands::transmit::transmit(transmit),
#[cfg(target_os = "linux")]
Commands::List(list) => commands::list::list(list),
#[cfg(target_os = "linux")]
Commands::Load(load) => commands::config::load(load),
#[cfg(target_os = "linux")]
Commands::Config(config) => commands::config::config(config),
#[cfg(target_os = "linux")]
Commands::Test(test) => commands::test::test(test),
Expand Down
Loading

0 comments on commit d2772ab

Please sign in to comment.