diff options
author | Sean Young <sean@mess.org> | 2017-01-17 16:33:39 +0000 |
---|---|---|
committer | Sean Young <sean@mess.org> | 2017-01-19 14:18:04 +0000 |
commit | c6b8f8da12ee914def59ecc0de80f4755298d053 (patch) | |
tree | a544cfd0e45783a96138dfd8b61d9e9cc49ef39d | |
parent | d0e34993c9aaec0229ab381b8400a476d22429f0 (diff) |
ir-ctl: ensure that device can record and that correct mode is set
Also ensure the correct recording and receiving mode is set. We might
add new modes in the future (e.g. scancodes).
Signed-off-by: Sean Young <sean@mess.org>
-rw-r--r-- | utils/ir-ctl/ir-ctl.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c index 6013b472..bc58cee0 100644 --- a/utils/ir-ctl/ir-ctl.c +++ b/utils/ir-ctl/ir-ctl.c @@ -20,6 +20,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> +#include <errno.h> #include <fcntl.h> #include <argp.h> #include <sysexits.h> @@ -733,12 +734,18 @@ static void lirc_features(struct arguments *args, int fd, unsigned features) static int lirc_send(struct arguments *args, int fd, unsigned features, struct file *f) { const char *dev = args->device; + int mode = LIRC_MODE_PULSE; if (!(features & LIRC_CAN_SEND_PULSE)) { - fprintf(stderr, _("%s: device cannot send\n"), dev); + fprintf(stderr, _("%s: device cannot send raw ir\n"), dev); return EX_UNAVAILABLE; } + if (ioctl(fd, LIRC_SET_SEND_MODE, &mode)) { + fprintf(stderr, _("%s: failed to set send mode: %m\n"), dev); + return EX_IOERR; + } + if (args->carrier && f->carrier) fprintf(stderr, _("warning: %s: carrier specified but overwritten on command line\n"), f->fname); else if (f->carrier && args->carrier == 0) @@ -775,6 +782,18 @@ int lirc_record(struct arguments *args, int fd, unsigned features) char *dev = args->device; FILE *out = stdout; int rc = EX_IOERR; + int mode = LIRC_MODE_MODE2; + + if (!(features & LIRC_CAN_REC_MODE2)) { + fprintf(stderr, _("%s: device cannot record raw ir\n"), dev); + return EX_UNAVAILABLE; + } + + // kernel v4.8 and v4.9 return ENOTTY + if (ioctl(fd, LIRC_SET_REC_MODE, &mode) && errno != ENOTTY) { + fprintf(stderr, _("%s: failed to set record mode: %m\n"), dev); + return EX_IOERR; + } if (args->savetofile) { out = fopen(args->savetofile, "w"); |