OSDN Git Service

Merge remote-tracking branch 'origin/abt/topic/gmin/l-dev/sensors/master' into gmin...
[android-x86/hardware-intel-libsensors.git] / description.c
index 2c6fec0..1d2927e 100644 (file)
  * 'panel' and 'rotation' specifiers can be used to express ACPI PLD placement
  * information ; if found they will be used in priority over the actual ACPI
  * data. That is intended as a way to verify values during development.
+ *
+ * It's possible to use the contents of the iio device name as a way to
+ * discriminate between sensors. Several sensors of the same type can coexist:
+ * e.g. ro.iio.temp.bmg160.name = BMG160 Thermometer will be used in priority
+ * over ro.iio.temp.name = BMC150 Thermometer if the sensor for which we query
+ * properties values happen to have its iio device name set to bmg160.
  */
 
 static int sensor_get_st_prop (int s, const char* sel, char val[MAX_NAME_SIZE])
 {
        char prop_name[PROP_NAME_MAX];
        char prop_val[PROP_VALUE_MAX];
+       char extended_sel[PROP_VALUE_MAX];
+
        int i                   = sensor_info[s].catalog_index;
        const char *prefix      = sensor_catalog[i].tag;
 
+       /* First try most specialized form, like ro.iio.anglvel.bmg160.name */
+
+       snprintf(extended_sel, PROP_NAME_MAX, "%s.%s",
+                sensor_info[s].internal_name, sel);
+
+       snprintf(prop_name, PROP_NAME_MAX, PROP_BASE, prefix, 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);
 
        if (property_get(prop_name, prop_val, "")) {
@@ -406,3 +429,65 @@ max_delay_t sensor_get_max_delay (int s)
        /* Return microseconds */
        return (max_delay_t)(1000000.0 / min_supported_rate);
 }
+
+/* this value depends on the reporting mode:
+ *
+ *   continuous: minimum sample period allowed in microseconds
+ *   on-change : 0
+ *   one-shot  :-1
+ *   special   : 0, unless otherwise noted
+ */
+int32_t sensor_get_min_delay(int s)
+{
+       char avail_sysfs_path[PATH_MAX];
+       int dev_num     = sensor_info[s].dev_num;
+       char freqs_buf[100];
+       char* cursor;
+       float max_supported_rate = 0;
+       float sr;
+       int catalog_index = sensor_info[s].catalog_index;
+       int sensor_type = sensor_catalog[catalog_index].type;
+
+
+       sprintf(avail_sysfs_path, DEVICE_AVAIL_FREQ_PATH, dev_num);
+
+       if (sysfs_read_str(avail_sysfs_path, freqs_buf, sizeof(freqs_buf)) < 0) {
+               /* If poll mode sensor */
+               if (!sensor_info[s].num_channels) {
+                       switch (sensor_type) {
+                               case SENSOR_TYPE_ACCELEROMETER:
+                                       max_supported_rate = 125; /* 125 Hz */
+                                       break;
+                               case SENSOR_TYPE_GYROSCOPE:
+                               case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
+                                       max_supported_rate = 200; /* 200 Hz */
+                                       break;
+                               case SENSOR_TYPE_MAGNETIC_FIELD:
+                                       max_supported_rate = 10; /* 10 Hz */
+                                       break;
+                               default:
+                                       max_supported_rate = 0;
+                       }
+               }
+       } else {
+               cursor = freqs_buf;
+               while (*cursor && cursor[0]) {
+
+                       /* Decode a single value */
+                       sr = strtod(cursor, NULL);
+
+                       if (sr > max_supported_rate && sr <= MAX_EVENTS)
+                               max_supported_rate = sr;
+
+                       /* Skip digits */
+                       while (cursor[0] && !isspace(cursor[0]))
+                               cursor++;
+
+                       /* Skip spaces */
+                       while (cursor[0] && isspace(cursor[0]))
+                               cursor++;
+               }
+       }
+
+       return (int32_t)(1000000.0 / max_supported_rate);
+}