aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2019-02-04 13:03:28 (GMT)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2019-02-04 13:03:28 (GMT)
commit2fea6c505c25be228c92f363fdebb5d31d9ed96e (patch)
tree4fb024d897566556791ad3f4782ad5daed8bf75f
parent09dfe99e13a71a09e2c353b4339106fa7540451c (diff)
cec-follower: add -D and -a support
With these options you can uniquely identify a CEC device without having to know the device node name. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r--utils/cec-follower/cec-follower.1.in10
-rw-r--r--utils/cec-follower/cec-follower.cpp37
2 files changed, 41 insertions, 6 deletions
diff --git a/utils/cec-follower/cec-follower.1.in b/utils/cec-follower/cec-follower.1.in
index 900c3ba..427f96f 100644
--- a/utils/cec-follower/cec-follower.1.in
+++ b/utils/cec-follower/cec-follower.1.in
@@ -48,6 +48,16 @@ clean and known initial state.
\fB\-d\fR, \fB\-\-device\fR \fI<dev>\fR
Use device <dev> as the CEC device. If <dev> is a number, then /dev/cec<dev> is used.
.TP
+\fB\-D\fR, \fB\-\-driver\fR \fI<drv>\fR
+Use a cec device that has driver name \fI<drv>\fR, as returned by the CEC_ADAP_G_CAPS ioctl.
+This option can be combined with \fB\-a\fR to uniquely identify a CEC device without
+having to rely on the device node number.
+.TP
+\fB\-a\fR, \fB\-\-adapter\fR \fI<adap-name>\fR
+Use a cec device that has adapter name \fI<adap-name>\fR, as returned by the CEC_ADAP_G_CAPS ioctl.
+This option can be combined with \fB\-D\fR to uniquely identify a CEC device without
+having to rely on the device node number.
+.TP
\fB\-v\fR, \fB\-\-verbose\fR
Turn on verbose reporting.
.TP
diff --git a/utils/cec-follower/cec-follower.cpp b/utils/cec-follower/cec-follower.cpp
index 9dbcd22..77394ab 100644
--- a/utils/cec-follower/cec-follower.cpp
+++ b/utils/cec-follower/cec-follower.cpp
@@ -33,7 +33,9 @@
In general the lower case is used to set something and the upper
case is used to retrieve a setting. */
enum Option {
+ OptSetAdapter = 'a',
OptSetDevice = 'd',
+ OptSetDriver = 'D',
OptHelp = 'h',
OptNoWarnings = 'n',
OptTrace = 'T',
@@ -54,6 +56,8 @@ unsigned warnings;
static struct option long_options[] = {
{"device", required_argument, 0, OptSetDevice},
+ {"adapter", required_argument, 0, OptSetAdapter},
+ {"driver", required_argument, 0, OptSetDriver},
{"help", no_argument, 0, OptHelp},
{"no-warnings", no_argument, 0, OptNoWarnings},
{"trace", no_argument, 0, OptTrace},
@@ -70,6 +74,8 @@ static void usage(void)
printf("Usage:\n"
" -d, --device <dev> Use device <dev> instead of /dev/cec0\n"
" If <dev> starts with a digit, then /dev/cec<dev> is used.\n"
+ " -D, --driver <driver> Use a cec device with this driver name\n"
+ " -a, --adapter <adapter> Use a cec device with this adapter name\n"
" -h, --help Display this help message\n"
" -n, --no-warnings Turn off warning messages\n"
" -T, --trace Trace all called ioctls\n"
@@ -296,7 +302,9 @@ void state_init(struct node &node)
int main(int argc, char **argv)
{
- const char *device = "/dev/cec0"; /* -d device */
+ std::string device;
+ const char *driver = NULL;
+ const char *adapter = NULL;
char short_options[26 * 2 * 2 + 1];
int idx = 0;
int fd = -1;
@@ -342,13 +350,19 @@ int main(int argc, char **argv)
return 0;
case OptSetDevice:
device = optarg;
- if (device[0] >= '0' && device[0] <= '9' && strlen(device) <= 3) {
+ if (device[0] >= '0' && device[0] <= '9' && device.length() <= 3) {
static char newdev[20];
- sprintf(newdev, "/dev/cec%s", device);
+ sprintf(newdev, "/dev/cec%s", optarg);
device = newdev;
}
break;
+ case OptSetDriver:
+ driver = optarg;
+ break;
+ case OptSetAdapter:
+ adapter = optarg;
+ break;
case OptNoWarnings:
show_warnings = false;
break;
@@ -385,8 +399,19 @@ int main(int argc, char **argv)
return 1;
}
- if ((fd = open(device, O_RDWR)) < 0) {
- fprintf(stderr, "Failed to open %s: %s\n", device,
+ if (device.empty() && (driver || adapter)) {
+ device = cec_device_find(driver, adapter);
+ if (device.empty()) {
+ fprintf(stderr,
+ "Could not find a CEC device for the given driver/adapter combination\n");
+ exit(1);
+ }
+ }
+ if (device.empty())
+ device = "/dev/cec0";
+
+ if ((fd = open(device.c_str(), O_RDWR)) < 0) {
+ fprintf(stderr, "Failed to open %s: %s\n", device.c_str(),
strerror(errno));
exit(1);
}
@@ -395,7 +420,7 @@ int main(int argc, char **argv)
struct cec_caps caps = { };
node.fd = fd;
- node.device = device;
+ node.device = device.c_str();
doioctl(&node, CEC_ADAP_G_CAPS, &caps);
node.caps = caps.capabilities;
node.available_log_addrs = caps.available_log_addrs;

Privacy Policy