OSDN Git Service

Checking raw and input paths on enumeration
authorViorel Suman <viorel.suman@intel.com>
Mon, 9 Feb 2015 16:52:24 +0000 (18:52 +0200)
committerViorel Suman <viorel.suman@intel.com>
Tue, 10 Feb 2015 12:54:50 +0000 (14:54 +0200)
Raw and input path checks introduced on enumeration
in order to avoid continuous reading of these files
while acquiring immediate values.

Change-Id: Ia5c4b21a3c6d95f2c99ef60f17fd3a4b968f0c82
Signed-off-by: Viorel Suman <viorel.suman@intel.com>
common.h
enumeration.c
transform.c

index 10411ac..156edac 100644 (file)
--- a/common.h
+++ b/common.h
@@ -116,6 +116,8 @@ typedef struct
                          * Optional correction scale read from a property such as iio.accel.x.scale, allowing late compensation of
                          * problems such as misconfigured axes ; set to 1 by default. Applied at the end of the scaling process.
                          */
+       int raw_path_present;   /* Flag signalling the presence of in_<sens>_<axis>_raw file */
+       int input_path_present; /* Flag signalling the presence of in_<sens>_input file */
 }
 channel_info_t;
 
index f87d7e3..f3e6752 100644 (file)
@@ -548,6 +548,17 @@ static void add_sensor (int dev_num, int catalog_index, int mode)
        for (c = 1; c < num_channels; c++)
                sensor[s].channel[c].opt_scale = 1;
 
+       for (c = 0; c < num_channels; c++) {
+               /* Check the presence of the channel's input_path */
+               sprintf(sysfs_path, BASE_PATH "%s", dev_num,
+                       sensor_catalog[catalog_index].channel[c].input_path);
+               sensor[s].channel[c].input_path_present = (access(sysfs_path, R_OK) != -1);
+               /* Check the presence of the channel's raw_path */
+               sprintf(sysfs_path, BASE_PATH "%s", dev_num,
+                       sensor_catalog[catalog_index].channel[c].raw_path);
+               sensor[s].channel[c].raw_path_present = (access(sysfs_path, R_OK) != -1);
+       }
+
        /* Read ACPI _PLD attributes for this sensor, if there are any */
        decode_placement_information(dev_num, num_channels, s);
 
index ffbe917..74d5ef1 100644 (file)
@@ -515,15 +515,15 @@ float acquire_immediate_float_value (int s, int c)
 
        /* Acquire a sample value for sensor s / channel c through sysfs */
 
-       if (input_path[0]) {
+       if (sensor[s].channel[c].input_path_present) {
                sprintf(sysfs_path, BASE_PATH "%s", dev_num, input_path);
                ret = sysfs_read_float(sysfs_path, &val);
 
                if (!ret)
                        return val * correction;
-       };
+       }
 
-       if (!raw_path[0])
+       if (!sensor[s].channel[c].raw_path_present)
                return 0;
 
        sprintf(sysfs_path, BASE_PATH "%s", dev_num, raw_path);
@@ -561,7 +561,7 @@ uint64_t acquire_immediate_uint64_value (int s, int c)
 
        /* Acquire a sample value for sensor s / channel c through sysfs */
 
-       if (input_path[0]) {
+       if (sensor[s].channel[c].input_path_present) {
                sprintf(sysfs_path, BASE_PATH "%s", dev_num, input_path);
                ret = sysfs_read_uint64(sysfs_path, &val);
 
@@ -569,7 +569,7 @@ uint64_t acquire_immediate_uint64_value (int s, int c)
                        return val * correction;
        };
 
-       if (!raw_path[0])
+       if (!sensor[s].channel[c].raw_path_present)
                return 0;
 
        sprintf(sysfs_path, BASE_PATH "%s", dev_num, raw_path);