From 115f76c8fe40f5e1ece9349b1da4fe1514767aee Mon Sep 17 00:00:00 2001 From: Viorel Suman Date: Mon, 9 Feb 2015 18:52:24 +0200 Subject: [PATCH] Checking raw and input paths on enumeration 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 --- common.h | 2 ++ enumeration.c | 11 +++++++++++ transform.c | 10 +++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common.h b/common.h index 10411ac..156edac 100644 --- 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___raw file */ + int input_path_present; /* Flag signalling the presence of in__input file */ } channel_info_t; diff --git a/enumeration.c b/enumeration.c index f87d7e3..f3e6752 100644 --- a/enumeration.c +++ b/enumeration.c @@ -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); diff --git a/transform.c b/transform.c index ffbe917..74d5ef1 100644 --- a/transform.c +++ b/transform.c @@ -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); -- 2.11.0