3 functions for slowly varying inputs
5 COMEDILIB - Linux Control and Measurement Device Interface Library
6 Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation, version 2.1
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <sys/types.h>
31 #include <sys/ioctl.h>
35 #include "libinternal.h"
39 int sv_measure_l(comedi_sv_t *it,double *data);
40 int sv_measure_s(comedi_sv_t *it,double *data);
42 EXPORT_ALIAS_DEFAULT(_comedi_sv_init,comedi_sv_init,0.7.18);
43 int _comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan)
45 if(!valid_chan(dev,subd,chan))return -1;
48 memset(it,0,sizeof(*it));
55 return comedi_sv_update(it);
58 EXPORT_ALIAS_DEFAULT(_comedi_sv_update,comedi_sv_update,0.7.18);
59 int _comedi_sv_update(comedi_sv_t *it)
62 if(!valid_chan(it->dev,it->subdevice,it->chan))return -1;
64 it->maxdata=comedi_get_maxdata(it->dev,it->subdevice,it->chan);
66 /* check current range policy */
72 EXPORT_ALIAS_DEFAULT(_comedi_sv_measure,comedi_sv_measure,0.7.18);
73 int _comedi_sv_measure(comedi_sv_t *it,double *data)
75 if(it->dev->subdevices[it->subdevice].subd_flags & SDF_LSAMPL){
76 return sv_measure_l(it,data);
78 return sv_measure_s(it,data);
82 int sv_measure_l(comedi_sv_t *it,double *data)
93 val=malloc(sizeof(*val)*it->n);
95 chan=CR_PACK(it->chan,it->range,it->aref);
97 t.subdev=it->subdevice;
106 rng=comedi_get_range(it->dev,it->subdevice,it->chan,it->range);
109 t.data=(void *)(val+n);
111 i = comedi_ioctl(it->dev->fd, COMEDI_TRIG, (unsigned long)&t);
120 for(i=0;i<it->n;i++){
121 sum+=comedi_to_phys(val[i],rng,it->maxdata);
131 /* yes, these functions are _almost_ exactly the same... */
133 int sv_measure_s(comedi_sv_t *it,double *data)
144 val=malloc(sizeof(*val)*it->n);
146 chan=CR_PACK(it->chan,it->range,it->aref);
148 t.subdev=it->subdevice;
159 rng=comedi_get_range(it->dev,it->subdevice,it->chan,it->range);
164 i = comedi_ioctl(it->dev->fd, COMEDI_TRIG, (unsigned long)&t);
173 for(i=0;i<it->n;i++){
174 sum+=comedi_to_phys(val[i],rng,it->maxdata);