OSDN Git Service

Transform Magnetometer raw data
authorsuyyala <sridhar.uyyala@intel.com>
Fri, 16 May 2014 23:36:11 +0000 (16:36 -0700)
committersuyyala <sridhar.uyyala@intel.com>
Fri, 16 May 2014 23:36:11 +0000 (16:36 -0700)
iio driver is providing data in gauss units and converting
to MicroTesla as Android expectes.

Issue: GMIN-355

Change-Id: I2eeb3eb4fbae315d176c8a990129e1eb38003626
Signed-off-by: suyyala <sridhar.uyyala@intel.com>
transform.c

index cce3077..5030d8d 100644 (file)
@@ -33,6 +33,8 @@
 #define CONVERT_M_Y                 (-CONVERT_M)
 #define CONVERT_M_Z                 (CONVERT_M)
 
+#define CONVERT_GAUSS_TO_MICROTESLA(x)        ( (x) * 100 )
+
 /* conversion of orientation data to degree units */
 #define CONVERT_O                   (1.0f/64.0f)
 #define CONVERT_O_A                 (CONVERT_O)
@@ -359,6 +361,7 @@ float acquire_immediate_value(int s, int c)
        const char* input_path = sensor_catalog[i].channel[c].input_path;
        float scale = sensor_info[s].scale;
        float offset = sensor_info[s].offset;
+       int sensor_type = sensor_catalog[i].type;
 
        /* Acquire a sample value for sensor s / channel c through sysfs */
 
@@ -380,5 +383,12 @@ float acquire_immediate_value(int s, int c)
        if (ret == -1)
                return 0;
 
+       /*
+       There is no transform ops defined yet for Raw sysfs values
+        Use this function to perform transformation as well.
+       */
+       if (sensor_type == SENSOR_TYPE_MAGNETIC_FIELD)
+                return CONVERT_GAUSS_TO_MICROTESLA ((val + offset) * scale); //Gauss to MicroTesla
+
        return (val + offset) * scale;
 }