2 * Author: Henry Bruce <henry.bruce@intel.com>
3 * Copyright (c) 2015 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 * @brief API to Industrial IO
38 * This file defines the C++ iio interface for libmraa
40 * @snippet iio_dummy_test.cpp Interesting
46 * Iio Constructor, takes a device number which will map directly to sysfs
47 * e.g. device 0 mAps to /sys/bus/iio/devices/iio:device0
49 * @param device IIO device number
51 * @throws std::invalid_argument if initialization fails
55 m_iio = mraa_iio_init(device);
57 std::ostringstream oss;
58 oss << "IIO device " << device << " is not valid";
59 throw std::invalid_argument(oss.str());
75 * @returns The device name
80 return mraa_iio_get_device_name(m_iio);
84 * Read an integer value from specified attribute.
86 * @returns The integer value
88 * @throws std::invalid_argument if read fails
91 readInt(const std::string& attributeName)
94 mraa_result_t res = mraa_iio_read_integer(m_iio, attributeName.c_str(), &value);
95 if (res != MRAA_SUCCESS) {
96 std::ostringstream oss;
97 oss << "IIO readInt for attibute " << attributeName << " failed";
98 throw std::runtime_error(oss.str());
104 * Read a float value from specified attribute.
106 * @returns The float value
108 * @throws std::invalid_argument if read fails
111 readFloat(const std::string& attributeName)
114 mraa_result_t res = mraa_iio_read_float(m_iio, attributeName.c_str(), &value);
115 if (res != MRAA_SUCCESS) {
116 std::ostringstream oss;
117 oss << "IIO readFloat for attibute " << attributeName << " failed";
118 throw std::runtime_error(oss.str());
124 * Write an integer value to specified attribute.
126 * @throws std::invalid_argument if write fails
129 writeInt(const std::string& attributeName, int value)
131 mraa_result_t res = mraa_iio_write_integer(m_iio, attributeName.c_str(), value);
132 if (res != MRAA_SUCCESS) {
133 std::ostringstream oss;
134 oss << "IIO writeInt for attibute " << attributeName << " failed";
135 throw std::runtime_error(oss.str());
141 * Write a float value to specified attribute.
143 * @throws std::invalid_argument if write fails
146 writeFloat(const std::string& attributeName, float value)
148 mraa_result_t res = mraa_iio_write_float(m_iio, attributeName.c_str(), value);
149 if (res != MRAA_SUCCESS) {
150 std::ostringstream oss;
151 oss << "IIO writeFloat for attibute " << attributeName << " failed";
152 throw std::runtime_error(oss.str());
159 mraa_iio_context m_iio;