From 1e8ca17ba9ce239f6aaef23896940dd03ff8452c Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 8 Nov 2016 14:20:49 +0000 Subject: [PATCH] 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. --- demo/mmap.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/demo/mmap.c b/demo/mmap.c index 6be495b..e29a122 100644 --- a/demo/mmap.c +++ b/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");