Private
Public Access
2
0

examples: Added iio_dummy_test, a test app that uses iio_dummy driver

Signed-off-by: Henry Bruce <henry.bruce@intel.com>
This commit is contained in:
Henry Bruce
2015-12-02 10:37:23 -08:00
committed by Brendan Le Foll
parent fbfe3e315f
commit 448f14f41c
2 changed files with 61 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ 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)
add_executable (iio_dummy_test iio_dummy_test.c)
include_directories(${PROJECT_SOURCE_DIR}/api)
# FIXME Hack to access mraa internal types used by mraa-i2c
@@ -34,6 +35,7 @@ target_link_libraries (mraa-gpio mraa)
target_link_libraries (mraa-i2c mraa)
target_link_libraries (spi_max7219 mraa)
target_link_libraries (iio_driver mraa)
target_link_libraries (iio_dummy_test mraa)
add_subdirectory (c++)

59
examples/iio_dummy_test.c Normal file
View File

@@ -0,0 +1,59 @@
/*
* 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>
#include "mraa/iio.h"
int
main()
{
mraa_iio_context iio_device0 = mraa_iio_init(0);
char* attr_name;
if (iio_device0 == NULL) {
fprintf(stderr, "IIO device %d not found\n", 0);
return EXIT_FAILURE;
}
fprintf(stderr, "Using IIO device %s\n", mraa_iio_get_device_name(iio_device0));
float iio_float;
int iio_integer;
mraa_result_t ret;
attr_name = "in_accel_x_raw";
fprintf(stdout, "IIO write in_accel_x_raw: ");
ret = mraa_iio_write_float(iio_device0, "in_accel_x_raw", 0.019163);
if (ret != MRAA_SUCCESS) {
mraa_result_print(ret);
}
fprintf(stdout, "IIO read in_accel_x_raw\n");
ret = mraa_iio_read_float(iio_device0, "in_accel_x_raw", &iio_float);
if (ret == MRAA_SUCCESS)
fprintf(stdout, "in_accel_x_raw: %f\n", iio_float);
else
mraa_result_print(ret);
return EXIT_SUCCESS;
}