From 4329a08403bc7b941271059c80d6dba01e85a02c Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 8 Nov 2016 13:24:02 +0000 Subject: [PATCH] demo/cmd: default to the 'read' subdevice instead of subdevice 0 If the '-s' option has not been specified, default to using the current 'read' subdevice if there is one instead of defaulting to subdevice 0. Fall back to using subdevice 0 if there is no 'read' subdevice. --- demo/cmd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/demo/cmd.c b/demo/cmd.c index 2934341..cd574e0 100644 --- a/demo/cmd.c +++ b/demo/cmd.c @@ -62,6 +62,7 @@ int main(int argc, char *argv[]) struct parsed_options options; init_parsed_options(&options); + options.subdevice = -1; parse_options(&options, argc, argv); /* The following variables used in this demo @@ -84,6 +85,17 @@ int main(int argc, char *argv[]) exit(1); } + if(options.subdevice < 0) { + /* Subdevice not set on command line. */ + /* Default to the 'read' subdevice (if any). */ + options.subdevice = comedi_get_read_subdevice(dev); + if(options.subdevice < 0) { + /* No 'read' subdevice, so default to 0 instead. */ + options.subdevice = 0; + } + fprintf(stderr, "defaulted to subdevice %d\n", options.subdevice); + } + // Print numbers for clipped inputs comedi_set_global_oor_behavior(COMEDI_OOR_NUMBER);