From 21423c3785df243d03cde5bc7817445f95e8fba1 Mon Sep 17 00:00:00 2001 From: mjc Date: Sat, 1 Jan 2000 00:01:01 +0900 Subject: make self-cal min count configurable --- device-functions.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'device-functions.c') diff --git a/device-functions.c b/device-functions.c index 9f3a086..b6df2af 100644 --- a/device-functions.c +++ b/device-functions.c @@ -65,11 +65,27 @@ static float get_bounded_float (float val_in, float default_val) { // limits returned value within +/- 1 order of magnitude - if (val_in > 10.0 * default_val) { + if (val_in > (10.0 * default_val)) { return default_val; } - if (val_in < default_val / 10.0) { + if (val_in < (default_val / 10.0)) { + return default_val; + } + + return val_in; +} + + +static int get_bounded_int (int val_in, int default_val) +{ + // limits returned value within +/- 1 order of magnitude + + if (val_in > (10 * default_val)) { + return default_val; + } + + if (val_in < (default_val / 10)) { return default_val; } @@ -81,7 +97,7 @@ static float get_float_with_min (float val_in, float default_val) { // limits returned value within +2 / -0 order of magnitude - if (val_in > 100.0 * default_val) { + if (val_in > (100.0 * default_val)) { return default_val; } @@ -3916,7 +3932,9 @@ int go_cal(CalStruct *caldata) caldata->max_change = 0.0; caldata->avg_change = 0.0; - min_val = 40e-6; + min_val = get_bounded_int (globals.Flash.self_cal_min_count, SELF_CAL_MIN_COUNT) / + get_bounded_float (globals.Flash.self_cal_ref_freq, SELF_CAL_REF_FREQ); + if (caldata->cal_type == pwl_period_values) { max_val = 4.0 / globals.Flash.min_freq[caldata->channel]; chk_val = 0.25 / globals.Flash.max_freq[caldata->channel]; -- cgit