OSDN Git Service

Merge branch 'lineage-16.0' of https://github.com/me176c-dev/android_hardware_iio...
[android-x86/hardware-intel-libsensors.git] / transform.c
index fd356fc..1b688d3 100644 (file)
@@ -1,6 +1,18 @@
 /*
- * Copyright (C) 2014-2015 Intel Corporation.
- */
+// Copyright (c) 2015 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
 
 #include <stdlib.h>
 #include <math.h>
@@ -41,8 +53,6 @@
 #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.0 / 64)
 #define CONVERT_O_A    (CONVERT_O)
@@ -404,10 +414,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;
 }
 
 
@@ -536,7 +550,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 */
@@ -548,8 +561,11 @@ float acquire_immediate_float_value (int s, int c)
                sprintf(sysfs_path, BASE_PATH "%s", dev_num, input_path);
                ret = sysfs_read_float(sysfs_path, &val);
 
-               if (!ret)
+               if (!ret) {
+                       if (sensor[s].type == SENSOR_TYPE_MAGNETIC_FIELD)
+                               return CONVERT_GAUSS_TO_MICROTESLA (val * correction);
                        return val * correction;
+               }
        }
 
        if (!sensor[s].channel[c].raw_path_present)
@@ -565,7 +581,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;
@@ -582,7 +598,6 @@ uint64_t acquire_immediate_uint64_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 */