[PATCH v4l-utils] ir-ctl: usb-uirt device reports carrier frequency for each pulse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The carrier frequency is reported a number of times. So, rather than
printing the last carrier reported, calculate the mean.

Possibly it would be better to calculate the mode rather than the mean.

Signed-off-by: Sean Young <sean@xxxxxxxx>
---
 utils/ir-ctl/ir-ctl.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c
index 3c3bcca1..3270a5e7 100644
--- a/utils/ir-ctl/ir-ctl.c
+++ b/utils/ir-ctl/ir-ctl.c
@@ -1148,7 +1148,8 @@ int lirc_receive(struct arguments *args, int fd, unsigned features)
 
 	bool keep_reading = true;
 	bool leading_space = true;
-	unsigned carrier = 0;
+	unsigned long long total_carriers = 0;
+	unsigned int no_carriers = 0;
 
 	while (keep_reading) {
 		ssize_t ret = TEMP_FAILURE_RETRY(read(fd, buf, sizeof(buf)));
@@ -1201,10 +1202,13 @@ int lirc_receive(struct arguments *args, int fd, unsigned features)
 				switch (msg) {
 				case LIRC_MODE2_TIMEOUT:
 					fprintf(out, "-%u\n", val);
-					if (carrier)
-						fprintf(out, " # carrier %uHz, timeout %u\n", carrier, val);
+					if (no_carriers) {
+						// averge of all the carriers reported mean (do we want the mode?)
+						fprintf(out, " # carrier %lluHz, timeout %u\n", total_carriers / no_carriers, val);
+					}
 					leading_space = true;
-					carrier = 0;
+					no_carriers = 0;
+					total_carriers = 0;
 					break;
 				case LIRC_MODE2_PULSE:
 					fprintf(out, "+%u ", val);
@@ -1213,7 +1217,8 @@ int lirc_receive(struct arguments *args, int fd, unsigned features)
 					fprintf(out, "-%u ", val);
 					break;
 				case LIRC_MODE2_FREQUENCY:
-					carrier = val;
+					total_carriers += val;
+					no_carriers += 1;
 					break;
 				}
 			}
-- 
2.31.1




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux