Changed the name of verbose_flag; Added a few more flags in main.c
authorDavid Schleef <ds@schleef.org>
Sat, 14 Jul 2001 00:50:52 +0000 (00:50 +0000)
committerDavid Schleef <ds@schleef.org>
Sat, 14 Jul 2001 00:50:52 +0000 (00:50 +0000)
15 files changed:
demo/Makefile
demo/README
demo/antialias.c
demo/examples.h
demo/inp.c
demo/insn.c
demo/ledclock.c
demo/main.c
demo/mmap.c
demo/outp.c
demo/poll.c
demo/receiver.c
demo/select.c
demo/sigio.c
demo/sv.c

index e51ba5b946839d2c32db72d2e827b0cba43b479f..0c5f2095d6cb40b8f095e9c706bc8ae2348afa64 100644 (file)
@@ -1,7 +1,7 @@
 
 
 
-CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes
+CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes -g
 #CFLAGS += -I ../include -I . -Wall -Wstrict-prototypes -g
 LDFLAGS = -L../lib/ -lcomedi -lm
 
index 37109f6ba372fd50f93ef1e2fd83ed8b1ee43afe..f32bbf19edd566ad3ba7809f612941c8e652ed6b 100644 (file)
@@ -110,14 +110,17 @@ Many of these demos are linked with the file main.c, which parses
 command line options.  Some options don't make sense with all programs.
 The options are:
 
--a <aref>      use analog reference <aref> (default: 0 == ground)
--c <chan>      use channel <chan> (default: 0)
--s <subd>      use subdevice <subd> (default: 0)
--r <index>     use voltage range <index> (default: 0)
--f <file>      use device file <file> (default: /dev/comedi0)
--v             verbose
--d             set analog reference to differential
--g             set analog reference to ground
--o             set analog reference to other
--m             set analog reference to common
+  -a <aref>    use analog reference <aref> (default: 0 == ground)
+  -c <chan>    use channel <chan> (default: 0)
+  -s <subd>    use subdevice <subd> (default: 0)
+  -r <index>   use voltage range <index> (default: 0)
+  -f <file>    use device file <file> (default: /dev/comedi0)
+  -n <value>   use <value> for the number of channels in a scan
+  -N <value>   use <value> for the number of scans
+  -F <freq>    use <freq> as the scan frequency
+  -v           verbose
+  -d           set analog reference to differential
+  -g           set analog reference to ground
+  -o           set analog reference to other
+  -m           set analog reference to common
 
index b3881fd50474239318caed7e095d8026247cf256..2e1e95778da69df147fd099c2b1e7d97bb9bb9ea 100644 (file)
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
        }
 
        data = value; 
-       if(verbose_flag){
+       if(verbose){
                printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
                        data,filename,subdevice,channel,range,aref);
        }
index 41cc3bc077d6af7e39a56c8aeed9edcba2353b26..65dcb59f23b8857595376faa009baa94d760761f 100644 (file)
@@ -2,6 +2,8 @@
 #ifndef _EXAMPLES_H
 #define _EXAMPLES_H
 
+#include <stdio.h>
+
 /*
  * Definitions of some of the common code.
  */
@@ -15,10 +17,14 @@ extern int subdevice;
 extern int channel;
 extern int aref;
 extern int range;
+extern int verbose;
+extern int n_chan;
+extern int n_scan;
+extern double freq;
 
 int parse_options(int argc, char *argv[]);
 char *cmd_src(int src,char *buf);
-void dump_cmd(comedi_cmd *cmd);
+void dump_cmd(FILE *file,comedi_cmd *cmd);
 
 
 #define sec_to_nsec(x) ((x)*1000000000)
index 02425a653a60d4bd2fa0932c1f1b188f2eaf71a7..d09b1659fa492ffbea6c0ea8ca2dacc78760f2bf 100644 (file)
@@ -37,7 +37,7 @@ int main(int argc, char *argv[])
                exit(0);
        }
 
-       if(verbose_flag){
+       if(verbose){
                printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
                        filename,subdevice,channel,range,aref);
        }
index 96a1c1030d0978d269a96497c07b1bbbbe2ae4a8..59fbbb9b778d27543598a23ecd392fafa6282a61 100644 (file)
@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
                exit(0);
        }
 
-       if(verbose_flag){
+       if(verbose){
                printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
                        filename,subdevice,channel,range,aref);
        }
index 7a6f96d3aa2dd5beaaf611aab8f31e97872261fe..695583f100bddce6f13a0a45992ef06645cc8c45 100644 (file)
@@ -179,7 +179,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret=comedi_command_test(dev,cmd);
 
@@ -190,7 +190,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret=comedi_command(dev,cmd);
 
index e11a5ffc3648e62f8e76fdebc35015bdc4061125..a2e73d8497701cb08203632a1855f7efed335c99 100644 (file)
 #include <ctype.h>
 #include <malloc.h>
 #include <string.h>
+#include <stdlib.h>
 #include "examples.h"
 
 
 char *filename="/dev/comedi0";
-int verbose_flag;
+int verbose;
 
 int value=0;
 int subdevice=0;
 int channel=0;
-int aref=0;
+int aref=AREF_GROUND;
 int range=0;
+int n_chan=4;
+int n_scan=1000;
+double freq=1000.0;
 
 
 int parse_options(int argc, char *argv[])
@@ -30,37 +34,46 @@ int parse_options(int argc, char *argv[])
        int c;
 
 
-       while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:vdgom"))) {
+       while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:n:N:F:vdgom"))) {
                switch (c) {
                case 'f':
                        filename = optarg;
                        break;
                case 's':
-                       sscanf(optarg,"%d",&subdevice);
+                       subdevice = strtoul(optarg,NULL,0);
                        break;
                case 'c':
-                       sscanf(optarg,"%d",&channel);
+                       channel = strtoul(optarg,NULL,0);
                        break;
                case 'a':
-                       sscanf(optarg,"%d",&aref);
+                       aref = strtoul(optarg,NULL,0);
                        break;
                case 'r':
-                       sscanf(optarg,"%d",&range);
+                       range = strtoul(optarg,NULL,0);
+                       break;
+               case 'n':
+                       n_chan = strtoul(optarg,NULL,0);
+                       break;
+               case 'N':
+                       n_scan = strtoul(optarg,NULL,0);
+                       break;
+               case 'F':
+                       freq = strtoul(optarg,NULL,0);
                        break;
                case 'v':
-                       verbose_flag = 1;
+                       verbose = 1;
                        break;
                case 'd':
-                       aref=AREF_DIFF;
+                       aref = AREF_DIFF;
                        break;
                case 'g':
-                       aref=AREF_GROUND;
+                       aref = AREF_GROUND;
                        break;
                case 'o':
-                       aref=AREF_OTHER;
+                       aref = AREF_OTHER;
                        break;
                case 'm':
-                       aref=AREF_COMMON;
+                       aref = AREF_COMMON;
                        break;
                default:
                        printf("bad option\n");
@@ -87,9 +100,12 @@ char *cmd_src(int src,char *buf)
        if(src&TRIG_COUNT)strcat(buf, "count|");
        if(src&TRIG_EXT)strcat(buf, "ext|");
        if(src&TRIG_INT)strcat(buf, "int|");
+#ifdef TRIG_OTHER
+       if(src&TRIG_OTHER)strcat(buf, "other|");
+#endif
 
        if(strlen(buf)==0){
-               sprintf(buf,"unknown(0x%02x)",src);
+               sprintf(buf,"unknown(0x%08x)",src);
        }else{
                buf[strlen(buf)-1]=0;
        }
@@ -97,27 +113,27 @@ char *cmd_src(int src,char *buf)
        return buf;
 }
 
-void dump_cmd(comedi_cmd *cmd)
+void dump_cmd(FILE *out,comedi_cmd *cmd)
 {
        char buf[100];
 
-       printf("start: %s %d\n",
+       fprintf(out,"start:      %-8s %d\n",
                cmd_src(cmd->start_src,buf),
                cmd->start_arg);
 
-       printf("scan_begin: %s %d\n",
+       fprintf(out,"scan_begin: %-8s %d\n",
                cmd_src(cmd->scan_begin_src,buf),
                cmd->scan_begin_arg);
 
-       printf("convert: %s %d\n",
+       fprintf(out,"convert:    %-8s %d\n",
                cmd_src(cmd->convert_src,buf),
                cmd->convert_arg);
 
-       printf("scan_end: %s %d\n",
+       fprintf(out,"scan_end:   %-8s %d\n",
                cmd_src(cmd->scan_end_src,buf),
                cmd->scan_end_arg);
 
-       printf("stop: %s %d\n",
+       fprintf(out,"stop:       %-8s %d\n",
                cmd_src(cmd->stop_src,buf),
                cmd->stop_arg);
 }
index f2aef3bf16fd68c0e76358bcffe621c578bd9a5d..301e19e553070f8fbceb3838e522da0569bd274c 100644 (file)
@@ -30,8 +30,6 @@
 #define N_SCANS                10
 #define N_CHANS                16
 
-double freq = 1000;
-
 #define BUFSZ 1000
 char buf[BUFSZ];
 
@@ -80,7 +78,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret = comedi_command_test(dev,cmd);
 
@@ -91,7 +89,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret = comedi_command(dev,cmd);
 
index 6fafef75138e46cc56fdc899b35723a7d4f0fa64..9a54b8533758fcf603e2ab5d0386ae3fba77f9fd 100644 (file)
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
        }
 
        data = value; 
-       if(verbose_flag){
+       if(verbose){
                printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
                        data,filename,subdevice,channel,range,aref);
        }
index 3ee5a0b77c4e136789ff9ed810acc3da019b2796..3acb8645f4ee551317a8f75f446e3042f9d2579b 100644 (file)
@@ -29,8 +29,6 @@
 #define N_SCANS                10
 #define N_CHANS                16
 
-double freq = 1000;
-
 #define BUFSZ 1000
 sampl_t buf[BUFSZ];
 
@@ -99,7 +97,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret=comedi_command_test(dev,cmd);
 
@@ -110,7 +108,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret=comedi_command(dev,cmd);
 
index 4bddf5194d52864ce9d380769535697b68cfe0ca..c0e687ef4dd85c0474f1d0c60c0762d0f41afc1b 100644 (file)
@@ -97,7 +97,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        cmd->chanlist =         chanlist;
        cmd->chanlist_len =     n_chans;
@@ -111,7 +111,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        cmd->chanlist =         chanlist;
        cmd->chanlist_len =     n_chans;
index 5e59c98140967c0c75a576bae33765dd665b3824..aeba724c8fb7cc4293921b285d6b292afd3d613b 100644 (file)
@@ -29,8 +29,6 @@
 #define N_SCANS                10
 #define N_CHANS                16
 
-double freq = 1000;
-
 #define BUFSZ 1000
 sampl_t buf[BUFSZ];
 
@@ -94,7 +92,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret=comedi_command_test(dev,cmd);
 
@@ -105,7 +103,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret=comedi_command(dev,cmd);
 
index 15bd4dfad53925cb8d25e182d8a628dd56b283e8..e096030e41f9e868421db6685d38466d261b6f74 100644 (file)
@@ -142,7 +142,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret=comedi_command_test(dev,cmd);
 
@@ -153,7 +153,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
                return;
        }
 
-       dump_cmd(cmd);
+       dump_cmd(stdout,cmd);
 
        ret=comedi_command(dev,cmd);
 
index 14c7c435841ec9f03c4cbc6e92a346bce2a9420f..ae51115f231a84849169ed5ecffa97a5bc9647f4 100644 (file)
--- a/demo/sv.c
+++ b/demo/sv.c
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
                exit(0);
        }
 
-       if(verbose_flag){
+       if(verbose){
                printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
                        filename,subdevice,channel,range,aref);
        }