added a couple convenience functions
authorFrank Mori Hess <fmhess@speakeasy.net>
Wed, 5 Feb 2003 19:04:53 +0000 (19:04 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Wed, 5 Feb 2003 19:04:53 +0000 (19:04 +0000)
comedi_calibrate/calib.h
comedi_calibrate/cb.c
comedi_calibrate/save_cal.c

index 84f0171084a8412f888c118c343ef17cd45650b4..5efa2d2b087dd88464f460abfe9398bd9e975429 100644 (file)
@@ -191,30 +191,38 @@ int new_sv_measure(comedi_t *dev, new_sv_t *sv);
 int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,unsigned int chanspec);
 
 /* saving calibrations to file */
-#define CAL_MAX_CHANNELS_LENGTH 128
-#define CAL_MAX_RANGES_LENGTH 128
-#define CAL_MAX_AREFS_LENGTH 16
+#define SC_MAX_CHANNELS_LENGTH 128
+#define SC_MAX_RANGES_LENGTH 128
+#define SC_MAX_AREFS_LENGTH 4
 typedef struct
 {
        unsigned int subdevice;
        caldac_t caldacs[ N_CALDACS ];
        unsigned int caldacs_length;
        /* channels that caldac settings are restricted to */
-       int channels[ CAL_MAX_CHANNELS_LENGTH ];
+       int channels[ SC_MAX_CHANNELS_LENGTH ];
        /* number of elements in channels array, 0 means allow all channels */
        unsigned int channels_length;
        /* ranges that caldac settings are restricted to */
-       int ranges[ CAL_MAX_RANGES_LENGTH ];
+       int ranges[ SC_MAX_RANGES_LENGTH ];
        /* number of elements in ranges array, 0 means allow all ranges */
        unsigned int ranges_length;
        /* arefs that caldac settings are used restricted to */
-       int arefs[ CAL_MAX_AREFS_LENGTH ];
+       int arefs[ SC_MAX_AREFS_LENGTH ];
        /* number of elements in arefs array, 0 means allow any aref */
        unsigned int arefs_length;
 } saved_calibration_t;
 
+static const int SC_ALL_CHANNELS = -1;
+static const int SC_ALL_RANGES = -1;
+static const int SC_ALL_AREFS = -1;
+
 int write_calibration_file( comedi_t *dev, saved_calibration_t settings[],
        unsigned int num_settings );
+void sc_push_caldac( saved_calibration_t *saved_cal, caldac_t caldac );
+void sc_push_channel( saved_calibration_t *saved_cal, int channel );
+void sc_push_range( saved_calibration_t *saved_cal, int range );
+void sc_push_aref( saved_calibration_t *saved_cal, int aref );
 
 #endif
 
index 0467b566026ada529f905554ae4bb2055e8686bf..25e0b8d599add9796f14f53560dc731031e21116 100644 (file)
@@ -768,32 +768,20 @@ int cal_cb_pci_60xx( calibration_setup_t *setup )
                ADC_GAIN_FINE,
        };
 
-       cal1( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_COARSE );
-       cal1_fine( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_COARSE );
-
-       cal1( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_FINE );
-       cal1_fine( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_FINE );
-
-       cal1( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_COARSE );
-       cal1_fine( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_COARSE );
-
-       cal1( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_FINE );
-       cal1_fine( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_FINE );
+       cal_binary( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_COARSE );
+       cal_binary( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_FINE );
+       cal_binary( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_COARSE );
+       cal_binary( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_FINE );
 
+       memset( &saved_cals[ 0 ], 0, sizeof( saved_calibration_t ) );
        saved_cals[ 0 ].subdevice = setup->ad_subdev;
-       saved_cals[ 0 ].caldacs_length = 0;
-       saved_cals[ 0 ].caldacs[ saved_cals[ 0 ].caldacs_length++ ] =
-               setup->caldacs[ ADC_OFFSET_FINE ];
-       saved_cals[ 0 ].caldacs[ saved_cals[ 0 ].caldacs_length++ ] =
-               setup->caldacs[ ADC_OFFSET_COARSE ];
-       saved_cals[ 0 ].caldacs[ saved_cals[ 0 ].caldacs_length++ ] =
-               setup->caldacs[ ADC_GAIN_COARSE ];
-       saved_cals[ 0 ].caldacs[ saved_cals[ 0 ].caldacs_length++ ] =
-               setup->caldacs[ ADC_GAIN_FINE ];
-       saved_cals[ 0 ].channels_length = 0;
-       saved_cals[ 0 ].ranges[ 0 ] = 0;
-       saved_cals[ 0 ].ranges_length = 1;
-       saved_cals[ 0 ].arefs_length = 0;
+       sc_push_caldac( &saved_cals[ 0 ], setup->caldacs[ ADC_OFFSET_FINE ] );
+       sc_push_caldac( &saved_cals[ 0 ], setup->caldacs[ ADC_OFFSET_COARSE ] );
+       sc_push_caldac( &saved_cals[ 0 ], setup->caldacs[ ADC_GAIN_FINE ] );
+       sc_push_caldac( &saved_cals[ 0 ], setup->caldacs[ ADC_GAIN_COARSE ] );
+       sc_push_channel( &saved_cals[ 0 ], SC_ALL_CHANNELS );
+       sc_push_range( &saved_cals[ 0 ], 0 );
+       sc_push_aref( &saved_cals[ 0 ], SC_ALL_AREFS );
 
        return write_calibration_file( setup->dev, saved_cals, 1 );
 }
index 29ae984a76cb26eb8d9c566176591fbbbfc858b0..e35605c3dad928642f5e75e0041dfe7fb5f43916 100644 (file)
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <assert.h>
 
 #include <comedilib.h>
 
@@ -117,7 +118,7 @@ int write_calibration_file( comedi_t *dev, saved_calibration_t settings[],
 
        if( fstat( comedi_fileno( dev ), &file_stats ) < 0 )
        {
-               fprintf( stderr, "failed to get dev_t of comedi device file\n" );
+               fprintf( stderr, "failed to get file stats of comedi device file\n" );
                return -1;
        }
 
@@ -144,3 +145,40 @@ int write_calibration_file( comedi_t *dev, saved_calibration_t settings[],
 
        return retval;
 }
+
+void sc_push_caldac( saved_calibration_t *saved_cal, caldac_t caldac )
+{
+       assert( saved_cal->caldacs_length < N_CALDACS );
+
+       saved_cal->caldacs[ saved_cal->caldacs_length++ ] = caldac;
+}
+
+void sc_push_channel( saved_calibration_t *saved_cal, int channel )
+{
+       assert( saved_cal->channels_length < SC_MAX_CHANNELS_LENGTH );
+
+       if( channel == SC_ALL_CHANNELS )
+               saved_cal->channels_length = 0;
+       else
+               saved_cal->channels[ saved_cal->channels_length++ ] = channel;
+}
+
+void sc_push_range( saved_calibration_t *saved_cal, int range )
+{
+       assert( saved_cal->ranges_length < SC_MAX_RANGES_LENGTH );
+
+       if( range == SC_ALL_RANGES )
+               saved_cal->ranges_length = 0;
+       else
+               saved_cal->ranges[ saved_cal->ranges_length++ ] = range;
+}
+
+void sc_push_aref( saved_calibration_t *saved_cal, int aref )
+{
+       assert( saved_cal->arefs_length < SC_MAX_AREFS_LENGTH );
+
+       if( aref == SC_ALL_AREFS )
+               saved_cal->arefs_length = 0;
+       else
+               saved_cal->arefs[ saved_cal->arefs_length++ ] = aref;
+}