Commit 30268a3d authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio: update example to handle case with no ring events

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Tested-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent b949793b
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/dir.h> #include <sys/dir.h>
#include <linux/types.h> #include <linux/types.h>
#include <string.h>
#include "iio_utils.h" #include "iio_utils.h"
const int buf_len = 128; const int buf_len = 128;
...@@ -134,10 +135,11 @@ int main(int argc, char **argv) ...@@ -134,10 +135,11 @@ int main(int argc, char **argv)
int dev_num, trig_num; int dev_num, trig_num;
char *buffer_access, *buffer_event; char *buffer_access, *buffer_event;
int scan_size; int scan_size;
int noevents = 0;
struct iio_channel_info *infoarray; struct iio_channel_info *infoarray;
while ((c = getopt(argc, argv, "t:n:")) != -1) { while ((c = getopt(argc, argv, "et:n:")) != -1) {
switch (c) { switch (c) {
case 'n': case 'n':
device_name = optarg; device_name = optarg;
...@@ -146,6 +148,9 @@ int main(int argc, char **argv) ...@@ -146,6 +148,9 @@ int main(int argc, char **argv)
trigger_name = optarg; trigger_name = optarg;
datardytrigger = 0; datardytrigger = 0;
break; break;
case 'e':
noevents = 1;
break;
case '?': case '?':
return -1; return -1;
} }
...@@ -260,22 +265,30 @@ int main(int argc, char **argv) ...@@ -260,22 +265,30 @@ int main(int argc, char **argv)
/* Wait for events 10 times */ /* Wait for events 10 times */
for (j = 0; j < num_loops; j++) { for (j = 0; j < num_loops; j++) {
read_size = fread(&dat, 1, sizeof(struct iio_event_data), if (!noevents) {
fp_ev); read_size = fread(&dat,
switch (dat.id) { 1,
case IIO_EVENT_CODE_RING_100_FULL: sizeof(struct iio_event_data),
toread = buf_len; fp_ev);
break; switch (dat.id) {
case IIO_EVENT_CODE_RING_75_FULL: case IIO_EVENT_CODE_RING_100_FULL:
toread = buf_len*3/4; toread = buf_len;
break; break;
case IIO_EVENT_CODE_RING_50_FULL: case IIO_EVENT_CODE_RING_75_FULL:
toread = buf_len/2; toread = buf_len*3/4;
break; break;
default: case IIO_EVENT_CODE_RING_50_FULL:
printf("Unexpecteded event code\n"); toread = buf_len/2;
continue; break;
default:
printf("Unexpecteded event code\n");
continue;
}
} else {
usleep(1000);
toread = 64;
} }
read_size = read(fp, read_size = read(fp,
data, data,
toread*scan_size); toread*scan_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment