Skip to content

Commit 2f1ced9

Browse files
committed
iio_widget: Reenable reading all device attributes
Signed-off-by: Dan <[email protected]>
1 parent ca5e656 commit 2f1ced9

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

iio_utils.c

+23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <gtk/gtk.h>
66
#include <errno.h>
77

8+
#define ARRAY_SIZE(x) (!sizeof(x) ?: sizeof(x) / sizeof((x)[0]))
9+
810
static gint iio_chn_cmp_by_name(gconstpointer ptr_a, gconstpointer ptr_b)
911
{
1012
struct iio_channel *ch_a = *(struct iio_channel **)ptr_a;
@@ -303,3 +305,24 @@ int chn_attr_write_longlong(struct iio_channel *chn, const char *attr_name, long
303305
else
304306
return -ENOENT;
305307
}
308+
309+
void dev_attr_read_all(struct iio_device *dev,
310+
int (*cb)(struct iio_device *dev, const char *attr, const char *value, size_t len, void *d),
311+
void *data)
312+
{
313+
unsigned int i, attr_cnt = iio_device_get_attrs_count(dev);
314+
const struct iio_attr *attr;
315+
char local_value[8192];
316+
int ret;
317+
318+
for (i = 0; i < attr_cnt; ++i) {
319+
attr = iio_device_get_attr(dev, i);
320+
ret = iio_attr_read_raw(attr, local_value, ARRAY_SIZE(local_value));
321+
if (ret < 0) {
322+
fprintf(stderr, "Failed to read attribute: %s\n", iio_attr_get_name(attr));
323+
continue;
324+
} else {
325+
cb(dev, iio_attr_get_name(attr), local_value, strlen(local_value), data);
326+
}
327+
}
328+
}

iio_utils.h

+5
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ inline int chn_attr_write_bool(struct iio_channel *chn, const char *attr_name, b
4848
inline int chn_attr_write_double(struct iio_channel *chn, const char *attr_name, double value);
4949
inline int chn_attr_write_longlong(struct iio_channel *chn, const char *attr_name, long long value);
5050

51+
/* Helpers to iterate through all attributes */
52+
inline void dev_attr_read_all(struct iio_device *dev,
53+
int (*cb)(struct iio_device *dev, const char *attr, const char *value, size_t len, void *d),
54+
void *data);
55+
5156
#endif /* __IIO_UTILS__ */

iio_widget.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <math.h>
1515

1616
#include "iio_widget.h"
17+
#include "iio_utils.h"
1718

1819
struct update_widgets_params {
1920
struct iio_widget *widgets;
@@ -696,7 +697,7 @@ void iio_update_widgets_of_device(struct iio_widget *widgets,
696697
};
697698

698699
// !!!!!!!!
699-
// iio_device_attr_read_all(dev, __cb_dev_update, &params);
700+
dev_attr_read_all(dev, __cb_dev_update, &params);
700701

701702
// for (i = 0; i < iio_device_get_channels_count(dev); i++)
702703
// iio_channel_attr_read_all(iio_device_get_channel(dev, i),

0 commit comments

Comments
 (0)