X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=description.c;h=302121fc05b4c4aed8a200ed1eb148484fafbf39;hb=378432a4f0cb62a7189340ee1424a529fcf2085a;hp=6d3239eb5ff43fa66e355a2fab246fef542b3eab;hpb=848c7083560fa745297e3a63694fbac41664c86c;p=android-x86%2Fhardware-intel-libsensors.git diff --git a/description.c b/description.c index 6d3239e..302121f 100644 --- a/description.c +++ b/description.c @@ -92,6 +92,7 @@ int sensor_get_st_prop (int s, const char* sel, char val[MAX_NAME_SIZE]) int i = sensor[s].catalog_index; const char *prefix = sensor_catalog[i].tag; + const char *shorthand = sensor_catalog[i].shorthand; /* First try most specialized form, like ro.iio.anglvel.bmg160.name */ @@ -106,9 +107,19 @@ int sensor_get_st_prop (int s, const char* sel, char val[MAX_NAME_SIZE]) return 0; } + if (shorthand[0] != '\0') { + /* Try with shorthand instead of prefix */ + snprintf(prop_name, PROP_NAME_MAX, PROP_BASE, shorthand, extended_sel); + + if (property_get(prop_name, prop_val, "")) { + strncpy(val, prop_val, MAX_NAME_SIZE-1); + val[MAX_NAME_SIZE-1] = '\0'; + return 0; + } + } /* Fall back to simple form, like ro.iio.anglvel.name */ - sprintf(prop_name, PROP_BASE, prefix, sel); + snprintf(prop_name, PROP_NAME_MAX, PROP_BASE, prefix, sel); if (property_get(prop_name, prop_val, "")) { strncpy(val, prop_val, MAX_NAME_SIZE-1); @@ -229,7 +240,7 @@ float sensor_get_max_range (int s) /* We should cap returned samples accordingly... */ - switch (sensor[s].type) { + switch (sensor_desc[s].type) { case SENSOR_TYPE_ACCELEROMETER: /* m/s^2 */ return 50; @@ -371,6 +382,24 @@ uint32_t sensor_get_quirks (int s) if (strstr(quirks_buf, "noisy")) sensor[s].quirks |= QUIRK_NOISY; + if (strstr(quirks_buf, "biased")) + sensor[s].quirks |= QUIRK_BIASED; + + if (strstr(quirks_buf, "spotty")) + sensor[s].quirks |= QUIRK_SPOTTY; + + if (strstr(quirks_buf, "no-event")) + sensor[s].quirks |= QUIRK_NO_EVENT_MODE; + + if (strstr(quirks_buf, "no-trig")) + sensor[s].quirks |= QUIRK_NO_TRIG_MODE; + + if (strstr(quirks_buf, "no-poll")) + sensor[s].quirks |= QUIRK_NO_POLL_MODE; + + if (strstr(quirks_buf, "hrtimer")) + sensor[s].quirks |= QUIRK_HRTIMER; + sensor[s].quirks |= QUIRK_ALREADY_DECODED; } @@ -401,10 +430,45 @@ int sensor_get_order (int s, unsigned char map[MAX_CHANNELS]) return 1; /* OK to use modified ordering map */ } +int sensor_get_mounting_matrix (int s, float mm[9]) +{ + int dev_num = sensor[s].dev_num, err, i; + char mm_path[PATH_MAX], mm_buf[100]; + char *tmp1 = mm_buf, *tmp2; + + switch (sensor[s].type) { + case SENSOR_TYPE_ACCELEROMETER: + case SENSOR_TYPE_MAGNETIC_FIELD: + case SENSOR_TYPE_GYROSCOPE: + break; + default: + return 0; + } + + sprintf(mm_path, MOUNTING_MATRIX_PATH, dev_num); + + err = sysfs_read_str(mm_path, mm_buf, sizeof(mm_buf)); + if (err < 0) + return 0; + + for(i = 0; i < 9; i++) { + float f; + + f = strtof(tmp1, &tmp2); + if (!f && tmp1 == tmp2) + return 0; + mm[i] = f; + tmp1 = tmp2 + 1; + } + + ALOGI("%s: %f %f %f %f %f %f %f %f %f\n", __func__, mm[0], mm[1], mm[2], mm[3], mm[4], mm[5], mm[6], mm[7], mm[8]); + return 1; +} + char* sensor_get_string_type (int s) { - switch (sensor[s].type) { + switch (sensor_desc[s].type) { case SENSOR_TYPE_ACCELEROMETER: return SENSOR_STRING_TYPE_ACCELEROMETER; @@ -451,7 +515,7 @@ flag_t sensor_get_flags (int s) { flag_t flags = 0; - switch (sensor[s].type) { + switch (sensor_desc[s].type) { case SENSOR_TYPE_LIGHT: case SENSOR_TYPE_AMBIENT_TEMPERATURE: case SENSOR_TYPE_TEMPERATURE: @@ -477,7 +541,7 @@ flag_t sensor_get_flags (int s) static int get_cdd_freq (int s, int must) { - switch (sensor[s].type) { + switch (sensor_desc[s].type) { case SENSOR_TYPE_ACCELEROMETER: return (must ? 100 : 200); /* must 100 Hz, should 200 Hz, CDD compliant */ @@ -509,7 +573,7 @@ max_delay_t sensor_get_max_delay (int s) int dev_num = sensor[s].dev_num; char freqs_buf[100]; char* cursor; - float min_supported_rate = 1000; + float min_supported_rate; float rate_cap; float sr; @@ -538,31 +602,42 @@ max_delay_t sensor_get_max_delay (int s) return 0; } } - 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) { - /* The must rate */ - min_supported_rate = get_cdd_freq(s, 1); - } - } else { - cursor = freqs_buf; - while (*cursor && cursor[0]) { + 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) { - /* Decode a single value */ - sr = strtod(cursor, NULL); + min_supported_rate = 1000; + cursor = freqs_buf; - if (sr < min_supported_rate) - min_supported_rate = sr; + while (*cursor && cursor[0]) { - /* Skip digits */ - while (cursor[0] && !isspace(cursor[0])) - cursor++; + /* Decode a single value */ + sr = strtod(cursor, NULL); - /* Skip spaces */ - while (cursor[0] && isspace(cursor[0])) - cursor++; - } + 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++; + } + + break; + } + + /* Fall through ... */ + + default: + /* Report 1 Hz */ + min_supported_rate = 1; + break; } /* Check if a minimum rate was specified for this sensor */