From d94e149cdd144e52e30dbc4b9686870d7c5a85e3 Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Sat, 25 Jan 2020 16:32:56 -0500 Subject: [PATCH] #352 First attempt to match global attributes for differential channels. Signed-off-by: fpagliughi --- local.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/local.c b/local.c index 5b51e1844..4671c33d6 100644 --- a/local.c +++ b/local.c @@ -1465,7 +1465,7 @@ static int add_channel(struct iio_device *dev, const char *name, static unsigned int is_global_attr(struct iio_channel *chn, const char *attr) { unsigned int len; - char *ptr; + char *ptr, *dashptr; if (!chn->is_output && !strncmp(attr, "in_", 3)) attr += 3; @@ -1480,6 +1480,19 @@ static unsigned int is_global_attr(struct iio_channel *chn, const char *attr) len = ptr - attr; + // Check if matching global differential attr, + // like "voltage-voltage" + dashptr = strchr(attr, '-'); + if (dashptr && dashptr > attr && dashptr < ptr) { + unsigned int len1 = dashptr - attr, + len2 = ptr - dashptr - 1; + if (chn->id[len1] >= '0' && chn->id[len1] <= '9' && + !strncmp(chn->id, attr, len1) && + chn->id[len+1] >= '0' && chn->id[len+1] <= '9' && + !strncmp(chn->id+len1+2, attr+len1+1, len2)) + return 1; + } + if (strncmp(chn->id, attr, len)) return 0;