49 virtual void onIioEvent(
const IioEventData& eventData) = 0;
75 std::ostringstream oss;
76 oss <<
"IIO device " << device <<
" is not valid";
77 throw std::invalid_argument(oss.str());
88 Iio(
const std::string& deviceName)
90 std::ostringstream oss;
91 int id = mraa_iio_get_device_num_by_name(deviceName.c_str());
93 oss <<
"IIO device name " << deviceName <<
" not found";
94 throw std::invalid_argument(oss.str());
98 oss <<
"IIO device " << deviceName <<
" is not valid";
99 throw std::invalid_argument(oss.str());
120 return mraa_iio_get_device_name(m_iio);
133 readInt(
const std::string& attributeName)
const
136 mraa_result_t res = mraa_iio_read_int(m_iio, attributeName.c_str(), &value);
138 std::ostringstream oss;
139 oss <<
"IIO readInt for attibute " << attributeName <<
" failed";
140 throw std::runtime_error(oss.str());
158 mraa_result_t res = mraa_iio_read_float(m_iio, attributeName.c_str(), &value);
160 std::ostringstream oss;
161 oss <<
"IIO readFloat for attibute " << attributeName <<
" failed";
162 throw std::runtime_error(oss.str());
176 writeInt(
const std::string& attributeName,
int value)
const
178 mraa_result_t res = mraa_iio_write_int(m_iio, attributeName.c_str(), value);
180 std::ostringstream oss;
181 oss <<
"IIO writeInt for attibute " << attributeName <<
" failed";
182 throw std::runtime_error(oss.str());
196 writeFloat(
const std::string& attributeName,
float value)
const
198 mraa_result_t res = mraa_iio_write_float(m_iio, attributeName.c_str(), value);
200 std::ostringstream oss;
201 oss <<
"IIO writeFloat for attibute " << attributeName <<
" failed";
202 throw std::runtime_error(oss.str());
217 mraa_result_t res = mraa_iio_event_setup_callback(m_iio, private_event_handler, handler);
219 throw std::runtime_error(
"registerEventHandler failed");
224 static void private_event_handler(
iio_event_data* data,
void *args)
229 int chan_type, modifier, type, direction, channel, channel2, different;
230 mraa_iio_event_extract_event(data, &chan_type, &modifier, &type, &direction, &channel, &channel2, &different);
231 eventData.channelType = chan_type;
232 eventData.modifier = modifier;
233 eventData.type = type;
234 eventData.direction = direction;
235 eventData.channel = channel;
236 eventData.channel2 = channel2;
237 eventData.diff = different;
238 handler->onIioEvent(eventData);
~Iio()
Definition: iio.hpp:106
Iio(int device)
Definition: iio.hpp:71
mraa_result_t mraa_iio_close(mraa_iio_context dev)
std::string getDeviceName() const
Definition: iio.hpp:118
int readInt(const std::string &attributeName) const
Definition: iio.hpp:133
API to Industrial IO.
Definition: iio.hpp:60
Iio(const std::string &deviceName)
Definition: iio.hpp:88
void registerEventHandler(IioHandler *handler) const
Definition: iio.hpp:215
float readFloat(const std::string &attributeName) const
Definition: iio.hpp:155
mraa_iio_context mraa_iio_init(int device)
void writeFloat(const std::string &attributeName, float value) const
Definition: iio.hpp:196
struct _iio * mraa_iio_context
Definition: iio.h:72
mraa_result_t
Definition: types.h:193
void writeInt(const std::string &attributeName, int value) const
Definition: iio.hpp:176
Definition: iio_kernel_headers.h:117