X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=control.c;h=14f5570fbf219e80873d5a12be93a11f80906127;hb=cce276f500d0c229e86314924c4e9dcf295e0ae6;hp=e1268a87626f26306841b3a2757b09837372cb8f;hpb=a4acc701321c8171dd1beb7029fbcfbd34fbf92c;p=android-x86%2Fhardware-intel-libsensors.git diff --git a/control.c b/control.c index e1268a8..14f5570 100644 --- a/control.c +++ b/control.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -816,9 +817,15 @@ static int setup_delay_sysfs (int s, float requested_rate) /* Decode a single value */ sr = strtod(cursor, NULL); - /* If this matches the selected rate, we're happy */ - if (arb_sampling_rate == sr) + /* + * If this matches the selected rate, we're happy. + * Have some tolerance to counter rounding errors and + * avoid needless jumps to higher rates. + */ + if (fabs(arb_sampling_rate - sr) <= 0.001) { + arb_sampling_rate = sr; break; + } /* * If we reached a higher value than the desired rate, @@ -1540,7 +1547,7 @@ int sensor_set_delay (int s, int64_t ns) return -EINVAL; } - requested_sampling_rate = 1000000000LL/ns; + requested_sampling_rate = 1000000000.0/ns; ALOGV("Entering set delay S%d (%s): current rate: %f, requested: %f\n", s, sensor[s].friendly_name, sensor[s].sampling_rate,