OSDN Git Service

GMINL-7944: Introduce internal sensor types for ALS
authorPatrick Porlan <patrick.porlan@intel.com>
Fri, 10 Apr 2015 17:06:05 +0000 (19:06 +0200)
committerAdriana Reus <adriana.reus@intel.com>
Wed, 15 Apr 2015 14:42:25 +0000 (17:42 +0300)
Decouple the sensor type retrieved from the catalog from the one
that is exposed to Android. This allows us to tailor processing
to specific iio sensor types. Start with the ALS, which comes in
several variants that we will want to arbitrate (i.e. if a sensor
exposes both illuminance and intensity, we'll keep illuminance).

This could enable finer processing per iio type, such as intensity
to lux conversions.

The type field in the sensor array becomes the internal type. The
type field on the sensor_desc array is the one exposed to Android.

Change-Id: Ie3a001d389af50f88732f71a3b06afc752255f4c
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
control.c
description.c
enumeration.c
enumeration.h
transform.c

index d72880d..e260b94 100644 (file)
--- a/control.c
+++ b/control.c
@@ -439,6 +439,7 @@ int adjust_counters (int s, int enabled, int from_virtual)
 static int get_field_count (int s, size_t *field_size)
 {
        *field_size = sizeof(float);
+
        switch (sensor[s].type) {
                case SENSOR_TYPE_ACCELEROMETER:         /* m/s^2        */
                case SENSOR_TYPE_MAGNETIC_FIELD:        /* micro-tesla  */
@@ -447,6 +448,8 @@ static int get_field_count (int s, size_t *field_size)
                case SENSOR_TYPE_GYROSCOPE:             /* radians/s    */
                        return 3;
 
+               case SENSOR_TYPE_INTERNAL_INTENSITY:
+               case SENSOR_TYPE_INTERNAL_ILLUMINANCE:
                case SENSOR_TYPE_LIGHT:                 /* SI lux units */
                case SENSOR_TYPE_AMBIENT_TEMPERATURE:   /* °C          */
                case SENSOR_TYPE_TEMPERATURE:           /* °C          */
@@ -1341,7 +1344,7 @@ static int propagate_vsensor_report (int s, sensors_event_t *data)
        memcpy(data, &sensor[s].sample, sizeof(sensors_event_t));
 
        data->sensor    = s;
-       data->type      = sensor[s].type;
+       data->type      = sensor_desc[s].type; /* sensor_desc[s].type can differ from sensor[s].type ; internal types are remapped */
        return 1;
 }
 
@@ -1377,7 +1380,7 @@ static int propagate_sensor_report (int s, sensors_event_t *data)
 
        data->version   = sizeof(sensors_event_t);
        data->sensor    = s;
-       data->type      = sensor[s].type;
+       data->type      = sensor_desc[s].type;  /* sensor_desc[s].type can differ from sensor[s].type ; internal types are remapped */
        data->timestamp = sensor[s].report_ts;
 
        if (sensor[s].mode == MODE_EVENT) {
index 6a3bec1..9349ad8 100644 (file)
@@ -229,7 +229,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;
 
@@ -419,7 +419,7 @@ int sensor_get_order (int s, unsigned char map[MAX_CHANNELS])
 
 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;
 
@@ -466,7 +466,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:
@@ -492,7 +492,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 */
 
index c4e8ead..fa02c28 100644 (file)
@@ -65,7 +65,7 @@ sensor_catalog_entry_t sensor_catalog[] = {
        },
        {
                .tag            = "intensity",
-               .type           = SENSOR_TYPE_LIGHT,
+               .type           = SENSOR_TYPE_INTERNAL_INTENSITY,
                .num_channels   = 1,
                .is_virtual     = 0,
                .channel = {
@@ -74,7 +74,7 @@ sensor_catalog_entry_t sensor_catalog[] = {
        },
        {
                .tag            = "illuminance",
-               .type           = SENSOR_TYPE_LIGHT,
+               .type           = SENSOR_TYPE_INTERNAL_ILLUMINANCE,
                .num_channels   = 1,
                .is_virtual     = 0,
                .channel = {
@@ -376,6 +376,20 @@ static void decode_placement_information (int dev_num, int num_channels, int s)
 }
 
 
+static int map_internal_to_external_type (int sensor_type)
+{
+       /* Most sensors are internally identified using the Android type, but for some we use a different type specification internally */
+
+       switch (sensor_type) {
+               case SENSOR_TYPE_INTERNAL_ILLUMINANCE:
+               case SENSOR_TYPE_INTERNAL_INTENSITY:
+                       return SENSOR_TYPE_LIGHT;
+
+               default:
+                       return sensor_type;
+       }
+}
+
 static void populate_descriptors (int s, int sensor_type)
 {
        int32_t         min_delay_us;
@@ -386,7 +400,7 @@ static void populate_descriptors (int s, int sensor_type)
        sensor_desc[s].vendor           = sensor_get_vendor(s);
        sensor_desc[s].version          = sensor_get_version(s);
        sensor_desc[s].handle           = s;
-       sensor_desc[s].type             = sensor_type;
+       sensor_desc[s].type             = map_internal_to_external_type(sensor_type);
 
        sensor_desc[s].maxRange         = sensor_get_max_range(s);
        sensor_desc[s].resolution       = sensor_get_resolution(s);
@@ -505,7 +519,7 @@ static int add_sensor (int dev_num, int catalog_index, int mode)
         * receiving the illumination sensor calibration inputs from
         * the Android properties and setting it within sysfs
         */
-       if (sensor_type == SENSOR_TYPE_LIGHT) {
+       if (sensor_type == SENSOR_TYPE_INTERNAL_ILLUMINANCE) {
                retval = sensor_get_illumincalib(s);
                 if (retval > 0) {
                        sprintf(sysfs_path, ILLUMINATION_CALIBPATH, dev_num);
index 1915249..c8ef2eb 100644 (file)
@@ -13,4 +13,11 @@ int  get_sensors_list        (struct sensors_module_t* module,
 void   enumerate_sensors       (void);
 void   delete_enumeration_data (void);
 
+/*
+ * These are fine-grained type definitions that are used internally, in the sensor array, but mapped to an Android sensor type in the processing pipeline.
+ * The sensor array uses these, not the desc array.
+ */
+#define SENSOR_TYPE_INTERNAL_ILLUMINANCE       -1      /* Global illuminance, in lux                            */
+#define SENSOR_TYPE_INTERNAL_INTENSITY         -2      /* Global intensity, in sensor specific units            */
+
 #endif
index 47b4481..6d20c2c 100644 (file)
@@ -13,7 +13,7 @@
 #include "transform.h"
 #include "utils.h"
 #include "filtering.h"
-
+#include "enumeration.h"
 
 #define        GYRO_MIN_SAMPLES 5 /* Drop first few gyro samples after enable */
 
@@ -421,7 +421,7 @@ static float transform_sample_ISH (int s, int c, unsigned char* sample_data)
        /* In case correction has been requested using properties, apply it */
        correction = sensor[s].channel[c].opt_scale;
 
-       switch (sensor[s].type) {
+       switch (sensor_desc[s].type) {
                case SENSOR_TYPE_ACCELEROMETER:
                        switch (c) {
                                case 0: