Skip to content

Commit

Permalink
iio_widget: Reenable reading all channel attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Dan <[email protected]>
  • Loading branch information
dNechita committed Dec 6, 2024
1 parent 2f1ced9 commit bf5e9f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
21 changes: 21 additions & 0 deletions iio_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,24 @@ void dev_attr_read_all(struct iio_device *dev,
}
}
}

void chn_attr_read_all(struct iio_channel *chn,
int (*cb)(struct iio_channel *chn, const char *attr, const char *value, size_t len, void *d),
void *data)
{
unsigned int i, attr_cnt = iio_channel_get_attrs_count(chn);
const struct iio_attr *attr;
char local_value[8192];
int ret;

for (i = 0; i < attr_cnt; ++i) {
attr = iio_channel_get_attr(chn, i);
ret = iio_attr_read_raw(attr, local_value, ARRAY_SIZE(local_value));
if (ret < 0) {
fprintf(stderr, "Failed to read attribute: %s\n", iio_attr_get_name(attr));
continue;
} else {
cb(chn, iio_attr_get_name(attr), local_value, strlen(local_value), data);
}
}
}
3 changes: 3 additions & 0 deletions iio_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ inline int chn_attr_write_longlong(struct iio_channel *chn, const char *attr_nam
inline void dev_attr_read_all(struct iio_device *dev,
int (*cb)(struct iio_device *dev, const char *attr, const char *value, size_t len, void *d),
void *data);
inline void chn_attr_read_all(struct iio_channel *chn,
int (*cb)(struct iio_channel *chn, const char *attr, const char *value, size_t len, void *d),
void *data);

#endif /* __IIO_UTILS__ */
7 changes: 3 additions & 4 deletions iio_widget.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,11 @@ void iio_update_widgets_of_device(struct iio_widget *widgets,
.nb = num_widgets,
};

// !!!!!!!!
dev_attr_read_all(dev, __cb_dev_update, &params);

// for (i = 0; i < iio_device_get_channels_count(dev); i++)
// iio_channel_attr_read_all(iio_device_get_channel(dev, i),
// __cb_chn_update, &params);
for (i = 0; i < iio_device_get_channels_count(dev); i++)
chn_attr_read_all(iio_device_get_channel(dev, i),
__cb_chn_update, &params);
}

void iio_save_widgets(struct iio_widget *widgets, unsigned int num_widgets)
Expand Down

0 comments on commit bf5e9f3

Please sign in to comment.