mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Public Member Functions
Iio Class Reference

Detailed Description

This file defines the C++ iio interface for libmraa

IioTestHandler testHandler;
std::string deviceName;
try {
mraa::Iio* iio_device0 = new mraa::Iio(0);
std::cout << "IIO device 0 found by id." << std::endl;
deviceName = iio_device0->getDeviceName();
delete iio_device0;
} catch (std::exception& e) {
std::cerr << "IIO device 0 not found." << std::endl;
return EXIT_FAILURE;
}
try {
mraa::Iio* iio_device1 = new mraa::Iio(1);
delete iio_device1;
} catch (std::exception& e) {
std::cerr << "IIO device 1 not found. This is expected behavior." << std::endl;
}
try {
iio_device = new mraa::Iio(deviceName);
std::cout << "IIO device 0 found by name." << std::endl;
} catch (std::exception& e) {
std::cerr << "IIO device 0 not found." << std::endl;
return EXIT_FAILURE;
}
std::cout << "Using IIO device0. Name is " << iio_device->getDeviceName() << std::endl;
IIO_RUN(writeFloat, "in_accel_x_raw", 100, EXPECT_FAILURE);
IIO_RUN(writeFloat, "in_voltage0_scale", 100, EXPECT_FAILURE);
IIO_RUN(writeInt, "out_voltage0_raw", 100, EXPECT_SUCCESS);
IIO_TEST(readInt, "in_accel_x_raw", 34, EXPECT_SUCCESS);
IIO_TEST(readFloat, "in_voltage0_scale", 0.001333, EXPECT_SUCCESS);
IIO_RUN(writeInt, "events/in_voltage0_thresh_rising_en", 1, EXPECT_SUCCESS);
IIO_TRY(registerEventHandler(&testHandler));
eventCount = 0;
generate_event();
usleep(500000);
log_result("eventReceived", "", (eventCount == 1), true);

Public Member Functions

 Iio (int device)
 
 Iio (const std::string &deviceName)
 
 Iio (void *iio_context)
 
 ~Iio ()
 
std::string getDeviceName () const
 
int readInt (const std::string &attributeName) const
 
float readFloat (const std::string &attributeName) const
 
void writeInt (const std::string &attributeName, int value) const
 
void writeFloat (const std::string &attributeName, float value) const
 
void registerEventHandler (IioHandler *handler) const
 

Constructor & Destructor Documentation

Iio ( int  device)
inline

Iio Constructor, takes a device number which will map directly to sysfs e.g. device 0 maps to /sys/bus/iio/devices/iio:device0

Parameters
deviceIIO device number
Exceptions
std::invalid_argumentif initialization fails

Here is the call graph for this function:

Iio ( const std::string &  deviceName)
inline

Iio Constructor

Parameters
deviceNameIIO device name
Exceptions
std::invalid_argumentif initialization fails

Here is the call graph for this function:

Iio ( void *  iio_context)
inline

IIO constructor, takes a pointer to a IIO context and initialises the IIO class

Parameters
iio_contextvoid * to an IIO context
~Iio ( )
inline

Iio destructor

Here is the call graph for this function:

Member Function Documentation

std::string getDeviceName ( ) const
inline

Get device name

Returns
The device name

Here is the call graph for this function:

int readInt ( const std::string &  attributeName) const
inline

Read an int value from specified attribute.

Parameters
attributeNameattribute mame
Returns
The int value
Exceptions
std::invalid_argumentif read fails

Here is the call graph for this function:

float readFloat ( const std::string &  attributeName) const
inline

Read a float value from specified attribute.

Parameters
attributeNameattribute mame
Returns
The float value
Exceptions
std::invalid_argumentif read fails

Here is the call graph for this function:

void writeInt ( const std::string &  attributeName,
int  value 
) const
inline

Write an int value to specified attribute.

Parameters
attributeNameattribute mame
valueint value
Exceptions
std::invalid_argumentif write fails

Here is the call graph for this function:

void writeFloat ( const std::string &  attributeName,
float  value 
) const
inline

Write a float value to specified attribute.

Parameters
attributeNameattribute mame
valuefloat value
Exceptions
std::invalid_argumentif write fails

Here is the call graph for this function:

void registerEventHandler ( IioHandler handler) const
inline

Register event handler.

Parameters
handlerhandler class that implements IioHandler
Exceptions
std::invalid_argumenton failure

Here is the call graph for this function:


The documentation for this class was generated from the following file: