Skip to contentSkip to conversation

ir-ctl: print correct transmitter count

PATCH In review Sean Young 1 participant 2 messages Jul 3, 2021 – Jul 5, 2021 Media (V4L/DVB)

lore
Share & tools
lore

Sean Young

author
#0 lore raw

PATCH 1/1 ir-ctl: print correct transmitter count

---
 utils/ir-ctl/ir-ctl.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
utils/ir-ctl/ir-ctl.c +6 -3
index 3c3bcca1..66a257a7 100644
@@ -933,7 +933,7 @@ static int lirc_options(struct arguments *args, int fd, unsigned features)
 		if (features & LIRC_CAN_SET_TRANSMITTER_MASK) {
 			rc = ioctl(fd, LIRC_SET_TRANSMITTER_MASK, &args->emitters);
 			if (rc > 0)
-				fprintf(stderr, _("warning: %s: failed to set send transmitters: only %d available\n"), dev, rc);
+				fprintf(stderr, _("warning: %s: failed to set send transmitters: only %d available\n"), dev, ffs(~rc) - 1);
 			else if (rc < 0)
 				fprintf(stderr, _("warning: %s: failed to set send transmitters: %m\n"), dev);
 		} else
@@ -1026,8 +1026,11 @@ static void lirc_features(struct arguments *args, int fd, unsigned features)
 				fprintf(stderr, _("warning: %s: device supports setting transmitter mask but returns 0 as number of transmitters\n"), dev);
 			else if (rc < 0)
 				fprintf(stderr, _("warning: %s: device supports setting transmitter mask but returns: %m\n"), dev);
-			else
-				printf(_(" - Set transmitter (%d available)\n"), rc);
+			else {
+				unsigned count = ffs(~rc) - 1;
+
+				printf(_(" - Set transmitter (%d available)\n"), count);
+			}
 		}
 	} else if (features & LIRC_CAN_SEND_LIRCCODE) {
 		printf(_(" - Device can send using device dependent LIRCCODE mode (not supported)\n"));
Signature · 1 line
2.31.1
author
#1 lore raw
Quoted 10 lines · Sean Young
---
 utils/ir-ctl/ir-ctl.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
utils/ir-ctl/ir-ctl.c +0 -0
index 3c3bcca1..66a257a7 100644

utils/ir-ctl/ir-ctl.c static int lirc_options(struct arguments *args, int fd, unsigned features) · line 936

Quoted 5 lines
utils/ir-ctl/ir-ctl.c +1 -1
@@ -933,7 +933,7 @@ static int lirc_options(struct arguments *args, int fd, unsigned features)
 		if (features & LIRC_CAN_SET_TRANSMITTER_MASK) {
 			rc = ioctl(fd, LIRC_SET_TRANSMITTER_MASK, &args->emitters);
 			if (rc > 0)
-				fprintf(stderr, _("warning: %s: failed to set send transmitters: only %d available\n"), dev, rc);
+				fprintf(stderr, _("warning: %s: failed to set send transmitters: only %d available\n"), dev, ffs(~rc) - 1);

I was mistaken; the ioctl does return the tx emitter count, not the valid mask.

All the existing drivers except rc-loopback return the count, not the mask. The documentation also says so.

I'll have to revert.

Sean

Quoted 19 lines
utils/ir-ctl/ir-ctl.c +5 -2
 			else if (rc < 0)
 				fprintf(stderr, _("warning: %s: failed to set send transmitters: %m\n"), dev);
 		} else
@@ -1026,8 +1026,11 @@ static void lirc_features(struct arguments *args, int fd, unsigned features)
 				fprintf(stderr, _("warning: %s: device supports setting transmitter mask but returns 0 as number of transmitters\n"), dev);
 			else if (rc < 0)
 				fprintf(stderr, _("warning: %s: device supports setting transmitter mask but returns: %m\n"), dev);
-			else
-				printf(_(" - Set transmitter (%d available)\n"), rc);
+			else {
+				unsigned count = ffs(~rc) - 1;
+
+				printf(_(" - Set transmitter (%d available)\n"), count);
+			}
 		}
 	} else if (features & LIRC_CAN_SEND_LIRCCODE) {
 		printf(_(" - Device can send using device dependent LIRCCODE mode (not supported)\n"));
Signature · 1 line
2.31.1