From c1f9d15f6759cc59829d4da4f393ded2984054e0 Mon Sep 17 00:00:00 2001 From: Noel Eck Date: Wed, 17 Aug 2016 17:58:21 -0700 Subject: [PATCH] upmc: Updates for building C modules w/base UPM Test commit for building C UPM modules. * Added C include directory * Added C utilities directory * Rename C++ upm.h -> upm.hpp to make room for C upm.h * Added upm_mixed_module_init function to src/CMakeLists.txt. This function takes filesnames similar to upm_module_init and does a bit of processing before calling upm_module_init. * Added c example directory. Changed c++ example names. * Added dfrph implemention for testing (C++ wraps C). Added mraa to .pc requires for dfrph. Tested against stand-alone project. Added dfrph c example. * Update implemention of pkg-config file generation. * Added two cmake cache variables: BUILDCPP and BUILDFTI * Removed src from swig_add_module calls, added libname to swig_link_libraries calls. Shrinks swig'ed binaries by ~13%. * Added install target in upm/CMakeLists.txt to install C header, directory. Is this where we want this? * C FTI header directory is include/fti Signed-off-by: Noel Eck --- CMakeLists.txt | 25 ++++-- docs/documentation.md | 2 +- doxy/Doxyfile.in | 2 +- doxy/Doxyfile.java.in | 2 +- examples/c++/CMakeLists.txt | 6 +- examples/c/CMakeLists.txt | 89 ++++++++++++++++++++ examples/c/dfrph.c | 76 +++++++++++++++++ include/fti/upm_acceleration.h | 45 ++++++++++ include/fti/upm_angle.h | 42 ++++++++++ include/fti/upm_audio.h | 44 ++++++++++ include/fti/upm_distance.h | 43 ++++++++++ include/fti/upm_heart_rate.h | 43 ++++++++++ include/fti/upm_joystick.h | 54 ++++++++++++ include/fti/upm_light.h | 48 +++++++++++ include/fti/upm_moisture.h | 33 ++++++++ include/fti/upm_ph.h | 48 +++++++++++ include/fti/upm_potentiometer.h | 42 ++++++++++ include/fti/upm_raw.h | 48 +++++++++++ include/fti/upm_sensor.h | 45 ++++++++++ include/fti/upm_servo.h | 41 ++++++++++ include/fti/upm_stream.h | 45 ++++++++++ include/fti/upm_switch.h | 42 ++++++++++ include/fti/upm_temperature.h | 44 ++++++++++ include/fti/upm_touch.h | 36 ++++++++ include/fti/upm_vibration.h | 40 +++++++++ include/fti/upm_voltage.h | 47 +++++++++++ include/upm.h | 45 ++++++++++ include/upm_fti.h | 122 ++++++++++++++++++++++++++++ include/upm_internal.h | 27 ++++++ include/upm_math.h | 39 +++++++++ include/upm_types.h | 60 ++++++++++++++ src/CMakeLists.txt | 140 ++++++++++++++++++++++++++------ src/dfrph/CMakeLists.txt | 14 ++-- src/dfrph/dfrph.c | 103 +++++++++++++++++++++++ src/dfrph/dfrph.cxx | 52 ++++++------ src/dfrph/dfrph.h | 97 ++++++++++++++++++++++ src/dfrph/dfrph.hpp | 36 ++++---- src/dfrph/dfrph_fti.c | 118 +++++++++++++++++++++++++++ src/lcd/CMakeLists.txt | 0 src/lcd/jsupm_i2clcd.i | 0 src/lcd/pyupm_i2clcd.i | 0 src/pkgconfig.in | 6 +- src/{upm.h => upm.hpp} | 0 src/utilities/CMakeLists.txt | 4 + src/utilities/upm_utilities.c | 69 ++++++++++++++++ src/utilities/upm_utilities.h | 68 ++++++++++++++++ 46 files changed, 1945 insertions(+), 87 deletions(-) create mode 100644 examples/c/CMakeLists.txt create mode 100644 examples/c/dfrph.c create mode 100644 include/fti/upm_acceleration.h create mode 100644 include/fti/upm_angle.h create mode 100644 include/fti/upm_audio.h create mode 100644 include/fti/upm_distance.h create mode 100644 include/fti/upm_heart_rate.h create mode 100644 include/fti/upm_joystick.h create mode 100644 include/fti/upm_light.h create mode 100644 include/fti/upm_moisture.h create mode 100644 include/fti/upm_ph.h create mode 100644 include/fti/upm_potentiometer.h create mode 100644 include/fti/upm_raw.h create mode 100644 include/fti/upm_sensor.h create mode 100644 include/fti/upm_servo.h create mode 100644 include/fti/upm_stream.h create mode 100644 include/fti/upm_switch.h create mode 100644 include/fti/upm_temperature.h create mode 100644 include/fti/upm_touch.h create mode 100644 include/fti/upm_vibration.h create mode 100644 include/fti/upm_voltage.h create mode 100644 include/upm.h create mode 100644 include/upm_fti.h create mode 100644 include/upm_internal.h create mode 100644 include/upm_math.h create mode 100644 include/upm_types.h create mode 100644 src/dfrph/dfrph.c create mode 100644 src/dfrph/dfrph.h create mode 100644 src/dfrph/dfrph_fti.c mode change 100755 => 100644 src/lcd/CMakeLists.txt mode change 100755 => 100644 src/lcd/jsupm_i2clcd.i mode change 100755 => 100644 src/lcd/pyupm_i2clcd.i rename src/{upm.h => upm.hpp} (100%) create mode 100644 src/utilities/CMakeLists.txt create mode 100644 src/utilities/upm_utilities.c create mode 100644 src/utilities/upm_utilities.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d4b47e56..8775c91c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,12 +48,14 @@ set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_ set (CMAKE_SWIG_FLAGS "") -option (BUILDDOC "Build all doc." OFF) -option (BUILDSWIGPYTHON "Build swig python modules." ON) -option (BUILDSWIGNODE "Build swig node modules." ON) +option (BUILDDOC "Build all doc" OFF) +option (BUILDCPP "Build CPP sensor libraries" ON) +option (BUILDFTI "Build Funtion Table Interface (FTI) in C sensor libraries" OFF) +option (BUILDSWIGPYTHON "Build swig python modules" ON) +option (BUILDSWIGNODE "Build swig node modules" ON) option (BUILDSWIGJAVA "Build swig java modules" OFF) option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF) -option (BUILDEXAMPLES "Build C++ example binaries" OFF) +option (BUILDEXAMPLES "Build C/C++ example binaries" OFF) option (BUILDJAVAEXAMPLES "Build java example jars" OFF) option (IPK "Generate IPK using CPack" OFF) option (RPM "Generate RPM using CPack" OFF) @@ -238,18 +240,29 @@ if (BUILDSWIGPYTHON OR BUILDTESTS) endif () endif () +# UPM common headers +set (UPM_COMMON_HEADER_DIRS + ${CMAKE_HOME_DIRECTORY}/include + ${CMAKE_HOME_DIRECTORY}/include/fti) + add_subdirectory (src) if(BUILDEXAMPLES) - add_subdirectory (examples/c++) + add_subdirectory (examples/c) + if(BUILDCPP) + add_subdirectory (examples/c++) + endif(BUILDCPP) endif() if(BUILDJAVAEXAMPLES) add_subdirectory (examples/java) endif() - if (BUILDTESTS) find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED) enable_testing () add_subdirectory (tests) endif() + +# Install C headers +install(DIRECTORY include/ DESTINATION include/upm + FILES_MATCHING PATTERN "*.h") diff --git a/docs/documentation.md b/docs/documentation.md index 13712bbb..cac443b9 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -66,7 +66,7 @@ Here's an example (disregard the "@verbatim" tags in your actual code): - `` Specifies if the sensor is part of a kit. *Optional* Existing groups that can be used for the manufacturer, connection, category and -kit tags are found in the src/upm.h file. +kit tags are found in the src/upm.hpp file. Optionally, a small representative image can be placed in the "docs/images" subfolder and linked with the "@image" tag. diff --git a/doxy/Doxyfile.in b/doxy/Doxyfile.in index 6db46feb..ac39ab4a 100644 --- a/doxy/Doxyfile.in +++ b/doxy/Doxyfile.in @@ -764,7 +764,7 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/upm.h \ +INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/upm.hpp \ @CMAKE_CURRENT_SOURCE_DIR@/src \ @CMAKE_CURRENT_SOURCE_DIR@/docs \ @CMAKE_CURRENT_SOURCE_DIR@/doxy/README.cpp.md diff --git a/doxy/Doxyfile.java.in b/doxy/Doxyfile.java.in index bc873d18..97373e1c 100644 --- a/doxy/Doxyfile.java.in +++ b/doxy/Doxyfile.java.in @@ -764,7 +764,7 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/upm.h \ +INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/upm.hpp \ @CMAKE_BINARY_DIR@/src \ @CMAKE_CURRENT_SOURCE_DIR@/docs \ @CMAKE_CURRENT_SOURCE_DIR@/doxy/README.java.md diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 8388f1de..f4a3dc7e 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -51,7 +51,7 @@ endmacro() # Note special case for grove based examples macro(add_example example_name) set(example_src "${example_name}.cxx") - set(example_bin "${example_name}-example") + set(example_bin "${example_name}-example-cxx") get_module_name(${example_name} module_name) set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}") if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}" @@ -73,6 +73,10 @@ endmacro() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples) +# UPM c include directories +include_directories (${PROJECT_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src/utilities) + # Set the mraa include and link directories prior to adding examples include_directories (${MRAA_INCLUDE_DIRS}) link_directories (${MRAA_LIBDIR}) diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt new file mode 100644 index 00000000..a6cbca89 --- /dev/null +++ b/examples/c/CMakeLists.txt @@ -0,0 +1,89 @@ +# Extract module name from non-standard example name +macro(get_module_name example_name module_name) + string(LENGTH ${example_name} length) + string(FIND ${example_name} "-" index) + if (${index} GREATER 1) + string(SUBSTRING ${example_name} 0 ${index} substr) + set(${module_name} ${substr}) + elseif (${example_name} MATCHES "^grove") + set (${module_name} "grove") + elseif ((${example_name} MATCHES "^mq" AND ${length} EQUAL 3) OR ${example_name} STREQUAL "tp401") + set (${module_name} "gas") + else() + set(${module_name} ${example_name}) + endif() +endmacro() + +# Set source file, include and linker settings for an example +# If example cannot be built, example_bin is cleared +macro(add_custom_example example_bin example_src example_module_list) + set(found_all_modules TRUE) + foreach (module ${example_module_list}) + if (NOT EXISTS "${PROJECT_SOURCE_DIR}/src/${module}") + set(found_all_modules FALSE) + endif() + if (MODULE_LIST) + list(FIND MODULE_LIST ${module} index) + if (${index} EQUAL -1) + set(found_all_modules FALSE) + endif() + endif() + endforeach() + if (found_all_modules) + add_executable (${example_bin} ${example_src}) + target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT}) + foreach (module ${example_module_list}) + set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}") + include_directories (${module_dir}) + if (${module} STREQUAL "lcd") + set(module "i2clcd") + endif() + target_link_libraries (${example_bin} ${module}) + endforeach() + else() + MESSAGE(INFO " Ignored ${example_bin}") + set (example_bin "") + endif() +endmacro() + + +# Add specified example by name +# Note special case for grove based examples +macro(add_example example_name) + set(example_src "${example_name}.c") + set(example_bin "${example_name}-example-c") + get_module_name(${example_name} module_name) + set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}") + if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}" + AND EXISTS ${module_dir} + AND IS_DIRECTORY ${module_dir}) + add_custom_example(${example_bin} ${example_src} ${module_name}) + if ((NOT ${example_bin} STREQUAL "") AND (${module_name} STREQUAL "grove")) + set(grove_module_path "${PROJECT_SOURCE_DIR}/src/${example_name}") + if (EXISTS ${grove_module_path}) + include_directories(${grove_module_path}) + target_link_libraries (${example_bin} ${example_name}) + endif() + endif() + else() + MESSAGE(INFO " Ignored ${example_bin}") + endif() +endmacro() + + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples) + +# UPM c include directories +include_directories (${PROJECT_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src/utilities) + +# Set the mraa include and link directories prior to adding examples +include_directories (${MRAA_INCLUDE_DIRS}) +link_directories (${MRAA_LIBDIR}) + +# If your sample source file matches the name of the module it tests, add it here +# Exceptions are as follows: +# string after first '-' is ignored (e.g. nrf24l01-transmitter maps to nrf24l01) +# mq? will use module gas +# grove* will use module grove +add_example (dfrph) diff --git a/examples/c/dfrph.c b/examples/c/dfrph.c new file mode 100644 index 00000000..4f53008a --- /dev/null +++ b/examples/c/dfrph.c @@ -0,0 +1,76 @@ +/* + * Author: Jon Trulson + * Copyright (c) 2016 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 +#include + +#include "dfrph.h" + +bool shouldRun = true; + +void sig_handler(int signo) +{ + if (signo == SIGINT) + shouldRun = false; +} + +int main() +{ + signal(SIGINT, sig_handler); + +//! [Interesting] + + // Instantiate a dfrph sensor on analog pin A0 + dfrph_context sensor = dfrph_init(0); + + if (!sensor) + { + printf("dfrph_init() failed.\n"); + return(1); + } + + // Every half a second, sample the URM37 and output the measured + // distance in cm. + + while (shouldRun) + { + float volts = 0.0, pH = 0.0; + + dfrph_get_raw_volts(sensor, &volts); + dfrph_get_ph(sensor, &pH); + + printf("Detected volts: %0.03f\n", volts); + printf("pH value: %0.03f\n", pH); + + usleep(500000); + } + +//! [Interesting] + + printf("Exiting\n"); + + dfrph_close(sensor); + + return 0; +} diff --git a/include/fti/upm_acceleration.h b/include/fti/upm_acceleration.h new file mode 100644 index 00000000..2f558210 --- /dev/null +++ b/include/fti/upm_acceleration.h @@ -0,0 +1,45 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_ACCELERATION_H_ +#define UPM_ACCELERATION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Acceleration units +typedef enum _upm_acceleration_u {G, METERS_PER_SECOND_SQ, FEET_PER_SECOND_SQ} upm_acceleration_u; + +// Acceleration function table +typedef struct _upm_acceleration_ft { + upm_result_t (*upm_acceleration_set_scale) (void* dev, float* scale); + upm_result_t (*upm_acceleration_set_offset) (void* dev, float* offset); + upm_result_t (*upm_acceleration_get_value) (void* dev, float* value, upm_acceleration_u unit); +} upm_acceleration_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_ACCELERATION_H_ */ diff --git a/include/fti/upm_angle.h b/include/fti/upm_angle.h new file mode 100644 index 00000000..4607e523 --- /dev/null +++ b/include/fti/upm_angle.h @@ -0,0 +1,42 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ + +#ifndef UPM_ANGLE_H_ +#define UPM_ANGLE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum _upm_angle_u {DEGREES, RADIANS} upm_angle_u; + +typedef struct _upm_angle_ft { + upm_result_t (*upm_angle_get_value) (void* dev, float* value, upm_angle_u unit); +} upm_angle_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_ANGLE_H_ */ diff --git a/include/fti/upm_audio.h b/include/fti/upm_audio.h new file mode 100644 index 00000000..7908ecfc --- /dev/null +++ b/include/fti/upm_audio.h @@ -0,0 +1,44 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ + +#ifndef UPM_AUDIO_H_ +#define UPM_AUDIO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Audio unit +typedef enum _upm_audio_u {DECIBELS} upm_audio_u; + +// Audio function table +typedef struct _upm_audio_ft { + upm_result_t (*upm_audio_get_value) (void* dev, float* value, upm_audio_u unit); +} upm_audio_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_AUDIO_H_ */ diff --git a/include/fti/upm_distance.h b/include/fti/upm_distance.h new file mode 100644 index 00000000..1b91403e --- /dev/null +++ b/include/fti/upm_distance.h @@ -0,0 +1,43 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_DISTANCE_H_ +#define UPM_DISTANCE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Distance units +typedef enum _upm_distance_u {CENTIMETER, INCH} upm_distance_u; + +// Distance function table +typedef struct _upm_dist_ft { + upm_result_t (*upm_distance_get_value) (void* dev, float* value, upm_distance_u unit); +} upm_distance_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_SENSOR_DISTANCE_H_ */ diff --git a/include/fti/upm_heart_rate.h b/include/fti/upm_heart_rate.h new file mode 100644 index 00000000..081680f1 --- /dev/null +++ b/include/fti/upm_heart_rate.h @@ -0,0 +1,43 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_HEART_RATE_H_ +#define UPM_HEART_RATE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Heart rate units +typedef enum _upm_heart_rate_u {BPM} upm_heart_rate_u; + +// Heart rate function table +typedef struct _upm_heart_rate_ft { + upm_result_t (*upm_heart_rate_get_value) (void* dev, int* value, upm_heart_rate_u unit); +} upm_heart_rate_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_HEART_RATE_H_ */ diff --git a/include/fti/upm_joystick.h b/include/fti/upm_joystick.h new file mode 100644 index 00000000..9eaa82dd --- /dev/null +++ b/include/fti/upm_joystick.h @@ -0,0 +1,54 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_JOYSTICK_H_ +#define UPM_JOYSTICK_H_ + +#include "upm_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Joytick function table */ +typedef struct _upm_joystick_ft +{ + /* Set sensor offset in raw counts */ + upm_result_t (*upm_joystick_set_offset_x) (const void* dev, float offset); + /* Set sensor offset in raw counts */ + upm_result_t (*upm_joystick_set_offset_y) (const void* dev, float offset); + /* Set sensor scale in raw counts */ + upm_result_t (*upm_joystick_set_scale_x) (const void* dev, float scale); + /* Set sensor scale in raw counts */ + upm_result_t (*upm_joystick_set_scale_y) (const void* dev, float scale); + /* Read sensor value, return normalized value */ + upm_result_t (*upm_joystick_get_value_x) (const void* dev, float* value); + /* Read sensor value, return normalized value */ + upm_result_t (*upm_joystick_get_value_y) (const void* dev, float* value); +} upm_joystick_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_JOYSTICK_H_ */ diff --git a/include/fti/upm_light.h b/include/fti/upm_light.h new file mode 100644 index 00000000..9af89bab --- /dev/null +++ b/include/fti/upm_light.h @@ -0,0 +1,48 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_LIGHT_H_ +#define UPM_LIGHT_H_ + +#include "upm_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* pH function table */ +typedef struct _upm_light_ft +{ + /* Set sensor offset in raw counts */ + upm_result_t (*upm_light_set_offset) (const void* dev, float offset); + /* Set sensor scale in raw counts */ + upm_result_t (*upm_light_set_scale) (const void* dev, float scale); + /* Read sensor value, return lux */ + upm_result_t (*upm_light_get_value) (const void* dev, float* value); +} upm_light_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_LIGHT_H_ */ diff --git a/include/fti/upm_moisture.h b/include/fti/upm_moisture.h new file mode 100644 index 00000000..49c8f1b8 --- /dev/null +++ b/include/fti/upm_moisture.h @@ -0,0 +1,33 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ + +#ifndef UPM_SENSOR_MOISTURE_H_ +#define UPM_SENSOR_MOISTURE_H_ +#include + +typedef struct _upm_moisture_ft { + upm_result_t (*upm_moisture_sensor_get_moisture) (void* dev, int* moisture); +} upm_moisture_ft; + +#endif /* UPM_SENSOR_MOISTURE_H_ */ diff --git a/include/fti/upm_ph.h b/include/fti/upm_ph.h new file mode 100644 index 00000000..3ef25fd9 --- /dev/null +++ b/include/fti/upm_ph.h @@ -0,0 +1,48 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_PH_H_ +#define UPM_PH_H_ + +#include "upm_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* pH function table */ +typedef struct _upm_ph_ft +{ + /* Set sensor offset in raw counts */ + upm_result_t (*upm_ph_set_offset) (const void* dev, float offset); + /* Set sensor scale in raw counts */ + upm_result_t (*upm_ph_set_scale) (const void* dev, float scale); + /* Read sensor value, return pH */ + upm_result_t (*upm_ph_get_value) (const void* dev, float* value); +} upm_ph_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_PH_H_ */ diff --git a/include/fti/upm_potentiometer.h b/include/fti/upm_potentiometer.h new file mode 100644 index 00000000..9f6f788d --- /dev/null +++ b/include/fti/upm_potentiometer.h @@ -0,0 +1,42 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ + +#ifndef UPM_POTENTIOMETER_H_ +#define UPM_POTENTIOMETER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum _upm_potentiometer_u {VOLTAGE} upm_potentiometer_u; + +typedef struct _upm_potentiometer_ft { + upm_result_t (*upm_potentiometer_get_value) (void* dev, float* value, upm_potentiometer_u unit); +} upm_potentiometer_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_POTENTIOMETER_H_ */ diff --git a/include/fti/upm_raw.h b/include/fti/upm_raw.h new file mode 100644 index 00000000..b29c64d0 --- /dev/null +++ b/include/fti/upm_raw.h @@ -0,0 +1,48 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_RAW_H_ +#define UPM_RAW_H_ + +#include "upm_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Raw counts function table */ +typedef struct _upm_raw_ft +{ + /* Set sensor offset in raw counts */ + upm_result_t (*upm_raw_set_offset) (const void* dev, float offset); + /* Set sensor scale in raw counts */ + upm_result_t (*upm_raw_set_scale) (const void* dev, float scale); + /* Read sensor value, return raw counts */ + upm_result_t (*upm_raw_get_value) (const void* dev, float* value); +} upm_raw_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_RAW_H_ */ diff --git a/include/fti/upm_sensor.h b/include/fti/upm_sensor.h new file mode 100644 index 00000000..5d0ad0e7 --- /dev/null +++ b/include/fti/upm_sensor.h @@ -0,0 +1,45 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_SENSOR_H_ +#define UPM_SENSOR_H_ + +#include "upm_types.h" +#include "upm_fti.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Generic sensor function table +typedef struct _upm_sensor_ft { + void* (*upm_sensor_init_name) (const char* protocol, const char* params); + void (*upm_sensor_close) (void* dev); + const upm_sensor_descriptor_t (*upm_sensor_get_descriptor) (const void* dev); +} upm_sensor_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_SENSOR_H_ */ diff --git a/include/fti/upm_servo.h b/include/fti/upm_servo.h new file mode 100644 index 00000000..1a5c43cc --- /dev/null +++ b/include/fti/upm_servo.h @@ -0,0 +1,41 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_SERVO_H_ +#define UPM_SERVO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Servo function table +typedef struct _upm_servo_ft { + upm_result_t (*upm_servo_set_angle) (void* dev, int angle); +} upm_servo_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_SERVO_H_ */ + diff --git a/include/fti/upm_stream.h b/include/fti/upm_stream.h new file mode 100644 index 00000000..4c4d0855 --- /dev/null +++ b/include/fti/upm_stream.h @@ -0,0 +1,45 @@ +/* + * Authors: Jon Trulson + * Copyright (c) 2016 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. + */ + +#ifndef UPM_STREAM_H_ +#define UPM_STREAM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct _upm_stream_ft { + /* read up to len bytes into buffer, return number of bytes read */ + int (*upm_stream_read) (void* dev, void *buffer, int len); + /* write up to len bytes from buffer, return number of bytes written */ + int (*upm_stream_write) (void* dev, void *buffer, int len); + /* return true if data is available to be read, false otherwise */ + bool (*upm_stream_data_available) (void* dev, unsigned int timeout); +} upm_stream_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_STREAM_H_ */ diff --git a/include/fti/upm_switch.h b/include/fti/upm_switch.h new file mode 100644 index 00000000..58c7e10f --- /dev/null +++ b/include/fti/upm_switch.h @@ -0,0 +1,42 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_SWITCH_H_ +#define UPM_SWITCH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Switch function table +typedef struct _upm_switch_ft { + upm_result_t (*upm_switch_get_value) (void* dev, bool* value, int num); + upm_result_t (*upm_switch_attach_isr) (void* dev, void (*isr)(void *), void *arg); + upm_result_t (*upm_switch_clear_isr) (void* dev); +} upm_switch_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_SWITCH_H_ */ diff --git a/include/fti/upm_temperature.h b/include/fti/upm_temperature.h new file mode 100644 index 00000000..e793ce08 --- /dev/null +++ b/include/fti/upm_temperature.h @@ -0,0 +1,44 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_TEMPERATURE_H_ +#define UPM_TEMPERATURE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Temperature units +typedef enum _upm_temperature_u {CELSIUS, FAHRENHEIT, KELVIN} upm_temperature_u; + +// Temperature function table +typedef struct _upm_temperature_ft { + upm_result_t (*upm_temperature_set_scale) (void* dev, float scale); + upm_result_t (*upm_temperature_get_value) (void* dev, float* value, upm_temperature_u unit); +} upm_temperature_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_TEMPERATURE_H_ */ diff --git a/include/fti/upm_touch.h b/include/fti/upm_touch.h new file mode 100644 index 00000000..7bf72733 --- /dev/null +++ b/include/fti/upm_touch.h @@ -0,0 +1,36 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ + +#ifndef UPM_TOUCH_H_ +#define UPM_TOUCH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_TOUCH_H_ */ diff --git a/include/fti/upm_vibration.h b/include/fti/upm_vibration.h new file mode 100644 index 00000000..f83726a3 --- /dev/null +++ b/include/fti/upm_vibration.h @@ -0,0 +1,40 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ + +#ifndef UPM_VIBRATION_H_ +#define UPM_VIBRATION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _upm_vibration_ft { + upm_result_t (*upm_vibration_get_value) (void* dev, float* value); +} upm_vibration_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_VIBRATION_H_ */ diff --git a/include/fti/upm_voltage.h b/include/fti/upm_voltage.h new file mode 100644 index 00000000..2128b526 --- /dev/null +++ b/include/fti/upm_voltage.h @@ -0,0 +1,47 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_VOLTAGE_H_ +#define UPM_VOLTAGE_H_ + +#include "upm_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Generic voltage function table */ +typedef struct _upm_voltage_ft { + /* Set sensor offset in volts */ + upm_result_t (*upm_voltage_set_offset) (const void* dev, float offset); + /* Set sensor scale in volts */ + upm_result_t (*upm_voltage_set_scale) (const void* dev, float scale); + /* Read sensor value in volts */ + upm_result_t (*upm_voltage_get_value) (const void* dev, float* value); +} upm_voltage_ft; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_VOLTAGE_H_ */ diff --git a/include/upm.h b/include/upm.h new file mode 100644 index 00000000..f5f49c5b --- /dev/null +++ b/include/upm.h @@ -0,0 +1,45 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_H_ +#define UPM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#if __STDC_VERSION__ >= 199901L +#define C99 +#endif + +#include +#include +#include + +#define upm_perror(...) perror(args, __VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_H_ */ diff --git a/include/upm_fti.h b/include/upm_fti.h new file mode 100644 index 00000000..41abba6f --- /dev/null +++ b/include/upm_fti.h @@ -0,0 +1,122 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ + +#ifndef UPM_FTI_H_ +#define UPM_FTI_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The UPM Function Table Interface (FTI) + */ + + +/* Sensor categories */ +typedef enum { + UPM_ACCELEROMETER, + UPM_ANGLE, + UPM_AUDIO, + UPM_COMPASS, + UPM_CURRENT, + UPM_DISPLAY, + UPM_DISTANCE, + UPM_ELECTRICITY, + UPM_FLOW, + UPM_FORCE, + UPM_GAS, + UPM_GYROSCOPE, + UPM_HEART_RATE, + UPM_HUMIDITY, + UPM_IMU, + UPM_JOYSTICK, + UPM_LED, + UPM_LIGHT, + UPM_MOISTURE, + UPM_NFC, + UPM_PH, + UPM_POTENTIOMETER, + UPM_PRESSURE, + UPM_RAW, + UPM_SENSOR, + UPM_SERVO, + UPM_STEPPER, + UPM_SWITCH, + UPM_TEMPERATURE, + UPM_TIME, + UPM_VIBRATION, + UPM_VIDEO, + UPM_VOLTAGE, + UPM_WIRELESS, + UPM_STREAM +} upm_sensor_t; + +/* Supported IO protocols via MRAA */ +typedef enum { + UPM_ANALOG, + UPM_GPIO, + UPM_PWM, + UPM_I2C, + UPM_SPI, + UPM_UART, + UPM_ONEWIRE +} upm_protocol_t; + +/* Sensor descriptor */ +typedef struct _upm_sensor_descriptor { + const char* name; + const char* description; + int protocol_size; + const upm_protocol_t* protocol; + int category_size; + const upm_sensor_t* category; +} upm_sensor_descriptor_t; + +/* Function pointer typedef helpers */ +typedef struct _upm_sensor_ft* (*func_get_upm_sensor_ft)(upm_sensor_t sensor_type); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_FTI_H_ */ diff --git a/include/upm_internal.h b/include/upm_internal.h new file mode 100644 index 00000000..ee99d286 --- /dev/null +++ b/include/upm_internal.h @@ -0,0 +1,27 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_INTERNAL_H_ +#define UPM_INTERNAL_H_ + +#endif /* UPM_INTERNAL_H_ */ diff --git a/include/upm_math.h b/include/upm_math.h new file mode 100644 index 00000000..451c05c7 --- /dev/null +++ b/include/upm_math.h @@ -0,0 +1,39 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_MATH_H_ +#define UPM_MATH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef linux +#include +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_MATH_H_ */ diff --git a/include/upm_types.h b/include/upm_types.h new file mode 100644 index 00000000..ecb9b166 --- /dev/null +++ b/include/upm_types.h @@ -0,0 +1,60 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_TYPES_H_ +#define UPM_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef C99 +#include +#elif __cplusplus +#else +typedef enum { + false = 0, + true = 1 +} bool; +#endif + +typedef enum { + UPM_SUCCESS = 0, /* Operation is successful, expected response */ + UPM_ERROR_NOT_IMPLEMENTED = 1, /* Trying to access a feature or mode that is not implemented */ + UPM_ERROR_NOT_SUPPORTED = 2, /* Trying to access a feature or mode that is not supported */ + UPM_ERROR_NO_RESOURCES = 3, /* No resources to perform operation */ + UPM_ERROR_NO_DATA = 4, /* No data received or available from the sensor */ + UPM_ERROR_INVALID_PARAMETER = 5, /* Invalid parameter passed to the function*/ + UPM_ERROR_INVALID_SIZE = 6, /* Invalid buffer size */ + UPM_ERROR_OUT_OF_RANGE = 7, /* When the input to drive is too high/low or -ve */ + UPM_ERROR_OPERATION_FAILED = 8, /* When a function isn't able to perform as expected */ + UPM_ERROR_TIMED_OUT = 9, /* Timed out while communicating with the sensor */ + + UPM_ERROR_UNSPECIFIED = 99 /* Unspecified/Unknown error */ +} upm_result_t; + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_TYPES_H_ */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 39927b13..3c04d010 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ macro (file_to_list readfile outlist) STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}") STRING(REGEX REPLACE "\n" ";" contents "${contents}") set("${outlist}" "${contents}" ) -endmacro() +endmacro(file_to_list) file_to_list ("javaswig_blacklist" JAVASWIG_BLACKLIST) file_to_list ("pythonswig_blacklist" PYTHONSWIG_BLACKLIST) @@ -18,15 +18,15 @@ macro(subdirlist result curdir) endif() endforeach() set(${result} ${dirlist}) -endmacro() +endmacro(subdirlist) -macro (upm_CREATE_INSTALL_PKGCONFIG generated_file install_location) +macro (upm_create_install_pkgconfig generated_file install_location) configure_file (${PROJECT_SOURCE_DIR}/src/pkgconfig.in ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location}) -endmacro (upm_CREATE_INSTALL_PKGCONFIG) +endmacro(upm_create_install_pkgconfig) -macro(upm_SWIG_PYTHON) +macro(upm_swig_python) if (BUILDSWIGPYTHON) include_directories ( @@ -35,8 +35,9 @@ macro(upm_SWIG_PYTHON) set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON) set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..") - swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src}) - swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES}) + + swig_add_module (pyupm_${libname} python pyupm_${libname}.i) + swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES} ${libname}) target_include_directories ( ${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PUBLIC "${PYTHON_INCLUDE_PATH}" @@ -47,9 +48,9 @@ macro(upm_SWIG_PYTHON) DESTINATION ${LIB_INSTALL_DIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/ COMPONENT ${libname}) endif() -endmacro() +endmacro(upm_swig_python) -macro(upm_SWIG_NODE) +macro(upm_swig_node) if (BUILDSWIGNODE) # SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is # required. This hardcodes V8_VERSION to be <10 but I assume that's not going @@ -68,8 +69,8 @@ macro(upm_SWIG_NODE) set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}") set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON) - swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src}) - swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES}) + swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i) + swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES} ${libname}) target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PUBLIC "${NODE_INCLUDE_DIRS}" @@ -109,9 +110,9 @@ macro(upm_SWIG_NODE) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname}) endif() -endmacro() +endmacro(upm_swig_node) -macro(upm_SWIG_JAVA) +macro(upm_swig_java) if (BUILDSWIGJAVA) FIND_PACKAGE (JNI REQUIRED) @@ -125,8 +126,8 @@ macro(upm_SWIG_JAVA) set_source_files_properties (javaupm_${libname}.i PROPERTIES CPLUSPLUS ON) set_source_files_properties (javaupm_${libname}.i PROPERTIES SWIG_FLAGS ";-package;upm_${libname};-I${CMAKE_BINARY_DIR}/src") - swig_add_module (javaupm_${libname} java javaupm_${libname}.i ${module_src}) - swig_link_libraries (javaupm_${libname} ${MRAAJAVA_LIBRARIES} ${MRAA_LIBRARIES} ${JAVA_LIBRARIES}) + swig_add_module (javaupm_${libname} java javaupm_${libname}.i) + swig_link_libraries (javaupm_${libname} ${MRAAJAVA_LIBRARIES} ${MRAA_LIBRARIES} ${JAVA_LIBRARIES} ${libname}) target_include_directories ( ${SWIG_MODULE_javaupm_${libname}_REAL_NAME} PUBLIC "${JAVA_INCLUDE_DIRS}" @@ -158,7 +159,7 @@ macro(upm_SWIG_JAVA) ) endif() -endmacro() +endmacro(upm_swig_java) macro(upm_doxygen) if (DOXYGEN_FOUND) @@ -173,7 +174,7 @@ macro(upm_doxygen) add_dependencies (${libname} doc) endif () endif () -endmacro() +endmacro(upm_doxygen) if (SWIG_FOUND) if (BUILDSWIGPYTHON) @@ -212,11 +213,96 @@ if (SWIG_FOUND) endif () install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname}) - endmacro() + endmacro(createpackagejson) endif(BUILDSWIGNODE) endif() +# Process C/C++ sensor modules +# This function pre-processes sensor library input and hands off the +# necessary global variables to upm_module_init for library creation, +# documenation, swigging, etc... +function (UPM_MIXED_MODULE_INIT) + # CPP_WRAPS_C -> Set to have CPP library link to C library + # DESCRIPTION -> Library description string + # CPP_HDR -> List of CPP header files + # CPP_SRC -> List of CPP source files + # C_HDR -> List of C header files + # C_SRC -> List of C source files + # FTI_SRC -> List of C FTI source files + # REQUIRES -> List requires libraries for pkg-config + set (options CPP_WRAPS_C) + set (oneValueArgs NAME DESCRIPTION) + set (multiValueArgs CPP_HDR CPP_SRC C_HDR C_SRC FTI_SRC FTI_HDR REQUIRES) + # Parse function parameters + cmake_parse_arguments(UPM_MIXED_MODULE_INIT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Set the description + set (libdescription ${UPM_MIXED_MODULE_INIT_DESCRIPTION}) + + # Always build C libs first + if (UPM_MIXED_MODULE_INIT_C_SRC) + set (libname ${UPM_MIXED_MODULE_INIT_NAME}) + # Set the src and hpp variables for upm_module_init + set (module_src ${UPM_MIXED_MODULE_INIT_C_SRC}) + set (module_hpp ${UPM_MIXED_MODULE_INIT_C_HDR}) + + # Create the reqlibname list + string(REPLACE ";" " " reqlibname "${UPM_MIXED_MODULE_INIT_REQUIRES}") + # Append upm-utilities to the reqlibs + set (reqlibname "${reqlibname} upm-utilities") + + # If building FTI, and FTI src exists, add it in + if (BUILDFTI AND UPM_MIXED_MODULE_INIT_FTI_SRC) + #set (module_src ${UPM_MIXED_MODULE_INIT_C_SRC} ${UPM_MIXED_MODULE_INIT_FTI_SRC}) + list (APPEND module_src ${UPM_MIXED_MODULE_INIT_FTI_SRC}) + message ( INFO " XXX BUILDING FTI ${UPM_MIXED_MODULE_INIT_FTI_SRC}") + endif (BUILDFTI AND UPM_MIXED_MODULE_INIT_FTI_SRC) + message ( INFO " XXX BUILDING C src ${module_src}") + + # Add include directories for C + include_directories (${UPM_COMMON_HEADER_DIRS} + ${CMAKE_SOURCE_DIR}/src/utilities) + + # Set a flag to tell upm_module_init that it's building a C library + set (IS_C_LIBRARY TRUE) + upm_module_init() + endif (UPM_MIXED_MODULE_INIT_C_SRC) + + # Build C++ if enabled AND C++ headers exist + if (BUILDCPP AND UPM_MIXED_MODULE_INIT_CPP_HDR) + # Set the src and hpp variables for upm_module_init + set (module_src ${UPM_MIXED_MODULE_INIT_CPP_SRC}) + set (module_hpp ${UPM_MIXED_MODULE_INIT_CPP_HDR}) + + # Create the reqlibname list + string(REPLACE ";" " " reqlibname "${UPM_MIXED_MODULE_INIT_REQUIRES}") + + # Reset the libname (upm_module_init can change it) + set (libname ${UPM_MIXED_MODULE_INIT_NAME}) + unset (IS_C_LIBRARY) + message ( INFO " XXX BUILDING C++ src ${module_src}") + upm_module_init() + + # If the C++ wraps the C target, add the C target as a dependency + if (UPM_MIXED_MODULE_INIT_CPP_WRAPS_C) + target_link_libraries(${libname} ${libname}-c) + endif (UPM_MIXED_MODULE_INIT_CPP_WRAPS_C) + endif (BUILDCPP AND UPM_MIXED_MODULE_INIT_CPP_HDR) +endfunction (UPM_MIXED_MODULE_INIT) + macro(upm_module_init) + set (basename ${libname}) + + # If this is a C library, handle different collateral naming + if (IS_C_LIBRARY) + set (libname ${libname}-c) + set (libprefix upmc-) + set (pcname upmc-${basename}.pc) + else () + set (libprefix upm-) + set (pcname upm-${basename}.pc) + endif (IS_C_LIBRARY) + link_directories (${MRAA_LIBDIR}) add_library (${libname} SHARED ${module_src}) foreach (linkflag ${ARGN}) @@ -226,12 +312,15 @@ macro(upm_module_init) target_link_libraries (${libname} ${MRAA_LIBRARIES}) set_target_properties( ${libname} - PROPERTIES PREFIX "libupm-" + PROPERTIES PREFIX lib${libprefix} + OUTPUT_NAME ${basename} SOVERSION ${upm_VERSION_MAJOR} VERSION ${upm_VERSION_STRING} ) - upm_create_install_pkgconfig (upm-${libname}.pc ${LIB_INSTALL_DIR}/pkgconfig) - if (SWIG_FOUND) + upm_create_install_pkgconfig (${pcname} ${LIB_INSTALL_DIR}/pkgconfig) + + # Don't SWIG C + if (SWIG_FOUND AND NOT IS_C_LIBRARY) if (NOT ";${PYTHONSWIG_BLACKLIST};" MATCHES ";${libname};") upm_swig_python() endif() @@ -241,11 +330,14 @@ macro(upm_module_init) if (NOT ";${JAVASWIG_BLACKLIST};" MATCHES ";${libname};") upm_swig_java() endif() - endif() - if (BUILDDOC) + endif (SWIG_FOUND AND NOT IS_C_LIBRARY) + + # Skip doxygen run on C (for now) + if (BUILDDOC AND NOT IS_C_LIBRARY) upm_doxygen() endif() - install(TARGETS ${libname} DESTINATION ${LIB_INSTALL_DIR}) + + install (TARGETS ${libname} DESTINATION ${LIB_INSTALL_DIR}) install (FILES ${module_hpp} DESTINATION include/upm COMPONENT ${libname}) if (IPK) diff --git a/src/dfrph/CMakeLists.txt b/src/dfrph/CMakeLists.txt index 6de74f52..c27335ed 100644 --- a/src/dfrph/CMakeLists.txt +++ b/src/dfrph/CMakeLists.txt @@ -1,5 +1,9 @@ -set (libname "dfrph") -set (libdescription "upm dfrobot pH sensors") -set (module_src ${libname}.cxx) -set (module_hpp ${libname}.hpp) -upm_module_init() +upm_mixed_module_init (NAME dfrph + DESCRIPTION "upm dfrobot pH sensor" + C_HDR dfrph.h + C_SRC dfrph.c + CPP_HDR dfrph.hpp + CPP_SRC dfrph.cxx + FTI_SRC dfrph_fti.c + CPP_WRAPS_C + REQUIRES mraa) diff --git a/src/dfrph/dfrph.c b/src/dfrph/dfrph.c new file mode 100644 index 00000000..7a493ba9 --- /dev/null +++ b/src/dfrph/dfrph.c @@ -0,0 +1,103 @@ +/* + * Author: + * 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 +#include + +#include "dfrph.h" + +dfrph_context dfrph_init(int16_t pin) +{ + dfrph_context dev = + (dfrph_context) malloc(sizeof(struct _dfrph_context)); + + if(dev == NULL) return NULL; + + /* Init aio pin */ + dev->aio = mraa_aio_init(pin); + + /* Set the ref, offset, and scale */ + dev->m_aref = 5.0; + dev->m_count_offset = 0.0; + dev->m_count_scale = 1.0; + + if(dev->aio == NULL) { + free(dev); + return NULL; + } + + return dev; +} + +void dfrph_close(dfrph_context dev) +{ + mraa_aio_close(dev->aio); + free(dev); +} + +upm_result_t dfrph_set_offset(const dfrph_context dev, float offset) +{ + dev->m_count_offset = offset; + return UPM_SUCCESS; +} + +upm_result_t dfrph_set_scale(const dfrph_context dev, float scale) +{ + dev->m_count_scale = scale; + return UPM_SUCCESS; +} + +upm_result_t dfrph_get_raw_volts(const dfrph_context dev, float *volts) +{ + *volts = mraa_aio_read_float(dev->aio); + if (*volts == -1.0) return UPM_ERROR_OPERATION_FAILED; + + /* Scale by aref */ + *volts *= dev->m_aref; + + return UPM_SUCCESS; +} + +upm_result_t dfrph_get_ph(const dfrph_context dev, float *value) +{ + /* Read counts */ + int counts = mraa_aio_read(dev->aio); + + /* Get max adc value range 1023, 2047, 4095, etc... */ + float max_adc = (1 << mraa_aio_get_bit(dev->aio)) - 1; + + /* Apply raw scale */ + *value = counts * dev->m_count_scale; + + /* Apply raw offset */ + *value += dev->m_count_offset * dev->m_count_scale; + + /* Normalize the value */ + *value /= max_adc; + + /* Vmax for sensor is 0.8 * Vref, so scale by 1/0.8 = 1.25 */ + *value *= 1.25 * 14; /* Convert to pH */ + + return UPM_SUCCESS; +} diff --git a/src/dfrph/dfrph.cxx b/src/dfrph/dfrph.cxx index 000d64d7..753e9895 100644 --- a/src/dfrph/dfrph.cxx +++ b/src/dfrph/dfrph.cxx @@ -23,52 +23,54 @@ */ #include +#include #include "dfrph.hpp" -using namespace std; using namespace upm; -DFRPH::DFRPH(int pin, float aref) : - m_aio(pin) +DFRPH::DFRPH(int pin, float vref) : _dev(dfrph_init(pin)) { - m_aRes = (1 << m_aio.getBit()); - m_aref = aref; - - m_offset = 0.0; + if (_dev == NULL) + throw std::invalid_argument(std::string(__FUNCTION__) + + ": dfrph_init() failed, invalid pin?"); } DFRPH::~DFRPH() { -} - -float DFRPH::volts() -{ - int val = m_aio.read(); - - return(val * (m_aref / m_aRes)); + dfrph_close(_dev); } void DFRPH::setOffset(float offset) { - m_offset = offset; + dfrph_set_offset(_dev, offset); +} + +void DFRPH::setScale(float scale) +{ + dfrph_set_scale(_dev, scale); +} + +float DFRPH::volts() +{ + float volts = 0.0; + dfrph_get_raw_volts(_dev, &volts); + return volts; } float DFRPH::pH(unsigned int samples) { - if (!samples) - samples = 1; + float ph_avg = 0.0; - float sum = 0.0; + // Read at least 1 sample + if (samples == 0) samples = 1; - for (int i=0; i #include -#include + +#include "dfrph.h" namespace upm { /** @@ -94,22 +95,15 @@ namespace upm { * DFRPH constructor * * @param pin Analog pin to use - * @param aref Analog reference voltage; default is 5.0 V + * @param vref Analog reference voltage; default is 5.0 V */ - DFRPH(int pin, float aref=5.0); + DFRPH(int pin, float vref = 5.0); /** * DFRPH destructor */ ~DFRPH(); - /** - * Returns the voltage detected on the analog pin - * - * @return The detected voltage - */ - float volts(); - /** * Specifies the offset determined from calibration. The default * is 0.0. @@ -118,6 +112,16 @@ namespace upm { */ void setOffset(float offset); + /** + * Specifies the scale determined from calibration. The default + * is 1.0. + * + * @param scale The scale value to use + */ + void setScale(float scale); + + float volts(); + /** * Take a number of samples and return the detected pH value. The * default number of samples is 15. @@ -125,18 +129,10 @@ namespace upm { * @param samples The number of samples to average over, default 15 * @return The pH value detected */ - float pH(unsigned int samples=15); - - protected: - mraa::Aio m_aio; + float pH(unsigned int samples = 15); private: - float m_aref; - // ADC resolution - int m_aRes; - - // voltage offset - float m_offset; + dfrph_context _dev; }; } diff --git a/src/dfrph/dfrph_fti.c b/src/dfrph/dfrph_fti.c new file mode 100644 index 00000000..24060eac --- /dev/null +++ b/src/dfrph/dfrph_fti.c @@ -0,0 +1,118 @@ +/* + * Author: + * 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 +#include + +#include "dfrph.h" +#include "upm_fti.h" +#include "fti/upm_sensor.h" + +/** + * This file implements the Function Table Interface (FTI) for this sensor + */ + +const char upm_dfrph_name[] = "DFRPH"; +const char upm_dfrph_description[] = "Analog pH Meter Pro"; +const upm_protocol_t upm_dfrph_protocol[] = {UPM_ANALOG}; +const upm_sensor_t upm_dfrph_category[] = {UPM_PH}; + +// forward declarations +const void* upm_dfrph_get_ft(upm_sensor_t sensor_type); +void* upm_dfrph_init_str(const char* protocol, const char* params); +void upm_dfrph_close(void* dev); +const upm_sensor_descriptor_t upm_dfrph_get_descriptor(); +upm_result_t upm_dfrph_set_offset(const void* dev, float offset); +upm_result_t upm_dfrph_set_scale(const void* dev, float scale); +upm_result_t upm_dfrph_get_value(const void* dev, float *value); + +/* This sensor implementes 2 function tables */ +/* 1. Generic base function table */ +static const upm_sensor_ft ft_gen = +{ + .upm_sensor_init_name = &upm_dfrph_init_str, + .upm_sensor_close = &upm_dfrph_close, + .upm_sensor_get_descriptor = &upm_dfrph_get_descriptor +}; + +/* 2. PH function table */ +static const upm_ph_ft ft_ph = +{ + .upm_ph_set_offset = &upm_dfrph_set_offset, + .upm_ph_set_scale = &upm_dfrph_set_scale, + .upm_ph_get_value = &upm_dfrph_get_value +}; + +const void* upm_dfrph_get_ft(upm_sensor_t sensor_type) +{ + switch(sensor_type) + { + case UPM_SENSOR: + return &ft_gen; + case UPM_PH: + return &ft_ph; + default: + return NULL; + } +} + +void* upm_dfrph_init_str(const char* protocol, const char* params) +{ + fprintf(stderr, "String initialization - not implemented, using ain0: %s\n", __FILENAME__); + return dfrph_init(0); +} + +void upm_dfrph_close(void* dev) +{ + dfrph_close(dev); +} + +const upm_sensor_descriptor_t upm_dfrph_get_descriptor() +{ + /* Fill in the descriptor */ + upm_sensor_descriptor_t usd; + usd.name = upm_dfrph_name; + usd.description = upm_dfrph_description; + usd.protocol_size = 1; + usd.protocol = upm_dfrph_protocol; + usd.category_size = 1; + usd.category = upm_dfrph_category; + + return usd; +} + +upm_result_t upm_dfrph_set_offset(const void* dev, float offset) +{ + return dfrph_set_offset((dfrph_context)dev, offset); +} + +upm_result_t upm_dfrph_set_scale(const void* dev, float scale) +{ + return dfrph_set_scale((dfrph_context)dev, scale); +} + +upm_result_t upm_dfrph_get_value(const void* dev, float *value) +{ + return dfrph_get_ph((dfrph_context)dev, value); +} diff --git a/src/lcd/CMakeLists.txt b/src/lcd/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/src/lcd/jsupm_i2clcd.i b/src/lcd/jsupm_i2clcd.i old mode 100755 new mode 100644 diff --git a/src/lcd/pyupm_i2clcd.i b/src/lcd/pyupm_i2clcd.i old mode 100755 new mode 100644 diff --git a/src/pkgconfig.in b/src/pkgconfig.in index 6020e982..81b79611 100644 --- a/src/pkgconfig.in +++ b/src/pkgconfig.in @@ -3,11 +3,11 @@ exec_prefix=${prefix} libdir=${exec_prefix}/lib@LIB_SUFFIX@ includedir=${prefix}/include -Name: upm-@libname@ -Description: upm lib @libname@ +Name: @libprefix@@basename@ +Description: @libdescription@ Version: @upm_VERSION_STRING@ -Libs: -L${libdir} -lupm-@libname@ +Libs: -L${libdir} -l@libprefix@@basename@ Cflags: -I${includedir}/upm Requires: @reqlibname@ diff --git a/src/upm.h b/src/upm.hpp similarity index 100% rename from src/upm.h rename to src/upm.hpp diff --git a/src/utilities/CMakeLists.txt b/src/utilities/CMakeLists.txt new file mode 100644 index 00000000..f3478687 --- /dev/null +++ b/src/utilities/CMakeLists.txt @@ -0,0 +1,4 @@ +upm_mixed_module_init (NAME utilities + DESCRIPTION "UPM Utilities Library" + C_HDR upm_utilities.h + C_SRC upm_utilities.c) diff --git a/src/utilities/upm_utilities.c b/src/utilities/upm_utilities.c new file mode 100644 index 00000000..fe04388e --- /dev/null +++ b/src/utilities/upm_utilities.c @@ -0,0 +1,69 @@ +#include + +void* upm_malloc(int mem_map, int size){ + void *mem; +#if defined(linux) + mem = malloc(size); + if(mem == NULL){ + printf("unable to allocate memory"); + } + else{ + printf("memory allocated successfully\n"); + } +#elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB) + kmemory_map_t map_name = (kmemory_map_t) mem_map; + if(task_mem_map_alloc(map_name, &mem, TICKS_UNLIMITED) == RC_OK){ + printf("memory allocated successfully\n"); + } + else{ + printf("unable to allocate memory"); + mem = NULL; + } +#endif + return mem; +} + +void upm_free(int mem_map, void* ptr){ +#if defined(linux) + free(ptr); +#elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB) + kmemory_map_t map_name = (kmemory_map_t) mem_map; + task_mem_map_free(map_name, &ptr); +#endif +} + +void upm_delay(int time){ +#if defined(linux) + sleep(time); +#elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB) + struct nano_timer timer; + void *timer_data[1]; + nano_timer_init(&timer, timer_data); + nano_timer_start(&timer, SECONDS(time)); + nano_timer_test(&timer, TICKS_UNLIMITED); +#endif +} + +void upm_delay_ms(int time){ +#if defined(linux) + usleep(1000 * time); +#elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB) + struct nano_timer timer; + void *timer_data[1]; + nano_timer_init(&timer, timer_data); + nano_timer_start(&timer, MSEC(time)); + nano_timer_test(&timer, TICKS_UNLIMITED); +#endif +} + +void upm_delay_us(int time){ +#if defined(linux) + usleep(time); +#elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB) + struct nano_timer timer; + void *timer_data[1]; + nano_timer_init(&timer, timer_data); + nano_timer_start(&timer, USEC(time)); + nano_timer_test(&timer, TICKS_UNLIMITED); +#endif +} diff --git a/src/utilities/upm_utilities.h b/src/utilities/upm_utilities.h new file mode 100644 index 00000000..8046b1f0 --- /dev/null +++ b/src/utilities/upm_utilities.h @@ -0,0 +1,68 @@ +/* + * Authors: + * Copyright (c) 2016 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. + */ +#ifndef UPM_UTILITIES_H_ +#define UPM_UTILITIES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(linux) +#include +#include +#include +#endif + +#if defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB) +#include +#include +#include + +#if defined(CONFIG_STDOUT_CONSOLE) +#include +#define PRINT printf +#else +#include +#define PRINT printk +#endif +#endif + +/* Get filename w/o path */ +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) + +void upm_delay(int time); + +void upm_delay_ms(int time); + +void upm_delay_us(int time); + +void* upm_malloc(int mem_map, int size); + +void upm_free(int mem_map, void* ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* UPM_UTILITIES_H_ */