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>
36 #include <libinternal.h>
40 int sv_measure_l(comedi_sv_t *it,double *data);
41 int sv_measure_s(comedi_sv_t *it,double *data);
44 int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan)
46 if(!valid_chan(dev,subd,chan))return -1;
49 memset(it,0,sizeof(*it));
56 return comedi_sv_update(it);
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 int comedi_sv_measure(comedi_sv_t *it,double *data)
74 if(it->dev->subdevices[it->subdevice].subd_flags & SDF_LSAMPL){
75 return sv_measure_l(it,data);
77 return sv_measure_s(it,data);
81 int sv_measure_l(comedi_sv_t *it,double *data)
92 val=malloc(sizeof(*val)*it->n);
94 chan=CR_PACK(it->chan,it->range,it->aref);
96 t.subdev=it->subdevice;
105 rng=comedi_get_range(it->dev,it->subdevice,it->chan,it->range);
108 t.data=(void *)(val+n);
110 i=ioctl_trigger(it->dev->fd,&t);
119 for(i=0;i<it->n;i++){
120 sum+=comedi_to_phys(val[i],rng,it->maxdata);
130 /* yes, these functions are _almost_ exactly the same... */
132 int sv_measure_s(comedi_sv_t *it,double *data)
143 val=malloc(sizeof(*val)*it->n);
145 chan=CR_PACK(it->chan,it->range,it->aref);
147 t.subdev=it->subdevice;
158 rng=comedi_get_range(it->dev,it->subdevice,it->chan,it->range);
163 i=ioctl_trigger(it->dev->fd,&t);
172 for(i=0;i<it->n;i++){
173 sum+=comedi_to_phys(val[i],rng,it->maxdata);