49 virtual void onIioEvent(
const IioEventData& eventData) = 0;
76 std::ostringstream oss;
77 oss <<
"IIO device " << device <<
" is not valid";
78 throw std::invalid_argument(oss.str());
89 Iio(
const std::string& deviceName)
91 std::ostringstream oss;
92 int id = mraa_iio_get_device_num_by_name(deviceName.c_str());
94 oss <<
"IIO device name " << deviceName <<
" not found";
95 throw std::invalid_argument(oss.str());
99 oss <<
"IIO device " << deviceName <<
" is not valid";
100 throw std::invalid_argument(oss.str());
121 return mraa_iio_get_device_name(m_iio);
134 readInt(
const std::string& attributeName)
const
137 mraa_result_t res = mraa_iio_read_int(m_iio, attributeName.c_str(), &value);
139 std::ostringstream oss;
140 oss <<
"IIO readInt for attibute " << attributeName <<
" failed";
141 throw std::runtime_error(oss.str());
159 mraa_result_t res = mraa_iio_read_float(m_iio, attributeName.c_str(), &value);
161 std::ostringstream oss;
162 oss <<
"IIO readFloat for attibute " << attributeName <<
" failed";
163 throw std::runtime_error(oss.str());
177 writeInt(
const std::string& attributeName,
int value)
const
179 mraa_result_t res = mraa_iio_write_int(m_iio, attributeName.c_str(), value);
181 std::ostringstream oss;
182 oss <<
"IIO writeInt for attibute " << attributeName <<
" failed";
183 throw std::runtime_error(oss.str());
197 writeFloat(
const std::string& attributeName,
float value)
const
199 mraa_result_t res = mraa_iio_write_float(m_iio, attributeName.c_str(), value);
201 std::ostringstream oss;
202 oss <<
"IIO writeFloat for attibute " << attributeName <<
" failed";
203 throw std::runtime_error(oss.str());
218 mraa_result_t res = mraa_iio_event_setup_callback(m_iio, private_event_handler, handler);
220 throw std::runtime_error(
"registerEventHandler failed");
225 static void private_event_handler(
iio_event_data* data,
void *args)
230 int chan_type, modifier, type, direction, channel, channel2, different;
231 mraa_iio_event_extract_event(data, &chan_type, &modifier, &type, &direction, &channel, &channel2, &different);
232 eventData.channelType = chan_type;
233 eventData.modifier = modifier;
234 eventData.type = type;
235 eventData.direction = direction;
236 eventData.channel = channel;
237 eventData.channel2 = channel2;
238 eventData.diff = different;
239 handler->onIioEvent(eventData);
~Iio()
Definition: iio.hpp:107
Iio(int device)
Definition: iio.hpp:72
mraa_result_t mraa_iio_close(mraa_iio_context dev)
std::string getDeviceName() const
Definition: iio.hpp:119
int readInt(const std::string &attributeName) const
Definition: iio.hpp:134
API to Industrial IO.
Definition: iio.hpp:61
Iio(const std::string &deviceName)
Definition: iio.hpp:89
void registerEventHandler(IioHandler *handler) const
Definition: iio.hpp:216
float readFloat(const std::string &attributeName) const
Definition: iio.hpp:156
mraa_iio_context mraa_iio_init(int device)
void writeFloat(const std::string &attributeName, float value) const
Definition: iio.hpp:197
struct _iio * mraa_iio_context
Definition: iio.h:72
mraa_result_t
Definition: types.h:204
void writeInt(const std::string &attributeName, int value) const
Definition: iio.hpp:177
Definition: iio_kernel_headers.h:122