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.
This commit is contained in:
Ian Abbott 2016-11-08 13:24:02 +00:00
parent 9cf2bba2e0
commit 4329a08403

View file

@ -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);