demo/mmap: default to '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:
parent
c2cf7c8018
commit
1e8ca17ba9
1 changed files with 12 additions and 0 deletions
12
demo/mmap.c
12
demo/mmap.c
|
@ -50,6 +50,7 @@ int main(int argc, char *argv[])
|
|||
struct parsed_options options;
|
||||
|
||||
init_parsed_options(&options);
|
||||
options.subdevice = -1;
|
||||
parse_options(&options, argc, argv);
|
||||
|
||||
dev = comedi_open(options.filename);
|
||||
|
@ -58,6 +59,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);
|
||||
}
|
||||
|
||||
ret = comedi_get_buffer_size(dev, options.subdevice);
|
||||
if(ret < 0){
|
||||
comedi_perror("comedi_get_buffer_size");
|
||||
|
|
Loading…
Add table
Reference in a new issue