OSDN Git Service

Enable Gauss-2-uT conversion for interrupt mode magneto
[android-x86/hardware-intel-libsensors.git] / transform.c
index eaf0faf..7aee50d 100644 (file)
@@ -187,6 +187,17 @@ static void reorder_fields (float* data, unsigned char map[MAX_CHANNELS])
                data[i] = temp[i];
 }
 
+static void mount_correction (float* data, float mm[9])
+{
+       int i;
+       float temp[3];
+
+       for (i=0; i<3; i++)
+               temp[i] = data[0] * mm[i * 3] + data[1] * mm[i * 3 + 1] + data[2] * mm[i * 3 + 2];
+
+       for (i=0; i<3; i++)
+               data[i] = temp[i];
+}
 
 static void clamp_gyro_readings_to_zero (int s, sensors_event_t* data)
 {
@@ -295,6 +306,8 @@ static int finalize_sample_default (int s, sensors_event_t* data)
        /* Swap fields if we have a custom channel ordering on this sensor */
        if (sensor[s].quirks & QUIRK_FIELD_ORDERING)
                reorder_fields(data->data, sensor[s].order);
+       if (sensor[s].quirks & QUIRK_MOUNTING_MATRIX)
+               mount_correction(data->data, sensor[s].mounting_matrix);
 
        sensor[s].event_count++;
 
@@ -391,10 +404,14 @@ static float transform_sample_default (int s, int c, unsigned char* sample_data)
        float scale = sensor[s].scale ? sensor[s].scale : sensor[s].channel[c].scale;
 
        /* In case correction has been requested using properties, apply it */
-       scale *= sensor[s].channel[c].opt_scale;
+       float correction = sensor[s].channel[c].opt_scale;
+
+       /* Correlated with "acquire_immediate_value" method */
+       if (sensor[s].type == SENSOR_TYPE_MAGNETIC_FIELD)
+                return CONVERT_GAUSS_TO_MICROTESLA((sensor[s].offset + s64) * scale) * correction;
 
        /* Apply default scaling rules */
-       return (sensor[s].offset + s64) * scale;
+       return (sensor[s].offset + s64) * scale * correction;
 }
 
 
@@ -523,7 +540,6 @@ float acquire_immediate_float_value (int s, int c)
        const char* input_path = sensor_catalog[i].channel[c].input_path;
        float scale = sensor[s].scale ? sensor[s].scale : sensor[s].channel[c].scale;
        float offset = sensor[s].offset;
-       int sensor_type = sensor_catalog[i].type;
        float correction;
 
        /* In case correction has been requested using properties, apply it */
@@ -552,7 +568,7 @@ float acquire_immediate_float_value (int s, int c)
         * 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)
+       if (sensor[s].type == SENSOR_TYPE_MAGNETIC_FIELD)
                 return CONVERT_GAUSS_TO_MICROTESLA ((val + offset) * scale) * correction;
 
        return (val + offset) * scale * correction;