All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Young <sean@mess.org>
To: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Cc: linux-media@vger.kernel.org
Subject: [PATCH v4l-utils 2/3] ir-ctl: add verbose option
Date: Wed,  9 Nov 2016 16:13:32 +0000	[thread overview]
Message-ID: <1478708015-1164-2-git-send-email-sean@mess.org> (raw)

This is useful to see what IR is actually being sent (e.g. after
scancode generation).

Signed-off-by: Sean Young <sean@mess.org>
---
 utils/ir-ctl/ir-ctl.1.in |  3 +++
 utils/ir-ctl/ir-ctl.c    | 15 ++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/utils/ir-ctl/ir-ctl.1.in b/utils/ir-ctl/ir-ctl.1.in
index 2efe293..a1d5aeb 100644
--- a/utils/ir-ctl/ir-ctl.1.in
+++ b/utils/ir-ctl/ir-ctl.1.in
@@ -99,6 +99,9 @@ Prints the help message
 \fB\-\-usage\fR
 Give a short usage message
 .TP
+\fB\-v\fR, \fB\-\-verbose\fR
+Verbose output; this prints the IR before sending.
+.TP
 \fB\-V\fR, \fB\-\-version\fR
 print the v4l2\-utils version
 .PP
diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c
index bdea741..f19bd05 100644
--- a/utils/ir-ctl/ir-ctl.c
+++ b/utils/ir-ctl/ir-ctl.c
@@ -65,6 +65,7 @@ struct arguments {
 	char *device;
 	bool features;
 	bool record;
+	bool verbose;
 	struct file *send;
 	bool oneshot;
 	char *savetofile;
@@ -85,6 +86,7 @@ static const struct argp_option options[] = {
 	{ "record",	'r',	N_("FILE"),	OPTION_ARG_OPTIONAL,	N_("record IR to stdout or file") },
 	{ "send",	's',	N_("FILE"),	0,	N_("send IR pulse and space file") },
 	{ "scancode", 'S',	N_("SCANCODE"),	0,	N_("send IR scancode in protocol specified") },
+	{ "verbose",	'v',	0,		0,	N_("verbose output") },
 		{ .doc = N_("Recording options:") },
 	{ "one-shot",	'1',	0,		0,	N_("end recording after first message") },
 	{ "wideband",	'w',	0,		0,	N_("use wideband receiver aka learning mode") },
@@ -397,6 +399,9 @@ static error_t parse_opt(int k, char *arg, struct argp_state *state)
 	case '1':
 		arguments->oneshot = true;
 		break;
+	case 'v':
+		arguments->verbose = true;
+		break;
 	case 'm':
 		if (arguments->carrier_reports == 2)
 			argp_error(state, _("cannot enable and disable carrier reports"));
@@ -515,7 +520,7 @@ static error_t parse_opt(int k, char *arg, struct argp_state *state)
 		return ARGP_ERR_UNKNOWN;
 	}
 
-	if (k != '1' && k != 'd')
+	if (k != '1' && k != 'd' && k != 'v')
 		arguments->work_to_do = true;
 
 	return 0;
@@ -739,6 +744,12 @@ static int lirc_send(struct arguments *args, int fd, unsigned features, struct f
 		lirc_set_send_carrier(fd, dev, features, f->carrier);
 
 	size_t size = f->len * sizeof(unsigned);
+	if (args->verbose) {
+		int i;
+		printf("Sending:\n");
+		for (i=0; i<f->len; i++)
+			printf("%s %u\n", i & 1 ? "space" : "pulse", f->buf[i]);
+	}
 	ssize_t ret = TEMP_FAILURE_RETRY(write(fd, f->buf, size));
 	if (ret < 0) {
 		fprintf(stderr, _("%s: failed to send: %m\n"), dev);
@@ -752,6 +763,8 @@ static int lirc_send(struct arguments *args, int fd, unsigned features, struct f
 				size / sizeof(unsigned));
 		return EX_IOERR;
 	}
+	if (args->verbose)
+		printf("Successfully sent\n");
 
 	return 0;
 }
-- 
2.7.4


                 reply	other threads:[~2016-11-09 16:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478708015-1164-2-git-send-email-sean@mess.org \
    --to=sean@mess.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@s-opensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.