aboutsummaryrefslogtreecommitdiffstats
path: root/tools/iio
diff options
context:
space:
mode:
authorIrina Tirdea <irina.tirdea@intel.com>2015-03-27 07:53:00 -0400
committerJonathan Cameron <jic23@kernel.org>2015-03-28 07:01:49 -0400
commitd9d7b990473889a17b0f54e860a65b141733799c (patch)
treec9d677ae26b93cd674dc02f5acbe8fcd2d0dd0be /tools/iio
parent8ea06893e66d03dc567845d65b42812efd71b9f3 (diff)
tools: iio: generic_buffer: Fix generic scale extraction
When using generic_buffer to read data, the scale is not properly detected for scale shared by type. This is caused by a problem with the generation of generic name out of the full name. E.g.: for current->name in_accel_z, the extracted generic name is "in" (when it should be "in_accel"). This is used in generic_buffer to generate scale and offset paths (in_accel_scale). Consider the in_ or out_ prefix when extracting the generic name from the full name. Signed-off-by: Irina Tirdea <irina.tirdea@intel.com> Reviewed-by: Daniel Baluta <daniel.baluta@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'tools/iio')
-rw-r--r--tools/iio/iio_utils.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index 2680a2e0f113..6f6452167b67 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -20,6 +20,11 @@
20 20
21const char *iio_dir = "/sys/bus/iio/devices/"; 21const char *iio_dir = "/sys/bus/iio/devices/";
22 22
23static char * const iio_direction[] = {
24 "in",
25 "out",
26};
27
23/** 28/**
24 * iioutils_break_up_name() - extract generic name from full channel name 29 * iioutils_break_up_name() - extract generic name from full channel name
25 * @full_name: the full channel name 30 * @full_name: the full channel name
@@ -30,10 +35,19 @@ int iioutils_break_up_name(const char *full_name,
30{ 35{
31 char *current; 36 char *current;
32 char *w, *r; 37 char *w, *r;
33 char *working; 38 char *working, *prefix = "";
39 int i;
34 40
35 current = strdup(full_name); 41 for (i = 0; i < sizeof(iio_direction) / sizeof(iio_direction[0]); i++)
42 if (!strncmp(full_name, iio_direction[i],
43 strlen(iio_direction[i]))) {
44 prefix = iio_direction[i];
45 break;
46 }
47
48 current = strdup(full_name + strlen(prefix) + 1);
36 working = strtok(current, "_\0"); 49 working = strtok(current, "_\0");
50
37 w = working; 51 w = working;
38 r = working; 52 r = working;
39 53
@@ -45,7 +59,7 @@ int iioutils_break_up_name(const char *full_name,
45 r++; 59 r++;
46 } 60 }
47 *w = '\0'; 61 *w = '\0';
48 *generic_name = strdup(working); 62 asprintf(generic_name, "%s_%s", prefix, working);
49 free(current); 63 free(current);
50 64
51 return 0; 65 return 0;