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 <noel.eck@intel.com>
This commit is contained in:
Noel Eck 2016-08-17 17:58:21 -07:00
parent d866b25f85
commit c1f9d15f67
46 changed files with 1945 additions and 87 deletions

View File

@ -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")

View File

@ -66,7 +66,7 @@ Here's an example (disregard the "@verbatim" tags in your actual code):
- `<component-kit>` 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.

View File

@ -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

View File

@ -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

View File

@ -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})

89
examples/c/CMakeLists.txt Normal file
View File

@ -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)

76
examples/c/dfrph.c Normal file
View File

@ -0,0 +1,76 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* 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 <unistd.h>
#include <signal.h>
#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;
}

View File

@ -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_ */

42
include/fti/upm_angle.h Normal file
View File

@ -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_ */

44
include/fti/upm_audio.h Normal file
View File

@ -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_ */

View File

@ -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_ */

View File

@ -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_ */

View File

@ -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_ */

48
include/fti/upm_light.h Normal file
View File

@ -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_ */

View File

@ -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 <stdarg.h>
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_ */

48
include/fti/upm_ph.h Normal file
View File

@ -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_ */

View File

@ -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_ */

48
include/fti/upm_raw.h Normal file
View File

@ -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_ */

45
include/fti/upm_sensor.h Normal file
View File

@ -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_ */

41
include/fti/upm_servo.h Normal file
View File

@ -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_ */

45
include/fti/upm_stream.h Normal file
View File

@ -0,0 +1,45 @@
/*
* Authors: Jon Trulson <jtrulson@ics.com>
* 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_ */

42
include/fti/upm_switch.h Normal file
View File

@ -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_ */

View File

@ -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_ */

36
include/fti/upm_touch.h Normal file
View File

@ -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_ */

View File

@ -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_ */

47
include/fti/upm_voltage.h Normal file
View File

@ -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_ */

45
include/upm.h Normal file
View File

@ -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 <upm_types.h>
#include <upm_math.h>
#include <upm_utilities.h>
#define upm_perror(...) perror(args, __VA_ARGS__)
#ifdef __cplusplus
}
#endif
#endif /* UPM_H_ */

122
include/upm_fti.h Normal file
View File

@ -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 <fti/upm_acceleration.h>
#include <fti/upm_angle.h>
#include <fti/upm_audio.h>
#include <fti/upm_distance.h>
#include <fti/upm_heart_rate.h>
#include <fti/upm_ph.h>
#include <fti/upm_potentiometer.h>
#include <fti/upm_servo.h>
#include <fti/upm_sensor.h>
#include <fti/upm_switch.h>
#include <fti/upm_temperature.h>
#include <fti/upm_touch.h>
#include <fti/upm_voltage.h>
#include <fti/upm_vibration.h>
#include <fti/upm_moisture.h>
#include <fti/upm_light.h>
#include <fti/upm_stream.h>
#ifdef __cplusplus
}
#endif
#endif /* UPM_FTI_H_ */

27
include/upm_internal.h Normal file
View File

@ -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_ */

39
include/upm_math.h Normal file
View File

@ -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 <math.h>
#endif
#ifdef __cplusplus
}
#endif
#endif /* UPM_MATH_H_ */

60
include/upm_types.h Normal file
View File

@ -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 <stdbool.h>
#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_ */

View File

@ -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)

View File

@ -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)

103
src/dfrph/dfrph.c Normal file
View File

@ -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 <string.h>
#include <stdlib.h>
#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;
}

View File

@ -23,52 +23,54 @@
*/
#include <iostream>
#include <stdexcept>
#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<samples; i++)
float ph = 0.0;
for (int i =0; i < samples; i++)
{
sum += volts();
usleep(20000);
dfrph_get_ph(_dev, &ph);
ph_avg += ph;
}
sum /= samples;
// 3.5 is a 'magic' DFRobot number. Seems to work though :)
return (3.5 * sum + m_offset);
return ph_avg/samples;
}

97
src/dfrph/dfrph.h Normal file
View File

@ -0,0 +1,97 @@
/*
* 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.
*/
#pragma once
#include "upm.h"
#include "mraa/aio.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* device context
*/
typedef struct _dfrph_context {
/* mraa aio pin context */
mraa_aio_context aio;
/* ADC reference */
float m_aref;
/* Raw count offset */
float m_count_offset;
/* Raw count scale */
float m_count_scale;
} *dfrph_context;
/**
* Initialize analog sensor
* @param pin is Analog pin
* @return sensor context as void pointer
*/
dfrph_context dfrph_init(int16_t pin);
/**
* Analog sensor destructor
* @param sensor context pointer deallocate memory
*/
void dfrph_close(dfrph_context dev);
/**
* Set sensor offset. This offset is applied to the return value:
* counts = counts + offset
* @param dev sensor context pointer
* @param offset count offset value used
* @return Function result code
*/
upm_result_t dfrph_set_offset(const dfrph_context dev, float offset);
/**
* Set sensor scale. This scale is applied to the return value:
* counts = counts * scale
* @param dev sensor context pointer
* @param scale count scale value used
* @return Function result code
*/
upm_result_t dfrph_set_scale(const dfrph_context dev, float scale);
/**
* Get raw volts
* @param dev sensor context pointer
* @param volts Raw sensor voltage
* @return Function result code
*/
upm_result_t dfrph_get_raw_volts(const dfrph_context dev, float *volts);
/**
* Read value from sensor
* @param dev sensor context pointer
* @param value pointer to returned pH value from sensor
* @return Function result code
*/
upm_result_t dfrph_get_ph(const dfrph_context dev, float *value);
#ifdef __cplusplus
}
#endif

View File

@ -25,7 +25,8 @@
#include <iostream>
#include <string>
#include <mraa/aio.hpp>
#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;
};
}

118
src/dfrph/dfrph_fti.c Normal file
View File

@ -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 <string.h>
#include <stdlib.h>
#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);
}

0
src/lcd/CMakeLists.txt Executable file → Normal file
View File

0
src/lcd/jsupm_i2clcd.i Executable file → Normal file
View File

0
src/lcd/pyupm_i2clcd.i Executable file → Normal file
View File

View File

@ -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@

View File

@ -0,0 +1,4 @@
upm_mixed_module_init (NAME utilities
DESCRIPTION "UPM Utilities Library"
C_HDR upm_utilities.h
C_SRC upm_utilities.c)

View File

@ -0,0 +1,69 @@
#include <upm_utilities.h>
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
}

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif
#if defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB)
#include <zephyr.h>
#include <device.h>
#include <sys_clock.h>
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT printf
#else
#include <misc/printk.h>
#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_ */