Avoid mixing declarations and code.
[comedilib.git] / demo / choose_filter.c
1 /*
2  * INSN_CONFIG_FILTER example
3  * Part of Comedilib
4  *
5  * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
6  * Copyright (c) 2007 Frank Mori Hess <fmhess@users.sourceforge.net>
7  *
8  * This file may be freely modified, distributed, and combined with
9  * other software, as long as proper attribution is given in the
10  * source code.
11  */
12 /*
13  * Requirements:  A board with a subdevice that supports
14  *    INSN_CONFIG_FILTER, such as the PFI subdevice on an NI m-series
15  *    or 660x board.
16  */
17
18 #define _GNU_SOURCE
19
20 #include <stdio.h>
21 #include <comedilib.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27 #include <getopt.h>
28 #include <ctype.h>
29 #include "examples.h"
30
31
32 comedi_t *device;
33
34 int main(int argc, char *argv[])
35 {
36         int retval;
37         lsampl_t filter_selection;
38         struct parsed_options options;
39         comedi_insn insn;
40         lsampl_t data[2];
41
42         init_parsed_options(&options);
43         parse_options(&options, argc, argv);
44
45         device = comedi_open(options.filename);
46         if(!device){
47                 comedi_perror(options.filename);
48                 exit(-1);
49         }
50         filter_selection = options.value;
51         printf("Selecting filter %d on subdevice %d channel %d.\n", filter_selection, options.subdevice, options.channel);
52         memset(&insn, 0, sizeof(comedi_insn));
53         insn.insn = INSN_CONFIG;
54         insn.subdev = options.subdevice;
55         insn.chanspec = options.channel;
56         insn.data = data;
57         insn.n = sizeof(data) / sizeof(data[0]);
58         data[0] = INSN_CONFIG_FILTER;
59         data[1] = filter_selection;
60
61         retval = comedi_do_insn(device, &insn);
62         if(retval < 0) comedi_perror("comedi_do_insn");
63         return retval;
64 }
65