don't save multiple values for the same caldac channel
authorFrank Mori Hess <fmhess@speakeasy.net>
Sun, 20 Jul 2003 03:20:50 +0000 (03:20 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sun, 20 Jul 2003 03:20:50 +0000 (03:20 +0000)
comedi_calibrate/save_cal.c

index 521f0a39a1c4c585841f870bd707b9bf194c511d..60ee087dd036199dfd6490335514bb4be5f24e82 100644 (file)
@@ -157,6 +157,20 @@ comedi_calibration_setting_t* sc_alloc_calibration_setting( calibration_setup_t
 
 void sc_push_caldac( comedi_calibration_setting_t *saved_cal, caldac_t caldac )
 {
+       int i;
+
+       /* check if caldac is already listed, in which case we just update */
+       for( i = 0; i < saved_cal->num_caldacs; i++ )
+       {
+               if( saved_cal->caldacs[ i ].subdevice != caldac.subdev ) continue;
+               if( saved_cal->caldacs[ i ].channel != caldac.chan ) continue;
+               break;
+       }
+       if( i < saved_cal->num_caldacs )
+       {
+               saved_cal->caldacs[ i ].value = caldac.current;
+               return;
+       }
        saved_cal->caldacs = realloc( saved_cal->caldacs,
                ( saved_cal->num_caldacs + 1 ) * sizeof( caldac_t ) );
        if( saved_cal->caldacs == NULL )