Skip to content

Instantly share code, notes, and snippets.

@pcercuei
Created May 11, 2016 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcercuei/6c87d464d4dc950bd8140c72fd6cc2b9 to your computer and use it in GitHub Desktop.
Save pcercuei/6c87d464d4dc950bd8140c72fd6cc2b9 to your computer and use it in GitHub Desktop.
#include <iio.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void scan_cb(const char *uri, const char *description,
bool connected, void *user_data)
{
bool *found = user_data;
printf("Device %s with URI %s %sconnected!\n",
description, uri, connected ? "" : "dis");
*found = true;
}
int main(void)
{
struct iio_scan_context *scan;
bool found = false;
scan = iio_create_scan_context(scan_cb, &found);
if (!scan) {
perror("Unable to create scan context");
return EXIT_FAILURE;
}
printf("Scan context created, polling now\n");
do {
if (!iio_scan_context_poll(scan))
usleep(4000);
} while (!found);
iio_scan_context_destroy(scan);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment