Bryan Mayland wrote:
I can submit a patch to either ivtvctl or cx28540ctl to add this function if Chris says it is ok.
Consider it done! This adds the long-only option --reset-ir to ivtvctl. We're like totally out of letters to use for short options, and I didn't think this would be something you'd use enough to get a short option. I declared static int option_reset_ir, I hope that's ok.
I also removed a whole mess of close(fd) calls which as far as I could tell would only be called with fd = -1 (the device isn't opened until after all the options are set up).
I'd also like to submit a patch to reorder the output of usage() to be in case-insensitive alphabetic order by short option character (keeping the grouping Usage, Expert though). I thought this should be separate from the above changes though, in case you don't want the help redone.
Index: ivtvctl.c
===================================================================
--- ivtvctl.c (revision 227)
+++ ivtvctl.c (working copy)
@@ -96,6 +96,7 @@
};
static char options[OptLast];
+static int option_reset_ir = 0;
/* Codec's specified */
#define CAspect (1L<<1)
@@ -170,6 +171,7 @@
{"set-ctrl", required_argument, 0, OptSetCtrl},
{"get-sapmode", no_argument, 0, OptGetSAPMode},
{"set-sapmode", required_argument, 0, OptSetSAPMode},
+ {"reset-ir", no_argument, &option_reset_ir, 1},
{0, 0, 0, 0}
};
@@ -305,6 +307,7 @@
(" set whether VBI data is embedded in the MPEG
stream [IVTV_IOC_S_VBI_EMBED]\n");
printf
(" If 1, embed VBI data in the MPEG stream, if
0, don't.\n");
+ printf(" --reset-ir reset the infrared receiver
[IVTV_IOC_RESET_IR]\n");
printf("\n");
printf("Expert options:\n");
printf(" -i, --set-gpio=<mode>\n");
@@ -654,7 +657,6 @@
fprintf(stderr,
"No value given to
suboption <aspect>\n");
usage();
- close(fd);
return 1;
}
codec.aspect = strtol(value, 0L, 0);
@@ -665,7 +667,6 @@
fprintf(stderr,
"No value given to
suboption <bitrate_mode>\n");
usage();
- close(fd);
exit(1);
}
codec.bitrate_mode =
@@ -677,7 +678,6 @@
fprintf(stderr,
"No value given to
suboption <bitrate>\n");
usage();
- close(fd);
return 1;
}
codec.bitrate = strtol(value, 0L, 0);
@@ -688,7 +688,6 @@
fprintf(stderr,
"No value given to
suboption <bitrate_peak>\n");
usage();
- close(fd);
return 1;
}
codec.bitrate_peak =
@@ -700,7 +699,6 @@
fprintf(stderr,
"No value given to
suboption <stream_type>\n");
usage();
- close(fd);
return 1;
}
codec.stream_type =
@@ -712,7 +710,6 @@
fprintf(stderr,
"No value given to
suboption <framerate>\n");
usage();
- close(fd);
return 1;
}
codec.framerate = strtol(value, 0L, 0);
@@ -723,7 +720,6 @@
fprintf(stderr,
"No value given to
suboption <framespergop>\n");
usage();
- close(fd);
return 1;
}
codec.framespergop =
@@ -735,7 +731,6 @@
fprintf(stderr,
"No value given to
suboption <bframes>\n");
usage();
- close(fd);
exit(1);
}
codec.bframes = strtol(value, 0L, 0);
@@ -746,7 +741,6 @@
fprintf(stderr,
"No value given to
suboption <gop_closure>\n");
usage();
- close(fd);
exit(1);
}
codec.gop_closure =
@@ -758,7 +752,6 @@
fprintf(stderr,
"No value given to
suboption <audio>\n");
usage();
- close(fd);
exit(1);
}
codec.audio_bitmask =
@@ -770,7 +763,6 @@
fprintf(stderr,
"No value given to
suboption <dnr_mode>\n");
usage();
- close(fd);
exit(1);
}
codec.dnr_mode = strtol(value, 0L, 0);
@@ -781,7 +773,6 @@
fprintf(stderr,
"No value given to
suboption <dnr_type>\n");
usage();
- close(fd);
exit(1);
}
codec.dnr_type = strtol(value, 0L, 0);
@@ -792,7 +783,6 @@
fprintf(stderr,
"No value given to
suboption <dnr_spatial>\n");
usage();
- close(fd);
exit(1);
}
codec.dnr_spatial =
@@ -804,7 +794,6 @@
fprintf(stderr,
"No value given to
suboption <dnr_temporal>\n");
usage();
- close(fd);
exit(1);
}
codec.dnr_temporal =
@@ -816,7 +805,6 @@
fprintf(stderr,
"No value given to
suboption <pulldown>\n");
usage();
- close(fd);
exit(1);
}
codec.pulldown = strtol(value, 0L, 0);
@@ -826,7 +814,6 @@
fprintf(stderr,
"Invalid suboptions
specified\n");
usage();
- close(fd);
exit(1);
break;
}
@@ -842,7 +829,6 @@
fprintf(stderr,
"No value given to
suboption <width>\n");
usage();
- close(fd);
exit(1);
}
vfmt.fmt.pix.width =
@@ -854,7 +840,6 @@
fprintf(stderr,
"No value given to
suboption <height>\n");
usage();
- close(fd);
exit(1);
}
vfmt.fmt.pix.height =
@@ -865,7 +850,6 @@
fprintf(stderr,
"Invalid suboptions
specified\n");
usage();
- close(fd);
exit(1);
break;
}
@@ -881,7 +865,6 @@
fprintf(stderr,
"No value given to
suboption <reg>\n");
usage();
- close(fd);
exit(1);
}
itvc_reg.reg =
@@ -893,7 +876,6 @@
fprintf(stderr,
"No value given to
suboption <val>\n");
usage();
- close(fd);
exit(1);
}
itvc_reg.val =
@@ -904,7 +886,6 @@
fprintf(stderr,
"Invalid suboptions
specified\n");
usage();
- close(fd);
exit(1);
break;
}
@@ -919,7 +900,6 @@
fprintf(stderr,
"No value given to
suboption <reg>\n");
usage();
- close(fd);
exit(1);
}
min_reg = (unsigned long)
@@ -930,7 +910,6 @@
fprintf(stderr,
"No value given to
suboption <reg>\n");
usage();
- close(fd);
exit(1);
}
max_reg = (unsigned long)
@@ -950,7 +929,6 @@
fprintf(stderr,
"No value given to
suboption <reg>\n");
usage();
- close(fd);
exit(1);
}
saa7115_reg.reg =
@@ -961,7 +939,6 @@
fprintf(stderr,
"No value given to
suboption <val>\n");
usage();
- close(fd);
exit(1);
}
saa7115_reg.val =
@@ -971,7 +948,6 @@
fprintf(stderr,
"Invalid suboptions
specified\n");
usage();
- close(fd);
exit(1);
break;
}
@@ -986,7 +962,6 @@
fprintf(stderr,
"No value given to
suboption <reg>\n");
usage();
- close(fd);
exit(1);
}
saa7115_reg.reg =
@@ -997,7 +972,6 @@
fprintf(stderr,
"No value given to
suboption <val>\n");
usage();
- close(fd);
exit(1);
}
saa7115_reg.val =
@@ -1007,7 +981,6 @@
fprintf(stderr,
"Invalid suboptions
specified\n");
usage();
- close(fd);
exit(1);
break;
}
@@ -1094,7 +1067,6 @@
fprintf(stderr,
"Invalid suboptions
specified\n");
usage();
- close(fd);
exit(1);
break;
}
@@ -1832,6 +1804,13 @@
printf("Setting passthrough mode\n");
}
+ if (option_reset_ir) {
+ if (ioctl(fd, IVTV_IOC_RESET_IR, NULL) < 0)
+ fprintf(stderr, "ioctl IVTV_IOC_RESET_IR failed: %s\n",
+ strerror(errno));
+ printf("Resetting IR\n");
+ }
+
close(fd);
exit(0);
}
