iio_driver.c: Add example for iio interface
authorBrendan Le Foll <brendan.le.foll@intel.com>
Mon, 28 Sep 2015 15:53:58 +0000 (16:53 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 15 Dec 2015 10:42:06 +0000 (10:42 +0000)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
examples/CMakeLists.txt
examples/iio_driver.c [new file with mode: 0644]

index 5ca1431..c0df374 100644 (file)
@@ -12,6 +12,7 @@ add_executable (uart uart.c)
 add_executable (mraa-gpio mraa-gpio.c)
 add_executable (mraa-i2c mraa-i2c.c)
 add_executable (spi_max7219 spi_max7219.c)
+add_executable (iio_driver iio_driver.c)
 
 include_directories(${PROJECT_SOURCE_DIR}/api)
 # FIXME Hack to access mraa internal types used by mraa-i2c
@@ -32,6 +33,7 @@ target_link_libraries (uart mraa)
 target_link_libraries (mraa-gpio mraa)
 target_link_libraries (mraa-i2c mraa)
 target_link_libraries (spi_max7219 mraa)
+target_link_libraries (iio_driver mraa)
 
 add_subdirectory (c++)
 
diff --git a/examples/iio_driver.c b/examples/iio_driver.c
new file mode 100644 (file)
index 0000000..eb9cedd
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Author: Brendan Le Foll
+ * Copyright (c) 2015 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <unistd.h>
+//! [Interesting]
+#include "mraa/iio.h"
+
+int
+main()
+{
+    mraa_iio_context iio_device0;
+
+    iio_device0 = mraa_iio_init(0);
+    if (iio_device0 == NULL) {
+        return EXIT_FAILURE;
+    }
+
+    float iio_value;
+    mraa_result_t ret = mraa_iio_read(iio_device0, 0, "raw", &iio_value);
+    if (ret == MRAA_SUCCESS) {
+        fprintf(stdout, "IIO read %f\n", iio_value);
+    }
+
+    mraa_iio_stop(iio_device0);
+
+    return EXIT_SUCCESS;
+}
+//! [Interesting]