Compare commits

..

6 Commits

Author SHA1 Message Date
c66bcc656a Minor JSON fixes
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2017-08-30 17:19:30 -07:00
d52c2df7c6 JSON: Adding ctest
This commit adds node based tests provided by Nico to the ctest
framework already established in UPM.

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2017-08-28 17:15:07 -07:00
02d8a16d4b check for examples and images path 2017-08-17 13:30:41 -07:00
4bb652cb4b use sensortemplate.json metadata to test json files 2017-08-17 11:17:24 -07:00
59dfed087e sensortemplate: added JSON for sensortemplate
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-08-16 11:56:57 -07:00
e7f4529711 add initial jsonlint and mocha test for json files
[ci skip]
2017-08-16 07:56:02 -07:00
2431 changed files with 34559 additions and 59571 deletions

View File

@ -7,26 +7,17 @@ services:
- docker - docker
before_install: before_install:
- sudo wget -q https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` -O /usr/local/bin/docker-compose - sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
jobs: jobs:
fast_finish: true fast_finish: true
allow_failures: allow_failures:
- env: TARGET=android - env: TARGET=sonar-scan
- env: TARGET=ipk
include: include:
- &run-with-clang-minimal
stage: Clang 3.8 - minimal with unit tests
env:
- TARGET=minimal
- CMAKE_BUILD_TYPE=Debug
before_script: docker-compose pull ${TARGET}
script:
- export CC=clang-3.8 CXX=clang++-3.8
- docker-compose run ${TARGET}
- <<: *run-with-clang-minimal
env:
- TARGET=minimal
- CMAKE_BUILD_TYPE=Release
- &run-with-clang - &run-with-clang
stage: Clang 3.8 stage: Clang 3.8
env: TARGET=python env: TARGET=python
@ -81,11 +72,11 @@ jobs:
- docker-compose run ${TARGET} - docker-compose run ${TARGET}
- <<: *run-additional-jobs - <<: *run-additional-jobs
env: TARGET=android env: TARGET=android
- <<: *run-additional-jobs
env: TARGET=cordova
- <<: *run-additional-jobs
env: TARGET=examples
- <<: *run-additional-jobs - <<: *run-additional-jobs
env: TARGET=sonar-scan env: TARGET=sonar-scan
- <<: *run-additional-jobs
env: TARGET=ipk
- <<: *run-additional-jobs
env: TARGET=rpm
- <<: *run-additional-jobs - <<: *run-additional-jobs
env: TARGET=npm env: TARGET=npm

View File

@ -8,8 +8,9 @@ option (BUILDFTI "Build Funtion Table Interface (FTI) in C sensor libraries" OFF
option (BUILDSWIGPYTHON "Build swig python modules" ON) option (BUILDSWIGPYTHON "Build swig python modules" ON)
option (BUILDSWIGNODE "Build swig node modules" ON) option (BUILDSWIGNODE "Build swig node modules" ON)
option (BUILDSWIGJAVA "Build swig java modules" OFF) option (BUILDSWIGJAVA "Build swig java modules" OFF)
option (BUILDCORDOVA "Build cordova bindings" OFF)
option (BUILDEXAMPLES "Build C/C++/JAVA examples" OFF) option (BUILDEXAMPLES "Build C/C++/JAVA examples" OFF)
option (IPK "Generate IPK using CPack" OFF)
option (RPM "Generate RPM using CPack" OFF)
option (NPM "Generate NPM/GYP tarballs" OFF) option (NPM "Generate NPM/GYP tarballs" OFF)
option (BUILDTESTS "Generate check-ups for upm" OFF) option (BUILDTESTS "Generate check-ups for upm" OFF)
option (WERROR "Make all warnings into errors." ON) option (WERROR "Make all warnings into errors." ON)
@ -89,15 +90,8 @@ endfunction ()
# Compiler flags common to both C and CXX # Compiler flags common to both C and CXX
# Enable -Wall # Enable -Wall
set (C_CXX_WARNING_FLAGS -Wall
-Wno-strict-aliasing
-Wno-deprecated-declarations # Temp fix for MRAA deprecated methods
)
# GCC-6 added -Wmisleading-indentation to -Wall, skip these for now # GCC-6 added -Wmisleading-indentation to -Wall, skip these for now
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "6") set (C_CXX_WARNING_FLAGS -Wall -Wno-misleading-indentation -Wno-strict-aliasing)
list (APPEND C_CXX_WARNING_FLAGS -Wno-misleading-indentation)
endif ()
# Warnings as errors? # Warnings as errors?
if (WERROR) if (WERROR)
@ -110,7 +104,6 @@ endif (WERROR)
upm_add_compile_flags(C ${C_CXX_WARNING_FLAGS} upm_add_compile_flags(C ${C_CXX_WARNING_FLAGS}
-Winit-self -Winit-self
-Wimplicit -Wimplicit
-Wsign-compare
-Wmissing-parameter-type) -Wmissing-parameter-type)
# Set CXX compiler warning flags at top-level scope and emit a warning about # Set CXX compiler warning flags at top-level scope and emit a warning about
@ -118,7 +111,6 @@ upm_add_compile_flags(C ${C_CXX_WARNING_FLAGS}
upm_add_compile_flags(CXX ${C_CXX_WARNING_FLAGS} upm_add_compile_flags(CXX ${C_CXX_WARNING_FLAGS}
-Wnon-virtual-dtor -Wnon-virtual-dtor
-Woverloaded-virtual -Woverloaded-virtual
-Wsign-compare
-Wreorder) -Wreorder)
# Allow exception error handling for Android C++ # Allow exception error handling for Android C++
@ -131,7 +123,7 @@ find_package (PkgConfig REQUIRED)
# Force a libmraa search and minimum required version every time a config is generated # Force a libmraa search and minimum required version every time a config is generated
unset(MRAA_FOUND CACHE) unset(MRAA_FOUND CACHE)
set(MRAA_MINIMUM 2.0.0) set(MRAA_MINIMUM 1.7.0)
pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM}) pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM})
# Also, get full path to the mraa library # Also, get full path to the mraa library
find_library(MRAA_LIBRARY NAMES mraa HINTS ${MRAA_LIBDIR}) find_library(MRAA_LIBRARY NAMES mraa HINTS ${MRAA_LIBDIR})
@ -151,11 +143,6 @@ pkg_check_modules (MODBUS libmodbus>=3.1.2)
# Check for OPENZWAVE # Check for OPENZWAVE
pkg_check_modules (OPENZWAVE libopenzwave) pkg_check_modules (OPENZWAVE libopenzwave)
# Check for TinyB
pkg_check_modules (TINYB tinyb>=0.5.1)
# And get full path to the tinyb library
find_library(TINYB_LIBRARY NAMES tinyb HINTS ${TINYB_LIBDIR})
# Find JPEG # Find JPEG
find_package (JPEG) find_package (JPEG)
@ -164,6 +151,11 @@ if (BUILDSWIGNODE)
find_package (Node REQUIRED) find_package (Node REQUIRED)
if (BUILDTESTS) if (BUILDTESTS)
find_package (Npm REQUIRED) find_package (Npm REQUIRED)
if(NPM_EXECUTABLE)
message(STATUS "NPM Executable found at: ${NPM_EXECUTABLE}")
else()
message(FATAL_ERROR "Please install NPM first, you can't run tests without it")
endif()
endif (BUILDTESTS) endif (BUILDTESTS)
endif (BUILDSWIGNODE) endif (BUILDSWIGNODE)
@ -176,17 +168,6 @@ if (BUILDSWIGJAVA)
find_library(MRAAJAVA_LIBRARY NAMES mraajava HINTS ${MRAA_LIBDIR}) find_library(MRAAJAVA_LIBRARY NAMES mraajava HINTS ${MRAA_LIBDIR})
endif (BUILDSWIGJAVA) endif (BUILDSWIGJAVA)
# Cordova binding
if (BUILDCORDOVA)
if (NOT BUILDSWIGJAVA)
message(FATAL_ERROR "Cordova bindings require JAVA packages, please enable BUILDSWIGJAVA (-DBUILDSWIGJAVA=on).")
endif()
find_package (Node REQUIRED)
find_package (Npm REQUIRED)
find_package (UpmCordovaGenerator 0.2.1 REQUIRED)
endif (BUILDCORDOVA)
# Find swig if any wrapper is enabled # Find swig if any wrapper is enabled
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA) if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
find_package (SWIG 3.0.5 REQUIRED) find_package (SWIG 3.0.5 REQUIRED)
@ -235,7 +216,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags") git_describe (VERSION "--tags")
# If git_describe fails, use a dirty version # If git_describe fails, use a dirty version
if (${VERSION} MATCHES -NOTFOUND) if (${VERSION} MATCHES -NOTFOUND)
set (VERSION "v1.7.1") set (VERSION "v1.3.0")
message (WARNING "Failed to retrieve UPM version with 'git describe' (using " message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
"${VERSION}). Check that git is installed and this is a valid git repo.") "${VERSION}). Check that git is installed and this is a valid git repo.")
endif () endif ()
@ -258,6 +239,11 @@ set (upm_VERSION_MINOR ${VERSION_MINOR})
set (upm_VERSION_PATCH ${VERSION_PATCH}) set (upm_VERSION_PATCH ${VERSION_PATCH})
set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}) set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH})
# Detect arch
include (TargetArch)
target_architecture (DETECTED_ARCH)
message (STATUS "Target arch is ${DETECTED_ARCH}")
# enable c++11 standards support unconditionally # enable c++11 standards support unconditionally
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
if (CMAKE_VERSION VERSION_LESS "3.1") if (CMAKE_VERSION VERSION_LESS "3.1")
@ -292,131 +278,151 @@ else()
set (C_EXTENSIONS OFF) set (C_EXTENSIONS OFF)
endif() endif()
# The doc target depends on the C/C++ source and all libraries # The doc target depends on each sensor target
# #
# doc # doc
# ├──> src
# ├──> include
# ├──> libupm_sensor0 # ├──> libupm_sensor0
# ├──> libupm_sensor1 # ├──> libupm_sensor1
# ├──> ... # ├──> libupm_sensor2
# └──> libupm_sensor_n # └──> libupm_sensor_n
# #
# The pydoc target builds documentation with sphinx via inspection by loading # The pydoc target builds documentation with sphinx via inspection by loading
# each python2 module. Those modules must include the CXX documentation via # each python module. Those modules must include the CXX documentation via
# a monolithic swig file generated by doxy2swig # a monolithic swig file generated by doxy2swig
# #
# pydoc # pydoc
# └──> _pyupm_sensor0_python2 # └──> _pyupm_sensor0_python2
# ├──> libupm_sensor0 # ├──────> libupm_sensor0
# └──> doxy2swig # └──────> doxy2swig
# #
# The doxy2swig target is dependent upon the doc target IF BUILDDOC=ON, # The doxy2swig target is dependent upon the doc target IF BUILDDOC=ON,
# otherwise doxy2swig uses an empty file. Doxy2swig also depends on each
# sensor target
# #
# doxy2swig # doxy2swig
# ──> BUILDDOC=ON───> doc # ──> BUILDDOC=ON───> doc
# └──> libupm_sensor0
# #
# The jsdoc target builds js documentation via yuidoc and only requires # The jsdoc target builds js documentation via yuidoc and only requires
# the doc target # the doc target
# #
# jsdoc ─> doc # jsdoc ─> doc
# #
function (CreateDocumentationTargets) if (BUILDDOC)
# Add a target to generate API documentation with Doxygen # Add a target to generate API documentation with Doxygen
find_package (Doxygen 1.8 REQUIRED) find_package (Doxygen REQUIRED)
if (DOXYGEN_FOUND AND DOXYGEN_VERSION VERSION_GREATER "1.8") configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) if (BUILDSWIGJAVA)
if (BUILDSWIGJAVA) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY) endif()
endif() file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/docs docs/icons/*.png)
file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/docs docs/icons/*.png) foreach(PNG_FILE ${PNG_FILES})
foreach(PNG_FILE ${PNG_FILES}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY) endforeach()
endforeach() add_custom_target (doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
# Custom command to run doxygen (note depends on ALL UPM C++ targets) COMMAND tar -czf html/xml.tar.gz -C xml .
add_custom_command ( WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
OUTPUT ${CMAKE_BINARY_DIR}/xml/index.xml COMMENT "Generating API documentation with Doxygen" VERBATIM
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile ${UPM_TARGETS_CXX} )
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND tar -czf html/xml.tar.gz -C xml .
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating C/C++ API documentation with Doxygen"
VERBATIM)
add_custom_target(doc DEPENDS ${CMAKE_BINARY_DIR}/xml/index.xml)
else ()
message (SEND_ERROR "ERROR - Failed to find a compatible version of Doxygen. API doc will not be generated")
endif (DOXYGEN_FOUND AND DOXYGEN_VERSION VERSION_GREATER "1.8")
# Check if Sphinx is installed and add target to generate API documentation # Check if Sphinx is installed and add target to generate API documentation
# Currently, the per-module documentation for python is generated from the # Currently, the per-module documentation for python is generated from the
# python2 modules. # python2 modules.
# Since python2 is required for documentation, only copy from python2 paths, this
# ensures that sphinx doesn't run across python2 and python3 binaries. When running
# the sphinx tools, explicitly run from the python2 interpreter (tested with the sphinx
# 1.3.6 python2 and python3 modules).
if(BUILDSWIGPYTHON) if(BUILDSWIGPYTHON)
# Generate python module documentation from doxygen collateral find_package (Sphinx REQUIRED)
# configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
# doxygen index.xml -> doxy2swig.py -> pyupm_doxy2swig.i configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
add_custom_command ( add_custom_target (pydoc ALL
OUTPUT ${CMAKE_BINARY_DIR}/src/pyupm_doxy2swig.i COMMAND rm -r -f ${CMAKE_BINARY_DIR}/pyupm && mkdir -p ${CMAKE_BINARY_DIR}/pyupm
COMMAND ${PYTHON2_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/doxy2swig.py COMMAND find ${CMAKE_BINARY_DIR}/src -name "_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
${CMAKE_BINARY_DIR}/xml/index.xml --quiet COMMAND find ${CMAKE_BINARY_DIR}/src -name "pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
${CMAKE_BINARY_DIR}/src/pyupm_doxy2swig.i COMMAND ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/pyupm
COMMENT "Generating pyupm_doxy2swig.i from Doxygen output for use by SWIG" # TODO: use a separate cmake FILE module for string replacement instead
COMMAND ${SPHINX_EXECUTABLE} -b html pydoc html/python
COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
COMMAND sed -i.bak s|[[:space:]][mM]odule</a>|</a>|g html/python/index.html html/python/modules.html
DEPENDS doc DEPENDS doc
VERBATIM) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
add_custom_target(pyupm_doxy2swig DEPENDS ${CMAKE_BINARY_DIR}/src/pyupm_doxy2swig.i) COMMENT "Generating API documentation with Sphinx" VERBATIM
foreach (_python2_target ${UPM_TARGETS_PYTHON2}) )
add_dependencies(${_python2_target} pyupm_doxy2swig)
endforeach()
find_package (Sphinx 1.3 REQUIRED)
if (SPHINX_FOUND AND SPHINX_VERSION VERSION_GREATER "1.3")
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
add_custom_command (
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pydoc.stamp
COMMAND rm -r -f ${CMAKE_BINARY_DIR}/pyupm && mkdir -p ${CMAKE_BINARY_DIR}/pyupm
COMMAND find ${CMAKE_BINARY_DIR}/src -path "*python${MIN_VER_PYTHON2}/_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
COMMAND find ${CMAKE_BINARY_DIR}/src -path "*python${MIN_VER_PYTHON2}/pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
COMMAND ${PYTHON2_EXECUTABLE} ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/pyupm
# TODO: use a separate cmake FILE module for string replacement instead
COMMAND ${PYTHON2_EXECUTABLE} ${SPHINX_EXECUTABLE} -b html pydoc html/python
COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
COMMAND sed -i.bak s|[[:space:]][mM]odule</a>|</a>|g html/python/index.html html/python/modules.html
COMMAND cmake -E touch ${CMAKE_CURRENT_BINARY_DIR}/pydoc.stamp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating Python API documentation with Sphinx"
DEPENDS doc ${UPM_TARGETS_PYTHON2}
VERBATIM)
add_custom_target(pydoc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pydoc.stamp)
else ()
message (SEND_ERROR "ERROR - Failed to find a compatible version of Sphinx. Python API doc will not be generated")
endif ()
endif(BUILDSWIGPYTHON) endif(BUILDSWIGPYTHON)
# Check if Yuidoc is installed and add target for API documentation # Check if Yuidoc is installed and add target for API documentation
if(BUILDSWIGNODE) if(BUILDSWIGNODE)
find_package (Yuidoc 0.10 REQUIRED) find_package(Yuidoc REQUIRED)
if (YUIDOC_FOUND AND YUIDOC_VERSION VERSION_GREATER "0.10") add_custom_target(jsdoc ALL
add_custom_command ( COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/docgen.js -m upm -i xml -o jsdoc -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/jsdoc/jsdoc.stamp COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers ${CMAKE_SOURCE_DIR}/doxy/node/generators/yuidoc/helper.js --themedir ${CMAKE_SOURCE_DIR}/doxy/node/generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/docgen.js -m upm -i xml -o jsdoc -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../ COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/tolower.js -i html/node
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers ${CMAKE_SOURCE_DIR}/doxy/node/generators/yuidoc/helper.js --themedir ${CMAKE_SOURCE_DIR}/doxy/node/generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm DEPENDS doc
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/tolower.js -i html/node WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND cmake -E touch ${CMAKE_CURRENT_BINARY_DIR}/jsdoc/jsdoc.stamp COMMENT "Generating API documentation with Yuidoc" VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )
COMMENT "Generating Javascript API documentation with Yuidoc"
DEPENDS doc
VERBATIM)
add_custom_target(jsdoc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/jsdoc/jsdoc.stamp)
else ()
message (SEND_ERROR "ERROR - Failed to find a compatible version of Yuidoc. Node.js API doc will not be generated")
endif ()
endif(BUILDSWIGNODE) endif(BUILDSWIGNODE)
endfunction() endif (BUILDDOC)
if (IPK)
# Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
if (DEFINED ENV{OECORE_TARGET_SYSROOT})
GET_FILENAME_COMPONENT (DETECTED_SYSROOT $ENV{OECORE_TARGET_SYSROOT} NAME)
string (REGEX REPLACE "-poky-linux" "" TARGET_ARCH "${DETECTED_SYSROOT}")
else ()
# Debian uses amd64 to denote x86_64
if (DETECTED_ARCH STREQUAL "x86_64")
set (TARGET_ARCH "amd64")
else ()
set (TARGET_ARCH ${DETECTED_ARCH})
endif ()
endif ()
message (STATUS "Package arch is ${TARGET_ARCH}")
set(CPACK_GENERATOR "DEB")
set(OPKG_ARCH ${TARGET_ARCH})
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
set(upm_PACKAGE_ON_TAG ".")
if ("${VERSION_COMMIT}" STREQUAL "")
set(upm_PACKAGE_ON_TAG "")
endif()
set(CPACK_PACKAGE_VERSION
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
set(CPACK_PACKAGE_NAME "upm")
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
set(CPACK_SYSTEM_NAME ${TARGET_ARCH})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "mraa (>= ${MRAA_VERSION})")
set(CPACK_DEBIAN_PACKAGE_PROVIDES "upm-dev, upm-dbg, upm-doc")
set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
include (CPack)
endif()
if (RPM)
message (STATUS "RPM packaging enabled for ${DETECTED_ARCH}")
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_NAME "upm")
set(upm_PACKAGE_ON_TAG ".")
if ("${VERSION_COMMIT}" STREQUAL "")
set(upm_PACKAGE_ON_TAG "")
endif()
set(CPACK_PACKAGE_VERSION
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
EXECUTE_PROCESS(COMMAND rpm --showrc
COMMAND grep -E "dist[[:space:]]*\\."
COMMAND sed -e "s/^.*dist\\s*\\.//"
COMMAND tr \\n \\t
COMMAND sed -e s/\\t//
OUTPUT_VARIABLE DIST_TAG)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${DIST_TAG}.${DETECTED_ARCH}")
include(CPack)
endif()
# UPM common headers # UPM common headers
set (UPM_COMMON_HEADER_DIRS ${CMAKE_HOME_DIRECTORY}/include) set (UPM_COMMON_HEADER_DIRS ${CMAKE_HOME_DIRECTORY}/include)
@ -436,12 +442,6 @@ if (BUILDTESTS)
add_subdirectory (tests) add_subdirectory (tests)
endif() endif()
# Setup documentation AFTER all source targets have been added
if (BUILDDOC)
CreateDocumentationTargets()
endif()
# Install C headers # Install C headers
install(DIRECTORY include/ DESTINATION include/upm install(DIRECTORY include/ DESTINATION include/upm
COMPONENT ${CMAKE_PROJECT_NAME}-dev FILES_MATCHING PATTERN "*.h")
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")

View File

@ -1,7 +1,3 @@
<p align="center">
<img src="https://github.com/intel-iot-devkit/upm/blob/master/docs/icons/upm_logo.png" height="150px" width="auto" algt="UPM Logo"/>
</p>
UPM (Useful Packages & Modules) Sensor/Actuator repository for MRAA UPM (Useful Packages & Modules) Sensor/Actuator repository for MRAA
============== ==============
@ -14,21 +10,20 @@ Programmers can access the interfaces for each sensor by including the sensor
corresponding header file and instantiating the associated sensor class. In the corresponding header file and instantiating the associated sensor class. In the
typical use case, a constructor initializes the sensor based on parameters that typical use case, a constructor initializes the sensor based on parameters that
identify the sensor, the I/O protocol used and the pin location of the sensor. identify the sensor, the I/O protocol used and the pin location of the sensor.
As of UPM 2.0, sensor initialization can also be done, in most cases, via
overloaded constructors that accept string identifiers.
We endorse additions that implement the generic C and C++ interfaces provided C++ interfaces have been defined for the following sensor/actuator types, but
with the libraries. With the 2.0 release, UPM introduces the following sensor they are subject to change:
interfaces: iAcceleration, iAngle, iButton, iClock, iCollision, iDistance,
iDistanceInterrupter, iEC, iElectromagnet, iEmg, iGas, iGps, iGyroscope,
iHallEffect, iHeartRate, iHumidity, iLight, iLineFinder, iMagnetometer,
iMoisture, iMotion, iOrp, iPH, iPressure, iProximity, iTemperature, iVDiv,
iWater.
The developer community is invited to propose new interfaces for actuator types. * Light controller
* Light sensor
* Temperature sensor
* Humidity sensor
* Pressure sensor
* Gas sensor
* Analog to digital converter
The UPM project is joining the Eclipse Foundation as an Eclipse IoT project. The developer community is encouraged to help expand the list of supported
You can read more about this [here](https://projects.eclipse.org/proposals/eclipse-upm). sensors and actuators and provide feedback on interface design.
### Example ### Example
@ -72,16 +67,12 @@ Supported [sensor list](http://iotdk.intel.com/docs/master/upm/modules.html) fro
You can also refer to the [Intel® IoT Developer Zone](https://software.intel.com/iot/hardware/sensors). You can also refer to the [Intel® IoT Developer Zone](https://software.intel.com/iot/hardware/sensors).
### IDE Support ### IDE Integration
The UPM sensor libraries are directly supported by the IDEs listed on the Intel® If you would like to create projects and run the UPM samples using an Intel recommended IDE,
Developer Zone Tools & IDEs page. please refer to the Intel Developer Zone IDE page.
<a href="https://software.intel.com/iot/tools"><img src="docs/icons/iss.png"/></a> <a href="https://software.intel.com/iot/software/ide"><img src="docs/icons/allides.png"/></a>
Intel® System Studio integration offers IoT specific features such as a sensor explorer,
library sync tools and the ability to easily import existing projects and samples that
use the UPM libraries. For further details please refer to the IoT User Guides on IDZ.
### Installing UPM ### Installing UPM
@ -97,16 +88,12 @@ See building documentation [here](docs/building.md).
A quick way to add a new sensor driver is to port existing code from another A quick way to add a new sensor driver is to port existing code from another
platform (e.g. Arduino) and swap the IO calls to the MRAA API. This of course platform (e.g. Arduino) and swap the IO calls to the MRAA API. This of course
assumes either ownership of the original code or a MIT compatible license that assumes either ownership of the original code or licensing that allows
allows unrestricted redistribution. unrestricted redistribution.
The [porting](docs/porting.md) section has more information on this process, The [porting](docs/porting.md) section has more information on this process,
and there is an example available based on the max31855 [sensor](docs/max31855.md). and there is an example available based on the max31855 [sensor](docs/max31855.md).
We have an [on demand webinar](https://software.seek.intel.com/IoT_WebinarSeries_Reg)
available that covers using an IDE to develop for the UPM project along with other
considerations for new contributions.
Read more on creating Java [bindings](docs/creating_java_bindings.md) for your Read more on creating Java [bindings](docs/creating_java_bindings.md) for your
new driver. new driver.
@ -118,8 +105,7 @@ The name you pick for a newly added sensor needs to be unique in the UPM library
Then, please go over this short set of rules for new [contributions](docs/contributions.md). Then, please go over this short set of rules for new [contributions](docs/contributions.md).
Make sure you add yourself as an author on every new code file submitted. Make sure you add yourself as an author on every new code file submitted.
If you are providing a fix with significant changes, feel free to add yourself If you are providing a fix with significant changes, feel free to add yourself
as a contributor. Signing-off your commits is mandatory and acts as an as a contributor. Signing-off your commits is mandatory.
acknowledgment of the committer agreement.
Documenting your code is also a big part of the task. We have a strict set of Documenting your code is also a big part of the task. We have a strict set of
tags used to classify our sensors and their capabilities. You can find out more tags used to classify our sensors and their capabilities. You can find out more
@ -142,6 +128,9 @@ our API in a way that will break backwards compatibility. If you find yourself
unable to compile code that was working fine before a library update, make sure unable to compile code that was working fine before a library update, make sure
you check the [API changes](docs/apichanges.md) section first. you check the [API changes](docs/apichanges.md) section first.
**NOTE** - Several important API changes are currently underway for some of our
widely used libraries including `libupm-grove` and `libupm-i2clcd`!
### Changelog ### Changelog
Version changelog [here](docs/changelog.md). Version changelog [here](docs/changelog.md).

View File

@ -0,0 +1,25 @@
# this toolchain file comes from gnuradio project
set( CMAKE_SYSTEM_NAME Linux )
#set( CMAKE_C_COMPILER $ENV{CC} )
#set( CMAKE_CXX_COMPILER $ENV{CXX} )
string(REGEX MATCH "sysroots/([a-zA-Z0-9]+)" CMAKE_SYSTEM_PROCESSOR $ENV{SDKTARGETSYSROOT})
string(REGEX REPLACE "sysroots/" "" CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
set( CMAKE_CXX_FLAGS $ENV{CXXFLAGS} CACHE STRING "" FORCE )
set( CMAKE_C_FLAGS $ENV{CFLAGS} CACHE STRING "" FORCE ) #same flags for C sources
set( CMAKE_LDFLAGS_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE ) #same flags for C sources
set( CMAKE_LIBRARY_PATH ${OECORE_TARGET_SYSROOT}/usr/lib )
set( CMAKE_FIND_ROOT_PATH $ENV{OECORE_TARGET_SYSROOT} $ENV{OECORE_NATIVE_SYSROOT} )
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
set( CMAKE_INSTALL_PREFIX $ENV{OECORE_TARGET_SYSROOT}/usr CACHE STRING "" FORCE)
set( ORC_INCLUDE_DIRS $ENV{OECORE_TARGET_SYSROOT}/usr/include/orc-0.4 )
set( ORC_LIBRARY_DIRS $ENV{OECORE_TARGET_SYSROOT}/usr/lib )
# for java
set( JAVA_AWT_INCLUDE_PATH $ENV{JAVA_HOME}/include CACHE PATH "" FORCE)
set( JAVA_AWT_LIBRARY $ENV{JAVA_HOME}/jre/lib/amd64/libjawt.so CACHE FILEPATH "" FORCE)
set( JAVA_INCLUDE_PATH $ENV{JAVA_HOME}/include CACHE PATH "" FORCE)
set( JAVA_INCLUDE_PATH2 $ENV{JAVA_HOME}/include/linux CACHE PATH "" FORCE)
set( JAVA_JVM_LIBRARY $ENV{JAVA_HOME}/jre/lib/amd64/libjvm.so CACHE FILEPATH "" FORCE)

View File

@ -1,66 +1,69 @@
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include # Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
macro(add_include_dir dir) macro(add_include_dir dir)
if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include") if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir}) set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
endif() endif()
endmacro() endmacro()
find_program (NODEJS_EXECUTABLE NAMES node nodejs find_program (NODEJS_EXECUTABLE NAMES node nodejs
HINTS HINTS
$ENV{NODE_DIR} $ENV{NODE_DIR}
PATH_SUFFIXES bin PATH_SUFFIXES bin
DOC "Node.js interpreter") DOC "Node.js interpreter"
)
include (FindPackageHandleStandardArgs) include (FindPackageHandleStandardArgs)
# If compat-libuv package exists, it must be at start of include path # If compat-libuv package exists, it must be at start of include path
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH) find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
if (UV_ROOT_DIR) if (UV_ROOT_DIR)
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR}) # set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
add_include_dir(${UV_ROOT_DIR}) add_include_dir(${UV_ROOT_DIR})
endif() endif()
# Now look for node. Flag an error if not found # Now look for node. Flag an error if not found
find_path (NODE_ROOT_DIR find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h" "src/node.h"
NAMES node.h src/node.h PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
PATH_SUFFIXES node node4 node5 node6 node7 node8 nodejs
PATHS /usr/include /usr/local/include)
if (NODE_ROOT_DIR) if (NODE_ROOT_DIR)
add_include_dir(${NODE_ROOT_DIR}) add_include_dir(${NODE_ROOT_DIR}/include/src)
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include) add_include_dir(${NODE_ROOT_DIR}/src)
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include) add_include_dir(${NODE_ROOT_DIR}/include/node)
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include) add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include) add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/include/node) add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
add_include_dir(${NODE_ROOT_DIR}/include/src) add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
add_include_dir(${NODE_ROOT_DIR}/src)
else() else()
unset(NODEJS_INCLUDE_DIRS) unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - node.h not found") message(ERROR " - node.h not found")
endif() endif()
# Check that v8.h is in NODEJS_INCLUDE_DIRS # Check that v8.h is in NODEJS_INCLUDE_DIRS
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS}) find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
if (NOT V8_ROOT_DIR) if (NOT V8_ROOT_DIR)
unset(NODEJS_INCLUDE_DIRS) unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - v8.h not found") message(ERROR " - v8.h not found")
endif() endif()
# Check that uv.h is in NODEJS_INCLUDE_DIRS # Check that uv.h is in NODEJS_INCLUDE_DIRS
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS}) find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
if (NOT UV_ROOT_DIR) if (NOT UV_ROOT_DIR)
unset(NODEJS_INCLUDE_DIRS) unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - uv.h not found") message(ERROR " - uv.h not found")
endif() endif()
find_package_handle_standard_args (Nodejs DEFAULT_MSG
NODEJS_EXECUTABLE
NODEJS_INCLUDE_DIRS
)
if (NODEJS_EXECUTABLE) if (NODEJS_EXECUTABLE)
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
OUTPUT_VARIABLE _VERSION OUTPUT_VARIABLE _VERSION
RESULT_VARIABLE _NODE_VERSION_RESULT) RESULT_VARIABLE _NODE_VERSION_RESULT)
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)" execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
OUTPUT_VARIABLE _V8_VERSION OUTPUT_VARIABLE _V8_VERSION
RESULT_VARIABLE _V8_RESULT) RESULT_VARIABLE _V8_RESULT)
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT) if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
string (REPLACE "v" "" NODE_VERSION_STRING "${_VERSION}") string (REPLACE "v" "" NODE_VERSION_STRING "${_VERSION}")
string (REPLACE "." ";" _VERSION_LIST "${NODE_VERSION_STRING}") string (REPLACE "." ";" _VERSION_LIST "${NODE_VERSION_STRING}")
@ -85,15 +88,13 @@ if (NODEJS_EXECUTABLE)
set (V8_VERSION_MINOR "28") set (V8_VERSION_MINOR "28")
set (V8_VERSION_PATCH "72") set (V8_VERSION_PATCH "72")
set (V8_VERSION_STRING "3.28.72") set (V8_VERSION_STRING "3.28.72")
message (STATUS "defaulted to node 0.10.30") message ("defaulted to node 0.10.30")
endif () endif ()
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING}) string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING}) string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
message (STATUS "Node version is ${NODE_VERSION_STRING}")
message (STATUS "Node using v8 ${V8_VERSION_STRING}")
mark_as_advanced (NODEJS_EXECUTABLE) mark_as_advanced (NODEJS_EXECUTABLE)
find_package_handle_standard_args (Nodejs
REQUIRED_VARS NODEJS_EXECUTABLE NODEJS_INCLUDE_DIRS
VERSION_VAR NODE_VERSION_STRING)
message(STATUS "Found v8: ${V8_ROOT_DIR}/v8.h (found version \"${V8_VERSION_STRING}\")")
endif () endif ()
mark_as_advanced (NODEJS_EXECUTABLE)

View File

@ -1,71 +1,13 @@
# FindNpm # Finding and pointing a variable to the npm executable if found
# -------- # Only works on Linux systems as of now
#
# Find npm
#
# This module finds an installed npm. It sets the following variables:
#
# NPM_FOUND - Set to true if npm is found
# NPM_DIR - The directory where npm is installed
# NPM_GLOBAL_NODE_MODULE_DIR - The global node_modules directory
# NPM_EXECUTABLE - The path to the npm executable
# NPM_VERSION - The version number of the npm executable
find_program(NPM_EXECUTABLE NAMES npm HINTS /usr) find_program(NPM_EXECUTABLE NAMES npm
HINTS
/usr
)
# If npm was found, fill in the rest if(NPM_EXECUTABLE)
if (NPM_EXECUTABLE) message(STATUS "NPM Executable found at ${NPM_EXECUTABLE}")
# Set the global node_modules location
execute_process(COMMAND ${NPM_EXECUTABLE} root -g
OUTPUT_VARIABLE NPM_GLOBAL_NODE_MODULE_DIR
ERROR_VARIABLE NPM_root_g_error
RESULT_VARIABLE NPM_root_g_result_code)
# Remove and newlines
string (STRIP ${NPM_GLOBAL_NODE_MODULE_DIR} NPM_GLOBAL_NODE_MODULE_DIR)
if(NPM_root_g_result_code)
if(NPM_FIND_REQUIRED)
message(SEND_ERROR "Command \"${NPM_EXECUTABLE} root -g\" failed with output:\n${NPM_root_g_error}")
else ()
message(STATUS "Command \"${NPM_EXECUTABLE} root -g\" failed with output:\n${NPM_root_g_error}")
endif ()
endif()
unset(NPM_root_g_error)
unset(NPM_root_g_result_code)
# Set the NPM dir
if (EXISTS "${NPM_GLOBAL_NODE_MODULE_DIR}/npm")
set(NPM_DIR "${NPM_GLOBAL_NODE_MODULE_DIR}/npm")
endif()
# Set the VERSION
execute_process(COMMAND ${NPM_EXECUTABLE} -v
OUTPUT_VARIABLE NPM_VERSION
ERROR_VARIABLE NPM_version_error
RESULT_VARIABLE NPM_version_result_code)
if(NPM_version_result_code)
if(NPM_FIND_REQUIRED)
message(SEND_ERROR "Command \"${NPM_EXECUTABLE} -v\" failed with output:\n${NPM_version_error}")
else()
message(STATUS "Command \"${NPM_EXECUTABLE} -v\" failed with output:\n${NPM_version_error}")
endif ()
endif ()
unset(NPM_version_error)
unset(NPM_version_result_code)
# Remove and newlines
string (STRIP ${NPM_VERSION} NPM_VERSION)
set (NPM_FOUND TRUE)
else() else()
# Fail on REQUIRED message(ERROR "Unable to find NPM installation, please install NPM")
if (Npm_FIND_REQUIRED) endif()
message(SEND_ERROR "Failed to find npm executable")
endif()
endif ()
find_package_handle_standard_args(NPM
REQUIRED_VARS NPM_EXECUTABLE NPM_DIR
VERSION_VAR NPM_VERSION )
mark_as_advanced(NPM_DIR NPM_GLOBAL_NODE_MODULE_DIR NPM_EXECUTABLE NPM_VERSION)

View File

@ -17,16 +17,14 @@ find_package_handle_standard_args (Sphinx DEFAULT_MSG
SPHINX_API_EXECUTABLE SPHINX_API_EXECUTABLE
) )
# Get Sphinx Version # Get Sphinx version
if (SPHINX_EXECUTABLE) if (SPHINX_EXECUTABLE)
execute_process(COMMAND ${SPHINX_EXECUTABLE} --version execute_process(COMMAND ${SPHINX_EXECUTABLE} --version
OUTPUT_VARIABLE SPHINX_VERSION_STRING OUTPUT_VARIABLE SPHINX_VERSION)
OUTPUT_STRIP_TRAILING_WHITESPACE if(SPHINX_VERSION)
ERROR_STRIP_TRAILING_WHITESPACE) string(REGEX MATCH "([0-9]\\.[0-9]\\.[0-9])" SPHINX_VERSION_STR ${SPHINX_VERSION})
if (SPHINX_VERSION_STRING) message (STATUS "Sphinx version is ${SPHINX_VERSION_STR}")
string(REPLACE "Sphinx (sphinx-build) " "" SPHINX_VERSION ${SPHINX_VERSION_STRING}) endif()
message (STATUS "Sphinx version is ${SPHINX_VERSION}")
endif ()
endif () endif ()
mark_as_advanced (SPHINX_EXECUTABLE) mark_as_advanced (SPHINX_EXECUTABLE)

View File

@ -1,20 +0,0 @@
find_program (UPM_CORDOVA_BINDING NAMES upm-cordova-binding
DOC "UPM Cordova binding generator")
include (FindPackageHandleStandardArgs)
# Get version
if (UPM_CORDOVA_BINDING)
execute_process(COMMAND ${NPM_EXECUTABLE} info upm-cordova-binding version
OUTPUT_VARIABLE UPM_CORDOVA_BINDING_VERSION
ERROR_VARIABLE UPM_CORDOVA_BINDING_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
endif()
find_package_handle_standard_args(UpmCordovaGenerator
REQUIRED_VARS UPM_CORDOVA_BINDING
VERSION_VAR UPM_CORDOVA_BINDING_VERSION
FAIL_MESSAGE "Unable to find the npm package for generating UPM Cordova bindings. The generator can be installed via: 'npm install -g upm-cordova-binding'")
mark_as_advanced (UPM_CORDOVA_BINDING UPM_CORDOVA_BINDING_VERSION)

View File

@ -0,0 +1,136 @@
# Based on the Qt 5 processor detection code, so should be very accurate
# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h
# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64)
# Regarding POWER/PowerPC, just as is noted in the Qt source,
# "There are many more known variants/revisions that we do not handle/detect."
set(archdetect_c_code "
#if defined(__arm__) || defined(__TARGET_ARCH_ARM)
#if defined(__ARM_ARCH_7__) \\
|| defined(__ARM_ARCH_7A__) \\
|| defined(__ARM_ARCH_7R__) \\
|| defined(__ARM_ARCH_7M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
#error cmake_ARCH armv7
#elif defined(__ARM_ARCH_6__) \\
|| defined(__ARM_ARCH_6J__) \\
|| defined(__ARM_ARCH_6T2__) \\
|| defined(__ARM_ARCH_6Z__) \\
|| defined(__ARM_ARCH_6K__) \\
|| defined(__ARM_ARCH_6ZK__) \\
|| defined(__ARM_ARCH_6M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
#error cmake_ARCH armv6
#elif defined(__ARM_ARCH_5TEJ__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
#error cmake_ARCH armv5
#else
#error cmake_ARCH arm
#endif
#elif defined(__i586) || defined(__i586__)
#error cmake_ARCH i586
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#error cmake_ARCH i386
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
#error cmake_ARCH x86_64
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#error cmake_ARCH ia64
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|| defined(_M_MPPC) || defined(_M_PPC)
#if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#error cmake_ARCH ppc64
#else
#error cmake_ARCH ppc
#endif
#endif
#error cmake_ARCH unknown
")
# Set ppc_support to TRUE before including this file or ppc and ppc64
# will be treated as invalid architectures since they are no longer supported by Apple
function(target_architecture output_var)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
# First let's normalize the order of the values
# Note that it's not possible to compile PowerPC applications if you are using
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
# disable it by default
# See this page for more information:
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
set(osx_arch_ppc TRUE)
elseif("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
set(osx_arch_ppc64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()
# Now add all the architectures in our normalized order
if(osx_arch_ppc)
list(APPEND ARCH ppc)
endif()
if(osx_arch_i386)
list(APPEND ARCH i386)
endif()
if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()
if(osx_arch_ppc64)
list(APPEND ARCH ppc64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
enable_language(C)
# Detect the architecture in a rather creative way...
# This compiles a small C program which is a series of ifdefs that selects a
# particular #error preprocessor directive whose message string contains the
# target architecture. The program will always fail to compile (both because
# file is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in this
# way, we can detect the correct target architecture even when cross-compiling,
# since the program itself never needs to be run (only the compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)
# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due
# to a typo in the code), then set it to unknown
if (NOT ARCH)
set(ARCH unknown)
endif()
endif()
set(${output_var} "${ARCH}" PARENT_SCOPE)
endfunction()

View File

@ -3,7 +3,7 @@ version: '2.1'
services: services:
base: base:
image: inteliotdevkit/upm-base image: dnoliver/upm-base
environment: environment:
- http_proxy - http_proxy
- https_proxy - https_proxy
@ -13,10 +13,8 @@ services:
- BUILDFTI=${BUILDFTI:-ON} - BUILDFTI=${BUILDFTI:-ON}
- BUILDSWIGPYTHON=${BUILDSWIGPYTHON:-OFF} - BUILDSWIGPYTHON=${BUILDSWIGPYTHON:-OFF}
- BUILDSWIGJAVA=${BUILDSWIGJAVA:-OFF} - BUILDSWIGJAVA=${BUILDSWIGJAVA:-OFF}
- BUILDCORDOVA=${BUILDCORDOVA:-OFF}
- BUILDSWIGNODE=${BUILDSWIGNODE:-OFF} - BUILDSWIGNODE=${BUILDSWIGNODE:-OFF}
- BUILDEXAMPLES=${BUILDEXAMPLES:-OFF} - BUILDEXAMPLES=${BUILDEXAMPLES:-ON}
- CMAKE_BUILD_TYPE
- IPK=${IPK:-OFF} - IPK=${IPK:-OFF}
- RPM=${RPM:-OFF} - RPM=${RPM:-OFF}
- NPM=${NPM:-OFF} - NPM=${NPM:-OFF}
@ -28,18 +26,9 @@ services:
volumes: volumes:
- .:${UPM_SRC_DIR:-/usr/src/app} - .:${UPM_SRC_DIR:-/usr/src/app}
all:
extends: base
image: inteliotdevkit/upm-all
minimal:
extends: base
environment:
- BUILDFTI=OFF
command: bash -c "./scripts/run-cmake.sh && cd build && make && ctest -R unit --output-on-failure"
doc: doc:
extends: all extends: base
image: dnoliver/upm-all
environment: environment:
- BUILDSWIGPYTHON=ON - BUILDSWIGPYTHON=ON
- BUILDSWIGJAVA=ON - BUILDSWIGJAVA=ON
@ -47,17 +36,22 @@ services:
- BUILDDOC=ON - BUILDDOC=ON
command: bash -c "./scripts/run-cmake.sh && ./scripts/build-doc.sh" command: bash -c "./scripts/run-cmake.sh && ./scripts/build-doc.sh"
examples: ipk:
extends: all extends: base
environment: environment:
- BUILDSWIGPYTHON=ON - IPK=ON
- BUILDSWIGJAVA=ON - BUILDDOC=OFF
- BUILDSWIGNODE=ON command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
- BUILDEXAMPLES=ON
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8" rpm:
extends: doc
environment:
- RPM=ON
- BUILDDOC=OFF
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
npm: npm:
extends: all extends: doc
environment: environment:
- NPM=ON - NPM=ON
- BUILDDOC=OFF - BUILDDOC=OFF
@ -65,9 +59,12 @@ services:
sonar-scan: sonar-scan:
extends: base extends: base
image: inteliotdevkit/upm-sonar image: dnoliver/upm-all
environment: environment:
- BUILDTESTS=OFF - BUILDSWIGPYTHON=ON
- BUILDSWIGNODE=ON
- BUILDSWIGJAVA=ON
- BUILDSWIGEXAMPLES=ON
- SONAR_TOKEN - SONAR_TOKEN
- SONAR_ORG - SONAR_ORG
- SONAR_PROJ_KEY - SONAR_PROJ_KEY
@ -80,43 +77,36 @@ services:
python: python:
extends: base extends: base
image: inteliotdevkit/upm-python image: dnoliver/upm-python
environment: environment:
- BUILDSWIGPYTHON=ON - BUILDSWIGPYTHON=ON
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure" command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
java: java:
extends: base extends: base
image: inteliotdevkit/upm-java image: dnoliver/upm-java
environment: environment:
- BUILDSWIGJAVA=ON - BUILDSWIGJAVA=ON
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure" command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
android: android:
extends: java extends: java
image: inteliotdevkit/upm-android image: dnoliver/upm-android
environment: environment:
- BUILDTESTS=OFF - BUILDTESTS=OFF
command: bash -c "./scripts/build-android.sh" command: bash -c "./scripts/build-android.sh"
cordova:
extends: all
environment:
- BUILDSWIGJAVA=ON
- BUILDCORDOVA=ON
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8"
node4: node4:
extends: base extends: base
image: inteliotdevkit/upm-node4 image: dnoliver/upm-node4
environment: environment:
- BUILDSWIGNODE=ON - BUILDSWIGNODE=ON
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure -E examplenames_js" command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure -E examplenames_js"
node5: node5:
extends: node4 extends: node4
image: inteliotdevkit/upm-node5 image: dnoliver/upm-node5
node6: node6:
extends: node4 extends: node4
image: inteliotdevkit/upm-node6 image: dnoliver/upm-node6

View File

@ -4,42 +4,6 @@ API Changes {#apichanges}
Here's a list of other API changes made to the library that break source/binary Here's a list of other API changes made to the library that break source/binary
compatibility between releases: compatibility between releases:
# v2.0.0
* Sensors implementing the old interfaces (bme280, bmpx8x, si7005, si1132,
max44009, lp8860, ds1808lc, hlg150h) have been updated to use the new ones,
hence some function names and parameters will be different.
* Removed deprecated basic grove classes from project, see API changes for
v1.1.0 and prior for a complete list
# v1.7.0
* The interface of **kx122** has been modified to return values instead
of receiving pointers. This applies to member functions: getWhoAmI,
getInterruptSource, getBufferStatus, getRawBufferSamples, and
getBufferSamples.
* The **tm1637** constructor has been updated and the fast GPIO parameter
has been removed with the deprecation of supporting MRAA functions. The
GPIO lines will initialize by default in fast mode when available.
* The generic **nmea_gps** library for GPS devices has been greatly enhanced
with new APIs to offer better control over acquisition intervals and simplify
parsing of the returned data.
# v1.6.0
* Several C libraries had their init function pin type modified from uint8_t
to int allowing usage with subplatforms
* Our **led** class constructor has been overloaded with a string based
variant that uses the new MRAA LED APIs
* The **i2clcd** library has finally been renamed to **lcd** and is now
mostly considered a bundle for ssd lcd display controllers only
* The **zfm20** class constructor has been overloaded with a string variant
that allows initialization using any UART device
# v1.5.0
* **VEML6070** This sensor class no longer needs an I2C address when
initialized, since they are fixed. Only the I2C bus number needs to
be provided.
# v1.3.0 # v1.3.0
* **The lsm303 driver has been renamed** There are a variety of * **The lsm303 driver has been renamed** There are a variety of
@ -168,13 +132,13 @@ compatibility between releases:
* **lcm1602/jhd1313m1** These drivers had been rewritten in C, with * **lcm1602/jhd1313m1** These drivers had been rewritten in C, with
C++ wrappers and placed into their own libraries in the previous C++ wrappers and placed into their own libraries in the previous
version of UPM, however, the original C++ implementation was kept in version of UPM, however, the original C++ implementation was kept in
the lcd library for compatibility reasons with existing code. the lcd/i2clcd library for compatibility reasons with existing code.
To avoid collisions with the header files, the new *lcm1602* and To avoid collisions with the header files, the new *lcm1602* and
*jhd1313m1* drivers had their C++ headers renamed to use a **.hxx** *jhd1313m1* drivers had their C++ headers renamed to use a **.hxx**
suffix. suffix.
In this version of UPM, the *lcm1602* and *jhd1313m1* drivers have In this version of UPM, the *lcm1602* and *jhd1313m1* drivers have
been removed from the lcd library. In addition, the header been removed from the lcd/i2clcd library. In addition, the header
files for the new implementation have been renamed from their files for the new implementation have been renamed from their
**.hxx** suffix to the normal **.hpp** suffix. **.hxx** suffix to the normal **.hpp** suffix.

View File

@ -34,12 +34,7 @@ make install
The last command will create the include/ and lib/ directories with a copy of The last command will create the include/ and lib/ directories with a copy of
the headers and library objects respectively in your build location. Note that the headers and library objects respectively in your build location. Note that
doing an out-of-source build may cause issues when rebuilding later on. In many doing an out-of-source build may cause issues when rebuilding later on.
cases you'll need elevated permissions to install:
~~~~~~~~~~~~~{.sh}
sudo make install
~~~~~~~~~~~~~
Our cmake configure has a number of options, *cmake-gui* or *ccmake* can show Our cmake configure has a number of options, *cmake-gui* or *ccmake* can show
you all the options. The interesting ones are detailed below: you all the options. The interesting ones are detailed below:
@ -96,35 +91,32 @@ You can also generate the include and lib directories containing all the sensor
headers and library files respectively with *make install*. Further, you may headers and library files respectively with *make install*. Further, you may
choose to generate these only for a specific sensor you modified, and this can choose to generate these only for a specific sensor you modified, and this can
be achieved by building from the individual makefile of the sensor. Assuming be achieved by building from the individual makefile of the sensor. Assuming
you're in the build directory, to build/install the lcd module you would: you're in the build directory, to make the lcd module you would:
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
cd src/lcd cd src/lcd
make install make install
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
Note: 'make install' under src/lcd will build all targets (and dependencies)
for the lcd but will NOT install dependencies.
Often developers are only interested in building one module or even just the Often developers are only interested in building one module or even just the
python/node module to do some quick testing using scripting. In order to do python/node module to do some quick testing using scripting. In order to do
this you need to use the target name for the python or node module you want to this you need to use the target name for the python or node module you want to
rebuild. For example, the lcd module target will have a python2 target prefixed rebuild. For example the lcd module target name is i2clcd. Therefore the python
by _pyupm_ (_pyupm_lcd-python2). Modules not using the UPM cmake macros may module target name will be prefixed by _pyupm_. Just do the following to build
have different naming. To build the python2 lcd module (and all dependencies), only that module. Modules not using the UPM cmake macros may have different
use the following make target: naming.
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
make _pyupm_lcd-python2 make _pyupm_i2clcd
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
Sometimes you want to build a small C++ example against an installed library. Sometimes you want to build a small C++ example against an installed library.
This is fairly easy if installed system-wide. Just link against the correct This is fairly easy if installed system-wide. Just link against the correct
library (in this case libupm-lcd) and then add /usr/include/upm to the library (in this case libupm-i2clcd) and then add /usr/include/upm to the
loader path: loader path:
~~~~~~~~~~~~ ~~~~~~~~~~~~
g++ test.cxx -lupm-lcd -I/usr/include/upm g++ test.cxx -lupm-i2clcd -I/usr/include/upm
~~~~~~~~~~~~ ~~~~~~~~~~~~
You can also use pkg-config to return the information to you, which is You can also use pkg-config to return the information to you, which is
@ -132,37 +124,9 @@ considered the correct way if including UPM in a build system like cmake or
autotools on linux. autotools on linux.
~~~~~~~~~~~ ~~~~~~~~~~~
pkg-config --cflags --libs upm-lcd pkg-config --cflags --libs upm-i2clcd
~~~~~~~~~~~ ~~~~~~~~~~~
## Building for Android Things
Requirements:
* [io.mraa.at](https://search.maven.org/#artifactdetails%7Cio.mraa.at%7Cmraa%7C1.8.0%7Caar)
* [io.mraa.at.upm](https://search.maven.org/#artifactdetails%7Cio.mraa.at.upm%7Cupm_zfm20%7C1.3.0%7Caar)
* [Android NDK](https://developer.android.com/ndk/downloads/index.html) >= 14b
### Android NDK r14b
~~~~~~~~~~~~~{.sh}
NDK_HOME="/path/to/android-ndk-r14b"
MRAA_INSTALL_DIR="/path/to/mraa/install"
cmake -DBUILDSWIG=ON \
-DBUILDSWIGPYTHON=OFF \
-DBUILDSWIGNODE=OFF \
-DBUILDSWIGJAVA=ON \
-DANDROID_COMPILER_FLAGS_CXX='-std=c++11' \
-DANDROID_PIE=1 \
-DANDROID_PLATFORM=android-24 \
-DANDROID_STL_FORCE_FEATURES=ON \
-DANDROID_STL=c++_shared \
-DANDROID_TOOLCHAIN_NAME=x86-i686 \
-DCMAKE_TOOLCHAIN_FILE=$NDK_HOME/build/cmake/android.toolchain.cmake \
-DCMAKE_FIND_ROOT_PATH=$MRAA_INSTALL_DIR \
..
~~~~~~~~~~~~~
## Building with Docker ## Building with Docker
You can use `docker` and `docker-compose` to generate a complete build environment You can use `docker` and `docker-compose` to generate a complete build environment
@ -223,7 +187,7 @@ $ docker run \
--env BUILDSWIGPYTHON=ON \ --env BUILDSWIGPYTHON=ON \
--env BUILDSWIGJAVA=OFF \ --env BUILDSWIGJAVA=OFF \
--env BUILDSWIGNODE=OFF \ --env BUILDSWIGNODE=OFF \
inteliotdevkit/upm-python \ dnoliver/upm-python \
bash -c "./scripts/run-cmake.sh && make -Cbuild" bash -c "./scripts/run-cmake.sh && make -Cbuild"
``` ```
@ -257,6 +221,6 @@ $ docker run \
--env http_proxy=$http_proxy \ --env http_proxy=$http_proxy \
--env https_proxy=$https_proxy \ --env https_proxy=$https_proxy \
--env no_proxy=$no_proxy \ --env no_proxy=$no_proxy \
inteliotdevkit/upm-python \ dnoliver/upm-python \
bash -c "./scripts/run-cmake.sh && make -Cbuild" bash -c "./scripts/run-cmake.sh && make -Cbuild"
``` ```

View File

@ -4,61 +4,6 @@ Changelog {#changelog}
Here's a list summarizing some of the key undergoing changes to our library Here's a list summarizing some of the key undergoing changes to our library
from earlier versions: from earlier versions:
### v2.0.0
* Reworked existing interfaces and extended the list to include iAcceleration,
iAngle, iButton, iClock, iCollision, iDistance, iDistanceInterrupter, iEC,
iElectromagnet, iEmg, iGas, iGps, iGyroscope, iHallEffect, iHeartRate, iHumidity,
iLight, iLineFinder, iMagnetometer, iMoisture, iMotion, iOrp, iPH, iPressure,
iProximity, iTemperature, iVDiv, iWater
* Provided overloaded string based constructors for a good number of sensors,
allowing initialization from external frameworks without type knowledge
* Removed deprecated basic grove classes from project
* Replaced 6 unsafe occurrences of sprintf() usage
* Cleaned-up build system around target arch detection and cpack usage, added
detection and resolution of tinyb library when used as a dependency
* New sensors: 2jciebu01_ble, 2jciebu01_usb
### v1.7.1
* Bumped library compatibility to new MRAA 2.0 APIs
* Added installation details for Fedora
* Minor fixes based on static analysis vulnerability report
### v1.7.0
* Added Cordova bindings based on Java packages
* Complete rework of the nmea_gps library giving more control over data
acquisition and parsing
* Added GTest support for unit tests
* Removed calls to deprecated MRAA fast GPIO functions
* Several bug fixes and improvements around SWIG type maps and gcc8 support
* New sensors: kx122, kxtj3, bh1792, bh1749
### v1.6.0
* Extended LED library to support the new MRAA gpio-leds APIs
* Many CMake changes around SWIG wrapper generation and improved FindNodejs
detection module
* Several code fixes based on static code analysis
* Improved documentation generation and Travis CI builds
* Cleaned-up doxygen tags in headers and class names in JSON library files
* New sensor: lis3dh
### v1.5.0
* Introduced a flexible JSON format for technical sensor specifications, notes
and classification. This is also used by our [new UPM website](http://upm.mraa.io)
* Revised all C++ sensor examples and switched to stack allocations where
possible along with other code and formatting clean-up
* Significantly improved docker workflow, CI integration, sanity and
consistency tests, static code scans and documentation generation
* Several improvements to a couple of existing sensor drivers and better
compatibility with subplatforms
* Added new std::vector to AbstractList<> typemap for Java bindings and
examples
* New sensors: lis2ds12, lsm6ds3h, lsm6dsl, lidarlitev3
### v1.3.0 ### v1.3.0
* Finalized all required build system and JAVA binding changes to release the * Finalized all required build system and JAVA binding changes to release the

View File

@ -125,8 +125,6 @@ function make_new_sensor {
# Search/replace the new files, replacing all instances of sensortemplate # Search/replace the new files, replacing all instances of sensortemplate
perl -p -i -e "s/SensorTemplate/${SensorName}/g" src/${sensorname}/* examples/*/*${sensorname}* examples/*/*${SensorName}* perl -p -i -e "s/SensorTemplate/${SensorName}/g" src/${sensorname}/* examples/*/*${sensorname}* examples/*/*${SensorName}*
perl -p -i -e "s/sensortemplate/${sensorname}/g" src/${sensorname}/* examples/*/*${sensorname}* examples/*/*${SensorName}* perl -p -i -e "s/sensortemplate/${sensorname}/g" src/${sensorname}/* examples/*/*${sensorname}* examples/*/*${SensorName}*
# Remove objects starting with "//" from the new library descriptor .json file
perl -p -i -e 'BEGIN{undef $/;} s/\s+"\/\/.*?},//smg' src/${sensorname}/${sensorname}.json
# Add mynewmodule example target for java # Add mynewmodule example target for java
perl -p -i -e "s/^((.*)SensorTemplateSample sensortemplate(.*))/\1\n\2${SensorName}Sample ${sensorname}\3/g" examples/java/CMakeLists.txt perl -p -i -e "s/^((.*)SensorTemplateSample sensortemplate(.*))/\1\n\2${SensorName}Sample ${sensorname}\3/g" examples/java/CMakeLists.txt
# Add mynewmodule example mappings for doxygen # Add mynewmodule example mappings for doxygen

View File

@ -12,87 +12,89 @@ Creating Java Bindings Guide
* [Implementing callbacks in Java](#implementing-callbacks-in-java) * [Implementing callbacks in Java](#implementing-callbacks-in-java)
## Overview ##Overview
The "Creating Java Bindings Guide" serves as a basic tutorial for using the SWIG software development tool to create 'glue code' required for Java to call into C/C++ code. It contains: guides for dealing with type conversions, exception handling, callbacks; recommendations on how to write/modify the native API to avoid issues on the Java side, and also workarounds for those issues that can't be avoided. The "Creating Java Bindings Guide" serves as a basic tutorial for using the SWIG software development tool to create 'glue code' required for Java to call into C/C++ code. It contains: guides for dealing with type conversions, exception handling, callbacks; recommendations on how to write/modify the native API to avoid issues on the Java side, and also workarounds for those issues that can't be avoided.
This guide was created with the [upm](https://github.com/intel-iot-devkit/upm/) and [mraa](https://github.com/intel-iot-devkit/mraa) libraries in mind, and uses examples taken from these sources, but its usage can be extended to any project of creating Java bindings for C/C++ libraries. This guide was created with the [upm](https://github.com/intel-iot-devkit/upm/) and [mraa](https://github.com/intel-iot-devkit/mraa) libraries in mind, and uses examples taken from these sources, but its usage can be extended to any project of creating Java bindings for C/C++ libraries.
## Tools of trade ##Tools of trade
[SWIG General Documentation](http://www.swig.org/Doc3.0/SWIGDocumentation.html) [SWIG General Documentation](http://www.swig.org/Doc3.0/SWIGDocumentation.html)
[SWIG Java-specific Documentation](http://www.swig.org/Doc3.0/Java.html) [SWIG Java-specific Documentation](http://www.swig.org/Doc3.0/Java.html)
## Recommendations for the native API ##Recommendations for the native API
### Pointers ###Pointers
As much as possible, avoid passing values/returning values through pointers given as as arguments to methods. As the Java language does not have pointers, SWIG provides a [workaround](http://www.swig.org/Doc3.0/Java.html#Java_tips_techniques) in the typemaps.i library. As much as possible, avoid passing values/returning values through pointers given as as arguments to methods. As the Java language does not have pointers, SWIG provides a [workaround](http://www.swig.org/Doc3.0/Java.html#Java_tips_techniques) in the typemaps.i library.
#### Alternatives: ####Alternatives:
1. Functions that read data from a driver, return it through a pointer given as argument, and return a bool value, should be __replaced by__ functions that return the value directly and throw a std::runtime_error if a read error occurs. E.g.: 1. Functions that read data from a driver, return it through a pointer given as argument, and return a bool value, should be __replaced by__ functions that return the value directly and throw a std::runtime_error if a read error occurs. E.g.:
```c++ ```c++
/* /*
* Function reads from sensor, places read value in variable bar and * Function reads from sensor, places read value in variable bar and
* returns true if succesful. Function returns false if read failed. * returns true if succesful. Function returns false if read failed.
*/ */
bool func(int *bar); bool func(int *bar);
``` ```
__Replaced by:__ __Replaced by:__
```c++ ```c++
/* /*
* Function reads from sensor and returns read value. * Function reads from sensor and returns read value.
* Or throws std::runtime_error if a read error occurs * Or throws std::runtime_error if a read error occurs
*/ */
int func(); int func();
``` ```
2. Functions that return multiple values through pointers, that make sense to be grouped together into an array<sup>1</sup> (e.g. speed values, acceleration values), should be __replaced by__ functions that return a pointer to an array in which the elements are the returned values. Afterwards, [wrap the C array with a Java array](#wrapping-unbound-c-arrays-with-java-arrays-if-array-is-output). E.g.: 2. Functions that return multiple values through pointers, that make sense to be grouped together into an array<sup>1</sup> (e.g. speed values, acceleration values), should be __replaced by__ functions that return a pointer to an array in which the elements are the returned values. Afterwards, [wrap the C array with a Java array](#wrapping-unbound-c-arrays-with-java-arrays-if-array-is-output). E.g.:
```c++ ```c++
/* /*
* Function returns the acceleration on the three * Function returns the acceleration on the three
* axis in the given variables. * axis in the given variables.
*/ */
void getAccel(int *accelX, int *accelY, int *accelZ); void getAccel(int *accelX, int *accelY, int *accelZ);
``` ```
__Replaced by:__ __Replaced by:__
```c++ ```c++
/* /*
* Function returns the acceleration on the three * Function returns the acceleration on the three
* axis as elements of a 3-element array. * axis as elements of a 3-element array.
*/ */
int *getAccel(); int *getAccel();
``` ```
3. Functions that return N values through pointers, that do not make sense to grouped together (e.g. a general purpose function that returns both the light intensity and air pollution), should be __replaced by__ N functions (one for each value) that read only one specific value. E.g.: 3. Functions that return N values through pointers, that do not make sense to grouped together (e.g. a general purpose function that returns both the light intensity and air pollution), should be __replaced by__ N functions (one for each value) that read only one specific value. E.g.:
```c++ ```c++
/* /*
* Function returns the light intensity and air pollution * Function returns the light intensity and air pollution
*/ */
void getData(int *light, int *air); void getData(int *light, int *air);
``` ```
__Replaced by:__ __Replaced by:__
```c++ ```c++
int getLight(); int getLight();
int getAir(); int getAir();
``` ```
4. Functions that return N values through pointers; values that do not make sense to be grouped together, but are time dependent, and make sense to be read at the same time. For example, a sensor that reads air humidity and temperature. A user may want to know the temperature value _temp_ read at the exact moment the humidity value _humid_ was read. These should be __replaced by__ N+1 functions: a _getData()_ function that reads all values at the same time and stores them in global variables; and N getter functions, one for each value. E.g. 4. Functions that return N values through pointers; values that do not make sense to be grouped together, but are time dependent, and make sense to be read at the same time. For example, a sensor that reads air humidity and temperature. A user may want to know the temperature value _temp_ read at the exact moment the humidity value _humid_ was read. These should be __replaced by__ N+1 functions: a _getData()_ function that reads all values at the same time and stores them in global variables; and N getter functions, one for each value. E.g.
```c++ ```c++
/* /*
* Function returns the light intensity and air pollution * Function returns the light intensity and air pollution
*/ */
void getData(int *temp, int *humid); void getData(int *temp, int *humid);
``` ```
__Replaced by:__ __Replaced by:__
```c++ ```c++
void getData(); void getData();
int getTemp(); int getTemp();
int getHumid(); int getHumid();
``` ```
<sup>1</sup>this depends on the interpretation of the returned data. For example, arguments that return the temperature and light intensity, don't make sense to be grouped into an array of size 2. But acceleration on the three axis can be grouped together in an array of size 3. where accelX is accel[0], accelY is accel[1], accelZ is accel[2]. <sup>1</sup>this depends on the interpretation of the returned data. For example, arguments that return the temperature and light intensity, don't make sense to be grouped into an array of size 2. But acceleration on the three axis can be grouped together in an array of size 3. where accelX is accel[0], accelY is accel[1], accelZ is accel[2].
@ -101,8 +103,8 @@ __Notice:__
Sometimes, you may be required to write JNI code. Be aware of the difference between the C JNI calling syntax and the C++ JNI calling syntax.The C++ calling syntax will not compile as C and also vice versa. It is however possible to write JNI calls which will compile under both C and C++ and is covered in the [Typemaps for both C and C++ compilation](http://www.swig.org/Doc3.0/Java.html#Java_typemaps_for_c_and_cpp) section of the SWIG Documentation. Sometimes, you may be required to write JNI code. Be aware of the difference between the C JNI calling syntax and the C++ JNI calling syntax.The C++ calling syntax will not compile as C and also vice versa. It is however possible to write JNI calls which will compile under both C and C++ and is covered in the [Typemaps for both C and C++ compilation](http://www.swig.org/Doc3.0/Java.html#Java_typemaps_for_c_and_cpp) section of the SWIG Documentation.
### Throwing Exceptions in Java ###Throwing Exceptions in Java
#### Language independent: ####Language independent:
The %exception directive allows you to define a general purpose exception handler. For example, you can specify the following: The %exception directive allows you to define a general purpose exception handler. For example, you can specify the following:
```c++ ```c++
@ -124,18 +126,18 @@ The exception.i library file provides support for creating language independent
```c++ ```c++
// Language independent exception handler // Language independent exception handler
%include exception.i %include exception.i
%exception { %exception {
try { try {
$action $action
} catch(OutOfMemory) { } catch(OutOfMemory) {
SWIG_exception(SWIG_MemoryError, "Out of memory"); SWIG_exception(SWIG_MemoryError, "Out of memory");
} catch(...) { } catch(...) {
SWIG_exception(SWIG_RuntimeError,"Unknown exception"); SWIG_exception(SWIG_RuntimeError,"Unknown exception");
} }
} }
``` ```
In the upm library, the upm_exception.i interface file provides the functionality to catch common exceptions and propagate them through SWIG. It uses the exception.i library file and is language independent. In the upm library, the upm_exception.i interface file provides the functionality to catch common exceptions and propagate them through SWIG. It uses the exception.i library file and is language independent.
@ -153,19 +155,19 @@ The upm_exception.i interface file is included in the upm.i file, therefor SWIG
* std::exception * std::exception
#### Java specific: ####Java specific:
To throw a specific Java exception: To throw a specific Java exception:
```c++ ```c++
%exception { %exception {
try { try {
$action $action
} catch (std::out_of_range &e) { } catch (std::out_of_range &e) {
jclass clazz = jenv->FindClass("java/lang/Exception"); jclass clazz = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(clazz, "Range error"); jenv->ThrowNew(clazz, "Range error");
return $null; return $null;
} }
} }
``` ```
Where FindClass and ThrowNew are [JNI functions](http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html). Where FindClass and ThrowNew are [JNI functions](http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html).
@ -177,99 +179,110 @@ The C++ compiler does not force the code to catch any exception.
The %exception directive does not specify if a method throws a checked exception (does not add classes to the throws clause). For this, the %javaexception(classes) directive is used; where classes is a string containing one or more comma separated Java classes. The %exception directive does not specify if a method throws a checked exception (does not add classes to the throws clause). For this, the %javaexception(classes) directive is used; where classes is a string containing one or more comma separated Java classes.
```c++ ```c++
%javaexception("java.lang.Exception") { %javaexception("java.lang.Exception") {
try { try {
$action $action
} catch (std::out_of_range &e) { } catch (std::out_of_range &e) {
jclass clazz = jenv->FindClass("java/lang/Exception"); jclass clazz = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(clazz, "Range error"); jenv->ThrowNew(clazz, "Range error");
return $null; return $null;
} }
} }
``` ```
In the upm library, the java_exceptions.i library file provides the functionality to catch exceptions and propagate them through SWIG as Java checked exceptions. The file provides SWIG wrappers, in the form of macros, that can be applied to methods.E.g. use the __READDATA_EXCEPTION(function)__ macro for functions that read data from a sensor and throw a std::runtime_error in case of a read failure. This will result in: In the upm library, the java_exceptions.i library file provides the functionality to catch exceptions and propagate them through SWIG as Java checked exceptions. The file provides SWIG wrappers, in the form of macros, that can be applied to methods.E.g. use the __READDATA_EXCEPTION(function)__ macro for functions that read data from a sensor and throw a std::runtime_error in case of a read failure. This will result in:
```java ```java
void function throws IOException (); void function throws IOException ();
``` ```
## Caveats & Challenges ##Caveats & Challenges
### Wrapping C arrays with Java arrays ###Wrapping C arrays with Java arrays
SWIG can wrap arrays in a more natural Java manner than the default by using the arrays_java.i library file. Just include this file into your SWIG interface file. SWIG can wrap arrays in a more natural Java manner than the default by using the arrays_java.i library file. Just include this file into your SWIG interface file.
### Wrapping unbound C arrays with Java arrays if array is output ###Wrapping unbound C arrays with Java arrays if array is output
Functions that return arrays, return a pointer to that array. E.g.: Functions that return arrays, return a pointer to that array. E.g.:
```c++ ```c++
/* /*
* Function returns the acceleration on the three * Function returns the acceleration on the three
* axis as elements of a 3-element array. * axis as elements of a 3-element array.
*/ */
int *getAccel(); int *getAccel();
``` ```
__SWIG:__ __SWIG:__
```c++ ```c++
%typemap(jni) int* "jintArray" %typemap(jni) int* "jintArray"
%typemap(jstype) int* "int[]" %typemap(jstype) int* "int[]"
%typemap(jtype) int* "int[]" %typemap(jtype) int* "int[]"
%typemap(javaout) int* { %typemap(javaout) int* {
return $jnicall; return $jnicall;
} }
%typemap(out) int *getAccel { %typemap(out) int *getAccel {
$result = JCALL1(NewIntArray, jenv, 3); $result = JCALL1(NewIntArray, jenv, 3);
JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const signed int*)$1); JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const signed int*)$1);
} }
``` ```
### Wrapping unbound C arrays with Java arrays if array is input ###Wrapping unbound C arrays with Java arrays if array is input
In C, arrays are tipically passed as pointers, with an integer value representig the length of the array. In Java, the length of an array is always known, so the length argument is redundant. This example shows how to wrap the C array and also get rid the length argument. E.g.: In C, arrays are tipically passed as pointers, with an integer value representig the length of the array. In Java, the length of an array is always known, so the length argument is redundant. This example shows how to wrap the C array and also get rid the length argument. E.g.:
```c++ ```c++
void func(uint8_t *buffer, int length); void func(uint8_t *buffer, int length);
``` ```
__SWIG:__ __SWIG:__
```c++ ```c++
%typemap(jtype) (uint8_t *buffer, int length) "byte[]" %typemap(jtype) (uint8_t *buffer, int length) "byte[]"
%typemap(jstype) (uint8_t *buffer, int length) "byte[]" %typemap(jstype) (uint8_t *buffer, int length) "byte[]"
%typemap(jni) (uint8_t *buffer, int length) "jbyteArray" %typemap(jni) (uint8_t *buffer, int length) "jbyteArray"
%typemap(javain) (uint8_t *buffer, int length) "$javainput" %typemap(javain) (uint8_t *buffer, int length) "$javainput"
%typemap(in,numinputs=1) (uint8_t *buffer, int length) { %typemap(in,numinputs=1) (uint8_t *buffer, int length) {
$1 = JCALL2(GetByteArrayElements, jenv, $input, NULL); $1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
$2 = JCALL1(GetArrayLength, jenv, $input); $2 = JCALL1(GetArrayLength, jenv, $input);
} }
``` ```
!!!! There is a difference between TYPE *name and TYPE * name in typemaps!!!!! !!!! There is a difference between TYPE *name and TYPE * name in typemaps!!!!!
### Implementing callbacks in Java ###Implementing callbacks in Java
Callbacks in the UPM Java library (as well as the MRAA Java library) make use of the _void mraa\_java\_isr\_callback(void\* data\)_ method from MRAA. Callbacks in the UPM Java library (as well as the MRAA Java library) make use of the _void mraa\_java\_isr\_callback(void\* data\)_ method from MRAA.
__Callbacks in the UPM Java library are implemented as follows (we use the a110x Hall Effect sensors as example):__ __Callbacks in the UPM Java library are implemented as follows (we use the a110x Hall Effect sensors as example):__
We extend the sensor class with another method, _installISR\(jobject runnable\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _mraa\_java\_isr\_callback\(\)_ method as the interrupt service routine \(ISR\) to be called, with _jobject runnable_ as argument. We extend the sensor class with another method, _installISR\(jobject runnable\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _mraa\_java\_isr\_callback\(\)_ method as the interrupt service routine \(ISR\) to be called, with _jobject runnable_ as argument.
Java callbacks are added at the SWIG interface level. For ease-of-use, a collection of macros are available in src/_upm.i. SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _installISR\(jobject runnable\)_ method in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
src/a110x/a110x.i:
```c++ ```c++
JAVA_ADD_INSTALLISR(upm::A110X) #if defined(SWIGJAVA)
void A110X::installISR(jobject runnable)
{
installISR(mraa_java_isr_callback, runnable);
}
#endif
``` ```
Will expand to the following SWIG wrapper code: We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(jobject runnable\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
```c++ ```c++
SWIGINTERN void upm_A110X_installISR__SWIG_1(upm::A110X *self,jobject runnable){ public:
self->installISR(mraa_java_isr_callback, runnable); #if defined(SWIGJAVA)
} void installISR(jobject runnable);
#else
void installISR(void (*isr)(void *), void *arg);
#endif
private:
#if defined(SWIGJAVA)
void installISR(void (*isr)(void *), void *arg);
#endif
``` ```
To use callback in java, we create a ISR class, which implements the Java Runnable interface, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received: To use callback in java, we create a ISR class, which implements the Java Runnable interface, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
@ -277,13 +290,13 @@ To use callback in java, we create a ISR class, which implements the Java Runnab
```java ```java
public class A110X_intrSample { public class A110X_intrSample {
public static int counter=0; public static int counter=0;
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
upm_a110x.A110X hall = new upm_a110x.A110X(2); upm_a110x.A110X hall = new upm_a110x.A110X(2);
A110XISR callback = new A110XISR(); A110XISR callback = new A110XISR();
hall.installISR(callback); hall.installISR(callback);
while(true){ while(true){
System.out.println("Counter: " + counter); System.out.println("Counter: " + counter);
Thread.sleep(1000); Thread.sleep(1000);
@ -300,3 +313,41 @@ class A110XISR implements Runnable {
} }
} }
``` ```
####Issues with java callbacks and workarounds
__SWIGJAVA not defined at compile time__
Consider the following files:
* example.h - Header file for our source file
* example.cxx - Source file containing the class Example, for which we build java bindings
* example.i - The SWIG interface, that includes the example.h header file
The build process of a java module using SWIG is split into two steps:
1. Generating the intermediate files, from the SWIG interface file. This will produce the java class file (Example.java), the JNI file (exampleJNI.java) and wrapper file (example_wrap.cxx). The source file (example.cxx) is not needed in the first step.
```
swig -c++ -java example.i
```
2. Generating the shared library from the C++ sources and wrapper file
```
g++ -fPIC -c example.cxx example_wrap.cxx -I/usr/lib/jvm/java-1.8.0/include -I/usr/lib/jvm/java-1.8.0/include/linux
g++ -shared example_wrap.o sensor.o -o libexample.so
```
SWIGJAVA is always defined when SWIG parses the interface file, meaning it will be defined when it parses the header file (example.h) that is included in the interface file (example.i).
SWIG also adds the "#define SWIGJAVA" directive in the wrapper file (example_wrap.cxx).
However, in generating the shared library the SWIGJAVA symbol is only defined in the example_wrap.cxx file, because of the added "#define SWIGJAVA" directive. But we have also used the "#if defined(SWIGJAVA)" check in the source file (example.cxx), and thus need to define SWIGJAVA for it too. If we define the SWIGJAVA symbol as a compile flag, when compiling the source code to object code, the SWIGJAVA compile flag and #define SWIGJAVA" directive will clash and give a double definition warning (only a warning).
In this example it is simple to compile the two source codes separately, one with the compile flag, the other without, and then create the shared library (libexample.so).
But in a big automatic build like the java upm libraries, this may prove too hard or too complicated to do. A workaround to this would be to define a custom symbol (e.q. JAVACALLBACK in the upm library) and also test for it. In short, replace:
```c++
#if defined(SWIGJAVA)
```
by
```c++
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
```

View File

@ -10,132 +10,93 @@ sensors that you want to add to UPM:
- Have the specific sensor manufacturer/model & version that you used, if you - Have the specific sensor manufacturer/model & version that you used, if you
support multiple versions please list. support multiple versions please list.
- Simple comments do not need full stops. - Simple comments do not need full stops.
- Stick to <80 chars per line where possible. - Stick to <80 chars per line even in comments.
- No text is allowed on the same line as the start or end of a comment /** */. - No text is allowed on the same line as the start or end of a comment /** */.
We currently document our libraries in the following way: ####The sensor block
* **Doxygen** is used for documenting the API and generating the categories on This is added just before the class declaration in your header(.h) file and has
the [UPM Libraries page](https://iotdk.intel.com/docs/master/upm/modules.html). mandatory fields. For single sensor libraries, this block will actually
You can learn more about the Doxygen syntax [here](http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html). follow immediately after the library block. If you have multiple physical
* **JSON** is used to provide sensor specifications, descriptions, supported sensors, add this to every one.
platforms, links and other details. Here's an example (disregard the "@verbatim" tags in your actual code):
When submitting a new driver, you will have to at least fill out the mandatory ```
fields as described below. @verbatim
/**
### The library JSON file * @library <lib-name>
* @sensor <chip-id>
Let's use the BME280 class snippet from the bmp280.json file as an example: * @comname <component-name>
* @altname <alt-name>
```json * @altid <alt-id>
{ * @type <component-category>
"Library": "bmp280", * @man <component-manufacturer>
"Description": "Bosch Atmospheric Sensor Library", * @web <component-weblinks>
"Sensor Class": * @con <connection-type>
{ * @kit <component-kit>
"BME280": *
{ * @brief Short class/sensor description
"Name": "Digital Humidity, Pressure, and Temperature Sensor", *
"Description": "The BME280 is as combined digital humidity, pressure and temperature sensor based on proven sensing principles. The sensor module is housed in an extremely compact metal-lid LGA package with a footprint of only 2.5 * 2.5 mm2 with a height of 0.93 mm. Its small dimensions and its low power consumption allow the implementation in battery driven devices such as handsets, GPS modules or watches. The BME280 is register and performance compatible to the Bosch Sensortec BMP280 digital pressure sensor", * Then add a longer
"Aliases": ["bme280", "Grove - Barometer Sensor(BME280)"], * description here.
"Categories": ["pressure", "humidity", "temperature"], *
"Connections": ["gpio", "i2c", "spi"], * @image html <component-img.jpeg>
"Project Type": ["prototyping", "industrial"], * @snippet <example-name.cxx> Interesting
"Manufacturers": ["adafruit", "seeed", "bosch"], */
"Examples": @endverbatim
{
"Java": ["BMP280_Example.java"],
"Python": ["bmp280.py"],
"Node.js": ["bmp280.js"],
"C++": ["bmp280.cxx"],
"C": ["bmp280.c"]
},
"Specifications":
{
"Vdd": {"unit": "v", "low" : 1.7, "high": 3.6},
"Ioff" : {"unit": "mA", "low" : 0.0, "high": 0.0},
"Iavg": {"unit": "mA", "low" : 1, "high": 2},
"Pressure Range": {"unit": "hpA", "low" : 300, "high": 1100},
"Temperature Range": {"unit": "C", "low" : -40, "high": 85}
},
"Platforms":
{
"Intel Joule Module":
{
"Notes": ["Requires pull-up resistors with carrier board"]
}
},
"Urls" :
{
"Product Pages": ["https://www.adafruit.com/products/2652"],
"Datasheets": ["https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf"],
"Schematics": ["https://learn.adafruit.com/assets/26693"]
}
}
}
}
``` ```
#### Mandatory fields: - `<lib-name>` When adding to an existing library this needs to match that
library's "@defgroup", otherwise this is a new library name, generally the
same as chip id. *Mandatory*
- `<chip-id>` Usually the chip number used by the sensor. When this is not
available or relevant, use a unique descriptor that makes sense. Must match
class name. *Mandatory*
- `<component-name>` Title Case descriptive name for your sensor, try to avoid
including the manufacturer's name here. Examples: Digital Pressure Sensor,
Serial MP3 Module, etc... *Mandatory*
- `<alt-name>` Alternative names that your sensor driver might have. This may
include manufacturer's name. *Optional*
- `<alt-id>` Alternative chip-ids that your sensor driver supports. *Optional*
- `<component-category>` Mention one or more categories the sensor fits in. Can
be 'other'. *Mandatory*
- `<component-manufacturer>` Sensor manufacturer. Can be 'generic'. *Mandatory*
- `<component-weblinks>` Links to vendors or data-sheets. *Optional*
- `<connection-type>` Specifies how does the sensor connect to the board
*Mandatory*
- `<component-kit>` Specifies if the sensor is part of a kit. *Optional*
For the library: Existing groups that can be used for the manufacturer, connection, category and
kit tags are found in the *src/groups.md* file.
- `Library` The name of the library. This is appended to the upm prefix during Optionally, a small representative image can be placed in the "docs/images"
a build. subfolder and linked with the "@image" tag.
- `Description` A short description of the library and what it contains. **Please do not use existing, copyrighted images with your sensors!**
For the sensor classes: The example should have an 'Interesting' section which will be highlighted as
a code sample in doxygen. Everything in between such tags will show up in the
class documentation when "@snippet" is added at the end of a class docstring.
Tags use this format (in "example-name.cxx"):
- `Sensor Class` This is the object containing the sensor class(es) within the ```
library. Class objects need to match the name used in code. @verbatim
- `Name` Title Case descriptive names for your sensor. Multiple values can be //! [Interesting]
used to capture the chip name, generic name, or specific name for a vendor.
Examples: Digital Pressure Sensor, Serial MP3 Module
- `Description` A more detailed explanation what the sensor does and how it
works.
- `Categories` Mention one or more categories the sensor fits in. Accepted
values are listed in the groups.md file.
- `Connections` Specifies how does the sensor connect to the board. Accepted
values are listed in the groups.md file.
- `Project Type` What time of projects is the sensor suited for. For example:
prototyping, industrial, commercial.
- `Manufacturers` List of sensor manufacturers or vendors. Can be 'generic',
other accepted values in groups.md.
- `Examples` Names of the example files provided with the library. At a minimum,
the `C++` example needs to be provided.
- `Urls` At least one link for `Product Pages` needs to be provided. Additional
links to `Datasheets` or `Schematics` can be added.
#### Optional and customizable fields ...example code here...
- `Kits` Specifies if the sensor is part of a kit. Accepted values are listed //! [Interesting]
in the groups.md file. @endverbatim
- `Image` Name of the image file provided with the sensor class. ```
- `Specifications` Relevant sensor specifications as listed in the datasheet.
- `Platforms` Platform specific notes or known limitations and workarounds.
As mentioned, accepted values for some of the fields are listed under the For more examples take a look at the existing headers in our github repository.
[groups.md](../src/groups.md) file. If needed, you can add new categories
for your sensor library following the existing format.
JSON files are automatically checked for correctness and required fields on ####The library block
code submissions.
**Please do not use copyrighted images with your sensors!**
Images from Seeed, DFRobot, Sparkfun or Adafruit are permitted.
### Doxygen tags
#### The library doxygen block
New libraries must have the "@brief", "@defgroup" and "@ingroup" tags in one New libraries must have the "@brief", "@defgroup" and "@ingroup" tags in one
block. This usually follows the namespace and it is common to have one sensor block. This usually follows the namespace and it is common to have one sensor
per library. per library.
You should end up with something like this (disregard the "@verbatim" tags in You should end up with something like this:
your actual code):
``` ```
@verbatim @verbatim
@ -150,43 +111,8 @@ your actual code):
@endverbatim @endverbatim
``` ```
Use `<lib-name>` to name the library. In "@defgroup" use the same `<lib-name>` used in the sensor block. Multiple
sensors can be added to the same library this way.
For "@ingroup" add the same values as in the sensor block for manufacturer, For "@ingroup" add the same values as in the sensor block for manufacturer,
category, connection type and kit. If you have multiple classes or sensors category, connection type and kit. If you have multiple classes or sensors
per library, only use the "@ingroup" tags that are common for all of them. per library, only use the "@ingroup" tags that are common for all of them.
Existing groups that can be used for the manufacturer, connection, category and
kit tags are found in the *src/groups.md* file.
#### The sensor doxygen block
This is added just before the class declaration in your header(.hpp) file and has
one mandatory field. For single sensor libraries, this block will actually follow
immediately after the library block. If you have multiple sensor classes, add
this to every one.
Here's an example:
```
@verbatim
/**
* @library <lib-name>
* @brief Short class/sensor description
*
* Then add a longer
* description here.
*/
@endverbatim
```
When adding to an existing library, `<lib-name>` needs to match that library's
"@defgroup".
For more examples take a look at the existing headers in our github repository.
Also, make sure to check our [sensortemplate](contributions.md#creating-a-new-sensor-library-using-the-sensortemplate)
as it can facilitate new sensor additions.
Existing header files might have additional fields under the sensor block. These
have been used in the past to generate sensor pages outside of doxygen, but they
are now deprecated and not required for new additions.

BIN
docs/icons/allides.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

BIN
docs/icons/wyliodrin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
docs/icons/xdk.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -0,0 +1,361 @@
Creative Commons Legal Code
Attribution-NonCommercial-ShareAlike 3.0 Unported
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR
DAMAGES RESULTING FROM ITS USE.
License
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE
TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY
BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS
CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
CONDITIONS.
1. Definitions
a. "Adaptation" means a work based upon the Work, or upon the Work and
other pre-existing works, such as a translation, adaptation,
derivative work, arrangement of music or other alterations of a
literary or artistic work, or phonogram or performance and includes
cinematographic adaptations or any other form in which the Work may be
recast, transformed, or adapted including in any form recognizably
derived from the original, except that a work that constitutes a
Collection will not be considered an Adaptation for the purpose of
this License. For the avoidance of doubt, where the Work is a musical
work, performance or phonogram, the synchronization of the Work in
timed-relation with a moving image ("synching") will be considered an
Adaptation for the purpose of this License.
b. "Collection" means a collection of literary or artistic works, such as
encyclopedias and anthologies, or performances, phonograms or
broadcasts, or other works or subject matter other than works listed
in Section 1(g) below, which, by reason of the selection and
arrangement of their contents, constitute intellectual creations, in
which the Work is included in its entirety in unmodified form along
with one or more other contributions, each constituting separate and
independent works in themselves, which together are assembled into a
collective whole. A work that constitutes a Collection will not be
considered an Adaptation (as defined above) for the purposes of this
License.
c. "Distribute" means to make available to the public the original and
copies of the Work or Adaptation, as appropriate, through sale or
other transfer of ownership.
d. "License Elements" means the following high-level license attributes
as selected by Licensor and indicated in the title of this License:
Attribution, Noncommercial, ShareAlike.
e. "Licensor" means the individual, individuals, entity or entities that
offer(s) the Work under the terms of this License.
f. "Original Author" means, in the case of a literary or artistic work,
the individual, individuals, entity or entities who created the Work
or if no individual or entity can be identified, the publisher; and in
addition (i) in the case of a performance the actors, singers,
musicians, dancers, and other persons who act, sing, deliver, declaim,
play in, interpret or otherwise perform literary or artistic works or
expressions of folklore; (ii) in the case of a phonogram the producer
being the person or legal entity who first fixes the sounds of a
performance or other sounds; and, (iii) in the case of broadcasts, the
organization that transmits the broadcast.
g. "Work" means the literary and/or artistic work offered under the terms
of this License including without limitation any production in the
literary, scientific and artistic domain, whatever may be the mode or
form of its expression including digital form, such as a book,
pamphlet and other writing; a lecture, address, sermon or other work
of the same nature; a dramatic or dramatico-musical work; a
choreographic work or entertainment in dumb show; a musical
composition with or without words; a cinematographic work to which are
assimilated works expressed by a process analogous to cinematography;
a work of drawing, painting, architecture, sculpture, engraving or
lithography; a photographic work to which are assimilated works
expressed by a process analogous to photography; a work of applied
art; an illustration, map, plan, sketch or three-dimensional work
relative to geography, topography, architecture or science; a
performance; a broadcast; a phonogram; a compilation of data to the
extent it is protected as a copyrightable work; or a work performed by
a variety or circus performer to the extent it is not otherwise
considered a literary or artistic work.
h. "You" means an individual or entity exercising rights under this
License who has not previously violated the terms of this License with
respect to the Work, or who has received express permission from the
Licensor to exercise rights under this License despite a previous
violation.
i. "Publicly Perform" means to perform public recitations of the Work and
to communicate to the public those public recitations, by any means or
process, including by wire or wireless means or public digital
performances; to make available to the public Works in such a way that
members of the public may access these Works from a place and at a
place individually chosen by them; to perform the Work to the public
by any means or process and the communication to the public of the
performances of the Work, including by public digital performance; to
broadcast and rebroadcast the Work by any means including signs,
sounds or images.
j. "Reproduce" means to make copies of the Work by any means including
without limitation by sound or visual recordings and the right of
fixation and reproducing fixations of the Work, including storage of a
protected performance or phonogram in digital form or other electronic
medium.
2. Fair Dealing Rights. Nothing in this License is intended to reduce,
limit, or restrict any uses free from copyright or rights arising from
limitations or exceptions that are provided for in connection with the
copyright protection under copyright law or other applicable laws.
3. License Grant. Subject to the terms and conditions of this License,
Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
perpetual (for the duration of the applicable copyright) license to
exercise the rights in the Work as stated below:
a. to Reproduce the Work, to incorporate the Work into one or more
Collections, and to Reproduce the Work as incorporated in the
Collections;
b. to create and Reproduce Adaptations provided that any such Adaptation,
including any translation in any medium, takes reasonable steps to
clearly label, demarcate or otherwise identify that changes were made
to the original Work. For example, a translation could be marked "The
original work was translated from English to Spanish," or a
modification could indicate "The original work has been modified.";
c. to Distribute and Publicly Perform the Work including as incorporated
in Collections; and,
d. to Distribute and Publicly Perform Adaptations.
The above rights may be exercised in all media and formats whether now
known or hereafter devised. The above rights include the right to make
such modifications as are technically necessary to exercise the rights in
other media and formats. Subject to Section 8(f), all rights not expressly
granted by Licensor are hereby reserved, including but not limited to the
rights described in Section 4(e).
4. Restrictions. The license granted in Section 3 above is expressly made
subject to and limited by the following restrictions:
a. You may Distribute or Publicly Perform the Work only under the terms
of this License. You must include a copy of, or the Uniform Resource
Identifier (URI) for, this License with every copy of the Work You
Distribute or Publicly Perform. You may not offer or impose any terms
on the Work that restrict the terms of this License or the ability of
the recipient of the Work to exercise the rights granted to that
recipient under the terms of the License. You may not sublicense the
Work. You must keep intact all notices that refer to this License and
to the disclaimer of warranties with every copy of the Work You
Distribute or Publicly Perform. When You Distribute or Publicly
Perform the Work, You may not impose any effective technological
measures on the Work that restrict the ability of a recipient of the
Work from You to exercise the rights granted to that recipient under
the terms of the License. This Section 4(a) applies to the Work as
incorporated in a Collection, but this does not require the Collection
apart from the Work itself to be made subject to the terms of this
License. If You create a Collection, upon notice from any Licensor You
must, to the extent practicable, remove from the Collection any credit
as required by Section 4(d), as requested. If You create an
Adaptation, upon notice from any Licensor You must, to the extent
practicable, remove from the Adaptation any credit as required by
Section 4(d), as requested.
b. You may Distribute or Publicly Perform an Adaptation only under: (i)
the terms of this License; (ii) a later version of this License with
the same License Elements as this License; (iii) a Creative Commons
jurisdiction license (either this or a later license version) that
contains the same License Elements as this License (e.g.,
Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License").
You must include a copy of, or the URI, for Applicable License with
every copy of each Adaptation You Distribute or Publicly Perform. You
may not offer or impose any terms on the Adaptation that restrict the
terms of the Applicable License or the ability of the recipient of the
Adaptation to exercise the rights granted to that recipient under the
terms of the Applicable License. You must keep intact all notices that
refer to the Applicable License and to the disclaimer of warranties
with every copy of the Work as included in the Adaptation You
Distribute or Publicly Perform. When You Distribute or Publicly
Perform the Adaptation, You may not impose any effective technological
measures on the Adaptation that restrict the ability of a recipient of
the Adaptation from You to exercise the rights granted to that
recipient under the terms of the Applicable License. This Section 4(b)
applies to the Adaptation as incorporated in a Collection, but this
does not require the Collection apart from the Adaptation itself to be
made subject to the terms of the Applicable License.
c. You may not exercise any of the rights granted to You in Section 3
above in any manner that is primarily intended for or directed toward
commercial advantage or private monetary compensation. The exchange of
the Work for other copyrighted works by means of digital file-sharing
or otherwise shall not be considered to be intended for or directed
toward commercial advantage or private monetary compensation, provided
there is no payment of any monetary compensation in con-nection with
the exchange of copyrighted works.
d. If You Distribute, or Publicly Perform the Work or any Adaptations or
Collections, You must, unless a request has been made pursuant to
Section 4(a), keep intact all copyright notices for the Work and
provide, reasonable to the medium or means You are utilizing: (i) the
name of the Original Author (or pseudonym, if applicable) if supplied,
and/or if the Original Author and/or Licensor designate another party
or parties (e.g., a sponsor institute, publishing entity, journal) for
attribution ("Attribution Parties") in Licensor's copyright notice,
terms of service or by other reasonable means, the name of such party
or parties; (ii) the title of the Work if supplied; (iii) to the
extent reasonably practicable, the URI, if any, that Licensor
specifies to be associated with the Work, unless such URI does not
refer to the copyright notice or licensing information for the Work;
and, (iv) consistent with Section 3(b), in the case of an Adaptation,
a credit identifying the use of the Work in the Adaptation (e.g.,
"French translation of the Work by Original Author," or "Screenplay
based on original Work by Original Author"). The credit required by
this Section 4(d) may be implemented in any reasonable manner;
provided, however, that in the case of a Adaptation or Collection, at
a minimum such credit will appear, if a credit for all contributing
authors of the Adaptation or Collection appears, then as part of these
credits and in a manner at least as prominent as the credits for the
other contributing authors. For the avoidance of doubt, You may only
use the credit required by this Section for the purpose of attribution
in the manner set out above and, by exercising Your rights under this
License, You may not implicitly or explicitly assert or imply any
connection with, sponsorship or endorsement by the Original Author,
Licensor and/or Attribution Parties, as appropriate, of You or Your
use of the Work, without the separate, express prior written
permission of the Original Author, Licensor and/or Attribution
Parties.
e. For the avoidance of doubt:
i. Non-waivable Compulsory License Schemes. In those jurisdictions in
which the right to collect royalties through any statutory or
compulsory licensing scheme cannot be waived, the Licensor
reserves the exclusive right to collect such royalties for any
exercise by You of the rights granted under this License;
ii. Waivable Compulsory License Schemes. In those jurisdictions in
which the right to collect royalties through any statutory or
compulsory licensing scheme can be waived, the Licensor reserves
the exclusive right to collect such royalties for any exercise by
You of the rights granted under this License if Your exercise of
such rights is for a purpose or use which is otherwise than
noncommercial as permitted under Section 4(c) and otherwise waives
the right to collect royalties through any statutory or compulsory
licensing scheme; and,
iii. Voluntary License Schemes. The Licensor reserves the right to
collect royalties, whether individually or, in the event that the
Licensor is a member of a collecting society that administers
voluntary licensing schemes, via that society, from any exercise
by You of the rights granted under this License that is for a
purpose or use which is otherwise than noncommercial as permitted
under Section 4(c).
f. Except as otherwise agreed in writing by the Licensor or as may be
otherwise permitted by applicable law, if You Reproduce, Distribute or
Publicly Perform the Work either by itself or as part of any
Adaptations or Collections, You must not distort, mutilate, modify or
take other derogatory action in relation to the Work which would be
prejudicial to the Original Author's honor or reputation. Licensor
agrees that in those jurisdictions (e.g. Japan), in which any exercise
of the right granted in Section 3(b) of this License (the right to
make Adaptations) would be deemed to be a distortion, mutilation,
modification or other derogatory action prejudicial to the Original
Author's honor and reputation, the Licensor will waive or not assert,
as appropriate, this Section, to the fullest extent permitted by the
applicable national law, to enable You to reasonably exercise Your
right under Section 3(b) of this License (right to make Adaptations)
but not otherwise.
5. Representations, Warranties and Disclaimer
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE
FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS
AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE
WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT
LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT
DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU.
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE
LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR
ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES
ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
7. Termination
a. This License and the rights granted hereunder will terminate
automatically upon any breach by You of the terms of this License.
Individuals or entities who have received Adaptations or Collections
from You under this License, however, will not have their licenses
terminated provided such individuals or entities remain in full
compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will
survive any termination of this License.
b. Subject to the above terms and conditions, the license granted here is
perpetual (for the duration of the applicable copyright in the Work).
Notwithstanding the above, Licensor reserves the right to release the
Work under different license terms or to stop distributing the Work at
any time; provided, however that any such election will not serve to
withdraw this License (or any other license that has been, or is
required to be, granted under the terms of this License), and this
License will continue in full force and effect unless terminated as
stated above.
8. Miscellaneous
a. Each time You Distribute or Publicly Perform the Work or a Collection,
the Licensor offers to the recipient a license to the Work on the same
terms and conditions as the license granted to You under this License.
b. Each time You Distribute or Publicly Perform an Adaptation, Licensor
offers to the recipient a license to the original Work on the same
terms and conditions as the license granted to You under this License.
c. If any provision of this License is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this License, and without further action
by the parties to this agreement, such provision shall be reformed to
the minimum extent necessary to make such provision valid and
enforceable.
d. No term or provision of this License shall be deemed waived and no
breach consented to unless such waiver or consent shall be in writing
and signed by the party to be charged with such waiver or consent.
e. This License constitutes the entire agreement between the parties with
respect to the Work licensed here. There are no understandings,
agreements or representations with respect to the Work not specified
here. Licensor shall not be bound by any additional provisions that
may appear in any communication from You. This License may not be
modified without the mutual written agreement of the Licensor and You.
f. The rights granted under, and the subject matter referenced, in this
License were drafted utilizing the terminology of the Berne Convention
for the Protection of Literary and Artistic Works (as amended on
September 28, 1979), the Rome Convention of 1961, the WIPO Copyright
Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996
and the Universal Copyright Convention (as revised on July 24, 1971).
These rights and subject matter take effect in the relevant
jurisdiction in which the License terms are sought to be enforced
according to the corresponding provisions of the implementation of
those treaty provisions in the applicable national law. If the
standard suite of rights granted under applicable copyright law
includes additional rights not granted under this License, such
additional rights are deemed to be included in the License; this
License is not intended to restrict the license of any rights under
applicable law.
Creative Commons Notice
Creative Commons is not a party to this License, and makes no warranty
whatsoever in connection with the Work. Creative Commons will not be
liable to You or any party on any legal theory for any damages
whatsoever, including without limitation any general, special,
incidental or consequential damages arising in connection to this
license. Notwithstanding the foregoing two (2) sentences, if Creative
Commons has expressly identified itself as the Licensor hereunder, it
shall have all rights and obligations of Licensor.
Except for the limited purpose of indicating to the public that the
Work is licensed under the CCPL, Creative Commons does not authorize
the use by either party of the trademark "Creative Commons" or any
related trademark or logo of Creative Commons without the prior
written consent of Creative Commons. Any permitted use will be in
compliance with Creative Commons' then-current trademark usage
guidelines, as may be published on its website or otherwise made
available upon request from time to time. For the avoidance of doubt,
this trademark restriction does not form part of this License.
Creative Commons may be contacted at https://creativecommons.org/.

BIN
docs/images/grovebutton.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
docs/images/groveehr.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

BIN
docs/images/grovegprs.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

BIN
docs/images/groveled.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

BIN
docs/images/grovelight.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
docs/images/grovemd.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
docs/images/groveo2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
docs/images/groverelay.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
docs/images/grovergblcd.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
docs/images/groverotary.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
docs/images/grovescam.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

BIN
docs/images/grovetemp.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
docs/images/grovevdiv.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

BIN
docs/images/grovewfs.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

View File

@ -48,23 +48,11 @@ To install:
```bash ```bash
sudo add-apt-repository ppa:mraa/mraa sudo add-apt-repository ppa:mraa/mraa
sudo apt-get update sudo apt-get update
sudo apt-get install libupm-dev libupm-java python-upm python3-upm node-upm upm-examples sudo apt-get install libupm-dev python-upm python3-upm upm-examples
``` ```
Running UPM applications on Ubuntu systems requires elevated permissions Note that the Ubuntu PPA only provides the C/C++ and Python packages. Node.js
(e.g. run with `sudo`). developers will have to install MRAA and UPM using NPM instead.
### Fedora Linux
MRAA and UPM are available through the default package repositories on Fedora and can be
installed in the standard method using dnf.
To install:
```bash
sudo dnf install upm
sudo dnf install paython3-upm nodejs-upm upm-examples
```
### Node.js bindings only (NPM) ### Node.js bindings only (NPM)

View File

@ -14,7 +14,8 @@ First thing to do is to create a tree structure like this in upm/src/max31855:
* max31855.cxx * max31855.cxx
* max31855.hpp * max31855.hpp
* max31855.i * jsupm_max31855.i
* pyupm_max31855.i
* CMakeLists.txt * CMakeLists.txt
And then an example file to use & test our lib with in upm/examples/max31855.cxx. And then an example file to use & test our lib with in upm/examples/max31855.cxx.

View File

@ -702,7 +702,7 @@ CITE_BIB_FILES =
# messages are off. # messages are off.
# The default value is: NO. # The default value is: NO.
QUIET = YES QUIET = NO
# The WARNINGS tag can be used to turn on/off the warning messages that are # The WARNINGS tag can be used to turn on/off the warning messages that are
# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES # generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES
@ -860,8 +860,7 @@ EXCLUDE_SYMLINKS = NO
# bmi160 driver contains code provided by bosch. This source contains # bmi160 driver contains code provided by bosch. This source contains
# tags which are picked up by doxygen (namely \mainpage) and # tags which are picked up by doxygen (namely \mainpage) and
# incorrectly get added to docs. # incorrectly get added to docs.
EXCLUDE_PATTERNS = bosch_* \ EXCLUDE_PATTERNS = bosch_*
sensortemplate*
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the # (namespaces, classes, functions, etc.) that should be excluded from the

View File

@ -702,7 +702,7 @@ CITE_BIB_FILES =
# messages are off. # messages are off.
# The default value is: NO. # The default value is: NO.
QUIET = YES QUIET = NO
# The WARNINGS tag can be used to turn on/off the warning messages that are # The WARNINGS tag can be used to turn on/off the warning messages that are
# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES # generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES

View File

@ -34,6 +34,13 @@ var lib = require('jsupm_<module-name>');
### Supported Sensors ### Supported Sensors
The full list is available on [Intel® IoT Developer Zone](https://software.intel.com/en-us/iot/hardware/sensors). The full list is available on [Intel® IoT Developer Zone](https://software.intel.com/en-us/iot/hardware/sensors).
### IDE Integration
Intel® XDK IoT Edition is the recommended IDE for Node.js development. Visit
the Intel® Developer Zone [IDE page](https://software.intel.com/iot/software/ide)
for more information on how to get started.
![Intel XDK](http://iotdk.intel.com/docs/master/upm/docs/icons/xdk.png)
### Building UPM ### Building UPM
See building documentation [here](https://github.com/intel-iot-devkit/upm/blob/master/docs/building.md). See building documentation [here](https://github.com/intel-iot-devkit/upm/blob/master/docs/building.md).

View File

@ -23,6 +23,15 @@ repository.
Individual sensor usage examples for Python are available `here <https://github.com/intel-iot-devkit/upm/tree/master/examples/python>`_. Individual sensor usage examples for Python are available `here <https://github.com/intel-iot-devkit/upm/tree/master/examples/python>`_.
``IDE Compatibility``
################
While there is no official IDE provided with our Python libraries, we do recommend the web-based IDE Wyliodrin. It can be used with multiple programming
languages, including Python. More information can be found on the Intel Developer Zone IDE page.
.. image:: ../docs/icons/wyliodrin.png
:target: https://software.intel.com/iot/software/ide
``Making your own UPM Module`` ``Making your own UPM Module``
############################## ##############################

View File

@ -36,6 +36,19 @@
href="https://github.com/intel-iot-devkit/upm/tree/master/examples/javascript">here</a>.</p> href="https://github.com/intel-iot-devkit/upm/tree/master/examples/javascript">here</a>.</p>
</div> </div>
<div class="section" id="ide">
<h3><tt class="docutils literal"><span class="pre">IDE Compatibility</span>
<span class="pre">UPM</span></tt><a class="headerlink"
href="#ide"
title="Permalink to this headline">*</a></h3>
<p>Intel&reg; XDK IoT Edition is the recommended IDE for Node.js development.
Visit the Intel&reg; Developer Zone IDE page for more information on how to get
started.<br>
<a href="https://software.intel.com/iot/software/ide"><img src="../docs/icons/xdk.png"/></a>
</p>
</div>
<div class="section" id="building-upm"> <div class="section" id="building-upm">
<h3><tt class="docutils literal"><span class="pre">Building</span> <h3><tt class="docutils literal"><span class="pre">Building</span>
<span class="pre">UPM</span></tt><a class="headerlink" <span class="pre">UPM</span></tt><a class="headerlink"

View File

@ -1,82 +1,79 @@
# Mapping examples across provided languages # Mapping examples across provided languages
a110x.cxx A110X_Example.java a110x.js a110x.py a110x.cxx A110XSample.java a110x.js a110x.py
a110x-intr.cxx A110X_intr_Example.java a110x-intr.js a110x-intr.py a110x-intr.cxx A110X_intrSample.java a110x-intr.js a110x-intr.py
adc121c021.cxx ADC121C021_Example.java adc121c021.js adc121c021.py adc121c021.cxx ADC121C021Sample.java adc121c021.js adc121c021.py
adxl345.cxx Adxl345_Example.java adxl345.js adxl345.py adxl345.cxx Adxl345Sample.java adxl345.js adxl345.py
bh1749.cxx BH1749_Example.java bh1749.js bh1749.py biss0001.cxx BISS0001Sample.java biss0001.js biss0001.py
bh1750.cxx BH1750_Example.java bh1750.js bh1750.py bmpx8x.cxx BMPX8XSample.java bmpx8x.js bmpx8x.py
bh1792.cxx BH1792_Example.java bh1792.js bh1792.py bno055.cxx BNO055_Example.java bno055.js bno055.py
biss0001.cxx BISS0001_Example.java biss0001.js biss0001.py button.cxx ButtonSample.java button.js button.py
bmpx8x.cxx BMPX8X_Example.java bmpx8x.js bmpx8x.py buzzer.cxx BuzzerSample.java buzzer.js buzzer.py
bno055.cxx BNO055_Example.java bno055.js bno055.py cjq4435.cxx CJQ4435Sample.java cjq4435.js cjq4435.py
button.cxx Button_Example.java button.js button.py ds1307.cxx DS1307Sample.java ds1307.js ds1307.py
buzzer.cxx Buzzer_Example.java buzzer.js buzzer.py enc03r.cxx ENC03RSample.java enc03r.js enc03r.py
cjq4435.cxx CJQ4435_Example.java cjq4435.js cjq4435.py servo-es08a.cxx ES08ASample.java es08a.js es08a.py
ds1307.cxx DS1307_Example.java ds1307.js ds1307.py groveehr.cxx GroveEHRSample.java groveehr.js groveehr.py
enc03r.cxx ENC03R_Example.java enc03r.js enc03r.py my9221-groveledbar.cxx GroveLEDBar.java groveledbar.js groveledbar.py
servo-es08a.cxx ES08A_Example.java es08a.js es08a.py grove-groveled.cxx GroveLEDSample.java groveled.js groveled.py
groveehr.cxx GroveEHR_Example.java groveehr.js groveehr.py grovelinefinder.cxx GroveLineFinderSample.java grovelinefinder.js grovelinefinder.py
my9221-groveledbar.cxx GroveLEDBar_Example.java groveledbar.js groveledbar.py grovemoisture.cxx GroveMoistureSample.java grovemoisture.js grovemoisture.py
grove-groveled.cxx GroveLED_Example.java groveled.js groveled.py grovescam.cxx GROVESCAMSample.java grovescam.js grovescam.py
grovelinefinder.cxx GroveLineFinder_Example.java grovelinefinder.js grovelinefinder.py grovewfs.cxx GroveWFSSample.java grovewfs.js grovewfs.py
grovemoisture.cxx GroveMoisture_Example.java grovemoisture.js grovemoisture.py guvas12d.cxx GUVAS12DSample.java guvas12d.js guvas12d.py
grovescam.cxx GROVESCAM_Example.java grovescam.js grovescam.py h3lis331dl.cxx H3LIS331DLSample.java h3lis331dl.js h3lis331dl.py
grovewfs.cxx GroveWFS_Example.java grovewfs.js grovewfs.py hcsr04.cxx HCSR04Sample.java hcsr04.js hcsr04.py
guvas12d.cxx GUVAS12D_Example.java guvas12d.js guvas12d.py hm11.cxx HM11Sample.java hm11.js hm11.py
h3lis331dl.cxx H3LIS331DL_Example.java h3lis331dl.js h3lis331dl.py hmc5883l.cxx Hmc5883lSample.java hmc5883l.js hmc5883l.py
hcsr04.cxx HCSR04_Example.java hcsr04.js hcsr04.py htu21d.cxx HTU21DSample.java htu21d.js htu21d.py
hm11.cxx HM11_Example.java hm11.js hm11.py ims.cxx IMS_Example.java ims.js ims.py
hmc5883l.cxx Hmc5883l_Example.java hmc5883l.js hmc5883l.py itg3200.cxx Itg3200Sample.java itg3200.js itg3200.py
htu21d.cxx HTU21D_Example.java htu21d.js htu21d.py jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java jhd1313m1-lcd.js jhd1313m1-lcd.py
ims.cxx IMS_Example.java ims.js ims.py joystick12.cxx Joystick12Sample.java joystick12.js joystick12.py
itg3200.cxx Itg3200_Example.java itg3200.js itg3200.py lcm1602-i2c.cxx Lcm1602_i2cSample.java lcm1602-i2c.js lcm1602-i2c.py
jhd1313m1-lcd.cxx Jhd1313m1_lcd_Example.java jhd1313m1-lcd.js jhd1313m1-lcd.py ldt0028.cxx LDT0028Sample.java ldt0028.js ldt0028.py
joystick12.cxx Joystick12_Example.java joystick12.js joystick12.py light.cxx LightSample.java light.js light.py
lcm1602-i2c.cxx Lcm1602_i2c_Example.java lcm1602-i2c.js lcm1602-i2c.py lol.cxx LoLSample.java lol.js lol.py
ldt0028.cxx LDT0028_Example.java ldt0028.js ldt0028.py lsm303dlh.cxx LSM303DLHSample.java lsm303dlh.js lsm303dlh.py
light.cxx Light_Example.java light.js light.py m24lr64e.cxx M24LR64ESample.java m24lr64e.js m24lr64e.py
lol.cxx LoL_Example.java lol.js lol.py max44000.cxx MAX44000Sample.java max44000.js max44000.py
lsm303dlh.cxx LSM303DLH_Example.java lsm303dlh.js lsm303dlh.py mic.cxx MicrophoneSample.java mic.js mic.py
m24lr64e.cxx M24LR64E_Example.java m24lr64e.js m24lr64e.py mma7455.cxx MMA7455Sample.java mma7455.js mma7455.py
max44000.cxx MAX44000_Example.java max44000.js max44000.py mma7660.cxx MMA7660Sample.java mma7660.js mma7660.py
mic.cxx Microphone_Example.java mic.js mic.py mpl3115a2.cxx MPL3115A2Sample.java mpl3115a2.js mpl3115a2.py
mma7455.cxx MMA7455_Example.java mma7455.js mma7455.py mpr121.cxx MPR121Sample.java mpr121.js mpr121.py
mma7660.cxx MMA7660_Example.java mma7660.js mma7660.py mpu9150.cxx MPU9150Sample.java mpu9150.js mpu9150.py
mpl3115a2.cxx MPL3115A2_Example.java mpl3115a2.js mpl3115a2.py gas-mq2.cxx MQ2Sample.java mq2.js mq2.py
mpr121.cxx MPR121_Example.java mpr121.js mpr121.py mq303a.cxx MQ303ASample.java mq303a.js mq303a.py
mpu9150.cxx MPU9150_Example.java mpu9150.js mpu9150.py gas-mq5.cxx MQ5Sample.java mq5.js mq5.py
gas-mq2.cxx MQ2_Example.java mq2.js mq2.py nrf24l01-receiver.cxx NRF24L01_receiverSample.java nrf24l01-receiver.js nrf24l01-receiver.py
mq303a.cxx MQ303A_Example.java mq303a.js mq303a.py nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java nrf24l01-transmitter.js nrf24l01-transmitter.py
gas-mq5.cxx MQ5_Example.java mq5.js mq5.py nunchuck.cxx NUNCHUCKSample.java nunchuck.js nunchuck.py
nrf24l01-receiver.cxx NRF24L01_receiver_Example.java nrf24l01-receiver.js nrf24l01-receiver.py otp538u.cxx OTP538USample.java otp538u.js otp538u.py
nrf24l01-transmitter.cxx NRF24L01_transmitter_Example.java nrf24l01-transmitter.js nrf24l01-transmitter.py ppd42ns.cxx PPD42NSSample.java ppd42ns.js ppd42ns.py
nunchuck.cxx NUNCHUCK_Example.java nunchuck.js nunchuck.py pulsensor.cxx PulsensorSample.java pulsensor.js pulsensor.py
otp538u.cxx OTP538U_Example.java otp538u.js otp538u.py relay.cxx RelaySample.java relay.js relay.py
ppd42ns.cxx PPD42NS_Example.java ppd42ns.js ppd42ns.py rfr359f.cxx RFR359FSample.java rfr359f.js rfr359f.py
pulsensor.cxx Pulsensor_Example.java pulsensor.js pulsensor.py rotary.cxx RotarySample.java rotary.js rotary.py
relay.cxx Relay_Example.java relay.js relay.py rotaryencoder.cxx RotaryEncoderSample.java rotaryencoder.js rotaryencoder.py
rfr359f.cxx RFR359F_Example.java rfr359f.js rfr359f.py rpr220.cxx RPR220Sample.java rpr220.js rpr220.py
rotary.cxx Rotary_Example.java rotary.js rotary.py rpr220-intr.cxx RPR220_intrSample.java rpr220-intr.js rpr220-intr.py
rotaryencoder.cxx RotaryEncoder_Example.java rotaryencoder.js rotaryencoder.py slide.cxx SlideSample.java slide.js slide.py
rpr220.cxx RPR220_Example.java rpr220.js rpr220.py speaker.cxx SpeakerSample.java speaker.js speaker.py
rpr220-intr.cxx RPR220_intr_Example.java rpr220-intr.js rpr220-intr.py i2clcd-ssd1308-oled.cxx SSD1308_oledSample.java ssd1308-oled.js ssd1308-oled.py
slide.cxx Slide_Example.java slide.js slide.py i2clcd-ssd1327-oled.cxx SSD1327_oledSample.java ssd1327-oled.js ssd1327-oled.py
speaker.cxx Speaker_Example.java speaker.js speaker.py st7735.cxx ST7735Sample.java st7735.js st7735.py
lcd-ssd1308-oled.cxx SSD1308_oled_Example.java ssd1308-oled.js ssd1308-oled.py stepmotor.cxx StepMotorSample.java stepmotor.js stepmotor.py
lcd-ssd1327-oled.cxx SSD1327_oled_Example.java ssd1327-oled.js ssd1327-oled.py tm1637.cxx TM1637Sample.java tm1637.js tm1637.py
st7735.cxx ST7735_Example.java st7735.js st7735.py gas-tp401.cxx TP401Sample.java tp401.js tp401.py
stepmotor.cxx StepMotor_Example.java stepmotor.js stepmotor.py tsl2561.cxx TSL2561Sample.java tsl2561.js tsl2561.py
tm1637.cxx TM1637_Example.java tm1637.js tm1637.py ttp223.cxx TTP223Sample.java ttp223.js ttp223.py
gas-tp401.cxx TP401_Example.java tp401.js tp401.py uln200xa.cxx ULN200XASample.java uln200xa.js uln200xa.py
tsl2561.cxx TSL2561_Example.java tsl2561.js tsl2561.py vdiv.cxx VDivSample.java vdiv.js vdiv.py
ttp223.cxx TTP223_Example.java ttp223.js ttp223.py water.cxx WaterSample.java water.js water.py
uln200xa.cxx ULN200XA_Example.java uln200xa.js uln200xa.py wt5001.cxx WT5001Sample.java wt5001.js wt5001.py
vdiv.cxx VDiv_Example.java vdiv.js vdiv.py yg1006.cxx YG1006Sample.java yg1006.js yg1006.py
water.cxx Water_Example.java water.js water.py sensortemplate.cxx SensorTemplateSample.java sensortemplate.js sensortemplate.py
wt5001.cxx WT5001_Example.java wt5001.js wt5001.py p9813.cxx P9813Sample.java p9813.js p9813.py
yg1006.cxx YG1006_Example.java yg1006.js yg1006.py
sensortemplate.cxx SensorTemplate_Example.java sensortemplate.js sensortemplate.py
p9813.cxx P9813_Example.java p9813.js p9813.py
tcs37727.cxx tcs37727.py tcs37727.cxx tcs37727.py
tmp006.cxx tmp006.py tmp006.cxx tmp006.py
mma8x5x.cxx mma8x5x.py mma8x5x.cxx mma8x5x.py

View File

@ -41,7 +41,7 @@
# a110x.c Requires libupmc-a110x # a110x.c Requires libupmc-a110x
# lcm1602-i2c.c Requires libupmc-lcm1602 # lcm1602-i2c.c Requires libupmc-lcm1602
# bmp280-bme280.c Requires libupmc-bmp280 # bmp280-bme280.c Requires libupmc-bmp280
# lcd-eboled.cxx Requires libupm-lcd # i2clcd-eboled.cxx Requires libupm-i2clcd
# #
# #
function (add_example example_src) function (add_example example_src)
@ -99,7 +99,7 @@ function (add_example example_src)
# Add each dependency to the library target # Add each dependency to the library target
foreach(_dep_target ${lib_target_names}) foreach(_dep_target ${lib_target_names})
target_link_libraries(${this_target_name} ${_dep_target} ${CMAKE_THREAD_LIBS_INIT} utilities-c) target_link_libraries(${this_target_name} ${_dep_target} ${CMAKE_THREAD_LIBS_INIT})
endforeach () endforeach ()
endfunction (add_example example_src) endfunction (add_example example_src)
@ -117,16 +117,4 @@ if(BUILDEXAMPLES)
if(BUILDSWIGJAVA) if(BUILDSWIGJAVA)
add_subdirectory (java) add_subdirectory (java)
endif() endif()
# Add all examples as an install component (if building examples)
install (DIRECTORY ${PROJECT_SOURCE_DIR}/examples
DESTINATION ${CMAKE_INSTALL_DATADIR}/upm
COMPONENT ${CMAKE_PROJECT_NAME}-examples
FILES_MATCHING
PATTERN "*.c"
PATTERN "*.cxx"
PATTERN "*.hpp"
PATTERN "*.java"
PATTERN "*.js"
PATTERN "*.py")
endif() endif()

View File

@ -1,539 +0,0 @@
/*
* Author: Hiroyuki Mino <omronsupportupm@omron.com>
* Copyright (c) 2019 Omron Electronic Components - Americas
*
* 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.
*/
/* standard headers */
#include <iostream>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
/* omron sensor headers */
#include "2jciebu01_ble.hpp"
using namespace std;
using namespace upm;
#define PREVIOUS_MENU_CHOICE 8
volatile sig_atomic_t flag = 1;
upm::OM2JCIEBU_BLE::om2jciebuData_t om2jciebuSensorData;
void
sig_handler(int signum)
{
if(signum == SIGABRT) {
std::cout << "Exiting..." << std::endl;
}
if(signum == SIGINT) {
flag = 0;
}
}
void getSensorData(OM2JCIEBU_BLE *p_om2jcieble)
{
if(p_om2jcieble == NULL) {
std::cout << "Null pointer received..." << std::endl;
return;
}
uint16_t parameterChoice = 0;
int displayDelay = 0;
uint16_t sensorParamData = 0;
uint32_t pressureData = 0;
bool seconds_validate = false;
p_om2jcieble->getDiscoveredServices(OM2JCIEBU_BLE::ALL_PARAM);
while(true) {
printf("************************************************************\r\n");
printf("Please select sensor attribute for display\r\n");
printf("0) All parameter\r\n");
printf("1) Temperature data\r\n");
printf("2) Relative humidity data\r\n");
printf("3) Ambient light data\r\n");
printf("4) Barometric pressure data\r\n");
printf("5) Sound noise data\r\n");
printf("6) eTVOC data\r\n");
printf("7) eCO2 data\r\n");
printf("8) Return to main menu\r\n");
printf("Note :: Press Ctrl+C for sensor attribute display menu\r\n");
printf("************************************************************\r\n");
while(!(std::cin >> parameterChoice)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
if(parameterChoice >= OM2JCIEBU_BLE::ALL_PARAM && parameterChoice <= OM2JCIEBU_BLE::ECO2) {
flag = 1;
printf("Please enter time interval (in Seconds), for display sensor data\r\n");
while(!seconds_validate) {
cin >> displayDelay;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (displayDelay >= 1 && displayDelay <= 10)) {
seconds_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an second between 1 to 10!" << endl;
}
}
while(flag) {
switch(parameterChoice) {
case OM2JCIEBU_BLE::ALL_PARAM:
if(p_om2jcieble->getSensorData(OM2JCIEBU_BLE::ALL_PARAM, &om2jciebuSensorData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Sensor Attribute Values ***************\r\n");
printf("Sequence Number :: %d \r\n", om2jciebuSensorData.sequence_number);
printf("Temperature :: %d degC\r\n", om2jciebuSensorData.temperature);
printf("Relative humidity :: %d RH\r\n", om2jciebuSensorData.relative_humidity);
printf("Ambient light :: %d lx\r\n", om2jciebuSensorData.ambient_light);
printf("Barometric pressure :: %d hPa\r\n", om2jciebuSensorData.pressure);
printf("Sound noise :: %d dB\r\n", om2jciebuSensorData.noise);
printf("eTVOC :: %d ppb\r\n", om2jciebuSensorData.eTVOC);
printf("eCO2 :: %d ppm\r\n", om2jciebuSensorData.eCO2);
printf("**********************************************************\r\n");
memset(&om2jciebuSensorData, 0, sizeof(om2jciebuSensorData));
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::TEMP:
if(p_om2jcieble->getSensorData(OM2JCIEBU_BLE::TEMP, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Temperature Attribute Values ***************\r\n");
printf("Temperature :: %d degC\r\n", sensorParamData);
printf("************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::HUMIDITY:
if(p_om2jcieble->getSensorData(OM2JCIEBU_BLE::HUMIDITY, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Relative humidity Attribute Values ***************\r\n");
printf("Relative humidity :: %d RH\r\n", sensorParamData);
printf("******************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::AMBIENT_LIGHT:
if(p_om2jcieble->getSensorData(OM2JCIEBU_BLE::AMBIENT_LIGHT, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Ambient light Attribute Values ***************\r\n");
printf("Ambient light :: %d lx\r\n", sensorParamData);
printf("***************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::PRESSURE:
if(p_om2jcieble->getSensorData(OM2JCIEBU_BLE::PRESSURE, &pressureData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Barometric pressure Attribute Values ***************\r\n");
printf("Barometric pressure :: %d hPa\r\n", pressureData);
printf("********************************************************************\r\n");
}
break;
case OM2JCIEBU_BLE::NOISE:
if(p_om2jcieble->getSensorData(OM2JCIEBU_BLE::NOISE, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Sound noise Attribute Values ***************\r\n");
printf("Sound noise :: %d dB\r\n", sensorParamData);
printf("*************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::ETVOC:
if(p_om2jcieble->getSensorData(OM2JCIEBU_BLE::ETVOC, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** eTVOC Attribute Values ***************\r\n");
printf("eTVOC :: %d ppb\r\n", sensorParamData);
printf("*******************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::ECO2:
if(p_om2jcieble->getSensorData(OM2JCIEBU_BLE::ECO2, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** eCO2 Attribute Values ***************\r\n");
printf("eCO2 :: %d ppm\r\n\r\n", sensorParamData);
printf("******************************************************\r\n");
} else {
flag = 0;
}
break;
}
printf("\r\n");
p_om2jcieble->delay(displayDelay);
}
} else if(parameterChoice == PREVIOUS_MENU_CHOICE) {
break;
} else {
printf("Invalid choice\r\n");
}
seconds_validate = false;
}
}
void getAdvSensorData(OM2JCIEBU_BLE *p_om2jcieble)
{
if(p_om2jcieble == NULL) {
std::cout << "Null pointer received..." << std::endl;
return;
}
uint16_t parameterChoice = 0, sensorParamData = 0;
int displayDelay = 0;
uint32_t pressureData = 0;
bool seconds_validate = false;
while(true) {
printf("************************************************************\r\n");
printf("Please select sensor attribute for display\r\n");
printf("0) All parameter\r\n");
printf("1) Temperature data\r\n");
printf("2) Relative humidity data\r\n");
printf("3) Ambient light data\r\n");
printf("4) Barometric pressure data\r\n");
printf("5) Sound noise data\r\n");
printf("6) eTVOC data\r\n");
printf("7) eCO2 data\r\n");
printf("8) Return to main menu\r\n");
printf("Note :: Press Ctrl+C for sensor attribute display menu\r\n");
printf("************************************************************\r\n");
while(!(std::cin >> parameterChoice)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
if(parameterChoice >= OM2JCIEBU_BLE::ALL_PARAM && parameterChoice <= OM2JCIEBU_BLE::ECO2) {
flag = 1;
printf("Please enter time interval (in Seconds), for display sensor data\r\n");
while(!seconds_validate) {
cin >> displayDelay;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (displayDelay >= 1 && displayDelay <= 10)) {
seconds_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an second between 1 and 10!" << endl;
}
}
while(flag) {
switch(parameterChoice) {
case OM2JCIEBU_BLE::ALL_PARAM:
if(p_om2jcieble->getAdvSensorData(OM2JCIEBU_BLE::ALL_PARAM, &om2jciebuSensorData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Advertisement Sensor Attribute Values ***************\r\n");
printf("Sequence Number :: %d \r\n", om2jciebuSensorData.sequence_number);
printf("Temperature :: %d degC\r\n", om2jciebuSensorData.temperature);
printf("Relative humidity :: %d RH\r\n", om2jciebuSensorData.relative_humidity);
printf("Ambient light :: %d lx\r\n", om2jciebuSensorData.ambient_light);
printf("Barometric pressure :: %d hPa\r\n", om2jciebuSensorData.pressure);
printf("Sound noise :: %d dB\r\n", om2jciebuSensorData.noise);
printf("eTVOC :: %d ppb\r\n", om2jciebuSensorData.eTVOC);
printf("eCO2 :: %d ppm\r\n", om2jciebuSensorData.eCO2);
printf("*********************************************************************\r\n");
memset(&om2jciebuSensorData, 0, sizeof(om2jciebuSensorData));
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::TEMP:
if(p_om2jcieble->getAdvSensorData(OM2JCIEBU_BLE::TEMP, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Advertisement Temperature Attribute Values ***************\r\n");
printf("Temperature :: %d degC\r\n", sensorParamData);
printf("**************************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::HUMIDITY:
if(p_om2jcieble->getAdvSensorData(OM2JCIEBU_BLE::HUMIDITY, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Advertisement Relative humidity Attribute Values ***************\r\n");
printf("Relative humidity :: %d RH\r\n", sensorParamData);
printf("********************************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::AMBIENT_LIGHT:
if(p_om2jcieble->getAdvSensorData(OM2JCIEBU_BLE::AMBIENT_LIGHT, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Advertisement Ambient light Attribute Values ***************\r\n");
printf("Ambient light :: %d lx\r\n", sensorParamData);
printf("***************************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::PRESSURE:
if(p_om2jcieble->getAdvSensorData(OM2JCIEBU_BLE::PRESSURE, &pressureData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Advertisement Barometric pressure Attribute Values ***************\r\n");
printf("Barometric pressure :: %d hPa\r\n", pressureData);
printf("*********************************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::NOISE:
if(p_om2jcieble->getAdvSensorData(OM2JCIEBU_BLE::NOISE, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Advertisement Sound noise Attribute Values ***************\r\n");
printf("Sound noise :: %d dB\r\n", sensorParamData);
printf("*************************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::ETVOC:
if(p_om2jcieble->getAdvSensorData(OM2JCIEBU_BLE::ETVOC, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("**************** Advertisement eTVOC Attribute Values ******************\r\n");
printf("eTVOC :: %d ppb\r\n", sensorParamData);
printf("************************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_BLE::ECO2:
if(p_om2jcieble->getAdvSensorData(OM2JCIEBU_BLE::ECO2, &sensorParamData) == OM2JCIEBU_BLE::SUCCESS) {
printf("************** Advertisement eCO2 Attribute Values ***************\r\n");
printf("eCO2 :: %d ppm\r\n\r\n", sensorParamData);
printf("******************************************************************\r\n");
} else {
flag = 0;
}
break;
}
printf("\r\n");
p_om2jcieble->delay(displayDelay);
}
} else if(parameterChoice == PREVIOUS_MENU_CHOICE) {
break;
} else {
printf("Invalid choice\r\n");
}
seconds_validate = false;
}
}
void configureLEDSetting(OM2JCIEBU_BLE *p_om2jcieble)
{
if(p_om2jcieble == NULL) {
std::cout << "Null pointer received..." << std::endl;
return;
}
int led_choice = 0;
unsigned short int red_scale = 0, green_scale = 0, blue_scale = 0;
bool red_scale_validate = false, green_scale_validate = false, blue_scale_validate = false;
printf("************** Sensor LED Configuration ***************\r\n");
printf("Please select a operation for LED\r\n");
printf("0) Normally OFF\r\n");
printf("1) Normally ON\r\n");
printf("2) Temperature value scales\r\n");
printf("3) Relative humidity value scales\r\n");
printf("4) Ambient light value scales\r\n");
printf("5) Barometric pressure value scales\r\n");
printf("6) Sound noise value scales\r\n");
printf("7) eTVOC value scales\r\n");
printf("8) SI vale scales\r\n");
printf("9) PGA value scales\r\n");
printf("**********************************************************\r\n");
while(!(std::cin >> led_choice)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
if(led_choice == OM2JCIEBU_BLE::NORMALLY_ON) {
printf("Please select a LED color scale\r\n");
printf("Please enter Red Color scale (scale range 0 to 255)\r\n");
while(!red_scale_validate) {
cin >> red_scale;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (red_scale >= 0 && red_scale <= 255)) {
red_scale_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an red color scale between 0 and 255!" << endl;
}
}
printf("Please enter Green Color scale(scale range 0 to 255)\r\n");
while(!green_scale_validate) {
cin >> green_scale;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (green_scale >= 0 && green_scale <= 255)) {
green_scale_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an green color scale between 0 and 255!" << endl;
}
}
printf("Please enter Blue Color scale(scale range 0 to 255)\r\n");
while(!blue_scale_validate) {
cin >> blue_scale;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (blue_scale >= 0 && blue_scale <= 255)) {
blue_scale_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an blue color scale between 0 and 255!" << endl;
}
}
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::NORMALLY_ON, red_scale, green_scale, blue_scale);
} else {
switch(led_choice) {
case OM2JCIEBU_BLE::NORMALLY_OFF:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::NORMALLY_OFF, 0, 0, 0);
break;
case OM2JCIEBU_BLE::TEMP_SACLE:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::TEMP_SACLE, 0, 0, 0);
break;
case OM2JCIEBU_BLE::HUMIDITY_SCALE:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::HUMIDITY_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_BLE::AMBIENT_LIGHT_SCALE:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::AMBIENT_LIGHT_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_BLE::PRESSURE_SCALE:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::PRESSURE_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_BLE::NOISE_SCALE:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::NOISE_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_BLE::ETVOC_SCALE:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::ETVOC_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_BLE::SI_SCALE:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::SI_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_BLE::PGA_SCALE:
p_om2jcieble->configureSensorLedState(OM2JCIEBU_BLE::PGA_SCALE, 0, 0, 0);
break;
default:
std::cout << "Wrong LED scale choice please try again" << std::endl;
}
}
}
void configureAdvInterval(OM2JCIEBU_BLE *p_om2jcieble)
{
if(p_om2jcieble == NULL) {
std::cout << "Null pointer received..." << std::endl;
return;
}
uint16_t millisecond = 0;
bool milisecond_validate = false;
int advertising_mode = 0;
printf("************** Sensor Advertise Configuration ***************\r\n");
printf("Please enter time interval (in Milliseconds), for changing Advertise interval, between 100 to 10240 milliseconds\r\n");
while(!milisecond_validate) {
cin >> millisecond;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (millisecond >= 100 && millisecond <= 10240)) {
milisecond_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an millisecond between 100 and 10240!" << endl;
}
}
printf("Please select an Advertise mode with the selected Advertise interval \r\n");
printf("1) Sensor data\r\n");
printf("2) Calculation data\r\n");
printf("3) Sensor data and Calculation data\r\n");
printf("4) Sensor flag and Calculation flag\r\n");
printf("5) Serial number\r\n");
while(!(std::cin >> advertising_mode)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
switch(advertising_mode) {
case OM2JCIEBU_BLE::SENSOR_DATA:
p_om2jcieble->configureSensorAdvSetting(millisecond, OM2JCIEBU_BLE::SENSOR_DATA);
break;
case OM2JCIEBU_BLE::ACCELERATION_DATA:
p_om2jcieble->configureSensorAdvSetting(millisecond, OM2JCIEBU_BLE::ACCELERATION_DATA);
break;
case OM2JCIEBU_BLE::ACCELERATION_SENSOR_DATA:
p_om2jcieble->configureSensorAdvSetting(millisecond, OM2JCIEBU_BLE::ACCELERATION_SENSOR_DATA);
break;
case OM2JCIEBU_BLE::ACCELERATION_SENSOR_FLAG:
p_om2jcieble->configureSensorAdvSetting(millisecond, OM2JCIEBU_BLE::ACCELERATION_SENSOR_FLAG);
break;
case OM2JCIEBU_BLE::SERIAL_NUMBER:
p_om2jcieble->configureSensorAdvSetting(millisecond, OM2JCIEBU_BLE::SERIAL_NUMBER);
break;
default:
std::cout << "Invalid choice\n";
}
printf("**************************************************************\r\n");
}
int
main(int argc, char *argv[])
{
int operation_choice = 0;
if(argc <= 1) {
std::cout << "usage ./a.out xx:xx:xx:xx:xx:xx" << std::endl;
return 0;
}
signal(SIGABRT, sig_handler);
signal(SIGINT, sig_handler);
upm::OM2JCIEBU_BLE om2jciebu_ble(argv[1]);
while(true) {
std::cout << "*************************************************************" << std::endl;
std::cout << "Please choose one option for Omron sensor operation" << std::endl;
std::cout << "1) Display Advertisement Sensor attriutes" << std::endl;
std::cout << "2) Display Sensor attriutes" << std::endl;
std::cout << "3) Configure LED setting " << std::endl;
std::cout << "4) Configure advertise setting" << std::endl;
std::cout << "5) Exit" << std::endl;
std::cout << "*************************************************************" << std::endl;
while(!(std::cin >> operation_choice)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
switch(operation_choice) {
case 1:
getAdvSensorData(&om2jciebu_ble);
break;
case 2:
getSensorData(&om2jciebu_ble);
break;
case 3:
configureLEDSetting(&om2jciebu_ble);
break;
case 4:
configureAdvInterval(&om2jciebu_ble);
break;
case 5:
std::cout << "Application Exited" << std::endl;
om2jciebu_ble.removeBleDevice();
exit(0);
break;
default:
std::cout << "Invalid choice" << std::endl;
break;
}
}
}

View File

@ -1,414 +0,0 @@
/*
* Author: Hiroyuki Mino <omronsupportupm@omron.com>
* Copyright (c) 2019 Omron Electronic Components - Americas
*
* 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.
*/
/* standard headers */
#include <iostream>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
/* omron sensor headers */
#include "2jciebu01_usb.hpp"
using namespace std;
using namespace upm;
volatile sig_atomic_t flag = 1;
#define PREVIOUS_MENU_CHOICE 10
upm::OM2JCIEBU_UART::om2jciebuData_t om2jciebuSensorData;
void
sig_handler(int signum)
{
if(signum == SIGABRT) { //check for Abort signal
std::cout << "Exiting..." << std::endl;
}
if(signum == SIGINT) { //check for Interrupt signal
std::cout << "Exiting..." << std::endl;
flag = 0;
}
}
void getSensorData(OM2JCIEBU_UART *p_om2jcieuart)
{
if(p_om2jcieuart == NULL) {
std::cout << "Null pointer received..." << std::endl;
return;
}
uint16_t parameterChoice = 0;
int displayDelay = 0;
bool seconds_validate = false;
uint16_t sensorParamData = 0;
uint32_t pressureData = 0;
while(true) {
printf("************************************************************\r\n");
printf("Please select sensor attribute for display\r\n");
printf("0) All parameter\r\n");
printf("1) Temperature data\r\n");
printf("2) Relative humidity data\r\n");
printf("3) Ambient light data\r\n");
printf("4) Barometric pressure data\r\n");
printf("5) Sound noise data\r\n");
printf("6) eTVOC data\r\n");
printf("7) eCO2 data\r\n");
printf("8) Discomfort index data\r\n");
printf("9) Heat stroke data\r\n");
printf("10) Return to main menu\r\n");
printf("Note :: Press Ctrl+C for sensor attribute display menu\r\n");
printf("************************************************************\r\n");
while(!(std::cin >> parameterChoice)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
if(parameterChoice >= OM2JCIEBU_UART::ALL_PARAM && parameterChoice <= OM2JCIEBU_UART::HEAT_STROKE) {
flag = 1;
printf("Please enter time interval (in Seconds), for display sensor data\r\n");
while(!seconds_validate) { //validate user input values
cin >> displayDelay;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (displayDelay >= 1 && displayDelay <= 10)) {
seconds_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an second between 1 to 10!" << endl;
}
}
while(flag) {
switch(parameterChoice) {
case OM2JCIEBU_UART::ALL_PARAM:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::ALL_PARAM, &om2jciebuSensorData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** Sensor Attribute Values ***************\r\n");
printf("Sequence Number :: %d \r\n", om2jciebuSensorData.sequence_number);
printf("Temperature :: %d degC\r\n", om2jciebuSensorData.temperature);
printf("Relative humidity :: %d RH\r\n", om2jciebuSensorData.relative_humidity);
printf("Ambient light :: %d lx\r\n", om2jciebuSensorData.ambient_light);
printf("Barometric pressure :: %d hPa\r\n", om2jciebuSensorData.pressure);
printf("Sound noise :: %d dB\r\n", om2jciebuSensorData.noise);
printf("eTVOC :: %d ppb\r\n", om2jciebuSensorData.eTVOC);
printf("eCO2 :: %d ppm\r\n", om2jciebuSensorData.eCO2);
printf("Discomfort index :: %d \r\n", om2jciebuSensorData.discomfort_index);
printf("Heat stroke :: %d degC\r\n", om2jciebuSensorData.heat_stroke);
printf("**********************************************************\r\n");
memset(&om2jciebuSensorData, 0, sizeof(om2jciebuSensorData));
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::TEMP:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::TEMP, &sensorParamData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** Temperature Attribute Values ***************\r\n");
printf("Temperature :: %d degC\r\n", sensorParamData);
printf("************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::HUMIDITY:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::HUMIDITY, &sensorParamData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** Relative humidity Attribute Values ***************\r\n");
printf("Relative humidity :: %d RH\r\n", sensorParamData);
printf("******************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::AMBIENT_LIGHT:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::AMBIENT_LIGHT, &sensorParamData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** Ambient light Attribute Values ***************\r\n");
printf("Ambient light :: %d lx\r\n", sensorParamData);
printf("**************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::PRESSURE:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::PRESSURE, &pressureData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** Barometric pressure Attribute Values ***************\r\n");
printf("Barometric pressure :: %d hPa\r\n", pressureData);
printf("********************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::NOISE:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::NOISE, &sensorParamData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** Sound noise Attribute Values ***************\r\n");
printf("Sound noise :: %d dB\r\n", sensorParamData);
printf("************************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::ETVOC:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::ETVOC, &sensorParamData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** eTVOC Attribute Values ***************\r\n");
printf("eTVOC :: %d ppb\r\n", sensorParamData);
printf("******************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::ECO2:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::ECO2, &sensorParamData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** eCO2 Attribute Values ***************\r\n");
printf("eCO2 :: %d ppm\r\n\r\n", sensorParamData);
printf("******************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::DISCOMFORT_INDEX:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::DISCOMFORT_INDEX, &sensorParamData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** eCO2 Attribute Values ***************\r\n");
printf("Discomfort index :: %d \r\n\r\n", sensorParamData);
printf("******************************************************\r\n");
} else {
flag = 0;
}
break;
case OM2JCIEBU_UART::HEAT_STROKE:
if(p_om2jcieuart->getSensorData(OM2JCIEBU_UART::HEAT_STROKE, &sensorParamData) == OM2JCIEBU_UART::SUCCESS) {
printf("************** eCO2 Attribute Values ***************\r\n");
printf("Heat stroke :: %d degC\r\n\r\n", sensorParamData);
printf("******************************************************\r\n");
} else {
flag = 0;
}
break;
}
printf("\r\n");
p_om2jcieuart->delay(displayDelay);
}
} else if(parameterChoice == PREVIOUS_MENU_CHOICE) {
break;
} else {
printf("Invalid choice\r\n");
}
seconds_validate = false;
}
}
void configureLEDSetting(OM2JCIEBU_UART *p_om2jcieuart)
{
if(p_om2jcieuart == NULL) {
std::cout << "Null pointer received..." << std::endl;
return;
}
int led_choice = 0;
bool red_scale_validate = false, green_scale_validate = false, blue_scale_validate = false;
unsigned short int red_scale = 0, green_scale = 0, blue_scale = 0;
printf("************** Sensor LED Configuration ***************\r\n");
printf("Please select a operation for LED\r\n");
printf("0) Normally OFF\r\n");
printf("1) Normally ON\r\n");
printf("2) Temperature value scales\r\n");
printf("3) Relative humidity value scales\r\n");
printf("4) Ambient light value scales\r\n");
printf("5) Barometric pressure value scales\r\n");
printf("6) Sound noise value scales\r\n");
printf("7) eTVOC value scales\r\n");
printf("8) SI vale scales\r\n");
printf("9) PGA value scales\r\n");
printf("**********************************************************\r\n");
while(!(std::cin >> led_choice)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
if(led_choice == OM2JCIEBU_UART::NORMALLY_ON) {
printf("Please Select a LED color scale\r\n");
printf("Please enter Red Color scale (scale range 0 to 255)\r\n");
while(!red_scale_validate) {
cin >> red_scale;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (red_scale >= 0 && red_scale <= 255)) {
red_scale_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an red color scale between 0 and 255!" << endl;
}
}
printf("Please enter Green Color scale(scale range 0 to 255)\r\n");
while(!green_scale_validate) {
cin >> green_scale;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (green_scale >= 0 && green_scale <= 255)) {
green_scale_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an green color scale between 0 and 255!" << endl;
}
}
printf("Please enter Blue Color scale(scale range 0 to 255)\r\n");
while(!blue_scale_validate) {
cin >> blue_scale;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (blue_scale >= 0 && blue_scale <= 255)) {
blue_scale_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an blue color scale between 0 and 255!" << endl;
}
}
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::NORMALLY_ON, red_scale, green_scale, blue_scale);
} else {
switch(led_choice) {
case OM2JCIEBU_UART::NORMALLY_OFF:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::NORMALLY_OFF, 0, 0, 0);
break;
case OM2JCIEBU_UART::TEMP_SACLE:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::TEMP_SACLE, 0, 0, 0);
break;
case OM2JCIEBU_UART::HUMIDITY_SCALE:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::HUMIDITY_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_UART::AMBIENT_LIGHT_SCALE:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::AMBIENT_LIGHT_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_UART::PRESSURE_SCALE:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::PRESSURE_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_UART::NOISE_SCALE:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::NOISE_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_UART::ETVOC_SCALE:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::ETVOC_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_UART::SI_SCALE:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::SI_SCALE, 0, 0, 0);
break;
case OM2JCIEBU_UART::PGA_SCALE:
p_om2jcieuart->configureSensorLedState(OM2JCIEBU_UART::PGA_SCALE, 0, 0, 0);
break;
default:
std::cout << "Wrong LED scale choice please try again" << std::endl;
}
}
}
void configureAdvInterval(OM2JCIEBU_UART *p_om2jcieuart)
{
if(p_om2jcieuart == NULL) {
std::cout << "Null pointer received..." << std::endl;
return;
}
bool millisecond_validate = false;
uint16_t millisecond = 0;
int advertising_mode = 0;
printf("************** Sensor Advertise Configuration ***************\r\n");
printf("Please enter time interval (in Milliseconds), for changing Advertise interval, between 100 to 10240 milliseconds\r\n");
while(!millisecond_validate) {//validate millisecond
cin >> millisecond;
if(!cin.fail() && (cin.peek() == EOF || cin.peek() == '\n') && (millisecond >= 100 && millisecond <= 10240)) {
millisecond_validate = true;
} else {
cin.clear();
cin.ignore();
cout << "Error, enter an milisecond between 100 and 10240!" << endl;
}
}
printf("Please select an Advertise mode with the selected Advertise interval \r\n");
printf("1) Sensor data\r\n");
printf("2) Calculation data\r\n");
printf("3) Sensor data and Calculation data\r\n");
printf("4) Sensor flag and Calculation flag\r\n");
printf("5) Serial number\r\n");
while(!(std::cin >> advertising_mode)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
switch(advertising_mode) {
case OM2JCIEBU_UART::SENSOR_DATA:
p_om2jcieuart->configureSensorAdvSetting(millisecond, OM2JCIEBU_UART::SENSOR_DATA);
break;
case OM2JCIEBU_UART::ACCELERATION_DATA:
p_om2jcieuart->configureSensorAdvSetting(millisecond, OM2JCIEBU_UART::ACCELERATION_DATA);
break;
case OM2JCIEBU_UART::ACCELERATION_SENSOR_DATA:
p_om2jcieuart->configureSensorAdvSetting(millisecond, OM2JCIEBU_UART::ACCELERATION_SENSOR_DATA);
break;
case OM2JCIEBU_UART::ACCELERATION_SENSOR_FLAG:
p_om2jcieuart->configureSensorAdvSetting(millisecond, OM2JCIEBU_UART::ACCELERATION_SENSOR_FLAG);
break;
case OM2JCIEBU_UART::SERIAL_NUMBER:
p_om2jcieuart->configureSensorAdvSetting(millisecond, OM2JCIEBU_UART::SERIAL_NUMBER);
break;
default:
std::cout << "Invalid choice\n";
}
printf("**************************************************************\r\n");
}
int
main(int argc, char *argv[])
{
int operation_choice = 0;
if(argc <= 1) {
std::cout << "usage ./a.out /dev/ttyUSB*" << std::endl;
return 0;
}
signal(SIGABRT, sig_handler);
signal(SIGINT, sig_handler);
upm::OM2JCIEBU_UART om2jciebu_uart(argv[1], 115200);
om2jciebu_uart.setMode(8, mraa::UART_PARITY_NONE, 1);
om2jciebu_uart.setFlowControl(false, false);
while(true) {
std::cout << "*************************************************************" << std::endl;
std::cout << "Please choose one option for Omron sensor operation" << std::endl;
std::cout << "1) Display Sensor attriutes" << std::endl;
std::cout << "2) Configure LED setting " << std::endl;
std::cout << "3) Configure advertise setting" << std::endl;
std::cout << "4) Exit" << std::endl;
std::cout << "*************************************************************" << std::endl;
while(!(std::cin >> operation_choice)) { //validate operation choice from user input
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}
switch(operation_choice) {
case 1:
getSensorData(&om2jciebu_uart);
break;
case 2:
configureLEDSetting(&om2jciebu_uart);
break;
case 3:
configureAdvInterval(&om2jciebu_uart);
break;
case 4:
std::cout << "Application Exited" << std::endl;
exit(0);
break;
default:
std::cout << "Invalid choice" << std::endl;
}
}
}

View File

@ -3,10 +3,16 @@ file (GLOB example_src_list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cxx")
# - Handle special cases here -------------------------------------------------- # - Handle special cases here --------------------------------------------------
# Test temperature interface for 2 sensor libraries # Test humidity interface for 2 sensor libraries
add_example(iTemperature_sample.cxx TARGETS interfaces lm35 abp) add_example(interfaces-humiditysensor.cxx TARGETS si7005 bmp280)
# Test light interface for 3 sensor libraries # Test pressure interface for 2 sensor libraries
add_example(iLight_sample.cxx TARGETS interfaces apds9002 bh1750 max44009) add_example(interfaces-pressuresensor.cxx TARGETS bmp280 bmpx8x)
# Test temperature interface for 3 sensor libraries
add_example(interfaces-temperaturesensor.cxx TARGETS bmp280 bmpx8x si7005)
# Test light interface for 2 sensor libraries
add_example(interfaces-lightsensor.cxx TARGETS si1132 max44009)
# Test light controller interface for 3 sensor libraries
add_example(interfaces-lightcontroller.cxx TARGETS lp8860 ds1808lc hlg150h)
# - Create an executable for all other src files in this directory ------------- # - Create an executable for all other src files in this directory -------------
foreach (_example_src ${example_src_list}) foreach (_example_src ${example_src_list})

View File

@ -22,58 +22,55 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include <stddef.h>
#include "a110x.hpp" #include "a110x.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
// Our pulse counter // Our pulse counter
volatile unsigned int counter = 0; volatile unsigned int counter = 0;
// Our interrupt handler // Our interrupt handler
void void hallISR(void *arg)
hallISR(void* arg)
{ {
counter++; counter++;
} }
int int main ()
main()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an A110X sensor on digital pin D2 // Instantiate an A110X sensor on digital pin D2
upm::A110X hall(2); upm::A110X* hall = new upm::A110X(2);
// This example uses a user-supplied interrupt handler to count
// pulses that occur when a magnetic field of the correct polarity
// is detected. This could be used to measure the rotations per
// minute (RPM) of a rotor for example.
// This example uses a user-supplied interrupt handler to count hall->installISR(hallISR, NULL);
// pulses that occur when a magnetic field of the correct polarity
// is detected. This could be used to measure the rotations per
// minute (RPM) of a rotor for example.
hall.installISR(hallISR, NULL); while (shouldRun)
{
cout << "Pulses detected: " << counter << endl;
while (shouldRun) { sleep(1);
cout << "Pulses detected: " << counter << endl;
upm_delay(1);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete hall;
return 0;
} }

View File

@ -22,46 +22,46 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "a110x.hpp" #include "a110x.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main() int main ()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an A110X sensor on digital pin D2 // Instantiate an A110X sensor on digital pin D2
upm::A110X hall(2); upm::A110X* hall = new upm::A110X(2);
// check every second for the presence of a magnetic field (south
// polarity)
while (shouldRun)
{
bool val = hall->magnetDetected();
if (val)
cout << "Magnet (south polarity) detected." << endl;
else
cout << "No magnet detected." << endl;
// check every second for the presence of a magnetic field (south sleep(1);
// polarity)
while (shouldRun) {
bool val = hall.magnetDetected();
if (val)
cout << "Magnet (south polarity) detected." << endl;
else
cout << "No magnet detected." << endl;
upm_delay(1);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete hall;
return 0;
} }

View File

@ -21,42 +21,41 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "abp.hpp" #include "abp.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main() int main ()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an ABP sensor on i2c bus 0 // Instantiate an ABP sensor on i2c bus 0
upm::ABP abp(0, ABP_DEFAULT_ADDRESS); upm::ABP* abp = new upm::ABP(0, ABP_DEFAULT_ADDRESS);
while (shouldRun) { while (shouldRun) {
abp.update(); abp->update();
cout << "Retrieved pressure: " << abp.getPressure() << endl; cout << "Retrieved pressure: " << abp->getPressure() << endl;
cout << "Retrieved Temperature: " << abp.getTemperature() << endl; cout << "Retrieved Temperature: " << abp->getTemperature() << endl;
upm_delay(1); sleep(1);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
delete abp;
return 0; return 0;
} }

View File

@ -22,45 +22,44 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "ad8232.hpp" #include "ad8232.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
bool shouldRun = true; bool shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int int main()
main()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-) // Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
// and an analog pin, 0 (OUTPUT) // and an analog pin, 0 (OUTPUT)
upm::AD8232 ad8232(10, 11, 0); upm::AD8232 *ad8232 = new upm::AD8232(10, 11, 0);
// Output the raw numbers from the ADC, for plotting elsewhere. // Output the raw numbers from the ADC, for plotting elsewhere.
// A return of 0 indicates a Lead Off (LO) condition. // A return of 0 indicates a Lead Off (LO) condition.
// In theory, this data could be fed to software like Processing // In theory, this data could be fed to software like Processing
// (https://www.processing.org/) to plot the data just like an // (https://www.processing.org/) to plot the data just like an
// EKG you would see in a hospital. // EKG you would see in a hospital.
while (shouldRun) { while (shouldRun)
cout << ad8232.value() << endl; {
upm_delay_us(1000); cout << ad8232->value() << endl;
usleep(1000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting" << endl; cout << "Exiting" << endl;
return 0; delete ad8232;
return 0;
} }

View File

@ -22,56 +22,61 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <signal.h>
#include <iostream> #include <iostream>
#include "adafruitms1438.hpp" #include "adafruitms1438.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
using namespace upm; using namespace upm;
int int main(int argc, char **argv)
main(int argc, char** argv)
{ {
//! [Interesting] //! [Interesting]
// Instantiate an Adafruit MS 1438 on I2C bus 0 // Instantiate an Adafruit MS 1438 on I2C bus 0
upm::AdafruitMS1438 ms(ADAFRUITMS1438_I2C_BUS, ADAFRUITMS1438_DEFAULT_I2C_ADDR); upm::AdafruitMS1438 *ms =
new upm::AdafruitMS1438(ADAFRUITMS1438_I2C_BUS,
ADAFRUITMS1438_DEFAULT_I2C_ADDR);
// Setup for use with a stepper motor connected to the M1 & M2 ports // Setup for use with a stepper motor connected to the M1 & M2 ports
// set a PWM period of 50Hz // set a PWM period of 50Hz
// disable first, to be safe // disable first, to be safe
ms.disableStepper(AdafruitMS1438::STEPMOTOR_M12); ms->disableStepper(AdafruitMS1438::STEPMOTOR_M12);
// configure for a NEMA-17, 200 steps per revolution // configure for a NEMA-17, 200 steps per revolution
ms.stepConfig(AdafruitMS1438::STEPMOTOR_M12, 200); ms->stepConfig(AdafruitMS1438::STEPMOTOR_M12, 200);
// set speed at 10 RPM's // set speed at 10 RPM's
ms.setStepperSpeed(AdafruitMS1438::STEPMOTOR_M12, 10); ms->setStepperSpeed(AdafruitMS1438::STEPMOTOR_M12, 10);
ms.setStepperDirection(AdafruitMS1438::STEPMOTOR_M12, AdafruitMS1438::DIR_CW); ms->setStepperDirection(AdafruitMS1438::STEPMOTOR_M12,
AdafruitMS1438::DIR_CW);
// enable // enable
cout << "Enabling..." << endl; cout << "Enabling..." << endl;
ms.enableStepper(AdafruitMS1438::STEPMOTOR_M12); ms->enableStepper(AdafruitMS1438::STEPMOTOR_M12);
cout << "Rotating 1 full revolution at 10 RPM speed." << endl; cout << "Rotating 1 full revolution at 10 RPM speed." << endl;
ms.stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 200); ms->stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 200);
cout << "Sleeping for 2 seconds..." << endl; cout << "Sleeping for 2 seconds..." << endl;
upm_delay(2); sleep(2);
cout << "Rotating 1/2 revolution in opposite direction at 10 RPM speed." << endl; cout << "Rotating 1/2 revolution in opposite direction at 10 RPM speed."
<< endl;
ms.setStepperDirection(AdafruitMS1438::STEPMOTOR_M12, AdafruitMS1438::DIR_CCW); ms->setStepperDirection(AdafruitMS1438::STEPMOTOR_M12,
ms.stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 100); AdafruitMS1438::DIR_CCW);
ms->stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 100);
cout << "Disabling..." << endl; cout << "Disabling..." << endl;
ms.disableStepper(AdafruitMS1438::STEPMOTOR_M12); ms->disableStepper(AdafruitMS1438::STEPMOTOR_M12);
cout << "Exiting" << endl; cout << "Exiting" << endl;
//! [Interesting] //! [Interesting]
return 0; delete ms;
return 0;
} }

View File

@ -22,51 +22,54 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <signal.h>
#include <iostream> #include <iostream>
#include "adafruitms1438.hpp" #include "adafruitms1438.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
using namespace upm; using namespace upm;
int int main(int argc, char **argv)
main(int argc, char** argv)
{ {
//! [Interesting] //! [Interesting]
// Instantiate an Adafruit MS 1438 on I2C bus 0 // Instantiate an Adafruit MS 1438 on I2C bus 0
upm::AdafruitMS1438 ms(ADAFRUITMS1438_I2C_BUS, ADAFRUITMS1438_DEFAULT_I2C_ADDR); upm::AdafruitMS1438 *ms =
new upm::AdafruitMS1438(ADAFRUITMS1438_I2C_BUS,
ADAFRUITMS1438_DEFAULT_I2C_ADDR);
// Setup for use with a DC motor connected to the M3 port // Setup for use with a DC motor connected to the M3 port
// set a PWM period of 50Hz // set a PWM period of 50Hz
ms.setPWMPeriod(50); ms->setPWMPeriod(50);
// disable first, to be safe // disable first, to be safe
ms.disableMotor(AdafruitMS1438::MOTOR_M3); ms->disableMotor(AdafruitMS1438::MOTOR_M3);
// set speed at 50% // set speed at 50%
ms.setMotorSpeed(AdafruitMS1438::MOTOR_M3, 50); ms->setMotorSpeed(AdafruitMS1438::MOTOR_M3, 50);
ms.setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CW); ms->setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CW);
cout << "Spin M3 at half speed for 3 seconds, then reverse for 3 seconds." << endl; cout << "Spin M3 at half speed for 3 seconds, then reverse for 3 seconds."
<< endl;
ms.enableMotor(AdafruitMS1438::MOTOR_M3); ms->enableMotor(AdafruitMS1438::MOTOR_M3);
upm_delay(3); sleep(3);
cout << "Reversing M3" << endl; cout << "Reversing M3" << endl;
ms.setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CCW); ms->setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CCW);
upm_delay(3); sleep(3);
cout << "Stopping M3" << endl; cout << "Stopping M3" << endl;
ms.disableMotor(AdafruitMS1438::MOTOR_M3); ms->disableMotor(AdafruitMS1438::MOTOR_M3);
cout << "Exiting" << endl; cout << "Exiting" << endl;
//! [Interesting] //! [Interesting]
return 0; delete ms;
return 0;
} }

View File

@ -22,57 +22,56 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
/** /**
* Description * Description
* Demo program for Adafruit 16 channel servo shield/controller * Demo program for Adafruit 16 channel servo shield/controller
* Physical setup for tests is a single servo attached to one channel. * Physical setup for tests is a single servo attached to one channel.
* Note - when 3 or more GWS servos attached results unpredictable. * Note - when 3 or more GWS servos attached results unpredictable.
* Adafruit do recommend a Cap be installed on the board which should alleviate * Adafruit do recommend a Cap be installed on the board which should alleviate the issue.
* the issue.
* I (and Adafruit) are unable to give any Capacitor sizing data. * I (and Adafruit) are unable to give any Capacitor sizing data.
*/ */
#include <iostream> #include <iostream>
#include "adafruitss.hpp" #include "adafruitss.hpp"
#include "upm_utilities.h" #include <unistd.h>
using namespace std; using namespace std;
int int main() {
main()
{
int n;
//! [Interesting] int n;
upm::adafruitss servos(6, 0x40);
for (;;) { //! [Interesting]
cout << "Setting all to 0" << endl; upm::adafruitss* servos = new upm::adafruitss(6,0x40);
for (n = 0; n < 16; n++)
servos.servo(n, 1, 0); // GWS Mini Servo = Type 1.
upm_delay_us(1000000); // Wait 1 second
cout << "Setting all to 45" << endl; for (;;)
for (n = 0; n < 16; n++) {
servos.servo(n, 1, 45); cout << "Setting all to 0" << endl;
upm_delay_us(1000000); // Wait 1 second for (n = 0; n < 16; n++)
servos->servo(n, 1, 0); // GWS Mini Servo = Type 1.
usleep(1000000); // Wait 1 second
cout << "Setting all to 90" << endl; cout << "Setting all to 45" << endl;
for (n = 0; n < 16; n++) for (n = 0; n < 16; n++)
servos.servo(n, 1, 90); servos->servo(n, 1, 45);
upm_delay_us(1000000); // Wait 1 second usleep(1000000); // Wait 1 second
cout << "Setting all to 135" << endl; cout << "Setting all to 90" << endl;
for (n = 0; n < 16; n++) for (n = 0; n < 16; n++)
servos.servo(n, 1, 135); servos->servo(n, 1, 90);
upm_delay_us(1000000); // Wait 1 second usleep(1000000); // Wait 1 second
cout << "Setting all to 180" << endl; cout << "Setting all to 135" << endl;
for (n = 0; n < 16; n++) for (n = 0; n < 16; n++)
servos.servo(n, 1, 160); servos->servo(n, 1, 135);
upm_delay_us(2000000); // Wait 1 second usleep(1000000); // Wait 1 second
}
//! [Interesting] cout << "Setting all to 180" << endl;
return 0; for (n = 0; n < 16; n++)
servos->servo(n, 1, 160);
usleep(2000000); // Wait 1 second
}
//! [Interesting]
return 0;
} }

View File

@ -22,44 +22,45 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <iostream> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <iostream>
#include "adc121c021.hpp" #include "adc121c021.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int int main(int argc, char **argv)
main(int argc, char** argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an ADC121C021 on I2C bus 0 // Instantiate an ADC121C021 on I2C bus 0
upm::ADC121C021 adc(ADC121C021_I2C_BUS, ADC121C021_DEFAULT_I2C_ADDR); upm::ADC121C021 *adc = new upm::ADC121C021(ADC121C021_I2C_BUS,
ADC121C021_DEFAULT_I2C_ADDR);
// An analog sensor, such as a Grove light sensor, // An analog sensor, such as a Grove light sensor,
// must be attached to the adc // must be attached to the adc
// Prints the value and corresponding voltage every 50 milliseconds // Prints the value and corresponding voltage every 50 milliseconds
while (shouldRun) { while (shouldRun)
uint16_t val = adc.value(); {
cout << "ADC value: " << val << " Volts = " << adc.valueToVolts(val) << endl; uint16_t val = adc->value();
upm_delay_us(50000); cout << "ADC value: " << val << " Volts = "
<< adc->valueToVolts(val) << endl;
usleep(50000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete adc;
return 0;
} }

View File

@ -12,12 +12,9 @@
// This example code runs on an Intel Edison and uses mraa to acquire data // This example code runs on an Intel Edison and uses mraa to acquire data
// from an ADIS16448. This data is then scaled and printed onto the terminal. // from an ADIS16448. This data is then scaled and printed onto the terminal.
// //
// This software has been tested to connect to an ADIS16448 through a level // This software has been tested to connect to an ADIS16448 through a level shifter
// shifter // such as the TI TXB0104. The SPI lines (DIN, DOUT, SCLK, /CS) are all wired through
// such as the TI TXB0104. The SPI lines (DIN, DOUT, SCLK, /CS) are all wired // the level shifter and the ADIS16448 is also being powered by the Intel Edison.
// through
// the level shifter and the ADIS16448 is also being powered by the Intel
// Edison.
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the // a copy of this software and associated documentation files (the
@ -39,29 +36,31 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h>
#include "adis16448.hpp" #include "adis16448.hpp"
#include "upm_utilities.h"
int int
main(int argc, char** argv) main(int argc, char **argv)
{ {
while (true) { while(true)
//! [Interesting] {
upm::ADIS16448 imu(0, 3); // upm::ADIS16448(SPI,RST) //! [Interesting]
upm::ADIS16448* imu = new upm::ADIS16448(0,3); //upm::ADIS16448(SPI,RST)
// Read the specified register, scale it, and display it on the screen //Read the specified register, scale it, and display it on the screen
std::cout << "XGYRO_OUT:" << imu.gyroScale(imu.regRead(XGYRO_OUT)) << std::endl; std::cout << "XGYRO_OUT:" << imu->gyroScale(imu->regRead(XGYRO_OUT)) << std::endl;
std::cout << "YGYRO_OUT:" << imu.gyroScale(imu.regRead(YGYRO_OUT)) << std::endl; std::cout << "YGYRO_OUT:" << imu->gyroScale(imu->regRead(YGYRO_OUT)) << std::endl;
std::cout << "ZGYRO_OUT:" << imu.gyroScale(imu.regRead(ZGYRO_OUT)) << std::endl; std::cout << "ZGYRO_OUT:" << imu->gyroScale(imu->regRead(ZGYRO_OUT)) << std::endl;
std::cout << " " << std::endl; std::cout << " " << std::endl;
std::cout << "XACCL_OUT:" << imu.accelScale(imu.regRead(XACCL_OUT)) << std::endl; std::cout << "XACCL_OUT:" << imu->accelScale(imu->regRead(XACCL_OUT)) << std::endl;
std::cout << "YACCL_OUT:" << imu.accelScale(imu.regRead(YACCL_OUT)) << std::endl; std::cout << "YACCL_OUT:" << imu->accelScale(imu->regRead(YACCL_OUT)) << std::endl;
std::cout << "ZACCL_OUT:" << imu.accelScale(imu.regRead(ZACCL_OUT)) << std::endl; std::cout << "ZACCL_OUT:" << imu->accelScale(imu->regRead(ZACCL_OUT)) << std::endl;
std::cout << " " << std::endl; std::cout << " " << std::endl;
//! [Interesting] //! [Interesting]
upm_delay(1); sleep(1);
} }
return (0); return (0);
} }

View File

@ -22,46 +22,59 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <exception> #include <unistd.h>
#include <iostream> #include <iostream>
#include <stddef.h>
#include "ads1015.hpp" #include "ads1015.hpp"
#include "mraa/gpio.hpp" #include "mraa/gpio.hpp"
#include "upm_utilities.h"
#define EDISON_I2C_BUS 1 #define EDISON_I2C_BUS 1
#define FT4222_I2C_BUS 0 #define FT4222_I2C_BUS 0
#define EDISON_GPIO_SI7005_CS 20 #define EDISON_GPIO_SI7005_CS 20
int
main() //! [Interesting]
// Simple example of using IADC to determine
// which sensor is present and return its name.
// IADC is then used to get readings from sensor
upm::IADC* getADC()
{ {
/* Create an instance of the ADS1015 sensor */ upm::IADC* adc = NULL;
upm::ADS1015 adc(EDISON_I2C_BUS); try {
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS); adc = new upm::ADS1015(EDISON_I2C_BUS);
gpio.dir(mraa::DIR_OUT_HIGH); mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
gpio.dir(mraa::DIR_OUT_HIGH);
return adc;
} catch (std::exception& e) {
std::cerr << "ADS1015: " << e.what() << std::endl;
}
return adc;
}
// if (adc == NULL) { int main ()
// std::cout << "ADC not detected" << std::endl; {
// return 1; upm::IADC* adc = getADC();
// } if (adc == NULL) {
std::cout << "ADC " << adc.getModuleName() << " detected. "; std::cout << "ADC not detected" << std::endl;
std::cout << adc.getNumInputs() << " inputs available" << std::endl; return 1;
while (true) { }
for (unsigned int i = 0; i < adc.getNumInputs(); ++i) { std::cout << "ADC " << adc->getModuleName() << " detected. " ;
std::cout << "Input " << i; std::cout << adc->getNumInputs() << " inputs available" << std::endl;
try { while (true) {
float voltage = adc.getVoltage(i); for (unsigned int i=0; i<adc->getNumInputs(); ++i) {
std::cout << ": Voltage = " << voltage << "V" << std::endl; std::cout << "Input " << i;
} catch (std::exception& e) { try {
std::cerr << e.what() << std::endl; float voltage = adc->getVoltage(i);
} std::cout << ": Voltage = " << voltage << "V" << std::endl;
} } catch (std::exception& e) {
upm_delay(1); std::cerr << e.what() << std::endl;
} }
}
return 0; sleep(1);
}
delete adc;
return 0;
} }
//! [Interesting] //! [Interesting]

View File

@ -29,13 +29,11 @@
*/ */
#include <fstream> #include <fstream>
#include <iostream>
#include <string> #include <string>
#include <thread> #include <thread>
#include <unistd.h>
#include "ads1015.hpp" #include "ads1015.hpp"
#include "ads1x15.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
using namespace upm; using namespace upm;
@ -43,41 +41,39 @@ using namespace upm;
bool running = true; // Controls main read/write loop bool running = true; // Controls main read/write loop
// Thread function // Thread function
void void stop()
stop()
{ {
upm_delay(10); sleep(10);
running = false; running = false;
} }
int int main()
main()
{ {
//! [Interesting] //! [Interesting]
long id = 0; // Sample number long id = 0; // Sample number
string fileName = "./ads1015.data"; // Output filename string fileName = "./ads1015.data"; // Output filename
ofstream f; ofstream f;
// Initialize and configure the ADS1015 // Initialize and configure the ADS1015
ADS1015 ads1015(0, 0x48); ADS1015 *ads1015 = new upm::ADS1015(0, 0x48);
// Put the ADC into differential mode for pins A0 and A1 // Put the ADC into differential mode for pins A0 and A1
ads1015.getSample(ADS1X15::DIFF_0_1); ads1015->getSample(ADS1X15::DIFF_0_1);
// Set the gain based on expected VIN range to -/+ 2.048 V // Set the gain based on expected VIN range to -/+ 2.048 V
// Can be adjusted based on application to as low as -/+ 0.256 V, see API // Can be adjusted based on application to as low as -/+ 0.256 V, see API
// documentation for details // documentation for details
ads1015.setGain(ADS1X15::GAIN_TWO); ads1015->setGain(ADS1X15::GAIN_TWO);
// Set the sample rate to 3300 samples per second (max) and turn on continuous // Set the sample rate to 3300 samples per second (max) and turn on continuous
// sampling // sampling
ads1015.setSPS(ADS1015::SPS_3300); ads1015->setSPS(ADS1015::SPS_3300);
ads1015.setContinuous(true); ads1015->setContinuous(true);
// Enable exceptions from the output stream // Enable exceptions from the output stream
f.exceptions(ofstream::failbit | ofstream::badbit); f.exceptions(ofstream::failbit | ofstream::badbit);
// Open the file // Open the file
try { try{
f.open(fileName); f.open(fileName);
// Output formatting // Output formatting
@ -85,18 +81,19 @@ main()
f.precision(7); f.precision(7);
// Start the thread that will stop logging after 10 seconds // Start the thread that will stop logging after 10 seconds
thread timer(stop); thread timer (stop);
// Read sensor data and write it to the output file every ms // Read sensor data and write it to the output file every ms
while (running) { while(running){
f << id++ << " " << ads1015.getLastSample() << endl; f << id++ << " " << ads1015->getLastSample() << endl;
upm_delay_us(1000); usleep(1000);
} }
// Clean-up and exit // Clean-up and exit
timer.join(); timer.join();
f.close(); f.close();
} catch (ios_base::failure& e) { delete ads1015;
} catch (ios_base::failure &e) {
cout << "Failed to write to file: " << e.what() << endl; cout << "Failed to write to file: " << e.what() << endl;
return 1; return 1;
} }
@ -104,3 +101,4 @@ main()
//! [Interesting] //! [Interesting]
return 0; return 0;
} }

View File

@ -28,13 +28,11 @@
*/ */
#include <fstream> #include <fstream>
#include <iostream>
#include <string> #include <string>
#include <thread> #include <thread>
#include <unistd.h>
#include "ads1115.hpp" #include "ads1115.hpp"
#include "ads1x15.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
using namespace upm; using namespace upm;
@ -42,18 +40,16 @@ using namespace upm;
bool running = true; // Controls main read/write loop bool running = true; // Controls main read/write loop
// Thread function // Thread function
void void stop()
stop()
{ {
upm_delay(10); sleep(10);
running = false; running = false;
} }
int int main()
main()
{ {
//! [Interesting] //! [Interesting]
long id = 0; // Sample number long id = 0; // Sample number
string fileName = "./ads1115.data"; // Output filename string fileName = "./ads1115.data"; // Output filename
ofstream f; ofstream f;
@ -61,26 +57,26 @@ main()
// There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus // There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus
// - 0x48 gives access to pins A0 - A3 // - 0x48 gives access to pins A0 - A3
// - 0x49 gives access to pins A4 - A7 // - 0x49 gives access to pins A4 - A7
ADS1115 ads1115(0, 0x48); ADS1115 *ads1115 = new upm::ADS1115(0, 0x48);
// Put the ADC into differential mode for pins A0 and A1, // Put the ADC into differential mode for pins A0 and A1,
// the SM-24 Geophone is connected to these pins // the SM-24 Geophone is connected to these pins
ads1115.getSample(ADS1X15::DIFF_0_1); ads1115->getSample(ADS1X15::DIFF_0_1);
// Set the gain based on expected VIN range to -/+ 2.048 V // Set the gain based on expected VIN range to -/+ 2.048 V
// Can be adjusted based on application to as low as -/+ 0.256 V, see API // Can be adjusted based on application to as low as -/+ 0.256 V, see API
// documentation for details // documentation for details
ads1115.setGain(ADS1X15::GAIN_TWO); ads1115->setGain(ADS1X15::GAIN_TWO);
// Set the sample rate to 860 samples per second (max) and turn on continuous // Set the sample rate to 860 samples per second (max) and turn on continuous
// sampling // sampling
ads1115.setSPS(ADS1115::SPS_860); ads1115->setSPS(ADS1115::SPS_860);
ads1115.setContinuous(true); ads1115->setContinuous(true);
// Enable exceptions from the output stream // Enable exceptions from the output stream
f.exceptions(ofstream::failbit | ofstream::badbit); f.exceptions(ofstream::failbit | ofstream::badbit);
// Open the file // Open the file
try { try{
f.open(fileName); f.open(fileName);
// Output formatting // Output formatting
@ -88,18 +84,19 @@ main()
f.precision(7); f.precision(7);
// Start the thread that will stop logging after 10 seconds // Start the thread that will stop logging after 10 seconds
thread timer(stop); thread timer (stop);
// Read sensor data and write it to the output file every ms // Read sensor data and write it to the output file every ms
while (running) { while(running){
f << id++ << " " << ads1115.getLastSample() << endl; f << id++ << " " << ads1115->getLastSample() << endl;
upm_delay_us(1000); usleep(1000);
} }
// Clean-up and exit // Clean-up and exit
timer.join(); timer.join();
f.close(); f.close();
} catch (ios_base::failure& e) { delete ads1115;
} catch (ios_base::failure &e) {
cout << "Failed to write to file: " << e.what() << endl; cout << "Failed to write to file: " << e.what() << endl;
return 1; return 1;
} }
@ -107,3 +104,4 @@ main()
//! [Interesting] //! [Interesting]
return 0; return 0;
} }

View File

@ -22,306 +22,301 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <iostream> #include "mraa.hpp"
#include <iostream>
#include <unistd.h>
#include "ads1015.hpp" #include "ads1015.hpp"
#include "ads1115.hpp" #include "ads1115.hpp"
#include "ads1x15.hpp"
int
main()
int main()
{ {
using namespace std;
using namespace upm;
int command;
//! [Interesting]
// Select the device you are testing here and adjust case 6 for the correct
// sample rates.
upm::ADS1115 ads(1, 0x49);
float inputVoltage;
int ans;
do { using namespace std;
cout << endl; using namespace upm;
cout << "1 - get Conversion \t"; int command;
cout << "2 - get last conversion" << endl; //! [Interesting]
cout << "3 - get Gain \t\t"; //Select the device you are testing here and adjust case 6 for the correct sample rates.
cout << "4 - set Gain" << endl; //upm::ADS1015 *ads = new upm::ADS1015(1);
; upm::ADS1115 *ads = new upm::ADS1115(1, 0x49);
cout << "5 - get Data Rate \t"; float inputVoltage;
cout << "6 - set Data Rate" << endl; int ans;
cout << "7 - Set Upper Threshold \t";
cout << "8 - Set Lower Threshold \t";
cout << "9 - Display Thresholds \t";
cout << "10 - Set Default Thresholds \t";
cout << "11 - Set conversion ready" << endl;
cout << "12 - get Comp Que \t";
cout << "13 - set Comp Que" << endl;
cout << "14 - get Comp Pol \t";
cout << "15 - set Comp Pol" << endl;
cout << "16 - get Comp mode \t";
cout << "17 - set Comp mode " << endl;
cout << "18 - get Comp Latch\t";
cout << "19 - set Comp Latch " << endl;
cout << "20 - get Continuous \t";
cout << "21 - set Continuous \t" << endl;
cout << "-1 - exit" << endl;
cout << "Enter a command: ";
cin >> command;
switch (command) { do
case 2: {
cout << ads.getLastSample() << endl;
break; cout << endl;
case 3: cout << "1 - get Conversion \t" ;
cout << std::hex << ads.getGain() << endl; cout << "2 - get last conversion" << endl;
break; cout << "3 - get Gain \t\t";
case 5: cout << "4 - set Gain" << endl;;
cout << std::hex << ads.getSPS() << endl; cout << "5 - get Data Rate \t";
break; cout << "6 - set Data Rate" << endl;
case 4: cout << "7 - Set Upper Threshold \t" ;
int gain; cout << "8 - Set Lower Threshold \t";
ADS1015::ADSGAIN set_gain; cout << "9 - Display Thresholds \t";
cout << "select one of the following:" << endl; cout << "10 - Set Default Thresholds \t";
cout << "1 -> gain 2/3 \t 2 -> gain1 \t 3 -> gain 2" << endl; cout << "11 - Set conversion ready" << endl;
cout << "4 -> gain 4 \t 5 -> gain 8 \t 6 -> gain 15" << endl; cout << "12 - get Comp Que \t" ;
cin >> gain; cout << "13 - set Comp Que" << endl;
switch (gain) { cout << "14 - get Comp Pol \t";
case 1: cout << "15 - set Comp Pol" << endl;
set_gain = ADS1X15::GAIN_TWOTHIRDS; cout << "16 - get Comp mode \t";
break; cout << "17 - set Comp mode " << endl;
case 2: cout << "18 - get Comp Latch\t";
set_gain = ADS1X15::GAIN_ONE; cout << "19 - set Comp Latch " << endl;
break; cout << "20 - get Continuous \t";
case 3: cout << "21 - set Continuous \t" << endl;
set_gain = ADS1X15::GAIN_TWO; cout << "-1 - exit" << endl;
break; cout << "Enter a command: ";
case 4: cin >> command;
set_gain = ADS1X15::GAIN_FOUR;
break;
case 5: switch(command)
set_gain = ADS1X15::GAIN_EIGHT; {
break;
case 6:
set_gain = ADS1X15::GAIN_SIXTEEN;
break;
default:
set_gain = ADS1X15::GAIN_ONE;
}
ads.setGain(set_gain);
break;
case 6:
int rate;
/*ADS1015::ADSDATARATE set_rate;
cout << "select one of the following:" << endl;
cout << "1 -> SPS_120 \t 2 -> SPS_250 \t 3 -> SPS_490 \t 4 -> SPS_920" <<
endl;
cout << "5 -> SPS_1600 \t 6 -> SPS_2400 \t 7 -> SPS_3300" << endl;
cin >> rate;
switch(rate){
case 1:
set_rate = ADS1015::SPS_128;
break;
case 2: case 2:
set_rate = ADS1015::SPS_250; cout << ads->getLastSample() << endl;
break; break;
case 3: case 3:
set_rate = ADS1015::SPS_490; cout << std::hex << ads->getGain() << endl;
break;
case 4:
set_rate = ADS1015::SPS_920;
break; break;
case 5: case 5:
set_rate = ADS1015::SPS_1600; cout << std::hex << ads->getSPS() << endl;
break;
case 4:
int gain;
ADS1015::ADSGAIN set_gain;
cout << "select one of the following:" << endl;
cout << "1 -> gain 2/3 \t 2 -> gain1 \t 3 -> gain 2" << endl;
cout << "4 -> gain 4 \t 5 -> gain 8 \t 6 -> gain 15" << endl;
cin >> gain;
switch(gain){
case 1:
set_gain = ADS1X15::GAIN_TWOTHIRDS;
break;
case 2:
set_gain = ADS1X15::GAIN_ONE;
break;
case 3:
set_gain = ADS1X15::GAIN_TWO;
break;
case 4:
set_gain = ADS1X15::GAIN_FOUR;
break;
case 5:
set_gain = ADS1X15::GAIN_EIGHT;
break;
case 6:
set_gain = ADS1X15::GAIN_SIXTEEN;
break;
default:
set_gain = ADS1X15::GAIN_ONE;
}
ads->setGain(set_gain);
break; break;
case 6: case 6:
set_rate = ADS1015::SPS_2400; int rate;
/*ADS1015::ADSDATARATE set_rate;
cout << "select one of the following:" << endl;
cout << "1 -> SPS_120 \t 2 -> SPS_250 \t 3 -> SPS_490 \t 4 -> SPS_920" << endl;
cout << "5 -> SPS_1600 \t 6 -> SPS_2400 \t 7 -> SPS_3300" << endl;
cin >> rate;
switch(rate){
case 1:
set_rate = ADS1015::SPS_128;
break;
case 2:
set_rate = ADS1015::SPS_250;
break;
case 3:
set_rate = ADS1015::SPS_490;
break;
case 4:
set_rate = ADS1015::SPS_920;
break;
case 5:
set_rate = ADS1015::SPS_1600;
break;
case 6:
set_rate = ADS1015::SPS_2400;
break;
case 7:
set_rate = ADS1015::SPS_3300;
break;
default:
set_rate = ADS1015::SPS_1600;
} */
ADS1115::ADSDATARATE set_rate;
cout << "select one of the following:" << endl;
cout << "1 -> SPS_8 \t 2 -> SPS_16 \t 3 -> SPS_32 \t 4 -> SPS_64" << endl;
cout << "5 -> SPS_128 \t 6 -> SPS_250 \t 7 -> SPS_475 \t 8-> SPS_860" << endl;
cin >> rate;
switch(rate){
case 1:
set_rate = ADS1115::SPS_8;
break;
case 2:
set_rate = ADS1115::SPS_16;
break;
case 3:
set_rate = ADS1115::SPS_32;
break;
case 4:
set_rate = ADS1115::SPS_64;
break;
case 5:
set_rate = ADS1115::SPS_128;
break;
case 6:
set_rate = ADS1115::SPS_250;
break;
case 7:
set_rate = ADS1115::SPS_475;
break;
case 8:
set_rate = ADS1115::SPS_860;
break;
default:
set_rate = ADS1115::SPS_128;
}
ads->setSPS(set_rate);
break;
case 1:
int mode;
ADS1X15::ADSMUXMODE set_mode;
cout << "select one of the following:" << endl;
cout << "1 -> MUX_0_1 \t 2 -> MUX_0_3 \t 3 -> MUX_1_3 \t 4 -> MUX_2_3" << endl;
cout << "5 -> SINGLE_0 \t 6 -> SINGLE_1 \t 7 -> SINGLE_2 \t 8 -> SINGLE_3" << endl;
cin >> mode;
switch(mode){
case 1:
set_mode = ADS1X15::DIFF_0_1;
break;
case 2:
set_mode = ADS1X15::DIFF_0_3;
break;
case 3:
set_mode = ADS1X15::DIFF_1_3;
break;
case 4:
set_mode = ADS1X15::DIFF_2_3;
break;
case 5:
set_mode = ADS1X15::SINGLE_0;
break;
case 6:
set_mode = ADS1X15::SINGLE_1;
break;
case 7:
set_mode = ADS1X15::SINGLE_2;
break;
case 8:
set_mode = ADS1X15::SINGLE_3;
break;
default:
set_mode = ADS1X15::DIFF_0_1;
break;
}
cout << ads->getSample(set_mode) << endl;
break; break;
case 7: case 7:
set_rate = ADS1015::SPS_3300; cout << " enter a float value: " ;
cin >> inputVoltage;
ads->setThresh(ADS1115::THRESH_HIGH, inputVoltage);
break;
case 8:
cout << " enter a float value: " ;
cin >> inputVoltage;
ads->setThresh(ADS1115::THRESH_LOW, inputVoltage);
break;
case 9:
cout << "Upper " << ads->getThresh(ADS1X15::THRESH_HIGH) << endl;
cout << "Lower " << ads->getThresh(ADS1X15::THRESH_LOW) << endl;
break;
case 10:
ads->setThresh(ADS1115::THRESH_DEFAULT);
break;
case 11:
ads->setThresh(ADS1015::CONVERSION_RDY);
break;
case 12:
cout << ads->getCompQue() << endl;
break;
case 13:
int que;
cout << "select one of the following:" << endl;
cout << "1 -> CQUE_1CONV \t 2 -> CQUE_2CONV \t 3 -> CQUE_3CONV \t 4 -> CQUE_NONE" << endl;
cin >> que;
switch(que){
case 1:
ads->setCompQue(ADS1X15::CQUE_1CONV);
break;
case 2:
ads->setCompQue(ADS1X15::CQUE_2CONV);
break;
case 3:
ads->setCompQue(ADS1X15::CQUE_4CONV);
break;
case 4:
default:
ads->setCompQue(ADS1X15::CQUE_NONE);
break;
}
break;
case 14:
cout << ads->getCompPol() << endl;
break;
case 15:
cout << "select one of the following:" << endl;
cout << "1 -> active high \t 2 -> active low" << endl;
cin >> ans;
if(ans == 1) ads->setCompPol(true);
else ads->setCompPol(false);
break;
case 16:
cout << ads->getCompMode() << endl;
break;
case 17:
cout << "select one of the following:" << endl;
cout << "1 -> Window \t 2 -> Traditional (default)" << endl;
cin >> ans;
if(ans == 1) ads->setCompMode(true);
else ads->setCompMode();
break;
case 18:
cout << ads->getCompLatch() << endl;
break;
case 19:
cout << "select one of the following:" << endl;
cout << "1 -> Latching \t 2 -> Non-latching (default)" << endl;
cin >> ans;
if(ans == 1) ads->setCompLatch(true);
else ads->setCompLatch();
break;
case 20:
cout << ads->getContinuous() << endl;
break;
case 21:
cout << "select one of the following:" << endl;
cout << "1 -> Power Down (default) \t 2 -> Continuous" << endl;
cin >> ans;
if(ans == 1) ads->setContinuous(true);
else ads->setContinuous();
break;
case -1:
break; break;
default: default:
set_rate = ADS1015::SPS_1600;
} */
ADS1115::ADSDATARATE set_rate;
cout << "select one of the following:" << endl;
cout << "1 -> SPS_8 \t 2 -> SPS_16 \t 3 -> SPS_32 \t 4 -> SPS_64" << endl;
cout << "5 -> SPS_128 \t 6 -> SPS_250 \t 7 -> SPS_475 \t 8-> SPS_860" << endl;
cin >> rate;
switch (rate) {
case 1:
set_rate = ADS1115::SPS_8;
break;
case 2:
set_rate = ADS1115::SPS_16;
break;
case 3:
set_rate = ADS1115::SPS_32;
break;
case 4:
set_rate = ADS1115::SPS_64;
break;
case 5:
set_rate = ADS1115::SPS_128;
break;
case 6:
set_rate = ADS1115::SPS_250;
break;
case 7:
set_rate = ADS1115::SPS_475;
break;
case 8:
set_rate = ADS1115::SPS_860;
break;
default:
set_rate = ADS1115::SPS_128;
}
ads.setSPS(set_rate); break;
break; }
case 1:
int mode;
ADS1X15::ADSMUXMODE set_mode;
cout << "select one of the following:" << endl;
cout << "1 -> MUX_0_1 \t 2 -> MUX_0_3 \t 3 -> MUX_1_3 \t 4 -> MUX_2_3" << endl;
cout << "5 -> SINGLE_0 \t 6 -> SINGLE_1 \t 7 -> SINGLE_2 \t 8 -> "
"SINGLE_3"
<< endl;
cin >> mode;
switch (mode) {
case 1:
set_mode = ADS1X15::DIFF_0_1;
break;
case 2:
set_mode = ADS1X15::DIFF_0_3;
break;
case 3:
set_mode = ADS1X15::DIFF_1_3;
break;
case 4:
set_mode = ADS1X15::DIFF_2_3;
break;
case 5:
set_mode = ADS1X15::SINGLE_0;
break;
case 6:
set_mode = ADS1X15::SINGLE_1;
break;
case 7:
set_mode = ADS1X15::SINGLE_2;
break;
case 8:
set_mode = ADS1X15::SINGLE_3;
break;
default:
set_mode = ADS1X15::DIFF_0_1;
break;
}
cout << ads.getSample(set_mode) << endl;
break;
case 7:
cout << " enter a float value: ";
cin >> inputVoltage;
ads.setThresh(ADS1115::THRESH_HIGH, inputVoltage);
break;
case 8:
cout << " enter a float value: ";
cin >> inputVoltage;
ads.setThresh(ADS1115::THRESH_LOW, inputVoltage);
break;
case 9:
cout << "Upper " << ads.getThresh(ADS1X15::THRESH_HIGH) << endl;
cout << "Lower " << ads.getThresh(ADS1X15::THRESH_LOW) << endl;
break;
case 10:
ads.setThresh(ADS1115::THRESH_DEFAULT);
break;
case 11:
ads.setThresh(ADS1015::CONVERSION_RDY);
break;
case 12:
cout << ads.getCompQue() << endl;
break;
case 13:
int que;
cout << "select one of the following:" << endl;
cout << "1 -> CQUE_1CONV \t 2 -> CQUE_2CONV \t 3 -> CQUE_3CONV \t 4 -> "
"CQUE_NONE"
<< endl;
cin >> que;
switch (que) {
case 1:
ads.setCompQue(ADS1X15::CQUE_1CONV);
break;
case 2:
ads.setCompQue(ADS1X15::CQUE_2CONV);
break;
case 3:
ads.setCompQue(ADS1X15::CQUE_4CONV);
break;
case 4:
default:
ads.setCompQue(ADS1X15::CQUE_NONE);
break;
}
break;
case 14:
cout << ads.getCompPol() << endl;
break;
case 15:
cout << "select one of the following:" << endl;
cout << "1 -> active high \t 2 -> active low" << endl;
cin >> ans;
if (ans == 1)
ads.setCompPol(true);
else
ads.setCompPol(false);
break;
case 16:
cout << ads.getCompMode() << endl;
break;
case 17:
cout << "select one of the following:" << endl;
cout << "1 -> Window \t 2 -> Traditional (default)" << endl;
cin >> ans;
if (ans == 1)
ads.setCompMode(true);
else
ads.setCompMode();
break;
case 18:
cout << ads.getCompLatch() << endl;
break;
case 19:
cout << "select one of the following:" << endl;
cout << "1 -> Latching \t 2 -> Non-latching (default)" << endl;
cin >> ans;
if (ans == 1)
ads.setCompLatch(true);
else
ads.setCompLatch();
break;
case 20:
cout << ads.getContinuous() << endl;
break;
case 21:
cout << "select one of the following:" << endl;
cout << "1 -> Power Down (default) \t 2 -> Continuous" << endl;
cin >> ans;
if (ans == 1)
ads.setContinuous(true);
else
ads.setContinuous();
break;
case -1:
break;
default:
break; }while (command != -1 );
}
} while (command != -1);
//! [Interesting] delete ads;
//! [Interesting]
return 0; return 0;
} }

View File

@ -22,58 +22,57 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include <string>
#include "adxl335.hpp" #include "adxl335.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main() int main ()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2 // Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2
upm::ADXL335 accel(0, 1, 2); upm::ADXL335* accel = new upm::ADXL335(0, 1, 2);
cout << "Please make sure the sensor is completely still. Sleeping for" cout << "Please make sure the sensor is completely still. Sleeping for"
<< " 2 seconds." << endl; << " 2 seconds." << endl;
upm_delay(2); sleep(2);
cout << "Calibrating..." << endl; cout << "Calibrating..." << endl;
accel.calibrate(); accel->calibrate();
while (shouldRun)
{
int x, y, z;
float aX, aY, aZ;
while (shouldRun) { accel->values(&x, &y, &z);
int x, y, z; cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl;
float aX, aY, aZ;
accel.values(&x, &y, &z); accel->acceleration(&aX, &aY, &aZ);
cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl; cout << "Acceleration: X: " << aX << "g" << endl;
cout << "Acceleration: Y: " << aY << "g" << endl;
cout << "Acceleration: Z: " << aZ << "g" << endl;
cout << endl;
accel.acceleration(&aX, &aY, &aZ); usleep(200000);
cout << "Acceleration: X: " << aX << "g" << endl;
cout << "Acceleration: Y: " << aY << "g" << endl;
cout << "Acceleration: Z: " << aZ << "g" << endl;
cout << endl;
upm_delay_us(200000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting" << endl; cout << "Exiting" << endl;
return 0; delete accel;
return 0;
} }

View File

@ -22,32 +22,30 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <stdio.h> #include <unistd.h>
#include "adxl345.hpp" #include "adxl345.hpp"
#include "upm_utilities.h"
int int
main(int argc, char** argv) main(int argc, char **argv)
{ {
//! [Interesting] //! [Interesting]
int16_t* raw; int16_t *raw;
float* acc; float *acc;
// Note: Sensor only works at 3.3V on the Intel Edison with Arduino breakout // Note: Sensor only works at 3.3V on the Intel Edison with Arduino breakout
upm::Adxl345 accel(0); upm::Adxl345* accel = new upm::Adxl345(0);
while (true) { while(true){
accel.update(); // Update the data accel->update(); // Update the data
raw = accel.getRawValues(); // Read raw sensor data raw = accel->getRawValues(); // Read raw sensor data
acc = accel.getAcceleration(); // Read acceleration (g) acc = accel->getAcceleration(); // Read acceleration (g)
fprintf(stdout, "Current scale: 0x%2xg\n", accel.getScale()); fprintf(stdout, "Current scale: 0x%2xg\n", accel->getScale());
fprintf(stdout, "Raw: %6d %6d %6d\n", raw[0], raw[1], raw[2]); fprintf(stdout, "Raw: %6d %6d %6d\n", raw[0], raw[1], raw[2]);
fprintf(stdout, "AccX: %5.2f g\n", acc[0]); fprintf(stdout, "AccX: %5.2f g\n", acc[0]);
fprintf(stdout, "AccY: %5.2f g\n", acc[1]); fprintf(stdout, "AccY: %5.2f g\n", acc[1]);
fprintf(stdout, "AccZ: %5.2f g\n", acc[2]); fprintf(stdout, "AccZ: %5.2f g\n", acc[2]);
upm_delay(1); sleep(1);
} }
//! [Interesting] //! [Interesting]
return 0; return 0;
} }

View File

@ -22,51 +22,50 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "adxrs610.hpp" #include "adxrs610.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
bool shouldRun = true; bool shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int int main()
main()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and // Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and
// analog A1 (temp out) with an analog reference voltage of // analog A1 (temp out) with an analog reference voltage of
// 5.0 // 5.0
upm::ADXRS610 sensor(0, 1, 5.0); upm::ADXRS610 *sensor = new upm::ADXRS610(0, 1, 5.0);
// set a deadband region around the zero point to report 0.0 (optional)
sensor->setDeadband(0.015);
// set a deadband region around the zero point to report 0.0 (optional) // Every tenth of a second, sample the ADXRS610 and output it's
sensor.setDeadband(0.015); // corresponding temperature and angular velocity
// Every tenth of a second, sample the ADXRS610 and output it's while (shouldRun)
// corresponding temperature and angular velocity {
cout << "Vel (deg/s): " << sensor->getAngularVelocity() << endl;
while (shouldRun) { cout << "Temp (C): " << sensor->getTemperature() << endl;
cout << "Vel (deg/s): " << sensor.getAngularVelocity() << endl;
cout << "Temp (C): " << sensor.getTemperature() << endl; usleep(100000);
upm_delay_us(100000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting" << endl; cout << "Exiting" << endl;
return 0; delete sensor;
return 0;
} }

View File

@ -22,15 +22,16 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include "am2315.hpp" #include "am2315.hpp"
#include "upm_utilities.h"
volatile int doWork = 0; volatile int doWork = 0;
upm::AM2315 *sensor = NULL;
void void
sig_handler(int signo) sig_handler(int signo)
{ {
@ -41,30 +42,34 @@ sig_handler(int signo)
} }
int int
main(int argc, char** argv) main(int argc, char **argv)
{ {
// Register signal handler // Register signal handler
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
float humidity = 0.0; float humidity = 0.0;
float temperature = 0.0; float temperature = 0.0;
upm::AM2315 sensor(0, AM2315_I2C_ADDRESS); sensor = new upm::AM2315(0, AM2315_I2C_ADDRESS);
sensor.testSensor(); sensor->testSensor();
while (!doWork) { while (!doWork) {
humidity = sensor.getHumidity(); humidity = sensor->getHumidity();
temperature = sensor.getTemperature(); temperature = sensor->getTemperature();
std::cout << "humidity value = " << humidity << ", temperature value = " << temperature std::cout << "humidity value = " <<
<< std::endl; humidity <<
upm_delay_us(500000); ", temperature value = " <<
temperature << std::endl;
usleep (500000);
} }
//! [Interesting] //! [Interesting]
std::cout << "exiting application" << std::endl; std::cout << "exiting application" << std::endl;
delete sensor;
return 0; return 0;
} }

View File

@ -23,6 +23,9 @@
*/ */
#include "apa102.hpp" #include "apa102.hpp"
#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std; using namespace std;
@ -31,17 +34,18 @@ main(int argc, char** argv)
{ {
//! [Interesting] //! [Interesting]
// Instantiate a strip of 30 LEDs on SPI bus 0 // Instantiate a strip of 30 LEDs on SPI bus 0
upm::APA102 ledStrip(800, 0); upm::APA102* ledStrip = new upm::APA102(800, 0);
// Set all LEDs to Red // Set all LEDs to Red
ledStrip.setAllLeds(31, 255, 0, 0); ledStrip->setAllLeds(31, 255, 0, 0);
// Set a section (10 to 20) to blue // Set a section (10 to 20) to blue
ledStrip.setLeds(10, 20, 31, 0, 0, 255); ledStrip->setLeds(10, 20, 31, 0, 0, 255);
// Set a single LED to green // Set a single LED to green
ledStrip.setLed(15, 31, 0, 255, 0); ledStrip->setLed(15, 31, 0, 255, 0);
delete ledStrip;
//! [Interesting] //! [Interesting]
return 0; return 0;
} }

View File

@ -22,41 +22,41 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "apds9002.hpp" #include "apds9002.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main() int main ()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a Grove Luminance sensor on analog pin A0 // Instantiate a Grove Luminance sensor on analog pin A0
upm::APDS9002 luminance(0); upm::APDS9002* luminance = new upm::APDS9002(0);
while (shouldRun)
{
int val = luminance->value();
cout << "Luminance value is " << val << endl;
while (shouldRun) { sleep(1);
int val = luminance.value();
cout << "Luminance value is " << val << endl;
upm_delay(1);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting" << endl; cout << "Exiting" << endl;
return 0; delete luminance;
return 0;
} }

View File

@ -22,11 +22,10 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "apds9930.hpp" #include "apds9930.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
@ -45,30 +44,31 @@ main()
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a Digital Proximity and Ambient Light sensor on iio device 4 // Instantiate a Digital Proximity and Ambient Light sensor on iio device 4
upm::APDS9930 light_proximity(4); upm::APDS9930* light_proximity = new upm::APDS9930(4);
// Kernel driver implement upm_delay 5000-5100us after enable illuminance // Kernel driver implement sleep 5000-5100us after enable illuminance sensor
// sensor light_proximity->enableIlluminance(true);
light_proximity.enableIlluminance(true);
// Kernel driver implement upm_delay 5000-5100us after enable proximity sensor // Kernel driver implement sleep 5000-5100us after enable proximity sensor
light_proximity.enableProximity(true); light_proximity->enableProximity(true);
// Tested this value works. Please change it on your platform // Tested this value works. Please change it on your platform
upm_delay_us(120000); usleep(120000);
while (shouldRun) { while (shouldRun) {
float lux = light_proximity.getAmbient(); float lux = light_proximity->getAmbient();
cout << "Luminance value is " << lux << endl; cout << "Luminance value is " << lux << endl;
float proximity = light_proximity.getProximity(); float proximity = light_proximity->getProximity();
cout << "Proximity value is " << proximity << endl; cout << "Proximity value is " << proximity << endl;
upm_delay(1); sleep(1);
} }
light_proximity.enableProximity(false); light_proximity->enableProximity(false);
light_proximity.enableIlluminance(false); light_proximity->enableIlluminance(false);
//! [Interesting] //! [Interesting]
cout << "Exiting" << endl; cout << "Exiting" << endl;
delete light_proximity;
return 0; return 0;
} }

View File

@ -22,68 +22,69 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <iostream> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <iostream>
#include "at42qt1070.hpp" #include "at42qt1070.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
void void printButtons(upm::AT42QT1070 *touch)
printButtons(upm::AT42QT1070& touch)
{ {
bool buttonPressed = false; bool buttonPressed = false;
uint8_t buttons = touch.getButtons(); uint8_t buttons = touch->getButtons();
cout << "Buttons Pressed: "; cout << "Buttons Pressed: ";
for (int i = 0; i < 7; i++) { for (int i=0; i<7; i++)
if (buttons & (1 << i)) { {
cout << i << " "; if (buttons & (1 << i))
buttonPressed = true; {
cout << i << " ";
buttonPressed = true;
} }
} }
if (!buttonPressed) if (!buttonPressed)
cout << "None"; cout << "None";
cout << endl; cout << endl;
if (touch.isCalibrating()) if (touch->isCalibrating())
cout << "Calibration is occurring." << endl; cout << "Calibration is occurring." << endl;
if (touch.isOverflowed()) if (touch->isOverflowed())
cout << "Overflow was detected." << endl; cout << "Overflow was detected." << endl;
} }
int int main(int argc, char **argv)
main(int argc, char** argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an AT42QT1070 on I2C bus 0 // Instantiate an AT42QT1070 on I2C bus 0
upm::AT42QT1070 touch(AT42QT1070_I2C_BUS, AT42QT1070_DEFAULT_I2C_ADDR); upm::AT42QT1070 *touch = new upm::AT42QT1070(AT42QT1070_I2C_BUS,
AT42QT1070_DEFAULT_I2C_ADDR);
while (shouldRun) { while (shouldRun)
touch.updateState(); {
printButtons(touch); touch->updateState();
upm_delay_us(100000); printButtons(touch);
usleep(100000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete touch;
return 0;
} }

View File

@ -1,71 +0,0 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 <iostream>
#include <unistd.h>
#include <stdexcept>
#include <signal.h>
#include <vector>
#include "bh1749.hpp"
#include "upm_utilities.h"
bool isStopped;
upm::BH1749 dev;
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
//! [Interesting]
void PrintData(void *args)
{
std::vector<uint16_t> result = dev.GetMeasurements();
std::cout << "R: " << result.at(0) <<
", G: " << result.at(1) <<
", B: " << result.at(2) <<
", IR: " << result.at(3) <<
", G2: " << result.at(4) << std::endl;
dev.ResetInterrupt();
}
int main(int argc, char **argv)
{
signal(SIGINT, signal_int_handler);
dev.SoftReset();
dev.SensorInit(INT_JUDGE_1, MEAS_240MS, RGB_GAIN_1X, IR_GAIN_1X, RED);
dev.SetThresholdHigh(511);
std::cout << "Installing ISR" << std::endl;
dev.InstallISR(MRAA_GPIO_EDGE_FALLING, 33, &PrintData, NULL);
dev.EnableInterrupt();
dev.Enable();
while(!isStopped) {
upm_delay_ms(1000);
}
return 0;
}
//! [Interesting]

View File

@ -22,45 +22,44 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bh1750.hpp" #include "bh1750.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
bool shouldRun = true; bool shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int int main()
main()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a BH1750 sensor using defaults (I2C bus (0), using // Instantiate a BH1750 sensor using defaults (I2C bus (0), using
// the default I2C address (0x23), and setting the mode to highest // the default I2C address (0x23), and setting the mode to highest
// resolution, lowest power mode). // resolution, lowest power mode).
upm::BH1750 sensor; upm::BH1750 *sensor = new upm::BH1750();
// Every second, sample the BH1750 and output the measured lux value // Every second, sample the BH1750 and output the measured lux value
while (shouldRun) { while (shouldRun)
cout << "Detected Light Level (lux): " << sensor.getLux() << endl; {
upm_delay(1); cout << "Detected Light Level (lux): " << sensor->getLux() << endl;
sleep(1);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting" << endl; cout << "Exiting" << endl;
return 0; delete sensor;
return 0;
} }

View File

@ -1,81 +0,0 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 <iostream>
#include <signal.h>
#include <sys/time.h>
#include "bh1792.hpp"
#include "upm_utilities.h"
bool isStopped;
upm::BH1792 dev;
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
//! [Interesting]
void PrintData(void *args)
{
std::vector<std::vector<int>> fifo;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
try {
fifo = dev.GetFifoData();
std::cout << "\nHeart beat sensor FIFO data:" << std::endl;
for(int i = 0; i < 32; i++)
std::cout << i << ": off: " << fifo.at(i).at(0) << ", on: " <<
fifo.at(i).at(1) << std::endl;
std::cout << "timestamp " << now.tv_sec << " sec, " << now.tv_nsec <<
" nsec" << std::endl;
} catch (std::exception& e) {
std::cout << "Failed to read FIFO data" << std::endl;
throw;
}
}
int main(int argc, char **argv)
{
float measTime;
signal(SIGINT, signal_int_handler);
dev.SoftReset();
dev.EnableSyncMode(256, 32);
std::cout << "Installing ISR" << std::endl;
dev.InstallISR(MRAA_GPIO_EDGE_FALLING, 33, &PrintData, NULL);
measTime = dev.GetMeasurementTimeMS();
dev.StartMeasurement();
while(!isStopped) {
usleep(measTime * 1000);
}
return 0;
}
//! [Interesting]

View File

@ -22,47 +22,47 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "biss0001.hpp" #include "biss0001.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main() int main ()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a Grove Motion sensor on GPIO pin D2 // Instantiate a Grove Motion sensor on GPIO pin D2
upm::BISS0001 motion(2); upm::BISS0001* motion = new upm::BISS0001(2);
while (shouldRun)
{
bool val = motion->value();
while (shouldRun) { if (val)
bool val = motion.value(); cout << "Detecting moving object";
else
cout << "No moving objects detected";
if (val) cout << endl;
cout << "Detecting moving object";
else
cout << "No moving objects detected";
cout << endl; sleep(1);
}
//! [Interesting]
upm_delay(1); cout << "Exiting" << endl;
}
//! [Interesting]
cout << "Exiting" << endl; delete motion;
return 0;
return 0;
} }

View File

@ -22,48 +22,49 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bma220.hpp" #include "bma220.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an BMA220 using default parameters (bus 0, addr 0x0a) // Instantiate an BMA220 using default parameters (bus 0, addr 0x0a)
upm::BMA220 sensor; upm::BMA220 *sensor = new upm::BMA220();
// Output data every half second until interrupted // Output data every half second until interrupted
while (shouldRun) { while (shouldRun)
sensor.update(); {
sensor->update();
float x, y, z;
sensor->getAccelerometer(&x, &y, &z);
cout << "Accelerometer: ";
cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
float x, y, z; usleep(500000);
sensor.getAccelerometer(&x, &y, &z);
cout << "Accelerometer: ";
cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
upm_delay_us(500000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete sensor;
return 0;
} }

View File

@ -22,56 +22,60 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bma250e.hpp" #include "bma250e.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an BMA250E using default I2C parameters // Instantiate an BMA250E using default I2C parameters
upm::BMA250E sensor; upm::BMA250E sensor;
// For SPI, bus 0, you would pass -1 as the address, and a valid pin // For SPI, bus 0, you would pass -1 as the address, and a valid pin
// for CS: BMA250E(0, -1, 10); // for CS: BMA250E(0, -1, 10);
// now output data every 250 milliseconds // now output data every 250 milliseconds
while (shouldRun) { while (shouldRun)
float x, y, z; {
float x, y, z;
sensor.update(); sensor.update();
sensor.getAccelerometer(&x, &y, &z); sensor.getAccelerometer(&x, &y, &z);
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl; cout << "Accelerometer x: " << x
<< " y: " << y
<< " z: " << z
<< " g"
<< endl;
// we show both C and F for temperature // we show both C and F for temperature
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / " cout << "Compensation Temperature: " << sensor.getTemperature()
<< sensor.getTemperature(true) << " F" << endl; << " C / " << sensor.getTemperature(true) << " F"
<< endl;
cout << endl; cout << endl;
upm_delay_us(250000); usleep(250000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; return 0;
} }

View File

@ -22,56 +22,60 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bmg160.hpp" #include "bmg160.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an BMG160 using default I2C parameters // Instantiate an BMG160 using default I2C parameters
upm::BMG160 sensor; upm::BMG160 sensor;
// For SPI, bus 0, you would pass -1 as the address, and a valid pin // For SPI, bus 0, you would pass -1 as the address, and a valid pin
// for CS: BMG160(0, -1, 10); // for CS: BMG160(0, -1, 10);
// now output data every 250 milliseconds // now output data every 250 milliseconds
while (shouldRun) { while (shouldRun)
float x, y, z; {
float x, y, z;
sensor.update(); sensor.update();
sensor.getGyroscope(&x, &y, &z); sensor.getGyroscope(&x, &y, &z);
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl; cout << "Gyroscope x: " << x
<< " y: " << y
<< " z: " << z
<< " degrees/s"
<< endl;
// we show both C and F for temperature // we show both C and F for temperature
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / " cout << "Compensation Temperature: " << sensor.getTemperature()
<< sensor.getTemperature(true) << " F" << endl; << " C / " << sensor.getTemperature(true) << " F"
<< endl;
cout << endl; cout << endl;
upm_delay_us(250000); usleep(250000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; return 0;
} }

View File

@ -22,57 +22,61 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bmi160.hpp" #include "bmi160.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a BMI160 instance using default i2c bus and address // Instantiate a BMI160 instance using default i2c bus and address
upm::BMI160 sensor; upm::BMI160 *sensor = new upm::BMI160();
while (shouldRun) { while (shouldRun)
// update our values from the sensor {
sensor.update(); // update our values from the sensor
sensor->update();
float dataX, dataY, dataZ; float dataX, dataY, dataZ;
sensor.getAccelerometer(&dataX, &dataY, &dataZ); sensor->getAccelerometer(&dataX, &dataY, &dataZ);
cout << "Accelerometer: "; cout << "Accelerometer: ";
cout << "AX: " << dataX << " AY: " << dataY << " AZ: " << dataZ << endl; cout << "AX: " << dataX << " AY: " << dataY << " AZ: "
<< dataZ << endl;
sensor.getGyroscope(&dataX, &dataY, &dataZ); sensor->getGyroscope(&dataX, &dataY, &dataZ);
cout << "Gryoscope: "; cout << "Gryoscope: ";
cout << "GX: " << dataX << " GY: " << dataY << " GZ: " << dataZ << endl; cout << "GX: " << dataX << " GY: " << dataY << " GZ: "
<< dataZ << endl;
sensor.getMagnetometer(&dataX, &dataY, &dataZ); sensor->getMagnetometer(&dataX, &dataY, &dataZ);
cout << "Magnetometer: "; cout << "Magnetometer: ";
cout << "MX: " << dataX << " MY: " << dataY << " MZ: " << dataZ << endl; cout << "MX: " << dataX << " MY: " << dataY << " MZ: "
<< dataZ << endl;
cout << endl; cout << endl;
upm_delay_us(500000); usleep(500000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete sensor;
return 0;
} }

View File

@ -22,52 +22,55 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bmm150.hpp" #include "bmm150.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an BMM150 using default I2C parameters // Instantiate an BMM150 using default I2C parameters
upm::BMM150 sensor; upm::BMM150 sensor;
// For SPI, bus 0, you would pass -1 as the address, and a valid pin // For SPI, bus 0, you would pass -1 as the address, and a valid pin
// for CS: BMM150(0, -1, 10); // for CS: BMM150(0, -1, 10);
// now output data every 250 milliseconds // now output data every 250 milliseconds
while (shouldRun) { while (shouldRun)
float x, y, z; {
float x, y, z;
sensor.update(); sensor.update();
sensor.getMagnetometer(&x, &y, &z); sensor.getMagnetometer(&x, &y, &z);
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl; cout << "Magnetometer x: " << x
<< " y: " << y
<< " z: " << z
<< " uT"
<< endl;
cout << endl; cout << endl;
upm_delay_us(250000); usleep(250000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; return 0;
} }

View File

@ -22,54 +22,57 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bme280.hpp" #include "bme280.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
using namespace upm; using namespace upm;
bool shouldRun = true; bool shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a BME280 instance using default i2c bus and address // Instantiate a BME280 instance using default i2c bus and address
upm::BME280 sensor; upm::BME280 *sensor = new upm::BME280();
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS: // For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
// BME280(0, -1, 10); // BME280(0, -1, 10);
while (shouldRun) { while (shouldRun)
// update our values from the sensor {
sensor.update(); // update our values from the sensor
sensor->update();
// we show both C and F for temperature // we show both C and F for temperature
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / " cout << "Compensation Temperature: " << sensor->getTemperature()
<< sensor.getTemperature(true) << " F" << endl; << " C / " << sensor->getTemperature(true) << " F"
cout << "Pressure: " << sensor.getPressure() << " Pa" << endl; << endl;
cout << "Computed Altitude: " << sensor.getAltitude() << " m" << endl; cout << "Pressure: " << sensor->getPressure() << " Pa" << endl;
cout << "Humidity: " << sensor.getHumidity() << " %RH" << endl; cout << "Computed Altitude: " << sensor->getAltitude() << " m" << endl;
cout << "Humidity: " << sensor->getHumidity() << " %RH" << endl;
cout << endl; cout << endl;
upm_delay(1); sleep(1);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete sensor;
return 0;
} }

View File

@ -24,53 +24,56 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bmp280.hpp" #include "bmp280.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
using namespace upm; using namespace upm;
bool shouldRun = true; bool shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a BMP280 instance using default i2c bus and address // Instantiate a BMP280 instance using default i2c bus and address
upm::BMP280 sensor; upm::BMP280 *sensor = new upm::BMP280();
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS: // For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
// BMP280(0, -1, 10); // BMP280(0, -1, 10);
while (shouldRun) { while (shouldRun)
// update our values from the sensor {
sensor.update(); // update our values from the sensor
sensor->update();
// we show both C and F for temperature // we show both C and F for temperature
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / " cout << "Compensation Temperature: " << sensor->getTemperature()
<< sensor.getTemperature(true) << " F" << endl; << " C / " << sensor->getTemperature(true) << " F"
cout << "Pressure: " << sensor.getPressure() << " Pa" << endl; << endl;
cout << "Computed Altitude: " << sensor.getAltitude() << " m" << endl; cout << "Pressure: " << sensor->getPressure() << " Pa" << endl;
cout << "Computed Altitude: " << sensor->getAltitude() << " m" << endl;
cout << endl; cout << endl;
upm_delay(1); sleep(1);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete sensor;
return 0;
} }

View File

@ -27,47 +27,52 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bmpx8x.hpp" #include "bmpx8x.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
bool shouldRun = true; bool shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int int main(int argc, char **argv)
main(int argc, char** argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a BMPX8X sensor on I2C using defaults. // Instantiate a BMPX8X sensor on I2C using defaults.
upm::BMPX8X sensor; upm::BMPX8X sensor;
// Print the pressure, altitude, sea level, and // Print the pressure, altitude, sea level, and
// temperature values every 0.5 seconds // temperature values every 0.5 seconds
while (shouldRun) { while (shouldRun)
{
sensor.update(); sensor.update();
cout << "Pressure: " << sensor.getPressure() cout << "Pressure: "
<< " Pa, Temperature: " << sensor.getTemperature() << sensor.getPressure()
<< " C, Altitude: " << sensor.getAltitude() << " Pa, Temperature: "
<< " m, Sea level: " << sensor.getSealevelPressure() << " Pa" << endl; << sensor.getTemperature()
<< " C, Altitude: "
<< sensor.getAltitude()
<< " m, Sea level: "
<< sensor.getSealevelPressure()
<< " Pa"
<< endl;
upm_delay_us(500000); usleep(500000);
} }
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
//! [Interesting] //! [Interesting]
return 0; return 0;
} }

View File

@ -22,52 +22,59 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bmc150.hpp" #include "bmc150.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an BMC150 using default I2C parameters // Instantiate an BMC150 using default I2C parameters
upm::BMC150 sensor; upm::BMC150 sensor;
// now output data every 250 milliseconds // now output data every 250 milliseconds
while (shouldRun) { while (shouldRun)
float x, y, z; {
float x, y, z;
sensor.update(); sensor.update();
sensor.getAccelerometer(&x, &y, &z); sensor.getAccelerometer(&x, &y, &z);
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl; cout << "Accelerometer x: " << x
<< " y: " << y
<< " z: " << z
<< " g"
<< endl;
sensor.getMagnetometer(&x, &y, &z); sensor.getMagnetometer(&x, &y, &z);
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl; cout << "Magnetometer x: " << x
<< " y: " << y
<< " z: " << z
<< " uT"
<< endl;
cout << endl; cout << endl;
upm_delay_us(250000); usleep(250000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; return 0;
} }

View File

@ -22,52 +22,59 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bmi055.hpp" #include "bmi055.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an BMI055 using default I2C parameters // Instantiate an BMI055 using default I2C parameters
upm::BMI055 sensor; upm::BMI055 sensor;
// now output data every 250 milliseconds // now output data every 250 milliseconds
while (shouldRun) { while (shouldRun)
float x, y, z; {
float x, y, z;
sensor.update(); sensor.update();
sensor.getAccelerometer(&x, &y, &z); sensor.getAccelerometer(&x, &y, &z);
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl; cout << "Accelerometer x: " << x
<< " y: " << y
<< " z: " << z
<< " g"
<< endl;
sensor.getGyroscope(&x, &y, &z); sensor.getGyroscope(&x, &y, &z);
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl; cout << "Gyroscope x: " << x
<< " y: " << y
<< " z: " << z
<< " degrees/s"
<< endl;
cout << endl; cout << endl;
upm_delay_us(250000); usleep(250000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; return 0;
} }

View File

@ -22,55 +22,66 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bmx055.hpp" #include "bmx055.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an BMX055 using default I2C parameters // Instantiate an BMX055 using default I2C parameters
upm::BMX055 sensor; upm::BMX055 sensor;
// now output data every 250 milliseconds // now output data every 250 milliseconds
while (shouldRun) { while (shouldRun)
float x, y, z; {
float x, y, z;
sensor.update(); sensor.update();
sensor.getAccelerometer(&x, &y, &z); sensor.getAccelerometer(&x, &y, &z);
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl; cout << "Accelerometer x: " << x
<< " y: " << y
<< " z: " << z
<< " g"
<< endl;
sensor.getGyroscope(&x, &y, &z); sensor.getGyroscope(&x, &y, &z);
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl; cout << "Gyroscope x: " << x
<< " y: " << y
<< " z: " << z
<< " degrees/s"
<< endl;
sensor.getMagnetometer(&x, &y, &z); sensor.getMagnetometer(&x, &y, &z);
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl; cout << "Magnetometer x: " << x
<< " y: " << y
<< " z: " << z
<< " uT"
<< endl;
cout << endl; cout << endl;
upm_delay_us(250000); usleep(250000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; return 0;
} }

View File

@ -22,82 +22,108 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "bno055.hpp" #include "bno055.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main(int argc, char** argv) int main(int argc, char **argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate an BNO055 using default parameters (bus 0, addr // Instantiate an BNO055 using default parameters (bus 0, addr
// 0x28). The default running mode is NDOF absolute orientation // 0x28). The default running mode is NDOF absolute orientation
// mode. // mode.
upm::BNO055 sensor; upm::BNO055 *sensor = new upm::BNO055();
// First we need to calibrate.... // First we need to calibrate....
cout << "First we need to calibrate. 4 numbers will be output every" << endl; cout << "First we need to calibrate. 4 numbers will be output every"
cout << "second for each sensor. 0 means uncalibrated, and 3 means" << endl; << endl;
cout << "fully calibrated." << endl; cout << "second for each sensor. 0 means uncalibrated, and 3 means"
cout << "See the UPM documentation on this sensor for instructions on" << endl; << endl;
cout << "what actions are required to calibrate." << endl; cout << "fully calibrated."
cout << endl; << endl;
cout << "See the UPM documentation on this sensor for instructions on"
<< endl;
cout << "what actions are required to calibrate."
<< endl;
cout << endl;
// do the calibration... // do the calibration...
while (shouldRun && !sensor.isFullyCalibrated()) { while (shouldRun && !sensor->isFullyCalibrated())
int mag, acc, gyr, sys; {
sensor.getCalibrationStatus(&mag, &acc, &gyr, &sys); int mag, acc, gyr, sys;
sensor->getCalibrationStatus(&mag, &acc, &gyr, &sys);
cout << "Magnetometer: " << mag << " Accelerometer: " << acc << " Gyroscope: " << gyr cout << "Magnetometer: " << mag
<< " System: " << sys << endl; << " Accelerometer: " << acc
<< " Gyroscope: " << gyr
<< " System: " << sys
<< endl;
upm_delay(1); sleep(1);
} }
cout << endl; cout << endl;
cout << "Calibration complete." << endl; cout << "Calibration complete." << endl;
cout << endl; cout << endl;
// now output various fusion data every 250 milliseconds // now output various fusion data every 250 milliseconds
while (shouldRun) { while (shouldRun)
float w, x, y, z; {
float w, x, y, z;
sensor.update(); sensor->update();
sensor.getEulerAngles(&x, &y, &z); sensor->getEulerAngles(&x, &y, &z);
cout << "Euler: Heading: " << x << " Roll: " << y << " Pitch: " << z << " degrees" << endl; cout << "Euler: Heading: " << x
<< " Roll: " << y
<< " Pitch: " << z
<< " degrees"
<< endl;
sensor.getQuaternions(&w, &x, &y, &z); sensor->getQuaternions(&w, &x, &y, &z);
cout << "Quaternion: W: " << w << " X: " << x << " Y: " << y << " Z: " << z << endl; cout << "Quaternion: W: " << w
<< " X: " << x
<< " Y: " << y
<< " Z: " << z
<< endl;
sensor.getLinearAcceleration(&x, &y, &z); sensor->getLinearAcceleration(&x, &y, &z);
cout << "Linear Acceleration: X: " << x << " Y: " << y << " Z: " << z << " m/s^2" << endl; cout << "Linear Acceleration: X: " << x
<< " Y: " << y
<< " Z: " << z
<< " m/s^2"
<< endl;
sensor.getGravityVectors(&x, &y, &z); sensor->getGravityVectors(&x, &y, &z);
cout << "Gravity Vector: X: " << x << " Y: " << y << " Z: " << z << " m/s^2" << endl; cout << "Gravity Vector: X: " << x
<< " Y: " << y
<< " Z: " << z
<< " m/s^2"
<< endl;
cout << endl; cout << endl;
upm_delay_us(250000); usleep(250000);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
return 0; delete sensor;
return 0;
} }

View File

@ -22,28 +22,28 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include "button.hpp" #include "button.hpp"
#include "upm_utilities.h"
int int
main(int argc, char** argv) main(int argc, char **argv)
{ {
// This example uses GPIO 0 // This example uses GPIO 0
//! [Interesting] //! [Interesting]
// Create the button object using GPIO pin 0 // Create the button object using GPIO pin 0
upm::Button button(0); upm::Button* button = new upm::Button(0);
// Read the input and print, waiting one second between readings // Read the input and print, waiting one second between readings
while (1) { while( 1 ) {
std::cout << button.name() << " value is " << button.value() << std::endl; std::cout << button->name() << " value is " << button->value() << std::endl;
upm_delay(1); sleep(1);
} }
// Delete the button object // Delete the button object
//! [Interesting] delete button;
//! [Interesting]
return 0; return 0;
} }

View File

@ -1,12 +0,0 @@
#include <iostream>
#include "buzzer.hpp"
#include "buzzer_tones.h"
#include "upm_utilities.h"
int
main(int argc, char** argv)
{
upm::Buzzer buzzer("p:32,vol:0.01,play:3800:500000");
return 0;
}

View File

@ -22,32 +22,37 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h>
#include "buzzer.hpp" #include "buzzer.hpp"
#include "buzzer_tones.h"
#include "upm_utilities.h" #include "upm_utilities.h"
int int
main(int argc, char** argv) main(int argc, char **argv) {
{
//! [Interesting] //! [Interesting]
int chord[] = { BUZZER_DO, BUZZER_RE, BUZZER_MI, BUZZER_FA, BUZZER_SOL, BUZZER_LA, BUZZER_SI }; int chord[] = { BUZZER_DO, BUZZER_RE, BUZZER_MI,
BUZZER_FA, BUZZER_SOL, BUZZER_LA,
BUZZER_SI };
// create Buzzer instance // create Buzzer instance
upm::Buzzer sound(32); upm::Buzzer* sound = new upm::Buzzer(5);
// print sensor name // print sensor name
std::cout << sound.name() << std::endl; std::cout << sound->name() << std::endl;
// play each sound (DO, RE, MI, etc...) for .5 seconds, pausing // play each sound (DO, RE, MI, etc...) for .5 seconds, pausing
// for 0.1 seconds between notes // for 0.1 seconds between notes
for (int chord_ind = 0; chord_ind < 7; chord_ind++) { for (int chord_ind = 0; chord_ind < 7; chord_ind++)
std::cout << sound.playSound(chord[chord_ind], 500000) << std::endl; {
std::cout << sound->playSound(chord[chord_ind], 500000) << std::endl;
upm_delay_ms(100); upm_delay_ms(100);
} }
//! [Interesting] //! [Interesting]
std::cout << "exiting application" << std::endl; std::cout << "exiting application" << std::endl;
delete sound;
return 0; return 0;
} }

View File

@ -22,54 +22,56 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include "cjq4435.hpp" #include "cjq4435.hpp"
#include "upm_utilities.h"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int
main() int main ()
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3 // Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3
upm::CJQ4435 mosfet(3); upm::CJQ4435* mosfet = new upm::CJQ4435(3);
mosfet.setPeriodMS(10); mosfet->setPeriodMS(10);
mosfet.enable(true); mosfet->enable(true);
while (shouldRun) { while (shouldRun)
{
// start with a duty cycle of 0.0 (off) and increment to 1.0 (on) // start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
for (float i = 0.0; i <= 1.0; i += 0.1) { for (float i=0.0; i <= 1.0; i+=0.1)
mosfet.setDutyCycle(i); {
upm_delay_us(100000); mosfet->setDutyCycle(i);
usleep(100000);
} }
upm_delay(1); sleep(1);
// Now take it back down // Now take it back down
// start with a duty cycle of 1.0 (on) and decrement to 0.0 (off) // start with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
for (float i = 1.0; i >= 0.0; i -= 0.1) { for (float i=1.0; i >= 0.0; i-=0.1)
mosfet.setDutyCycle(i); {
upm_delay_us(100000); mosfet->setDutyCycle(i);
usleep(100000);
} }
upm_delay(1); sleep(1);
} }
//! [Interesting] //! [Interesting]
cout << "Exiting..." << endl; cout << "Exiting..." << endl;
delete mosfet;
return 0; return 0;
} }

View File

@ -22,45 +22,48 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <iostream> #include <iostream>
#include <unistd.h>
#include <signal.h> #include <signal.h>
#include "collision.hpp" #include "collision.hpp"
using namespace std; using namespace std;
int shouldRun = true; int shouldRun = true;
void void sig_handler(int signo)
sig_handler(int signo)
{ {
if (signo == SIGINT) if (signo == SIGINT)
shouldRun = false; shouldRun = false;
} }
int int main(int argc, char **argv)
main(int argc, char** argv)
{ {
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// The was tested with the Collision Sensor // The was tested with the Collision Sensor
// Instantiate a Collision on digital pin D2 // Instantiate a Collision on digital pin D2
upm::Collision collision(2); upm::Collision* collision = new upm::Collision(2);
bool collisionState = false; bool collisionState = false;
cout << "No collision" << endl; cout << "No collision" << endl;
while (shouldRun) { while (shouldRun)
if (collision.isColliding() && !collisionState) { {
cout << "Collision!" << endl; if (collision->isColliding() && !collisionState)
collisionState = true; {
} else if (collisionState) { cout << "Collision!" << endl;
cout << "No collision" << endl; collisionState = true;
collisionState = false; }
} else if (collisionState)
} {
cout << "No collision" << endl;
collisionState = false;
}
}
//! [Interesting] //! [Interesting]
cout << "Exiting" << endl; cout << "Exiting" << endl;
return 0; delete collision;
return 0;
} }

View File

@ -24,50 +24,58 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream>
#include "curieimu.hpp" #include "curieimu.hpp"
#include "upm_utilities.h"
#include "mraa.h" #include "mraa.h"
#include "mraa/firmata.h" #include "mraa/firmata.h"
#include <iostream>
#include <math.h> #include <math.h>
#include <unistd.h>
int int
main(int argc, char** argv) main(int argc, char **argv)
{ {
//! [Interesting] //! [Interesting]
mraa_init(); mraa_init();
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0"); mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
upm::CurieImu sensor; upm::CurieImu* sensor = new upm::CurieImu();
std::cout << "temperature is: " << (sensor.getTemperature() * pow(0.5, 9) + 23) << std::endl; std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
sensor.updateAccel(); sensor->updateAccel();
int x = sensor.getAccelX(), y = sensor.getAccelY(), z = sensor.getAccelZ(); int x = sensor->getAccelX(),
y = sensor->getAccelY(),
z = sensor->getAccelZ();
printf("accelerometer is: %d, %d, %d\n", x, y, z); printf("accelerometer is: %d, %d, %d\n", x, y, z);
sensor.updateGyro(); sensor->updateGyro();
int a = sensor.getGyroX(), b = sensor.getGyroY(), c = sensor.getGyroZ(); int a = sensor->getGyroX(),
b = sensor->getGyroY(),
c = sensor->getGyroZ();
printf("gyroscope is: %d, %d, %d\n", a, b, c); printf("gyroscope is: %d, %d, %d\n", a, b, c);
int axis, direction; int axis, direction;
sensor.enableShockDetection(true); sensor->enableShockDetection(true);
for (int i = 0; i < 300; i++) { for(int i=0; i<300; i++) {
if (sensor.isShockDetected()) { if (sensor->isShockDetected()) {
sensor.getNextShock(); sensor->getNextShock();
axis = sensor.getAxis(); axis = sensor->getAxis();
direction = sensor.getDirection(); direction = sensor->getDirection();
printf("shock data is: %d, %d\n", axis, direction); printf("shock data is: %d, %d\n", axis, direction);
} }
upm_delay_us(10000); usleep(10000);
} }
sensor.updateMotion(); sensor->updateMotion();
int m = sensor.getAccelX(), n = sensor.getAccelY(), o = sensor.getAccelZ(), int m = sensor->getAccelX(),
p = sensor.getGyroX(), q = sensor.getGyroY(), r = sensor.getGyroZ(); n = sensor->getAccelY(),
o = sensor->getAccelZ(),
p = sensor->getGyroX(),
q = sensor->getGyroY(),
r = sensor->getGyroZ();
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r); printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
delete sensor;
//! [Interesting] //! [Interesting]
return 0; return 0;

Some files were not shown because too many files have changed in this diff Show More