OSDN Git Service

Support for channel specific scale value
authorsuyyala <sridhar.uyyala@intel.com>
Sat, 17 May 2014 01:03:53 +0000 (18:03 -0700)
committersuyyala <sridhar.uyyala@intel.com>
Mon, 19 May 2014 23:53:38 +0000 (16:53 -0700)
Sensor devices are exporting channel specific scale values as well.
example: in_magn_x_scale, in_magn_y_scale, in_magn_z_scale, etc.
Channel specific scales are enumerated when no common scale(example:
in_magn_scale) is provided.

Issue: GMIN-355

Change-Id: Ib49750228a2f0a44528470672be93dc3945c2bae
Signed-off-by: suyyala <sridhar.uyyala@intel.com>
common.h
enumeration.c
enumeration.h
transform.c

index 23faa7a..93286fb 100644 (file)
--- a/common.h
+++ b/common.h
@@ -13,6 +13,7 @@
 
 #define BASE_PATH      "/sys/bus/iio/devices/iio:device%d/"
 
+
 #define CHANNEL_PATH           BASE_PATH "scan_elements/"
 #define ENABLE_PATH            BASE_PATH "buffer/enable"
 #define NAME_PATH              BASE_PATH "name"
@@ -33,6 +34,7 @@
 
 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
 
+
 struct channel_descriptor_t
 {
        /* sysfs entries located under scan_elements */
@@ -43,6 +45,7 @@ struct channel_descriptor_t
        /* sysfs entries located in /sys/bus/iio/devices/iio:deviceX */
        const char *raw_path;   /* _raw sysfs file name  */
        const char *input_path; /* _input sysfs file name */
+       const char *scale_path; /* _scale sysfs file name */
 };
 
 struct sensor_catalog_entry_t
@@ -66,6 +69,7 @@ struct channel_info_t
 {
        int offset; /* Offset in bytes within the iio character device report */
        int size;                       /* Field size in bytes */
+       float scale;                    /* scale for each channel */
        char type_spec[MAX_TYPE_SPEC_LEN]; /* From driver; ex: le:u10/16>>0 */
        struct datum_info_t type_info;     /* Decoded contents of type spec */
 };
@@ -90,7 +94,7 @@ struct sensor_info_t
        float power;
 
        float offset;   /* (cooked = raw + offset) * scale */
-       float scale;
+       float scale;    /*default: 1. when set to 0, use channel specific value*/
        float illumincalib;     /* to set the calibration for the ALS */
 
        int sampling_rate;      /* requested events / second */
index 5fd7a70..6d7c838 100644 (file)
@@ -45,6 +45,7 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        char sysfs_path[PATH_MAX];
        const char* prefix;
         float scale;
+       int c;
 
        if (sensor_count == MAX_SENSORS) {
                ALOGE("Too many sensors!\n");
@@ -92,10 +93,26 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        sysfs_read_float(sysfs_path, &sensor_info[s].offset);
 
        sprintf(sysfs_path, SENSOR_SCALE_PATH, dev_num, prefix);
-       if (!sysfs_read_float(sysfs_path, &scale))
+       if (!sysfs_read_float(sysfs_path, &scale)) {
                 sensor_info[s].scale = scale;
-        else
+               ALOGI("Scale path %s  scale: %f, dev_num =%d \n",
+                                        sysfs_path, scale, dev_num);
+       }else {
                 sensor_info[s].scale = 1;
+                /* Read channel specific scale if any*/
+                for (c = 0; c < sensor_catalog[catalog_index].num_channels; c++)
+                {
+                        sprintf(sysfs_path, BASE_PATH "%s", dev_num,
+                                sensor_catalog[catalog_index].channel[c].scale_path);
+
+                        if (!sysfs_read_float(sysfs_path, &scale)) {
+                                sensor_info[s].channel[c].scale = scale;
+                               sensor_info[s].scale = 0;
+                        }
+                        ALOGI("Scale path %s  channel scale: %f dev_num %d\n",
+                                        sysfs_path, scale, dev_num);
+                }
+        }
 
        /* Initialize Android-visible descriptor */
        sensor_desc[s].name             = sensor_get_name(s);
index 16af2fe..28c891e 100644 (file)
@@ -20,6 +20,7 @@
                        "in_"tag spacer name"_index",   \
                        "in_"tag spacer name"_raw",     \
                        "in_"tag spacer name"_input",   \
+                       "in_"tag spacer name"_scale",   \
                 },
 
 #define DECLARE_NAMED_CHANNEL(tag, name)       DECLARE_CHANNEL(tag, "_", name)
index 5030d8d..1c281c3 100644 (file)
@@ -230,9 +230,10 @@ static float transform_sample_default(int s, int c, unsigned char* sample_data)
 {
        struct datum_info_t* sample_type = &sensor_info[s].channel[c].type_info;
        int64_t              s64 = sample_as_int64(sample_data, sample_type);
-
+       float scale = sensor_info[s].scale ?
+                       sensor_info[s].scale : sensor_info[s].channel[c].scale;
        /* Apply default scaling rules */
-       return (sensor_info[s].offset + s64) * sensor_info[s].scale;
+       return (sensor_info[s].offset + s64) * scale;
 }
 
 
@@ -359,7 +360,8 @@ float acquire_immediate_value(int s, int c)
        int i = sensor_info[s].catalog_index;
        const char* raw_path = sensor_catalog[i].channel[c].raw_path;
        const char* input_path = sensor_catalog[i].channel[c].input_path;
-       float scale = sensor_info[s].scale;
+       float scale = sensor_info[s].scale ?
+                       sensor_info[s].scale : sensor_info[s].channel[c].scale;
        float offset = sensor_info[s].offset;
        int sensor_type = sensor_catalog[i].type;