}
-static float sensor_get_max_freq (int s)
+float sensor_get_max_freq (int s)
{
float max_freq;
return 1; /* OK to use modified ordering map */
}
+int sensor_get_available_frequencies (int s)
+{
+ int dev_num = sensor[s].dev_num, err, i;
+ char avail_sysfs_path[PATH_MAX], freqs_buf[100];
+ char *p, *end;
+ float f;
+
+ sensor[s].avail_freqs_count = 0;
+ sensor[s].avail_freqs = 0;
+
+ sprintf(avail_sysfs_path, DEVICE_AVAIL_FREQ_PATH, dev_num);
+
+ err = sysfs_read_str(avail_sysfs_path, freqs_buf, sizeof(freqs_buf));
+ if (err < 0)
+ return 0;
+
+ for (p = freqs_buf, f = strtof(p, &end); p != end; p = end, f = strtof(p, &end))
+ sensor[s].avail_freqs_count++;
+
+ if (sensor[s].avail_freqs_count) {
+ sensor[s].avail_freqs = (float*) calloc(sensor[s].avail_freqs_count, sizeof(float));
+
+ for (p = freqs_buf, f = strtof(p, &end), i = 0; p != end; p = end, f = strtof(p, &end), i++)
+ sensor[s].avail_freqs[i] = f;
+ }
+
+ return 0;
+}
+
int sensor_get_mounting_matrix (int s, float mm[9])
{
int dev_num = sensor[s].dev_num, err, i;
*/
max_delay_t sensor_get_max_delay (int s)
{
- char avail_sysfs_path[PATH_MAX];
- int dev_num = sensor[s].dev_num;
- char freqs_buf[100];
- char* cursor;
+ int dev_num = sensor[s].dev_num, i;
float min_supported_rate;
float rate_cap;
- float sr;
/*
* continuous, on-change: maximum sampling period allowed in microseconds.
switch (sensor[s].mode) {
case MODE_TRIGGER:
/* For interrupt-based devices, obey the list of supported sampling rates */
- sprintf(avail_sysfs_path, DEVICE_AVAIL_FREQ_PATH, dev_num);
- if (sysfs_read_str(avail_sysfs_path, freqs_buf, sizeof(freqs_buf)) > 0) {
-
+ if (!(sensor_get_quirks(s) & QUIRK_HRTIMER) &&
+ sensor[s].avail_freqs_count) {
min_supported_rate = 1000;
- cursor = freqs_buf;
-
- while (*cursor && cursor[0]) {
-
- /* Decode a single value */
- sr = strtod(cursor, NULL);
-
- if (sr < min_supported_rate)
- min_supported_rate = sr;
-
- /* Skip digits */
- while (cursor[0] && !isspace(cursor[0]))
- cursor++;
-
- /* Skip spaces */
- while (cursor[0] && isspace(cursor[0]))
- cursor++;
+ for (i = 0; i < sensor[s].avail_freqs_count; i++) {
+ if (sensor[s].avail_freqs[i] < min_supported_rate)
+ min_supported_rate = sensor[s].avail_freqs[i];
}
-
break;
}
-
/* Fall through ... */
default:
int32_t sensor_get_min_delay (int s)
{
- char avail_sysfs_path[PATH_MAX];
- int dev_num = sensor[s].dev_num;
- char freqs_buf[100];
- char* cursor;
+ int dev_num = sensor[s].dev_num, i;
float max_supported_rate = 0;
float max_from_prop = sensor_get_max_freq(s);
- float sr;
+ int hrtimer_quirk_enabled = sensor_get_quirks(s) & QUIRK_HRTIMER;
/* continuous, on change: minimum sampling period allowed in microseconds.
* special : 0, unless otherwise noted
}
}
- sprintf(avail_sysfs_path, DEVICE_AVAIL_FREQ_PATH, dev_num);
-
- if (sysfs_read_str(avail_sysfs_path, freqs_buf, sizeof(freqs_buf)) < 0) {
- if (sensor[s].mode == MODE_POLL) {
+ if (hrtimer_quirk_enabled || !sensor[s].avail_freqs_count) {
+ if (hrtimer_quirk_enabled || (sensor[s].mode == MODE_POLL)) {
/* If we have max specified via a property use it */
if (max_from_prop != ANDROID_MAX_FREQ)
max_supported_rate = max_from_prop;
max_supported_rate = get_cdd_freq(s, 0);
}
} else {
- cursor = freqs_buf;
- while (*cursor && cursor[0]) {
-
- /* Decode a single value */
- sr = strtod(cursor, NULL);
-
- if (sr > max_supported_rate && sr <= max_from_prop)
- max_supported_rate = sr;
-
- /* Skip digits */
- while (cursor[0] && !isspace(cursor[0]))
- cursor++;
-
- /* Skip spaces */
- while (cursor[0] && isspace(cursor[0]))
- cursor++;
+ for (i = 0; i < sensor[s].avail_freqs_count; i++) {
+ if (sensor[s].avail_freqs[i] > max_supported_rate &&
+ sensor[s].avail_freqs[i] <= max_from_prop) {
+ max_supported_rate = sensor[s].avail_freqs[i];
+ }
}
}