#include <fcntl.h>
#include <pthread.h>
#include <time.h>
+#include <math.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <utils/Log.h>
/* 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,
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,