30 #include <linux/types.h>
50 while (i < num_channels) {
51 if (bytes % channels[i].bytes == 0)
74 input = input >> info->
shift;
101 switch (channels[k].
bytes) {
110 (data + channels[k].location);
111 printf(
"%05f ", ((
float)val +
118 if (channels[k].is_signed) {
119 int64_t
val = *(int64_t *)
121 channels[k].location);
122 if ((val >> channels[k].bits_used) & 1)
123 val = (val & channels[k].
mask) |
126 if (channels[k].scale == 1.0
f &&
130 printf(
"%05f ", ((
float)val +
143 unsigned long num_loops = 2;
144 unsigned long timedelay = 1000000;
145 unsigned long buf_len = 128;
152 char *dev_dir_name, *buf_dir_name;
154 int datardytrigger = 1;
157 int dev_num, trig_num;
165 while ((c = getopt(argc, argv,
"l:w:c:et:n:")) != -1) {
168 device_name = optarg;
171 trigger_name = optarg;
178 num_loops = strtoul(optarg, &dummy, 10);
181 timedelay = strtoul(optarg, &dummy, 10);
184 buf_len = strtoul(optarg, &dummy, 10);
191 if (device_name ==
NULL)
197 printf(
"Failed to find the %s\n", device_name);
201 printf(
"iio device number being used is %d\n", dev_num);
203 asprintf(&dev_dir_name,
"%siio:device%d",
iio_dir, dev_num);
204 if (trigger_name ==
NULL) {
210 ret = asprintf(&trigger_name,
211 "%s-dev%d", device_name, dev_num);
221 printf(
"Failed to find the trigger %s\n", trigger_name);
223 goto error_free_triggername;
225 printf(
"iio trigger number being used is %d\n", trig_num);
233 printf(
"Problem reading scan element information\n");
234 printf(
"diag %s\n", dev_dir_name);
235 goto error_free_triggername;
243 ret = asprintf(&buf_dir_name,
244 "%siio:device%d/buffer",
iio_dir, dev_num);
247 goto error_free_triggername;
249 printf(
"%s %s\n", dev_dir_name, trigger_name);
255 printf(
"Failed to write current_trigger file\n");
256 goto error_free_buf_dir_name;
262 goto error_free_buf_dir_name;
267 goto error_free_buf_dir_name;
269 data =
malloc(scan_size*buf_len);
272 goto error_free_buf_dir_name;
275 ret = asprintf(&buffer_access,
"/dev/iio:device%d", dev_num);
278 goto error_free_data;
284 printf(
"Failed to open %s\n", buffer_access);
286 goto error_free_buffer_access;
290 for (j = 0; j < num_loops; j++) {
308 if (read_size == -
EAGAIN) {
309 printf(
"nothing available\n");
312 for (i = 0; i < read_size/scan_size; i++)
321 goto error_close_buffer_access;
325 dev_dir_name,
"NULL");
327 error_close_buffer_access:
331 error_free_buffer_access:
333 error_free_buf_dir_name:
335 error_free_triggername: