void generic_prep_dac_caldacs( calibration_setup_t *setup, const generic_layout_t *layout, unsigned int channel, unsigned int range ) { int retval; if( setup->da_subdev < 0 ) return; if( setup->old_calibration == NULL ) { reset_caldac( setup, layout->dac_offset( channel ) ); reset_caldac( setup, layout->dac_gain( channel ) ); reset_caldac( setup, layout->dac_linearity( channel ) ); reset_caldac( setup, layout->dac_offset_fine( channel ) ); reset_caldac( setup, layout->dac_gain_fine( channel ) ); reset_caldac( setup, layout->dac_linearity_fine( channel ) ); }else { retval = comedi_apply_parsed_calibration( setup->dev, setup->da_subdev, channel, range, AREF_GROUND, setup->old_calibration ); if( retval < 0 ) { DPRINT( 0, "Failed to apply existing calibration, reseting dac caldacs.\n" ); reset_caldac( setup, layout->dac_offset( channel ) ); reset_caldac( setup, layout->dac_gain( channel ) ); reset_caldac( setup, layout->dac_linearity( channel ) ); reset_caldac( setup, layout->dac_offset_fine( channel ) ); reset_caldac( setup, layout->dac_gain_fine( channel ) ); reset_caldac( setup, layout->dac_linearity_fine( channel ) ); } } }
static void generic_prep_adc_for_dac( calibration_setup_t *setup, comedi_calibration_t *calibration, int observable ) { unsigned int adc_channel, adc_range; int chanspec; if( observable < 0 ) return; chanspec = setup->observables[ observable ].observe_insn.chanspec; adc_channel = CR_CHAN( chanspec ); adc_range = CR_RANGE( chanspec ); comedi_apply_parsed_calibration( setup->dev, setup->ad_subdev, adc_channel, adc_range, 0, calibration ); }
/** * facq_comedi_misc_get_polynomial: * @dev: A comedi_t device. * @subindex: The subdevice index. * @chanlist: A #FacqChanlist object. * @err: A #GError. * * The functions makes some magic to obtain a per channel, * comedi_polynomial_t array. Each polynomial can be used * to convert from comedi data to physical samples. * See <function>comedi_to_physical()</function> for more * info. * * Returns: An array of comedi_polynomial_t members. Free it * when it's no longer needed. %NULL in case of error. * The array length equals the number of I/O Channels in the * chanlist. */ comedi_polynomial_t *facq_comedi_misc_get_polynomial(comedi_t *dev,guint subindex,const FacqChanlist *chanlist,GError **err) { guint subd_flags = 0; guint i = 0, chan = 0, range = 0, aref = 0, iochans_n = 0; guint chanspec = 0; gchar *cal_filename = NULL; comedi_calibration_t *cc = NULL; GError *local_err = NULL; comedi_polynomial_t *p = NULL; g_return_val_if_fail(FACQ_IS_CHANLIST(chanlist),NULL); iochans_n = facq_chanlist_get_io_chans_n(chanlist); if(iochans_n < 1){ g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR, FACQ_COMEDI_MISC_ERROR_FAILED, "Chanlist is empty"); goto error; } cal_filename = comedi_get_default_calibration_path(dev); if(!cal_filename){ g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR, FACQ_COMEDI_MISC_ERROR_FAILED, comedi_strerror(comedi_errno())); goto error; } cc = comedi_parse_calibration_file(cal_filename); if(!cc){ g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR, FACQ_COMEDI_MISC_ERROR_FAILED, comedi_strerror(comedi_errno())); goto error; } g_free(cal_filename); subd_flags = comedi_get_subdevice_flags(dev,subindex); if(subd_flags < 0){ g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR, FACQ_COMEDI_MISC_ERROR_FAILED, comedi_strerror(comedi_errno())); goto error; } for(i = 0;i < iochans_n;i++){ chanspec = facq_chanlist_get_io_chanspec(chanlist,i); facq_chanlist_chanspec_to_src_values(chanspec, &chan, &range, &aref, NULL); if( comedi_apply_parsed_calibration(dev,subindex, chan, range, aref, cc) < 0){ g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR, FACQ_COMEDI_MISC_ERROR_FAILED, comedi_strerror(comedi_errno())); goto error; } } if(subd_flags & SDF_SOFT_CALIBRATED){ p = facq_comedi_misc_get_polynomial_soft(dev, subindex, chanlist, cc, &local_err); comedi_cleanup_calibration(cc); } else { comedi_cleanup_calibration(cc); p = facq_comedi_misc_get_polynomial_hard(dev, subindex, chanlist, &local_err); } if(!p) goto error; return p; error: if(cal_filename) g_free(cal_filename); if(cc) comedi_cleanup_calibration(cc); if(local_err) g_propagate_error(err,local_err); return NULL; }