diff options
author | Thomas Jansen <mithi@mithi.net> | 2008-11-07 08:16:41 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-11-07 08:16:41 +0100 |
commit | d88a1718bbca660e13ad60f8f1aec6084fcf7788 (patch) | |
tree | 808e721f1fffeafa4a9fa6e169e5467ae3dd28f3 /src/lirc.c | |
parent | 8221502e87f6c1a652b7c3148467248f538970bd (diff) | |
download | mpd-d88a1718bbca660e13ad60f8f1aec6084fcf7788.tar.gz mpd-d88a1718bbca660e13ad60f8f1aec6084fcf7788.tar.xz mpd-d88a1718bbca660e13ad60f8f1aec6084fcf7788.zip |
native LIRC support for ncmpc
The attachment includes the patch and a sample .lircrc config for
testing purposes (i. e. only a few commands are mapped to IR events).
The config is rather simple to write: For each button add a block like
this to ~/.lircrc:
begin
button = <button name from /etc/lircd.conf>
prog = ncmpc
config = <command name from src/command.c>
end
The patch is not finished, there are several problems that still need to
be solved:
1. the configure.ac modifications are just for testing purposes and
should be made optional with a parameter like --enable-lirc
for ./configure. Unfortunately I'm not an expert on autoconfig tools.
2. LIRC example code [1] suggests looping over lirc_code2char, probably
to have multiple actions that can be triggered from one button. Perhaps
lirc_event(...) should be moved to lirc.c and be heavily modified, no
longer being a mere copy of keyboard_event(...).
Diffstat (limited to '')
-rw-r--r-- | src/lirc.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/lirc.c b/src/lirc.c new file mode 100644 index 000000000..0ad34ca2f --- /dev/null +++ b/src/lirc.c @@ -0,0 +1,41 @@ +#include <lirc/lirc_client.h> +#include "lirc.h" + +static struct lirc_config *lc = NULL; +static int lirc_socket = 0; + +int ncmpc_lirc_open() +{ + if ((lirc_socket = lirc_init("ncmpc", 0)) == -1) + return -1; + + if (lirc_readconfig(NULL, &lc, NULL)) { + lirc_deinit(); + return -1; + } + + return lirc_socket; +} + +void ncmpc_lirc_close() +{ + if (lc) + lirc_freeconfig(lc); + lirc_deinit(); +} + +command_t ncmpc_lirc_get_command() +{ + char *code = NULL, *cmd = NULL; + + if (lirc_nextcode(&code) != 0) + return CMD_NONE; + + if (lirc_code2char(lc, code, &cmd) != 0) + return CMD_NONE; + + if (!cmd) + return CMD_NONE; + + return get_key_command_from_name(cmd); +} |