Event Handling Functions

static inline enum iio_event_type iio_event_get_type(const struct iio_event *event)

Get the type of a given IIO event.

NOTE:Corresponds to the IIO_EVENT_CODE_EXTRACT_TYPE macro of <linux/iio/events.h>.

Parameters:

event – A pointer to an iio_event structure

Returns:

An enum iio_event_type.

static inline enum iio_event_direction iio_event_get_direction(const struct iio_event *event)

Get the direction of a given IIO event.

NOTE:Corresponds to the IIO_EVENT_CODE_EXTRACT_DIR macro of <linux/iio/events.h>.

Parameters:

event – A pointer to an iio_event structure

Returns:

An enum iio_event_direction.

const struct iio_channel *iio_event_get_channel(const struct iio_event *event, const struct iio_device *dev, bool diff)

Get a pointer to the IIO channel that corresponds to this event.

Parameters:
  • event – A pointer to an iio_event structure

  • dev – A pointer to the iio_device structure that delivered the event

  • diff – If set, retrieve the differential channel

Returns:

On success, a pointer to an iio_channel structure

Returns:

On error, NULL is returned

struct iio_event_stream *iio_device_create_event_stream(const struct iio_device *dev)

Create an events stream for the given IIO device.

Parameters:

dev – A pointer to an iio_device structure

Returns:

On success, a pointer to an iio_event_stream structure

Returns:

On failure, a pointer-encoded error is returned

void iio_event_stream_destroy(struct iio_event_stream *stream)

Destroy the given event stream.

Parameters:

stream – A pointer to an iio_event_stream structure

int iio_event_stream_read(struct iio_event_stream *stream, struct iio_event *out_event, bool nonblock)

Read an event from the event stream.

NOTE: it is possible to stop a blocking call of iio_event_stream_read by calling iio_event_stream_destroy in a different thread or signal handler. In that case, iio_event_stream_read will return -EINTR.

Parameters:
  • stream – A pointer to an iio_event_stream structure

  • out_event – An pointer to an iio_event structure, that will be filled by this function.

  • nonblock – if True, the operation won’t block and return -EBUSY if there is currently no event in the queue.

Returns:

On success, 0 is returned

Returns:

On error, a negative errno code is returned.

struct iio_event
#include <iio.h>

Represents a IIO event.

This structure is the same as ‘iio_event_data’ from <linux/iio/events.h>.