Skip to content

Commit

Permalink
#352 First attempt to match global attributes for differential channels.
Browse files Browse the repository at this point in the history
Signed-off-by: fpagliughi <[email protected]>
  • Loading branch information
fpagliughi committed Jan 25, 2020
1 parent 634eb37 commit d94e149
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion local.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit d94e149

Please sign in to comment.