From 9799051d65f499b88c0829eaa8b1f60664c1f273 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 5 May 2003 03:18:19 +0000 Subject: [PATCH] fixed comedi_apply_calibration so it applies all matching calibrations instead of just the first one --- lib/calib.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/calib.c b/lib/calib.c index 0aa8cbd..b22b376 100644 --- a/lib/calib.c +++ b/lib/calib.c @@ -27,6 +27,9 @@ #include #include "libinternal.h" +static int set_calibration( comedi_t *dev, struct calibration_file_contents *parsed_file, + unsigned int cal_index ); + static int check_cal_file( comedi_t *dev, struct calibration_file_contents *parsed_file ) { if( strcmp( comedi_get_driver_name( dev ), parsed_file->driver_name ) ) @@ -94,10 +97,11 @@ static inline int valid_aref( struct calibration_file_contents *parsed_file, return 0; } -static int find_calibration( struct calibration_file_contents *parsed_file, +static int apply_calibration( comedi_t *dev, struct calibration_file_contents *parsed_file, unsigned int subdev, unsigned int channel, unsigned int range, unsigned int aref ) { - int num_cals, i; + int num_cals, i, retval; + int found_cal = 0; num_cals = parsed_file->num_calibrations; @@ -107,15 +111,18 @@ static int find_calibration( struct calibration_file_contents *parsed_file, if( valid_range( parsed_file, i, range ) == 0 ) continue; if( valid_channel( parsed_file, i, channel ) == 0 ) continue; if( valid_aref( parsed_file, i, aref ) == 0 ) continue; - break; + + retval = set_calibration( dev, parsed_file, i ); + if( retval < 0 ) return retval; + found_cal = 1; } - if( i == num_cals ) + if( found_cal == 0 ) { COMEDILIB_DEBUG( 3, "failed to find matching calibration\n" ); return -1; } - return i; + return 0; } static int set_calibration( comedi_t *dev, struct calibration_file_contents *parsed_file, @@ -148,7 +155,6 @@ int comedi_apply_calibration( comedi_t *dev, unsigned int subdev, unsigned int c struct stat file_stats; char file_path[ 1024 ]; int retval; - int cal_index; FILE *cal_file; struct calibration_file_contents *parsed_file; @@ -191,19 +197,10 @@ int comedi_apply_calibration( comedi_t *dev, unsigned int subdev, unsigned int c return retval; } - cal_index = find_calibration( parsed_file, subdev, channel, range, aref ); - if( cal_index < 0 ) - { - cleanup_calibration_parse( parsed_file ); - return cal_index; - } + retval = apply_calibration( dev, parsed_file, subdev, channel, range, aref ); + if( retval < 0 ) return retval; - retval = set_calibration( dev, parsed_file, cal_index ); - if( retval < 0 ) - { - cleanup_calibration_parse( parsed_file ); - return retval; - } + cleanup_calibration_parse( parsed_file ); return 0; } -- 2.26.2