mirror of
https://github.com/eclipse/upm.git
synced 2025-07-06 20:01:12 +03:00
Compare commits
2 Commits
v1.6.0
...
iio_change
Author | SHA1 | Date | |
---|---|---|---|
93054c382b | |||
6ac2557b7d |
@ -7,7 +7,10 @@ services:
|
||||
- docker
|
||||
|
||||
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:
|
||||
fast_finish: true
|
||||
@ -68,8 +71,6 @@ jobs:
|
||||
- docker-compose run ${TARGET}
|
||||
- <<: *run-additional-jobs
|
||||
env: TARGET=android
|
||||
- <<: *run-additional-jobs
|
||||
env: TARGET=examples
|
||||
- <<: *run-additional-jobs
|
||||
env: TARGET=sonar-scan
|
||||
- <<: *run-additional-jobs
|
||||
|
108
CMakeLists.txt
108
CMakeLists.txt
@ -104,7 +104,6 @@ endif (WERROR)
|
||||
upm_add_compile_flags(C ${C_CXX_WARNING_FLAGS}
|
||||
-Winit-self
|
||||
-Wimplicit
|
||||
-Wsign-compare
|
||||
-Wmissing-parameter-type)
|
||||
|
||||
# Set CXX compiler warning flags at top-level scope and emit a warning about
|
||||
@ -112,7 +111,6 @@ upm_add_compile_flags(C ${C_CXX_WARNING_FLAGS}
|
||||
upm_add_compile_flags(CXX ${C_CXX_WARNING_FLAGS}
|
||||
-Wnon-virtual-dtor
|
||||
-Woverloaded-virtual
|
||||
-Wsign-compare
|
||||
-Wreorder)
|
||||
|
||||
# Allow exception error handling for Android C++
|
||||
@ -125,7 +123,7 @@ find_package (PkgConfig REQUIRED)
|
||||
|
||||
# Force a libmraa search and minimum required version every time a config is generated
|
||||
unset(MRAA_FOUND CACHE)
|
||||
set(MRAA_MINIMUM 1.9.0)
|
||||
set(MRAA_MINIMUM 1.8.0)
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM})
|
||||
# Also, get full path to the mraa library
|
||||
find_library(MRAA_LIBRARY NAMES mraa HINTS ${MRAA_LIBDIR})
|
||||
@ -153,6 +151,11 @@ if (BUILDSWIGNODE)
|
||||
find_package (Node REQUIRED)
|
||||
if (BUILDTESTS)
|
||||
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 (BUILDSWIGNODE)
|
||||
|
||||
@ -213,7 +216,7 @@ include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
# If git_describe fails, use a dirty version
|
||||
if (${VERSION} MATCHES -NOTFOUND)
|
||||
set (VERSION "v1.6.0")
|
||||
set (VERSION "v1.3.0")
|
||||
message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
|
||||
"${VERSION}). Check that git is installed and this is a valid git repo.")
|
||||
endif ()
|
||||
@ -307,71 +310,55 @@ endif()
|
||||
#
|
||||
if (BUILDDOC)
|
||||
# Add a target to generate API documentation with Doxygen
|
||||
find_package (Doxygen 1.8 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)
|
||||
if (BUILDSWIGJAVA)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
|
||||
endif()
|
||||
file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/docs docs/icons/*.png)
|
||||
foreach(PNG_FILE ${PNG_FILES})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
|
||||
endforeach()
|
||||
add_custom_target (doc
|
||||
${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
|
||||
)
|
||||
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")
|
||||
find_package (Doxygen REQUIRED)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
||||
if (BUILDSWIGJAVA)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
|
||||
endif()
|
||||
file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/docs docs/icons/*.png)
|
||||
foreach(PNG_FILE ${PNG_FILES})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
|
||||
endforeach()
|
||||
add_custom_target (doc
|
||||
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||
COMMAND tar -czf html/xml.tar.gz -C xml .
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
||||
)
|
||||
|
||||
# Check if Sphinx is installed and add target to generate API documentation
|
||||
# Currently, the per-module documentation for python is generated from the
|
||||
# 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)
|
||||
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_target (pydoc ALL
|
||||
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
|
||||
DEPENDS doc
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating Python API documentation with Sphinx" VERBATIM
|
||||
)
|
||||
else ()
|
||||
message (SEND_ERROR "ERROR - Failed to find a compatible version of Sphinx. Python API doc will not be generated")
|
||||
endif ()
|
||||
find_package (Sphinx REQUIRED)
|
||||
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_target (pydoc ALL
|
||||
COMMAND rm -r -f ${CMAKE_BINARY_DIR}/pyupm && mkdir -p ${CMAKE_BINARY_DIR}/pyupm
|
||||
COMMAND find ${CMAKE_BINARY_DIR}/src -name "_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
|
||||
COMMAND find ${CMAKE_BINARY_DIR}/src -name "pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
|
||||
COMMAND ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/pyupm
|
||||
# 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
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Sphinx" VERBATIM
|
||||
)
|
||||
endif(BUILDSWIGPYTHON)
|
||||
|
||||
# Check if Yuidoc is installed and add target for API documentation
|
||||
if(BUILDSWIGNODE)
|
||||
find_package (Yuidoc 0.10 REQUIRED)
|
||||
if (YUIDOC_FOUND AND YUIDOC_VERSION VERSION_GREATER "0.10")
|
||||
add_custom_target (jsdoc ALL
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/docgen.js -m upm -i xml -o jsdoc -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
||||
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/tolower.js -i html/node
|
||||
DEPENDS doc
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating Javascript API documentation with Yuidoc" VERBATIM
|
||||
)
|
||||
else ()
|
||||
message (SEND_ERROR "ERROR - Failed to find a compatible version of Yuidoc. Node.js API doc will not be generated")
|
||||
endif ()
|
||||
find_package(Yuidoc REQUIRED)
|
||||
add_custom_target(jsdoc ALL
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/docgen.js -m upm -i xml -o jsdoc -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
||||
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/tolower.js -i html/node
|
||||
DEPENDS doc
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
||||
)
|
||||
endif(BUILDSWIGNODE)
|
||||
endif (BUILDDOC)
|
||||
|
||||
@ -457,5 +444,4 @@ endif()
|
||||
|
||||
# Install C headers
|
||||
install(DIRECTORY include/ DESTINATION include/upm
|
||||
COMPONENT ${CMAKE_PROJECT_NAME}-dev
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
27
README.md
27
README.md
@ -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
|
||||
==============
|
||||
|
||||
@ -15,9 +11,8 @@ corresponding header file and instantiating the associated sensor class. In the
|
||||
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.
|
||||
|
||||
We endorse additions that implement the generic C and C++ interfaces provided
|
||||
with the libraries. Multiple sensor and actuator types have been defined, for
|
||||
instance:
|
||||
C++ interfaces have been defined for the following sensor/actuator types, but
|
||||
they are subject to change:
|
||||
|
||||
* Light controller
|
||||
* Light sensor
|
||||
@ -27,8 +22,8 @@ instance:
|
||||
* Gas sensor
|
||||
* Analog to digital converter
|
||||
|
||||
The developer community is welcome to submit feedback on existing categories or
|
||||
suggest new ones.
|
||||
The developer community is encouraged to help expand the list of supported
|
||||
sensors and actuators and provide feedback on interface design.
|
||||
|
||||
### 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).
|
||||
|
||||
### IDE Support
|
||||
### IDE Integration
|
||||
|
||||
The UPM sensor libraries are directly supported by the IDEs listed on the Intel®
|
||||
Developer Zone Tools & IDEs page.
|
||||
If you would like to create projects and run the UPM samples using an Intel recommended IDE,
|
||||
please refer to the Intel Developer Zone IDE page.
|
||||
|
||||
<a href="https://software.intel.com/iot/tools"><img src="docs/icons/iss.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.
|
||||
<a href="https://software.intel.com/iot/software/ide"><img src="docs/icons/allides.png"/></a>
|
||||
|
||||
### Installing UPM
|
||||
|
||||
@ -138,7 +129,7 @@ unable to compile code that was working fine before a library update, make sure
|
||||
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`
|
||||
widely used libraries including `libupm-grove` and `libupm-i2clcd`!
|
||||
|
||||
### Changelog
|
||||
Version changelog [here](docs/changelog.md).
|
||||
|
@ -1,66 +1,69 @@
|
||||
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
|
||||
macro(add_include_dir dir)
|
||||
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
|
||||
macro(add_include_dir dir)
|
||||
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()
|
||||
endmacro()
|
||||
|
||||
|
||||
find_program (NODEJS_EXECUTABLE NAMES node nodejs
|
||||
HINTS
|
||||
$ENV{NODE_DIR}
|
||||
PATH_SUFFIXES bin
|
||||
DOC "Node.js interpreter")
|
||||
DOC "Node.js interpreter"
|
||||
)
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
# 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)
|
||||
if (UV_ROOT_DIR)
|
||||
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
|
||||
add_include_dir(${UV_ROOT_DIR})
|
||||
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
|
||||
add_include_dir(${UV_ROOT_DIR})
|
||||
endif()
|
||||
|
||||
# Now look for node. Flag an error if not found
|
||||
find_path (NODE_ROOT_DIR
|
||||
NAMES node.h src/node.h
|
||||
PATH_SUFFIXES node node4 node5 node6 node7 node8 nodejs
|
||||
PATHS /usr/include /usr/local/include)
|
||||
|
||||
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h" "src/node.h"
|
||||
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
||||
if (NODE_ROOT_DIR)
|
||||
add_include_dir(${NODE_ROOT_DIR})
|
||||
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
|
||||
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
|
||||
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/node)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
||||
add_include_dir(${NODE_ROOT_DIR}/src)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
||||
add_include_dir(${NODE_ROOT_DIR}/src)
|
||||
add_include_dir(${NODE_ROOT_DIR}/include/node)
|
||||
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/deps/uv/include)
|
||||
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
|
||||
else()
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - node.h not found")
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - node.h not found")
|
||||
endif()
|
||||
|
||||
# Check that v8.h is in NODEJS_INCLUDE_DIRS
|
||||
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
|
||||
if (NOT V8_ROOT_DIR)
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - v8.h not found")
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - v8.h not found")
|
||||
endif()
|
||||
|
||||
# Check that uv.h is in NODEJS_INCLUDE_DIRS
|
||||
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
|
||||
if (NOT UV_ROOT_DIR)
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - uv.h not found")
|
||||
unset(NODEJS_INCLUDE_DIRS)
|
||||
message(ERROR " - uv.h not found")
|
||||
endif()
|
||||
|
||||
find_package_handle_standard_args (Nodejs DEFAULT_MSG
|
||||
NODEJS_EXECUTABLE
|
||||
NODEJS_INCLUDE_DIRS
|
||||
)
|
||||
|
||||
if (NODEJS_EXECUTABLE)
|
||||
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
|
||||
OUTPUT_VARIABLE _VERSION
|
||||
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
||||
OUTPUT_VARIABLE _VERSION
|
||||
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
||||
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
|
||||
OUTPUT_VARIABLE _V8_VERSION
|
||||
RESULT_VARIABLE _V8_RESULT)
|
||||
OUTPUT_VARIABLE _V8_VERSION
|
||||
RESULT_VARIABLE _V8_RESULT)
|
||||
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
||||
string (REPLACE "v" "" NODE_VERSION_STRING "${_VERSION}")
|
||||
string (REPLACE "." ";" _VERSION_LIST "${NODE_VERSION_STRING}")
|
||||
@ -85,15 +88,13 @@ if (NODEJS_EXECUTABLE)
|
||||
set (V8_VERSION_MINOR "28")
|
||||
set (V8_VERSION_PATCH "72")
|
||||
set (V8_VERSION_STRING "3.28.72")
|
||||
message (STATUS "defaulted to node 0.10.30")
|
||||
message ("defaulted to node 0.10.30")
|
||||
endif ()
|
||||
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_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)
|
||||
|
||||
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 ()
|
||||
|
||||
mark_as_advanced (NODEJS_EXECUTABLE)
|
||||
|
@ -1,71 +1,13 @@
|
||||
# FindNpm
|
||||
# --------
|
||||
#
|
||||
# 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
|
||||
# Finding and pointing a variable to the npm executable if found
|
||||
# Only works on Linux systems as of now
|
||||
|
||||
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)
|
||||
# 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)
|
||||
if(NPM_EXECUTABLE)
|
||||
message(STATUS "NPM Executable found at ${NPM_EXECUTABLE}")
|
||||
else()
|
||||
# Fail on REQUIRED
|
||||
if (Npm_FIND_REQUIRED)
|
||||
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)
|
||||
message(ERROR "Unable to find NPM installation, please install NPM")
|
||||
endif()
|
||||
|
@ -17,16 +17,14 @@ find_package_handle_standard_args (Sphinx DEFAULT_MSG
|
||||
SPHINX_API_EXECUTABLE
|
||||
)
|
||||
|
||||
# Get Sphinx Version
|
||||
# Get Sphinx version
|
||||
if (SPHINX_EXECUTABLE)
|
||||
execute_process(COMMAND ${SPHINX_EXECUTABLE} --version
|
||||
OUTPUT_VARIABLE SPHINX_VERSION_STRING
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_STRIP_TRAILING_WHITESPACE)
|
||||
if (SPHINX_VERSION_STRING)
|
||||
string(REPLACE "Sphinx (sphinx-build) " "" SPHINX_VERSION ${SPHINX_VERSION_STRING})
|
||||
message (STATUS "Sphinx version is ${SPHINX_VERSION}")
|
||||
endif ()
|
||||
OUTPUT_VARIABLE SPHINX_VERSION)
|
||||
if(SPHINX_VERSION)
|
||||
string(REGEX MATCH "([0-9]\\.[0-9]\\.[0-9])" SPHINX_VERSION_STR ${SPHINX_VERSION})
|
||||
message (STATUS "Sphinx version is ${SPHINX_VERSION_STR}")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
mark_as_advanced (SPHINX_EXECUTABLE)
|
||||
|
@ -3,7 +3,7 @@ version: '2.1'
|
||||
services:
|
||||
|
||||
base:
|
||||
image: inteliotdevkit/upm-base
|
||||
image: dnoliver/upm-base
|
||||
environment:
|
||||
- http_proxy
|
||||
- https_proxy
|
||||
@ -14,7 +14,7 @@ services:
|
||||
- BUILDSWIGPYTHON=${BUILDSWIGPYTHON:-OFF}
|
||||
- BUILDSWIGJAVA=${BUILDSWIGJAVA:-OFF}
|
||||
- BUILDSWIGNODE=${BUILDSWIGNODE:-OFF}
|
||||
- BUILDEXAMPLES=${BUILDEXAMPLES:-OFF}
|
||||
- BUILDEXAMPLES=${BUILDEXAMPLES:-ON}
|
||||
- IPK=${IPK:-OFF}
|
||||
- RPM=${RPM:-OFF}
|
||||
- NPM=${NPM:-OFF}
|
||||
@ -26,12 +26,9 @@ services:
|
||||
volumes:
|
||||
- .:${UPM_SRC_DIR:-/usr/src/app}
|
||||
|
||||
all:
|
||||
extends: base
|
||||
image: inteliotdevkit/upm-all
|
||||
|
||||
doc:
|
||||
extends: all
|
||||
extends: base
|
||||
image: dnoliver/upm-all
|
||||
environment:
|
||||
- BUILDSWIGPYTHON=ON
|
||||
- BUILDSWIGJAVA=ON
|
||||
@ -39,43 +36,35 @@ services:
|
||||
- BUILDDOC=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && ./scripts/build-doc.sh"
|
||||
|
||||
examples:
|
||||
extends: all
|
||||
environment:
|
||||
- BUILDSWIGPYTHON=ON
|
||||
- BUILDSWIGJAVA=ON
|
||||
- BUILDSWIGNODE=ON
|
||||
- BUILDEXAMPLES=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8"
|
||||
|
||||
ipk:
|
||||
extends: all
|
||||
extends: base
|
||||
environment:
|
||||
- IPK=ON
|
||||
- BUILDDOC=OFF
|
||||
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
|
||||
|
||||
rpm:
|
||||
extends: all
|
||||
extends: doc
|
||||
environment:
|
||||
- RPM=ON
|
||||
- BUILDDOC=OFF
|
||||
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
|
||||
|
||||
npm:
|
||||
extends: all
|
||||
extends: doc
|
||||
environment:
|
||||
- NPM=ON
|
||||
- BUILDDOC=OFF
|
||||
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 npmpkg"
|
||||
|
||||
sonar-scan:
|
||||
extends: all
|
||||
extends: base
|
||||
image: dnoliver/upm-all
|
||||
environment:
|
||||
- BUILDSWIGPYTHON=ON
|
||||
- BUILDSWIGNODE=ON
|
||||
- BUILDSWIGJAVA=ON
|
||||
- BUILDEXAMPLES=ON
|
||||
- BUILDSWIGEXAMPLES=ON
|
||||
- SONAR_TOKEN
|
||||
- SONAR_ORG
|
||||
- SONAR_PROJ_KEY
|
||||
@ -88,36 +77,36 @@ services:
|
||||
|
||||
python:
|
||||
extends: base
|
||||
image: inteliotdevkit/upm-python
|
||||
image: dnoliver/upm-python
|
||||
environment:
|
||||
- BUILDSWIGPYTHON=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
|
||||
|
||||
java:
|
||||
extends: base
|
||||
image: inteliotdevkit/upm-java
|
||||
image: dnoliver/upm-java
|
||||
environment:
|
||||
- BUILDSWIGJAVA=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
|
||||
|
||||
android:
|
||||
extends: java
|
||||
image: inteliotdevkit/upm-android
|
||||
image: dnoliver/upm-android
|
||||
environment:
|
||||
- BUILDTESTS=OFF
|
||||
command: bash -c "./scripts/build-android.sh"
|
||||
|
||||
node4:
|
||||
extends: base
|
||||
image: inteliotdevkit/upm-node4
|
||||
image: dnoliver/upm-node4
|
||||
environment:
|
||||
- BUILDSWIGNODE=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure -E examplenames_js"
|
||||
|
||||
node5:
|
||||
extends: node4
|
||||
image: inteliotdevkit/upm-node5
|
||||
image: dnoliver/upm-node5
|
||||
|
||||
node6:
|
||||
extends: node4
|
||||
image: inteliotdevkit/upm-node6
|
||||
image: dnoliver/upm-node6
|
||||
|
@ -4,23 +4,6 @@ API Changes {#apichanges}
|
||||
Here's a list of other API changes made to the library that break source/binary
|
||||
compatibility between releases:
|
||||
|
||||
# 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
|
||||
|
||||
* **The lsm303 driver has been renamed** There are a variety of
|
||||
@ -149,13 +132,13 @@ compatibility between releases:
|
||||
* **lcm1602/jhd1313m1** These drivers had been rewritten in C, with
|
||||
C++ wrappers and placed into their own libraries in the previous
|
||||
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
|
||||
*jhd1313m1* drivers had their C++ headers renamed to use a **.hxx**
|
||||
suffix.
|
||||
|
||||
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
|
||||
**.hxx** suffix to the normal **.hpp** suffix.
|
||||
|
||||
|
@ -34,12 +34,7 @@ make install
|
||||
|
||||
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
|
||||
doing an out-of-source build may cause issues when rebuilding later on. In many
|
||||
cases you'll need elevated permissions to install:
|
||||
|
||||
~~~~~~~~~~~~~{.sh}
|
||||
sudo make install
|
||||
~~~~~~~~~~~~~
|
||||
doing an out-of-source build may cause issues when rebuilding later on.
|
||||
|
||||
Our cmake configure has a number of options, *cmake-gui* or *ccmake* can show
|
||||
you all the options. The interesting ones are detailed below:
|
||||
@ -106,22 +101,22 @@ make install
|
||||
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
|
||||
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
|
||||
by _pyupm_ (_pyupm_lcd-python2). Modules not using the UPM cmake macros may
|
||||
have different naming. To build the python2 lcd module (and all dependencies),
|
||||
use the following make target:
|
||||
rebuild. For example the lcd module target name is i2clcd. Therefore the python
|
||||
module target name will be prefixed by _pyupm_. Just do the following to build
|
||||
only that module. Modules not using the UPM cmake macros may have different
|
||||
naming.
|
||||
|
||||
~~~~~~~~~~~~~
|
||||
make _pyupm_lcd-python2
|
||||
make _pyupm_i2clcd
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
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
|
||||
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:
|
||||
|
||||
~~~~~~~~~~~~
|
||||
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
|
||||
@ -129,37 +124,9 @@ considered the correct way if including UPM in a build system like cmake or
|
||||
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
|
||||
|
||||
You can use `docker` and `docker-compose` to generate a complete build environment
|
||||
@ -220,7 +187,7 @@ $ docker run \
|
||||
--env BUILDSWIGPYTHON=ON \
|
||||
--env BUILDSWIGJAVA=OFF \
|
||||
--env BUILDSWIGNODE=OFF \
|
||||
inteliotdevkit/upm-python \
|
||||
dnoliver/upm-python \
|
||||
bash -c "./scripts/run-cmake.sh && make -Cbuild"
|
||||
```
|
||||
|
||||
@ -254,6 +221,6 @@ $ docker run \
|
||||
--env http_proxy=$http_proxy \
|
||||
--env https_proxy=$https_proxy \
|
||||
--env no_proxy=$no_proxy \
|
||||
inteliotdevkit/upm-python \
|
||||
dnoliver/upm-python \
|
||||
bash -c "./scripts/run-cmake.sh && make -Cbuild"
|
||||
```
|
||||
|
@ -4,30 +4,6 @@ Changelog {#changelog}
|
||||
Here's a list summarizing some of the key undergoing changes to our library
|
||||
from earlier versions:
|
||||
|
||||
### 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
|
||||
|
||||
* Finalized all required build system and JAVA binding changes to release the
|
||||
|
@ -125,8 +125,6 @@ function make_new_sensor {
|
||||
# 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}*
|
||||
# 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
|
||||
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
|
||||
|
@ -12,87 +12,89 @@ Creating Java Bindings Guide
|
||||
* [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.
|
||||
|
||||
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 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.
|
||||
|
||||
#### 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.:
|
||||
```c++
|
||||
/*
|
||||
* Function reads from sensor, places read value in variable bar and
|
||||
* returns true if succesful. Function returns false if read failed.
|
||||
*/
|
||||
bool func(int *bar);
|
||||
/*
|
||||
* Function reads from sensor, places read value in variable bar and
|
||||
* returns true if succesful. Function returns false if read failed.
|
||||
*/
|
||||
bool func(int *bar);
|
||||
```
|
||||
__Replaced by:__
|
||||
```c++
|
||||
/*
|
||||
* Function reads from sensor and returns read value.
|
||||
* Or throws std::runtime_error if a read error occurs
|
||||
*/
|
||||
int func();
|
||||
/*
|
||||
* Function reads from sensor and returns read value.
|
||||
* Or throws std::runtime_error if a read error occurs
|
||||
*/
|
||||
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.:
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis in the given variables.
|
||||
*/
|
||||
void getAccel(int *accelX, int *accelY, int *accelZ);
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis in the given variables.
|
||||
*/
|
||||
void getAccel(int *accelX, int *accelY, int *accelZ);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
__Replaced by:__
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis as elements of a 3-element array.
|
||||
*/
|
||||
int *getAccel();
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis as elements of a 3-element array.
|
||||
*/
|
||||
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.:
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the light intensity and air pollution
|
||||
*/
|
||||
void getData(int *light, int *air);
|
||||
/*
|
||||
* Function returns the light intensity and air pollution
|
||||
*/
|
||||
void getData(int *light, int *air);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
__Replaced by:__
|
||||
```c++
|
||||
int getLight();
|
||||
int getAir();
|
||||
int getLight();
|
||||
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.
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the light intensity and air pollution
|
||||
*/
|
||||
void getData(int *temp, int *humid);
|
||||
/*
|
||||
* Function returns the light intensity and air pollution
|
||||
*/
|
||||
void getData(int *temp, int *humid);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
__Replaced by:__
|
||||
```c++
|
||||
void getData();
|
||||
int getTemp();
|
||||
int getHumid();
|
||||
void getData();
|
||||
int getTemp();
|
||||
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].
|
||||
@ -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.
|
||||
|
||||
|
||||
### Throwing Exceptions in Java
|
||||
#### Language independent:
|
||||
###Throwing Exceptions in Java
|
||||
####Language independent:
|
||||
The %exception directive allows you to define a general purpose exception handler. For example, you can specify the following:
|
||||
|
||||
```c++
|
||||
@ -124,18 +126,18 @@ The exception.i library file provides support for creating language independent
|
||||
|
||||
|
||||
```c++
|
||||
// Language independent exception handler
|
||||
%include exception.i
|
||||
// Language independent exception handler
|
||||
%include exception.i
|
||||
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch(OutOfMemory) {
|
||||
SWIG_exception(SWIG_MemoryError, "Out of memory");
|
||||
} catch(...) {
|
||||
SWIG_exception(SWIG_RuntimeError,"Unknown exception");
|
||||
}
|
||||
}
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch(OutOfMemory) {
|
||||
SWIG_exception(SWIG_MemoryError, "Out of memory");
|
||||
} catch(...) {
|
||||
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.
|
||||
@ -153,19 +155,19 @@ The upm_exception.i interface file is included in the upm.i file, therefor SWIG
|
||||
* std::exception
|
||||
|
||||
|
||||
#### Java specific:
|
||||
####Java specific:
|
||||
To throw a specific Java exception:
|
||||
|
||||
```c++
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range &e) {
|
||||
jclass clazz = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(clazz, "Range error");
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range &e) {
|
||||
jclass clazz = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(clazz, "Range error");
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```c++
|
||||
%javaexception("java.lang.Exception") {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range &e) {
|
||||
jclass clazz = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(clazz, "Range error");
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
%javaexception("java.lang.Exception") {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range &e) {
|
||||
jclass clazz = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(clazz, "Range error");
|
||||
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:
|
||||
|
||||
```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.
|
||||
|
||||
### 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.:
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis as elements of a 3-element array.
|
||||
*/
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis as elements of a 3-element array.
|
||||
*/
|
||||
|
||||
int *getAccel();
|
||||
int *getAccel();
|
||||
```
|
||||
|
||||
__SWIG:__
|
||||
__SWIG:__
|
||||
```c++
|
||||
%typemap(jni) int* "jintArray"
|
||||
%typemap(jstype) int* "int[]"
|
||||
%typemap(jtype) int* "int[]"
|
||||
%typemap(jni) int* "jintArray"
|
||||
%typemap(jstype) int* "int[]"
|
||||
%typemap(jtype) int* "int[]"
|
||||
|
||||
%typemap(javaout) int* {
|
||||
return $jnicall;
|
||||
}
|
||||
%typemap(javaout) int* {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
%typemap(out) int *getAccel {
|
||||
$result = JCALL1(NewIntArray, jenv, 3);
|
||||
JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const signed int*)$1);
|
||||
}
|
||||
%typemap(out) int *getAccel {
|
||||
$result = JCALL1(NewIntArray, jenv, 3);
|
||||
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.:
|
||||
|
||||
```c++
|
||||
void func(uint8_t *buffer, int length);
|
||||
void func(uint8_t *buffer, int length);
|
||||
```
|
||||
|
||||
__SWIG:__
|
||||
__SWIG:__
|
||||
```c++
|
||||
%typemap(jtype) (uint8_t *buffer, int length) "byte[]"
|
||||
%typemap(jstype) (uint8_t *buffer, int length) "byte[]"
|
||||
%typemap(jni) (uint8_t *buffer, int length) "jbyteArray"
|
||||
%typemap(javain) (uint8_t *buffer, int length) "$javainput"
|
||||
%typemap(jtype) (uint8_t *buffer, int length) "byte[]"
|
||||
%typemap(jstype) (uint8_t *buffer, int length) "byte[]"
|
||||
%typemap(jni) (uint8_t *buffer, int length) "jbyteArray"
|
||||
%typemap(javain) (uint8_t *buffer, int length) "$javainput"
|
||||
|
||||
%typemap(in,numinputs=1) (uint8_t *buffer, int length) {
|
||||
$1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
|
||||
$2 = JCALL1(GetArrayLength, jenv, $input);
|
||||
}
|
||||
%typemap(in,numinputs=1) (uint8_t *buffer, int length) {
|
||||
$1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
|
||||
$2 = JCALL1(GetArrayLength, jenv, $input);
|
||||
}
|
||||
```
|
||||
|
||||
!!!! There is a difference between TYPE *name and TYPE * name in typemaps!!!!!
|
||||
|
||||
|
||||
### 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.
|
||||
###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 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.
|
||||
|
||||
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/javaupm_a110x.i:
|
||||
```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++
|
||||
SWIGINTERN void upm_A110X_installISR__SWIG_1(upm::A110X *self,jobject runnable){
|
||||
self->installISR(mraa_java_isr_callback, runnable);
|
||||
}
|
||||
public:
|
||||
#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:
|
||||
@ -277,13 +290,13 @@ To use callback in java, we create a ISR class, which implements the Java Runnab
|
||||
```java
|
||||
public class A110X_intrSample {
|
||||
public static int counter=0;
|
||||
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
upm_a110x.A110X hall = new upm_a110x.A110X(2);
|
||||
|
||||
A110XISR callback = new A110XISR();
|
||||
hall.installISR(callback);
|
||||
|
||||
|
||||
while(true){
|
||||
System.out.println("Counter: " + counter);
|
||||
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)
|
||||
```
|
||||
|
||||
|
@ -10,132 +10,93 @@ sensors that you want to add to UPM:
|
||||
- Have the specific sensor manufacturer/model & version that you used, if you
|
||||
support multiple versions please list.
|
||||
- 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 /** */.
|
||||
|
||||
We currently document our libraries in the following way:
|
||||
####The sensor block
|
||||
|
||||
* **Doxygen** is used for documenting the API and generating the categories on
|
||||
the [UPM Libraries page](https://iotdk.intel.com/docs/master/upm/modules.html).
|
||||
You can learn more about the Doxygen syntax [here](http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html).
|
||||
* **JSON** is used to provide sensor specifications, descriptions, supported
|
||||
platforms, links and other details.
|
||||
This is added just before the class declaration in your header(.h) file and has
|
||||
mandatory fields. For single sensor libraries, this block will actually
|
||||
follow immediately after the library block. If you have multiple physical
|
||||
sensors, add this to every one.
|
||||
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.
|
||||
|
||||
### The library JSON file
|
||||
|
||||
Let's use the BME280 class snippet from the bmp280.json file as an example:
|
||||
|
||||
```json
|
||||
{
|
||||
"Library": "bmp280",
|
||||
"Description": "Bosch Atmospheric Sensor Library",
|
||||
"Sensor Class":
|
||||
{
|
||||
"BME280":
|
||||
{
|
||||
"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",
|
||||
"Aliases": ["bme280", "Grove - Barometer Sensor(BME280)"],
|
||||
"Categories": ["pressure", "humidity", "temperature"],
|
||||
"Connections": ["gpio", "i2c", "spi"],
|
||||
"Project Type": ["prototyping", "industrial"],
|
||||
"Manufacturers": ["adafruit", "seeed", "bosch"],
|
||||
"Examples":
|
||||
{
|
||||
"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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@verbatim
|
||||
/**
|
||||
* @library <lib-name>
|
||||
* @sensor <chip-id>
|
||||
* @comname <component-name>
|
||||
* @altname <alt-name>
|
||||
* @altid <alt-id>
|
||||
* @type <component-category>
|
||||
* @man <component-manufacturer>
|
||||
* @web <component-weblinks>
|
||||
* @con <connection-type>
|
||||
* @kit <component-kit>
|
||||
*
|
||||
* @brief Short class/sensor description
|
||||
*
|
||||
* Then add a longer
|
||||
* description here.
|
||||
*
|
||||
* @image html <component-img.jpeg>
|
||||
* @snippet <example-name.cxx> Interesting
|
||||
*/
|
||||
@endverbatim
|
||||
```
|
||||
|
||||
#### 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
|
||||
a build.
|
||||
- `Description` A short description of the library and what it contains.
|
||||
Optionally, a small representative image can be placed in the "docs/images"
|
||||
subfolder and linked with the "@image" tag.
|
||||
**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.
|
||||
- `Name` Title Case descriptive names for your sensor. Multiple values can be
|
||||
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.
|
||||
```
|
||||
@verbatim
|
||||
//! [Interesting]
|
||||
|
||||
#### Optional and customizable fields
|
||||
...example code here...
|
||||
|
||||
- `Kits` Specifies if the sensor is part of a kit. Accepted values are listed
|
||||
in the groups.md file.
|
||||
- `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.
|
||||
//! [Interesting]
|
||||
@endverbatim
|
||||
```
|
||||
|
||||
As mentioned, accepted values for some of the fields are listed under the
|
||||
[groups.md](../src/groups.md) file. If needed, you can add new categories
|
||||
for your sensor library following the existing format.
|
||||
For more examples take a look at the existing headers in our github repository.
|
||||
|
||||
JSON files are automatically checked for correctness and required fields on
|
||||
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
|
||||
####The library block
|
||||
|
||||
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
|
||||
per library.
|
||||
|
||||
You should end up with something like this (disregard the "@verbatim" tags in
|
||||
your actual code):
|
||||
You should end up with something like this:
|
||||
|
||||
```
|
||||
@verbatim
|
||||
@ -150,43 +111,8 @@ your actual code):
|
||||
@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,
|
||||
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.
|
||||
|
||||
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.
|
||||
|
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 |
@ -48,11 +48,11 @@ To install:
|
||||
```bash
|
||||
sudo add-apt-repository ppa:mraa/mraa
|
||||
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
|
||||
(e.g. run with `sudo`).
|
||||
Note that the Ubuntu PPA only provides the C/C++ and Python packages. Node.js
|
||||
developers will have to install MRAA and UPM using NPM instead.
|
||||
|
||||
### Node.js bindings only (NPM)
|
||||
|
||||
|
@ -702,7 +702,7 @@ CITE_BIB_FILES =
|
||||
# messages are off.
|
||||
# The default value is: NO.
|
||||
|
||||
QUIET = YES
|
||||
QUIET = NO
|
||||
|
||||
# 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
|
||||
@ -860,8 +860,7 @@ EXCLUDE_SYMLINKS = NO
|
||||
# bmi160 driver contains code provided by bosch. This source contains
|
||||
# tags which are picked up by doxygen (namely \mainpage) and
|
||||
# incorrectly get added to docs.
|
||||
EXCLUDE_PATTERNS = bosch_* \
|
||||
sensortemplate*
|
||||
EXCLUDE_PATTERNS = bosch_*
|
||||
|
||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||
|
@ -702,7 +702,7 @@ CITE_BIB_FILES =
|
||||
# messages are off.
|
||||
# The default value is: NO.
|
||||
|
||||
QUIET = YES
|
||||
QUIET = NO
|
||||
|
||||
# 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
|
||||
|
@ -59,8 +59,8 @@ rpr220.cxx RPR220Sample.java rpr220.js rpr220.py
|
||||
rpr220-intr.cxx RPR220_intrSample.java rpr220-intr.js rpr220-intr.py
|
||||
slide.cxx SlideSample.java slide.js slide.py
|
||||
speaker.cxx SpeakerSample.java speaker.js speaker.py
|
||||
lcd-ssd1308-oled.cxx SSD1308_oledSample.java ssd1308-oled.js ssd1308-oled.py
|
||||
lcd-ssd1327-oled.cxx SSD1327_oledSample.java ssd1327-oled.js ssd1327-oled.py
|
||||
i2clcd-ssd1308-oled.cxx SSD1308_oledSample.java ssd1308-oled.js ssd1308-oled.py
|
||||
i2clcd-ssd1327-oled.cxx SSD1327_oledSample.java ssd1327-oled.js ssd1327-oled.py
|
||||
st7735.cxx ST7735Sample.java st7735.js st7735.py
|
||||
stepmotor.cxx StepMotorSample.java stepmotor.js stepmotor.py
|
||||
tm1637.cxx TM1637Sample.java tm1637.js tm1637.py
|
||||
|
@ -41,7 +41,7 @@
|
||||
# a110x.c Requires libupmc-a110x
|
||||
# lcm1602-i2c.c Requires libupmc-lcm1602
|
||||
# bmp280-bme280.c Requires libupmc-bmp280
|
||||
# lcd-eboled.cxx Requires libupm-lcd
|
||||
# i2clcd-eboled.cxx Requires libupm-i2clcd
|
||||
#
|
||||
#
|
||||
function (add_example example_src)
|
||||
@ -99,7 +99,7 @@ function (add_example example_src)
|
||||
|
||||
# Add each dependency to the library target
|
||||
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 ()
|
||||
endfunction (add_example example_src)
|
||||
|
||||
@ -117,16 +117,4 @@ if(BUILDEXAMPLES)
|
||||
if(BUILDSWIGJAVA)
|
||||
add_subdirectory (java)
|
||||
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()
|
||||
|
@ -22,58 +22,55 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "a110x.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
// Our pulse counter
|
||||
volatile unsigned int counter = 0;
|
||||
|
||||
// Our interrupt handler
|
||||
void
|
||||
hallISR(void* arg)
|
||||
void hallISR(void *arg)
|
||||
{
|
||||
counter++;
|
||||
counter++;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an A110X sensor on digital pin D2
|
||||
upm::A110X hall(2);
|
||||
//! [Interesting]
|
||||
// Instantiate an A110X sensor on digital pin D2
|
||||
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
|
||||
// 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);
|
||||
|
||||
hall.installISR(hallISR, NULL);
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Pulses detected: " << counter << endl;
|
||||
|
||||
while (shouldRun) {
|
||||
cout << "Pulses detected: " << counter << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
delete hall;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,46 +22,46 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "a110x.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an A110X sensor on digital pin D2
|
||||
upm::A110X hall(2);
|
||||
//! [Interesting]
|
||||
// Instantiate an A110X sensor on digital pin D2
|
||||
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
|
||||
// polarity)
|
||||
while (shouldRun) {
|
||||
bool val = hall.magnetDetected();
|
||||
if (val)
|
||||
cout << "Magnet (south polarity) detected." << endl;
|
||||
else
|
||||
cout << "No magnet detected." << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
delete hall;
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,42 +21,41 @@
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "abp.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
// 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) {
|
||||
abp.update();
|
||||
cout << "Retrieved pressure: " << abp.getPressure() << endl;
|
||||
cout << "Retrieved Temperature: " << abp.getTemperature() << endl;
|
||||
abp->update();
|
||||
cout << "Retrieved pressure: " << abp->getPressure() << endl;
|
||||
cout << "Retrieved Temperature: " << abp->getTemperature() << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete abp;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,45 +22,44 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ad8232.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
|
||||
// and an analog pin, 0 (OUTPUT)
|
||||
upm::AD8232 ad8232(10, 11, 0);
|
||||
|
||||
// Output the raw numbers from the ADC, for plotting elsewhere.
|
||||
// A return of 0 indicates a Lead Off (LO) condition.
|
||||
// In theory, this data could be fed to software like Processing
|
||||
// (https://www.processing.org/) to plot the data just like an
|
||||
// EKG you would see in a hospital.
|
||||
while (shouldRun) {
|
||||
cout << ad8232.value() << endl;
|
||||
upm_delay_us(1000);
|
||||
//! [Interesting]
|
||||
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
|
||||
// and an analog pin, 0 (OUTPUT)
|
||||
upm::AD8232 *ad8232 = new upm::AD8232(10, 11, 0);
|
||||
|
||||
// Output the raw numbers from the ADC, for plotting elsewhere.
|
||||
// A return of 0 indicates a Lead Off (LO) condition.
|
||||
// In theory, this data could be fed to software like Processing
|
||||
// (https://www.processing.org/) to plot the data just like an
|
||||
// EKG you would see in a hospital.
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << ad8232->value() << endl;
|
||||
usleep(1000);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete ad8232;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,56 +22,61 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "adafruitms1438.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate an Adafruit MS 1438 on I2C bus 0
|
||||
//! [Interesting]
|
||||
// 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
|
||||
ms.disableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||
// disable first, to be safe
|
||||
ms->disableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||
|
||||
// configure for a NEMA-17, 200 steps per revolution
|
||||
ms.stepConfig(AdafruitMS1438::STEPMOTOR_M12, 200);
|
||||
// configure for a NEMA-17, 200 steps per revolution
|
||||
ms->stepConfig(AdafruitMS1438::STEPMOTOR_M12, 200);
|
||||
|
||||
// set speed at 10 RPM's
|
||||
ms.setStepperSpeed(AdafruitMS1438::STEPMOTOR_M12, 10);
|
||||
ms.setStepperDirection(AdafruitMS1438::STEPMOTOR_M12, AdafruitMS1438::DIR_CW);
|
||||
// set speed at 10 RPM's
|
||||
ms->setStepperSpeed(AdafruitMS1438::STEPMOTOR_M12, 10);
|
||||
ms->setStepperDirection(AdafruitMS1438::STEPMOTOR_M12,
|
||||
AdafruitMS1438::DIR_CW);
|
||||
|
||||
// enable
|
||||
cout << "Enabling..." << endl;
|
||||
ms.enableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||
// enable
|
||||
cout << "Enabling..." << endl;
|
||||
ms->enableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||
|
||||
cout << "Rotating 1 full revolution at 10 RPM speed." << endl;
|
||||
ms.stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 200);
|
||||
cout << "Rotating 1 full revolution at 10 RPM speed." << endl;
|
||||
ms->stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 200);
|
||||
|
||||
cout << "Sleeping for 2 seconds..." << endl;
|
||||
upm_delay(2);
|
||||
cout << "Rotating 1/2 revolution in opposite direction at 10 RPM speed." << endl;
|
||||
cout << "Sleeping for 2 seconds..." << endl;
|
||||
sleep(2);
|
||||
cout << "Rotating 1/2 revolution in opposite direction at 10 RPM speed."
|
||||
<< endl;
|
||||
|
||||
ms.setStepperDirection(AdafruitMS1438::STEPMOTOR_M12, AdafruitMS1438::DIR_CCW);
|
||||
ms.stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 100);
|
||||
ms->setStepperDirection(AdafruitMS1438::STEPMOTOR_M12,
|
||||
AdafruitMS1438::DIR_CCW);
|
||||
ms->stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 100);
|
||||
|
||||
cout << "Disabling..." << endl;
|
||||
ms.disableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||
cout << "Disabling..." << endl;
|
||||
ms->disableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
delete ms;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,51 +22,54 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "adafruitms1438.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate an Adafruit MS 1438 on I2C bus 0
|
||||
//! [Interesting]
|
||||
// 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
|
||||
ms.setPWMPeriod(50);
|
||||
// set a PWM period of 50Hz
|
||||
ms->setPWMPeriod(50);
|
||||
|
||||
// disable first, to be safe
|
||||
ms.disableMotor(AdafruitMS1438::MOTOR_M3);
|
||||
// disable first, to be safe
|
||||
ms->disableMotor(AdafruitMS1438::MOTOR_M3);
|
||||
|
||||
// set speed at 50%
|
||||
ms.setMotorSpeed(AdafruitMS1438::MOTOR_M3, 50);
|
||||
ms.setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CW);
|
||||
// set speed at 50%
|
||||
ms->setMotorSpeed(AdafruitMS1438::MOTOR_M3, 50);
|
||||
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;
|
||||
ms.setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CCW);
|
||||
cout << "Reversing M3" << endl;
|
||||
ms->setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CCW);
|
||||
|
||||
upm_delay(3);
|
||||
sleep(3);
|
||||
|
||||
cout << "Stopping M3" << endl;
|
||||
ms.disableMotor(AdafruitMS1438::MOTOR_M3);
|
||||
cout << "Stopping M3" << endl;
|
||||
ms->disableMotor(AdafruitMS1438::MOTOR_M3);
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
delete ms;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,57 +22,56 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Description
|
||||
* Demo program for Adafruit 16 channel servo shield/controller
|
||||
* Physical setup for tests is a single servo attached to one channel.
|
||||
* Note - when 3 or more GWS servos attached results unpredictable.
|
||||
* Adafruit do recommend a Cap be installed on the board which should alleviate
|
||||
* the issue.
|
||||
* Adafruit do recommend a Cap be installed on the board which should alleviate the issue.
|
||||
* I (and Adafruit) are unable to give any Capacitor sizing data.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "adafruitss.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int n;
|
||||
int main() {
|
||||
|
||||
//! [Interesting]
|
||||
upm::adafruitss servos(6, 0x40);
|
||||
int n;
|
||||
|
||||
for (;;) {
|
||||
cout << "Setting all to 0" << endl;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos.servo(n, 1, 0); // GWS Mini Servo = Type 1.
|
||||
upm_delay_us(1000000); // Wait 1 second
|
||||
//! [Interesting]
|
||||
upm::adafruitss* servos = new upm::adafruitss(6,0x40);
|
||||
|
||||
cout << "Setting all to 45" << endl;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos.servo(n, 1, 45);
|
||||
upm_delay_us(1000000); // Wait 1 second
|
||||
for (;;)
|
||||
{
|
||||
cout << "Setting all to 0" << endl;
|
||||
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;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos.servo(n, 1, 90);
|
||||
upm_delay_us(1000000); // Wait 1 second
|
||||
cout << "Setting all to 45" << endl;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos->servo(n, 1, 45);
|
||||
usleep(1000000); // Wait 1 second
|
||||
|
||||
cout << "Setting all to 135" << endl;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos.servo(n, 1, 135);
|
||||
upm_delay_us(1000000); // Wait 1 second
|
||||
cout << "Setting all to 90" << endl;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos->servo(n, 1, 90);
|
||||
usleep(1000000); // Wait 1 second
|
||||
|
||||
cout << "Setting all to 180" << endl;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos.servo(n, 1, 160);
|
||||
upm_delay_us(2000000); // Wait 1 second
|
||||
}
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
cout << "Setting all to 135" << endl;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos->servo(n, 1, 135);
|
||||
usleep(1000000); // Wait 1 second
|
||||
|
||||
cout << "Setting all to 180" << endl;
|
||||
for (n = 0; n < 16; n++)
|
||||
servos->servo(n, 1, 160);
|
||||
usleep(2000000); // Wait 1 second
|
||||
}
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,44 +22,45 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <iostream>
|
||||
#include "adc121c021.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an ADC121C021 on I2C bus 0
|
||||
//! [Interesting]
|
||||
// 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,
|
||||
// must be attached to the adc
|
||||
// Prints the value and corresponding voltage every 50 milliseconds
|
||||
while (shouldRun) {
|
||||
uint16_t val = adc.value();
|
||||
cout << "ADC value: " << val << " Volts = " << adc.valueToVolts(val) << endl;
|
||||
upm_delay_us(50000);
|
||||
// An analog sensor, such as a Grove light sensor,
|
||||
// must be attached to the adc
|
||||
// Prints the value and corresponding voltage every 50 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
uint16_t val = adc->value();
|
||||
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;
|
||||
}
|
||||
|
@ -12,12 +12,9 @@
|
||||
// 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.
|
||||
//
|
||||
// This software has been tested to connect to an ADIS16448 through a level
|
||||
// shifter
|
||||
// such as the TI TXB0104. The SPI lines (DIN, DOUT, SCLK, /CS) are all wired
|
||||
// through
|
||||
// the level shifter and the ADIS16448 is also being powered by the Intel
|
||||
// Edison.
|
||||
// This software has been tested to connect to an ADIS16448 through a level shifter
|
||||
// such as the TI TXB0104. The SPI lines (DIN, DOUT, SCLK, /CS) are all wired 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
|
||||
// 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.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "adis16448.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
while (true) {
|
||||
//! [Interesting]
|
||||
upm::ADIS16448 imu(0, 3); // upm::ADIS16448(SPI,RST)
|
||||
while(true)
|
||||
{
|
||||
//! [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
|
||||
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 << "ZGYRO_OUT:" << imu.gyroScale(imu.regRead(ZGYRO_OUT)) << std::endl;
|
||||
//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 << "YGYRO_OUT:" << imu->gyroScale(imu->regRead(YGYRO_OUT)) << std::endl;
|
||||
std::cout << "ZGYRO_OUT:" << imu->gyroScale(imu->regRead(ZGYRO_OUT)) << std::endl;
|
||||
std::cout << " " << 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 << "ZACCL_OUT:" << imu.accelScale(imu.regRead(ZACCL_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 << "ZACCL_OUT:" << imu->accelScale(imu->regRead(ZACCL_OUT)) << std::endl;
|
||||
std::cout << " " << std::endl;
|
||||
//! [Interesting]
|
||||
upm_delay(1);
|
||||
//! [Interesting]
|
||||
sleep(1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -22,50 +22,59 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <exception>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "ads1015.hpp"
|
||||
#include "iADC.hpp"
|
||||
#include "mraa/gpio.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
#define EDISON_I2C_BUS 1
|
||||
#define FT4222_I2C_BUS 0
|
||||
#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::ADS1015 sensor(EDISON_I2C_BUS);
|
||||
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
|
||||
gpio.dir(mraa::DIR_OUT_HIGH);
|
||||
upm::IADC* adc = NULL;
|
||||
try {
|
||||
adc = new upm::ADS1015(EDISON_I2C_BUS);
|
||||
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;
|
||||
}
|
||||
|
||||
/* Show usage from the IADC interface */
|
||||
upm::IADC* adc = static_cast<upm::IADC*>(&sensor);
|
||||
|
||||
if (adc == NULL) {
|
||||
std::cout << "ADC not detected" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "ADC " << adc->getModuleName() << " detected. ";
|
||||
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
||||
while (true) {
|
||||
for (unsigned int i = 0; i < adc->getNumInputs(); ++i) {
|
||||
std::cout << "Input " << i;
|
||||
try {
|
||||
float voltage = adc->getVoltage(i);
|
||||
std::cout << ": Voltage = " << voltage << "V" << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
int main ()
|
||||
{
|
||||
upm::IADC* adc = getADC();
|
||||
if (adc == NULL) {
|
||||
std::cout << "ADC not detected" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "ADC " << adc->getModuleName() << " detected. " ;
|
||||
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
||||
while (true) {
|
||||
for (unsigned int i=0; i<adc->getNumInputs(); ++i) {
|
||||
std::cout << "Input " << i;
|
||||
try {
|
||||
float voltage = adc->getVoltage(i);
|
||||
std::cout << ": Voltage = " << voltage << "V" << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
delete adc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -29,13 +29,11 @@
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ads1015.hpp"
|
||||
#include "ads1x15.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
@ -43,41 +41,39 @@ using namespace upm;
|
||||
bool running = true; // Controls main read/write loop
|
||||
|
||||
// Thread function
|
||||
void
|
||||
stop()
|
||||
void stop()
|
||||
{
|
||||
upm_delay(10);
|
||||
sleep(10);
|
||||
running = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
//! [Interesting]
|
||||
long id = 0; // Sample number
|
||||
long id = 0; // Sample number
|
||||
string fileName = "./ads1015.data"; // Output filename
|
||||
ofstream f;
|
||||
|
||||
// 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
|
||||
ads1015.getSample(ADS1X15::DIFF_0_1);
|
||||
ads1015->getSample(ADS1X15::DIFF_0_1);
|
||||
|
||||
// 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
|
||||
// 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
|
||||
// sampling
|
||||
ads1015.setSPS(ADS1015::SPS_3300);
|
||||
ads1015.setContinuous(true);
|
||||
ads1015->setSPS(ADS1015::SPS_3300);
|
||||
ads1015->setContinuous(true);
|
||||
|
||||
// Enable exceptions from the output stream
|
||||
f.exceptions(ofstream::failbit | ofstream::badbit);
|
||||
// Open the file
|
||||
try {
|
||||
try{
|
||||
f.open(fileName);
|
||||
|
||||
// Output formatting
|
||||
@ -85,18 +81,19 @@ main()
|
||||
f.precision(7);
|
||||
|
||||
// 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
|
||||
while (running) {
|
||||
f << id++ << " " << ads1015.getLastSample() << endl;
|
||||
upm_delay_us(1000);
|
||||
while(running){
|
||||
f << id++ << " " << ads1015->getLastSample() << endl;
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
// Clean-up and exit
|
||||
timer.join();
|
||||
f.close();
|
||||
} catch (ios_base::failure& e) {
|
||||
delete ads1015;
|
||||
} catch (ios_base::failure &e) {
|
||||
cout << "Failed to write to file: " << e.what() << endl;
|
||||
return 1;
|
||||
}
|
||||
@ -104,3 +101,4 @@ main()
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,11 @@
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ads1115.hpp"
|
||||
#include "ads1x15.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
@ -42,18 +40,16 @@ using namespace upm;
|
||||
bool running = true; // Controls main read/write loop
|
||||
|
||||
// Thread function
|
||||
void
|
||||
stop()
|
||||
void stop()
|
||||
{
|
||||
upm_delay(10);
|
||||
sleep(10);
|
||||
running = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
//! [Interesting]
|
||||
long id = 0; // Sample number
|
||||
long id = 0; // Sample number
|
||||
string fileName = "./ads1115.data"; // Output filename
|
||||
ofstream f;
|
||||
|
||||
@ -61,26 +57,26 @@ main()
|
||||
// There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus
|
||||
// - 0x48 gives access to pins A0 - A3
|
||||
// - 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,
|
||||
// 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
|
||||
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
|
||||
// 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
|
||||
// sampling
|
||||
ads1115.setSPS(ADS1115::SPS_860);
|
||||
ads1115.setContinuous(true);
|
||||
ads1115->setSPS(ADS1115::SPS_860);
|
||||
ads1115->setContinuous(true);
|
||||
|
||||
// Enable exceptions from the output stream
|
||||
f.exceptions(ofstream::failbit | ofstream::badbit);
|
||||
// Open the file
|
||||
try {
|
||||
try{
|
||||
f.open(fileName);
|
||||
|
||||
// Output formatting
|
||||
@ -88,18 +84,19 @@ main()
|
||||
f.precision(7);
|
||||
|
||||
// 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
|
||||
while (running) {
|
||||
f << id++ << " " << ads1115.getLastSample() << endl;
|
||||
upm_delay_us(1000);
|
||||
while(running){
|
||||
f << id++ << " " << ads1115->getLastSample() << endl;
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
// Clean-up and exit
|
||||
timer.join();
|
||||
f.close();
|
||||
} catch (ios_base::failure& e) {
|
||||
delete ads1115;
|
||||
} catch (ios_base::failure &e) {
|
||||
cout << "Failed to write to file: " << e.what() << endl;
|
||||
return 1;
|
||||
}
|
||||
@ -107,3 +104,4 @@ main()
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -22,306 +22,301 @@
|
||||
* 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 "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 {
|
||||
cout << endl;
|
||||
cout << "1 - get Conversion \t";
|
||||
cout << "2 - get last conversion" << endl;
|
||||
cout << "3 - get Gain \t\t";
|
||||
cout << "4 - set Gain" << endl;
|
||||
;
|
||||
cout << "5 - get Data Rate \t";
|
||||
cout << "6 - set Data Rate" << endl;
|
||||
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;
|
||||
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::ADS1015 *ads = new upm::ADS1015(1);
|
||||
upm::ADS1115 *ads = new upm::ADS1115(1, 0x49);
|
||||
float inputVoltage;
|
||||
int ans;
|
||||
|
||||
switch (command) {
|
||||
case 2:
|
||||
cout << ads.getLastSample() << endl;
|
||||
break;
|
||||
case 3:
|
||||
cout << std::hex << ads.getGain() << endl;
|
||||
break;
|
||||
case 5:
|
||||
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;
|
||||
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;
|
||||
do
|
||||
{
|
||||
|
||||
cout << endl;
|
||||
cout << "1 - get Conversion \t" ;
|
||||
cout << "2 - get last conversion" << endl;
|
||||
cout << "3 - get Gain \t\t";
|
||||
cout << "4 - set Gain" << endl;;
|
||||
cout << "5 - get Data Rate \t";
|
||||
cout << "6 - set Data Rate" << endl;
|
||||
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)
|
||||
{
|
||||
case 2:
|
||||
set_rate = ADS1015::SPS_250;
|
||||
cout << ads->getLastSample() << endl;
|
||||
break;
|
||||
case 3:
|
||||
set_rate = ADS1015::SPS_490;
|
||||
break;
|
||||
case 4:
|
||||
set_rate = ADS1015::SPS_920;
|
||||
cout << std::hex << ads->getGain() << endl;
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} while (command != -1);
|
||||
}while (command != -1 );
|
||||
|
||||
//! [Interesting]
|
||||
delete ads;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,58 +22,57 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <string>
|
||||
|
||||
#include "adxl335.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2
|
||||
upm::ADXL335 accel(0, 1, 2);
|
||||
//! [Interesting]
|
||||
// Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2
|
||||
upm::ADXL335* accel = new upm::ADXL335(0, 1, 2);
|
||||
|
||||
cout << "Please make sure the sensor is completely still. Sleeping for"
|
||||
<< " 2 seconds." << endl;
|
||||
upm_delay(2);
|
||||
cout << "Calibrating..." << endl;
|
||||
cout << "Please make sure the sensor is completely still. Sleeping for"
|
||||
<< " 2 seconds." << endl;
|
||||
sleep(2);
|
||||
cout << "Calibrating..." << endl;
|
||||
|
||||
accel.calibrate();
|
||||
accel->calibrate();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
int x, y, z;
|
||||
float aX, aY, aZ;
|
||||
|
||||
while (shouldRun) {
|
||||
int x, y, z;
|
||||
float aX, aY, aZ;
|
||||
accel->values(&x, &y, &z);
|
||||
cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl;
|
||||
|
||||
accel.values(&x, &y, &z);
|
||||
cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl;
|
||||
accel->acceleration(&aX, &aY, &aZ);
|
||||
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);
|
||||
cout << "Acceleration: X: " << aX << "g" << endl;
|
||||
cout << "Acceleration: Y: " << aY << "g" << endl;
|
||||
cout << "Acceleration: Z: " << aZ << "g" << endl;
|
||||
cout << endl;
|
||||
|
||||
upm_delay_us(200000);
|
||||
usleep(200000);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete accel;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,32 +22,30 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include "adxl345.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
int16_t* raw;
|
||||
float* acc;
|
||||
//! [Interesting]
|
||||
int16_t *raw;
|
||||
float *acc;
|
||||
|
||||
// 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) {
|
||||
accel.update(); // Update the data
|
||||
raw = accel.getRawValues(); // Read raw sensor data
|
||||
acc = accel.getAcceleration(); // Read acceleration (g)
|
||||
fprintf(stdout, "Current scale: 0x%2xg\n", accel.getScale());
|
||||
while(true){
|
||||
accel->update(); // Update the data
|
||||
raw = accel->getRawValues(); // Read raw sensor data
|
||||
acc = accel->getAcceleration(); // Read acceleration (g)
|
||||
fprintf(stdout, "Current scale: 0x%2xg\n", accel->getScale());
|
||||
fprintf(stdout, "Raw: %6d %6d %6d\n", raw[0], raw[1], raw[2]);
|
||||
fprintf(stdout, "AccX: %5.2f g\n", acc[0]);
|
||||
fprintf(stdout, "AccY: %5.2f g\n", acc[1]);
|
||||
fprintf(stdout, "AccZ: %5.2f g\n", acc[2]);
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,51 +22,50 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "adxrs610.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and
|
||||
// analog A1 (temp out) with an analog reference voltage of
|
||||
// 5.0
|
||||
upm::ADXRS610 sensor(0, 1, 5.0);
|
||||
// Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and
|
||||
// analog A1 (temp out) with an analog reference voltage of
|
||||
// 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)
|
||||
sensor.setDeadband(0.015);
|
||||
// Every tenth of a second, sample the ADXRS610 and output it's
|
||||
// corresponding temperature and angular velocity
|
||||
|
||||
// Every tenth of a second, sample the ADXRS610 and output it's
|
||||
// corresponding temperature and angular velocity
|
||||
|
||||
while (shouldRun) {
|
||||
cout << "Vel (deg/s): " << sensor.getAngularVelocity() << endl;
|
||||
cout << "Temp (C): " << sensor.getTemperature() << endl;
|
||||
|
||||
upm_delay_us(100000);
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Vel (deg/s): " << sensor->getAngularVelocity() << endl;
|
||||
cout << "Temp (C): " << sensor->getTemperature() << endl;
|
||||
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,15 +22,16 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "am2315.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
volatile int doWork = 0;
|
||||
|
||||
upm::AM2315 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
@ -41,30 +42,34 @@ sig_handler(int signo)
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Register signal handler
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
float humidity = 0.0;
|
||||
float humidity = 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) {
|
||||
humidity = sensor.getHumidity();
|
||||
temperature = sensor.getTemperature();
|
||||
humidity = sensor->getHumidity();
|
||||
temperature = sensor->getTemperature();
|
||||
|
||||
std::cout << "humidity value = " << humidity << ", temperature value = " << temperature
|
||||
<< std::endl;
|
||||
upm_delay_us(500000);
|
||||
std::cout << "humidity value = " <<
|
||||
humidity <<
|
||||
", temperature value = " <<
|
||||
temperature << std::endl;
|
||||
usleep (500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,6 +23,9 @@
|
||||
*/
|
||||
|
||||
#include "apa102.hpp"
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -31,17 +34,18 @@ main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// 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
|
||||
ledStrip.setAllLeds(31, 255, 0, 0);
|
||||
ledStrip->setAllLeds(31, 255, 0, 0);
|
||||
|
||||
// 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
|
||||
ledStrip.setLed(15, 31, 0, 255, 0);
|
||||
ledStrip->setLed(15, 31, 0, 255, 0);
|
||||
|
||||
delete ledStrip;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,41 +22,41 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "apds9002.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Luminance sensor on analog pin A0
|
||||
upm::APDS9002 luminance(0);
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Luminance sensor on analog pin A0
|
||||
upm::APDS9002* luminance = new upm::APDS9002(0);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
int val = luminance->value();
|
||||
cout << "Luminance value is " << val << endl;
|
||||
|
||||
while (shouldRun) {
|
||||
int val = luminance.value();
|
||||
cout << "Luminance value is " << val << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete luminance;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,11 +22,10 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "apds9930.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -45,30 +44,31 @@ main()
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
// 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
|
||||
// sensor
|
||||
light_proximity.enableIlluminance(true);
|
||||
// Kernel driver implement sleep 5000-5100us after enable illuminance sensor
|
||||
light_proximity->enableIlluminance(true);
|
||||
|
||||
// Kernel driver implement upm_delay 5000-5100us after enable proximity sensor
|
||||
light_proximity.enableProximity(true);
|
||||
// Kernel driver implement sleep 5000-5100us after enable proximity sensor
|
||||
light_proximity->enableProximity(true);
|
||||
|
||||
// Tested this value works. Please change it on your platform
|
||||
upm_delay_us(120000);
|
||||
usleep(120000);
|
||||
|
||||
while (shouldRun) {
|
||||
float lux = light_proximity.getAmbient();
|
||||
float lux = light_proximity->getAmbient();
|
||||
cout << "Luminance value is " << lux << endl;
|
||||
float proximity = light_proximity.getProximity();
|
||||
float proximity = light_proximity->getProximity();
|
||||
cout << "Proximity value is " << proximity << endl;
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
light_proximity.enableProximity(false);
|
||||
light_proximity.enableIlluminance(false);
|
||||
light_proximity->enableProximity(false);
|
||||
light_proximity->enableIlluminance(false);
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete light_proximity;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,68 +22,69 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <iostream>
|
||||
#include "at42qt1070.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
void
|
||||
printButtons(upm::AT42QT1070& touch)
|
||||
void printButtons(upm::AT42QT1070 *touch)
|
||||
{
|
||||
bool buttonPressed = false;
|
||||
uint8_t buttons = touch.getButtons();
|
||||
bool buttonPressed = false;
|
||||
uint8_t buttons = touch->getButtons();
|
||||
|
||||
cout << "Buttons Pressed: ";
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (buttons & (1 << i)) {
|
||||
cout << i << " ";
|
||||
buttonPressed = true;
|
||||
cout << "Buttons Pressed: ";
|
||||
for (int i=0; i<7; i++)
|
||||
{
|
||||
if (buttons & (1 << i))
|
||||
{
|
||||
cout << i << " ";
|
||||
buttonPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buttonPressed)
|
||||
cout << "None";
|
||||
if (!buttonPressed)
|
||||
cout << "None";
|
||||
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
|
||||
if (touch.isCalibrating())
|
||||
cout << "Calibration is occurring." << endl;
|
||||
if (touch->isCalibrating())
|
||||
cout << "Calibration is occurring." << endl;
|
||||
|
||||
if (touch.isOverflowed())
|
||||
cout << "Overflow was detected." << endl;
|
||||
if (touch->isOverflowed())
|
||||
cout << "Overflow was detected." << endl;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an AT42QT1070 on I2C bus 0
|
||||
//! [Interesting]
|
||||
// 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) {
|
||||
touch.updateState();
|
||||
printButtons(touch);
|
||||
upm_delay_us(100000);
|
||||
while (shouldRun)
|
||||
{
|
||||
touch->updateState();
|
||||
printButtons(touch);
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
delete touch;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,45 +22,44 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bh1750.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BH1750 sensor using defaults (I2C bus (0), using
|
||||
// the default I2C address (0x23), and setting the mode to highest
|
||||
// resolution, lowest power mode).
|
||||
upm::BH1750 sensor;
|
||||
// Instantiate a BH1750 sensor using defaults (I2C bus (0), using
|
||||
// the default I2C address (0x23), and setting the mode to highest
|
||||
// resolution, lowest power mode).
|
||||
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) {
|
||||
cout << "Detected Light Level (lux): " << sensor.getLux() << endl;
|
||||
upm_delay(1);
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Detected Light Level (lux): " << sensor->getLux() << endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,47 +22,47 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "biss0001.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Motion sensor on GPIO pin D2
|
||||
upm::BISS0001 motion(2);
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Motion sensor on GPIO pin D2
|
||||
upm::BISS0001* motion = new upm::BISS0001(2);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
bool val = motion->value();
|
||||
|
||||
while (shouldRun) {
|
||||
bool val = motion.value();
|
||||
if (val)
|
||||
cout << "Detecting moving object";
|
||||
else
|
||||
cout << "No moving objects detected";
|
||||
|
||||
if (val)
|
||||
cout << "Detecting moving object";
|
||||
else
|
||||
cout << "No moving objects detected";
|
||||
cout << endl;
|
||||
|
||||
cout << endl;
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete motion;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,48 +22,49 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bma220.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMA220 using default parameters (bus 0, addr 0x0a)
|
||||
upm::BMA220 sensor;
|
||||
// Instantiate an BMA220 using default parameters (bus 0, addr 0x0a)
|
||||
upm::BMA220 *sensor = new upm::BMA220();
|
||||
|
||||
// Output data every half second until interrupted
|
||||
while (shouldRun) {
|
||||
sensor.update();
|
||||
// Output data every half second until interrupted
|
||||
while (shouldRun)
|
||||
{
|
||||
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;
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer: ";
|
||||
cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
|
||||
|
||||
upm_delay_us(500000);
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,56 +22,60 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bma250e.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMA250E using default I2C parameters
|
||||
upm::BMA250E sensor;
|
||||
// Instantiate an BMA250E using default I2C parameters
|
||||
upm::BMA250E sensor;
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMA250E(0, -1, 10);
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMA250E(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun) {
|
||||
float x, y, z;
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
|
||||
<< sensor.getTemperature(true) << " F" << endl;
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||
<< " 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;
|
||||
}
|
||||
|
@ -22,56 +22,60 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmg160.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMG160 using default I2C parameters
|
||||
upm::BMG160 sensor;
|
||||
// Instantiate an BMG160 using default I2C parameters
|
||||
upm::BMG160 sensor;
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMG160(0, -1, 10);
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMG160(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun) {
|
||||
float x, y, z;
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
sensor.update();
|
||||
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl;
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " degrees/s"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
|
||||
<< sensor.getTemperature(true) << " F" << endl;
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||
<< " 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;
|
||||
}
|
||||
|
@ -22,57 +22,61 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmi160.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BMI160 instance using default i2c bus and address
|
||||
upm::BMI160 sensor;
|
||||
// Instantiate a BMI160 instance using default i2c bus and address
|
||||
upm::BMI160 *sensor = new upm::BMI160();
|
||||
|
||||
while (shouldRun) {
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
float dataX, dataY, dataZ;
|
||||
float dataX, dataY, dataZ;
|
||||
|
||||
sensor.getAccelerometer(&dataX, &dataY, &dataZ);
|
||||
cout << "Accelerometer: ";
|
||||
cout << "AX: " << dataX << " AY: " << dataY << " AZ: " << dataZ << endl;
|
||||
sensor->getAccelerometer(&dataX, &dataY, &dataZ);
|
||||
cout << "Accelerometer: ";
|
||||
cout << "AX: " << dataX << " AY: " << dataY << " AZ: "
|
||||
<< dataZ << endl;
|
||||
|
||||
sensor.getGyroscope(&dataX, &dataY, &dataZ);
|
||||
cout << "Gryoscope: ";
|
||||
cout << "GX: " << dataX << " GY: " << dataY << " GZ: " << dataZ << endl;
|
||||
sensor->getGyroscope(&dataX, &dataY, &dataZ);
|
||||
cout << "Gryoscope: ";
|
||||
cout << "GX: " << dataX << " GY: " << dataY << " GZ: "
|
||||
<< dataZ << endl;
|
||||
|
||||
sensor.getMagnetometer(&dataX, &dataY, &dataZ);
|
||||
cout << "Magnetometer: ";
|
||||
cout << "MX: " << dataX << " MY: " << dataY << " MZ: " << dataZ << endl;
|
||||
sensor->getMagnetometer(&dataX, &dataY, &dataZ);
|
||||
cout << "Magnetometer: ";
|
||||
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;
|
||||
}
|
||||
|
@ -22,52 +22,55 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmm150.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMM150 using default I2C parameters
|
||||
upm::BMM150 sensor;
|
||||
// Instantiate an BMM150 using default I2C parameters
|
||||
upm::BMM150 sensor;
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMM150(0, -1, 10);
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMM150(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun) {
|
||||
float x, y, z;
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
sensor.update();
|
||||
|
||||
sensor.getMagnetometer(&x, &y, &z);
|
||||
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl;
|
||||
sensor.getMagnetometer(&x, &y, &z);
|
||||
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;
|
||||
}
|
||||
|
@ -22,54 +22,57 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bme280.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BME280 instance using default i2c bus and address
|
||||
upm::BME280 sensor;
|
||||
// Instantiate a BME280 instance using default i2c bus and address
|
||||
upm::BME280 *sensor = new upm::BME280();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BME280(0, -1, 10);
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BME280(0, -1, 10);
|
||||
|
||||
while (shouldRun) {
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
|
||||
<< sensor.getTemperature(true) << " F" << endl;
|
||||
cout << "Pressure: " << sensor.getPressure() << " Pa" << endl;
|
||||
cout << "Computed Altitude: " << sensor.getAltitude() << " m" << endl;
|
||||
cout << "Humidity: " << sensor.getHumidity() << " %RH" << endl;
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
cout << "Pressure: " << sensor->getPressure() << " Pa" << 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;
|
||||
}
|
||||
|
@ -24,53 +24,56 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmp280.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BMP280 instance using default i2c bus and address
|
||||
upm::BMP280 sensor;
|
||||
// Instantiate a BMP280 instance using default i2c bus and address
|
||||
upm::BMP280 *sensor = new upm::BMP280();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BMP280(0, -1, 10);
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BMP280(0, -1, 10);
|
||||
|
||||
while (shouldRun) {
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
|
||||
<< sensor.getTemperature(true) << " F" << endl;
|
||||
cout << "Pressure: " << sensor.getPressure() << " Pa" << endl;
|
||||
cout << "Computed Altitude: " << sensor.getAltitude() << " m" << endl;
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< 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;
|
||||
}
|
||||
|
@ -27,47 +27,52 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmpx8x.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BMPX8X sensor on I2C using defaults.
|
||||
upm::BMPX8X sensor;
|
||||
|
||||
// Print the pressure, altitude, sea level, and
|
||||
// temperature values every 0.5 seconds
|
||||
while (shouldRun) {
|
||||
while (shouldRun)
|
||||
{
|
||||
sensor.update();
|
||||
|
||||
cout << "Pressure: " << sensor.getPressure()
|
||||
<< " Pa, Temperature: " << sensor.getTemperature()
|
||||
<< " C, Altitude: " << sensor.getAltitude()
|
||||
<< " m, Sea level: " << sensor.getSealevelPressure() << " Pa" << endl;
|
||||
cout << "Pressure: "
|
||||
<< sensor.getPressure()
|
||||
<< " Pa, Temperature: "
|
||||
<< sensor.getTemperature()
|
||||
<< " C, Altitude: "
|
||||
<< sensor.getAltitude()
|
||||
<< " m, Sea level: "
|
||||
<< sensor.getSealevelPressure()
|
||||
<< " Pa"
|
||||
<< endl;
|
||||
|
||||
upm_delay_us(500000);
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,52 +22,59 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmc150.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMC150 using default I2C parameters
|
||||
upm::BMC150 sensor;
|
||||
// Instantiate an BMC150 using default I2C parameters
|
||||
upm::BMC150 sensor;
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun) {
|
||||
float x, y, z;
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor.getMagnetometer(&x, &y, &z);
|
||||
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl;
|
||||
sensor.getMagnetometer(&x, &y, &z);
|
||||
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;
|
||||
}
|
||||
|
@ -22,52 +22,59 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmi055.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMI055 using default I2C parameters
|
||||
upm::BMI055 sensor;
|
||||
// Instantiate an BMI055 using default I2C parameters
|
||||
upm::BMI055 sensor;
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun) {
|
||||
float x, y, z;
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl;
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
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;
|
||||
}
|
||||
|
@ -22,55 +22,66 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmx055.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMX055 using default I2C parameters
|
||||
upm::BMX055 sensor;
|
||||
// Instantiate an BMX055 using default I2C parameters
|
||||
upm::BMX055 sensor;
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun) {
|
||||
float x, y, z;
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl;
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " degrees/s"
|
||||
<< endl;
|
||||
|
||||
sensor.getMagnetometer(&x, &y, &z);
|
||||
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl;
|
||||
sensor.getMagnetometer(&x, &y, &z);
|
||||
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;
|
||||
}
|
||||
|
@ -22,82 +22,108 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bno055.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BNO055 using default parameters (bus 0, addr
|
||||
// 0x28). The default running mode is NDOF absolute orientation
|
||||
// mode.
|
||||
upm::BNO055 sensor;
|
||||
// Instantiate an BNO055 using default parameters (bus 0, addr
|
||||
// 0x28). The default running mode is NDOF absolute orientation
|
||||
// mode.
|
||||
upm::BNO055 *sensor = new upm::BNO055();
|
||||
|
||||
// First we need to calibrate....
|
||||
cout << "First we need to calibrate. 4 numbers will be output every" << endl;
|
||||
cout << "second for each sensor. 0 means uncalibrated, and 3 means" << endl;
|
||||
cout << "fully calibrated." << endl;
|
||||
cout << "See the UPM documentation on this sensor for instructions on" << endl;
|
||||
cout << "what actions are required to calibrate." << endl;
|
||||
cout << endl;
|
||||
// First we need to calibrate....
|
||||
cout << "First we need to calibrate. 4 numbers will be output every"
|
||||
<< endl;
|
||||
cout << "second for each sensor. 0 means uncalibrated, and 3 means"
|
||||
<< endl;
|
||||
cout << "fully calibrated."
|
||||
<< 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...
|
||||
while (shouldRun && !sensor.isFullyCalibrated()) {
|
||||
int mag, acc, gyr, sys;
|
||||
sensor.getCalibrationStatus(&mag, &acc, &gyr, &sys);
|
||||
// do the calibration...
|
||||
while (shouldRun && !sensor->isFullyCalibrated())
|
||||
{
|
||||
int mag, acc, gyr, sys;
|
||||
sensor->getCalibrationStatus(&mag, &acc, &gyr, &sys);
|
||||
|
||||
cout << "Magnetometer: " << mag << " Accelerometer: " << acc << " Gyroscope: " << gyr
|
||||
<< " System: " << sys << endl;
|
||||
cout << "Magnetometer: " << mag
|
||||
<< " Accelerometer: " << acc
|
||||
<< " Gyroscope: " << gyr
|
||||
<< " System: " << sys
|
||||
<< endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
cout << "Calibration complete." << endl;
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
cout << "Calibration complete." << endl;
|
||||
cout << endl;
|
||||
|
||||
// now output various fusion data every 250 milliseconds
|
||||
while (shouldRun) {
|
||||
float w, x, y, z;
|
||||
// now output various fusion data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float w, x, y, z;
|
||||
|
||||
sensor.update();
|
||||
sensor->update();
|
||||
|
||||
sensor.getEulerAngles(&x, &y, &z);
|
||||
cout << "Euler: Heading: " << x << " Roll: " << y << " Pitch: " << z << " degrees" << endl;
|
||||
sensor->getEulerAngles(&x, &y, &z);
|
||||
cout << "Euler: Heading: " << x
|
||||
<< " Roll: " << y
|
||||
<< " Pitch: " << z
|
||||
<< " degrees"
|
||||
<< endl;
|
||||
|
||||
sensor.getQuaternions(&w, &x, &y, &z);
|
||||
cout << "Quaternion: W: " << w << " X: " << x << " Y: " << y << " Z: " << z << endl;
|
||||
sensor->getQuaternions(&w, &x, &y, &z);
|
||||
cout << "Quaternion: W: " << w
|
||||
<< " X: " << x
|
||||
<< " Y: " << y
|
||||
<< " Z: " << z
|
||||
<< endl;
|
||||
|
||||
sensor.getLinearAcceleration(&x, &y, &z);
|
||||
cout << "Linear Acceleration: X: " << x << " Y: " << y << " Z: " << z << " m/s^2" << endl;
|
||||
sensor->getLinearAcceleration(&x, &y, &z);
|
||||
cout << "Linear Acceleration: X: " << x
|
||||
<< " Y: " << y
|
||||
<< " Z: " << z
|
||||
<< " m/s^2"
|
||||
<< endl;
|
||||
|
||||
sensor.getGravityVectors(&x, &y, &z);
|
||||
cout << "Gravity Vector: X: " << x << " Y: " << y << " Z: " << z << " m/s^2" << endl;
|
||||
sensor->getGravityVectors(&x, &y, &z);
|
||||
cout << "Gravity Vector: X: " << x
|
||||
<< " Y: " << y
|
||||
<< " Z: " << z
|
||||
<< " m/s^2"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
upm_delay_us(250000);
|
||||
cout << endl;
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,28 +22,28 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "button.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// This example uses GPIO 0
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// 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
|
||||
while (1) {
|
||||
std::cout << button.name() << " value is " << button.value() << std::endl;
|
||||
upm_delay(1);
|
||||
while( 1 ) {
|
||||
std::cout << button->name() << " value is " << button->value() << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the button object
|
||||
//! [Interesting]
|
||||
delete button;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,32 +22,37 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <signal.h>
|
||||
#include "buzzer.hpp"
|
||||
#include "buzzer_tones.h"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
main(int argc, char **argv) {
|
||||
//! [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
|
||||
upm::Buzzer sound(5);
|
||||
upm::Buzzer* sound = new upm::Buzzer(5);
|
||||
// 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
|
||||
// for 0.1 seconds between notes
|
||||
for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
|
||||
std::cout << sound.playSound(chord[chord_ind], 500000) << std::endl;
|
||||
for (int chord_ind = 0; chord_ind < 7; chord_ind++)
|
||||
{
|
||||
std::cout << sound->playSound(chord[chord_ind], 500000) << std::endl;
|
||||
upm_delay_ms(100);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sound;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,54 +22,56 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "cjq4435.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
// 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.enable(true);
|
||||
mosfet->setPeriodMS(10);
|
||||
mosfet->enable(true);
|
||||
|
||||
while (shouldRun) {
|
||||
while (shouldRun)
|
||||
{
|
||||
// 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) {
|
||||
mosfet.setDutyCycle(i);
|
||||
upm_delay_us(100000);
|
||||
for (float i=0.0; i <= 1.0; i+=0.1)
|
||||
{
|
||||
mosfet->setDutyCycle(i);
|
||||
usleep(100000);
|
||||
}
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
// Now take it back down
|
||||
// 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) {
|
||||
mosfet.setDutyCycle(i);
|
||||
upm_delay_us(100000);
|
||||
for (float i=1.0; i >= 0.0; i-=0.1)
|
||||
{
|
||||
mosfet->setDutyCycle(i);
|
||||
usleep(100000);
|
||||
}
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete mosfet;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,45 +22,48 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "collision.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Collision Sensor
|
||||
// Instantiate a Collision on digital pin D2
|
||||
upm::Collision collision(2);
|
||||
//! [Interesting]
|
||||
// The was tested with the Collision Sensor
|
||||
// Instantiate a Collision on digital pin D2
|
||||
upm::Collision* collision = new upm::Collision(2);
|
||||
|
||||
bool collisionState = false;
|
||||
cout << "No collision" << endl;
|
||||
while (shouldRun) {
|
||||
if (collision.isColliding() && !collisionState) {
|
||||
cout << "Collision!" << endl;
|
||||
collisionState = true;
|
||||
} else if (collisionState) {
|
||||
cout << "No collision" << endl;
|
||||
collisionState = false;
|
||||
}
|
||||
}
|
||||
bool collisionState = false;
|
||||
cout << "No collision" << endl;
|
||||
while (shouldRun)
|
||||
{
|
||||
if (collision->isColliding() && !collisionState)
|
||||
{
|
||||
cout << "Collision!" << endl;
|
||||
collisionState = true;
|
||||
}
|
||||
else if (collisionState)
|
||||
{
|
||||
cout << "No collision" << endl;
|
||||
collisionState = false;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete collision;
|
||||
return 0;
|
||||
}
|
||||
|
@ -24,50 +24,58 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "curieimu.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
#include "mraa/firmata.h"
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
mraa_init();
|
||||
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();
|
||||
int x = sensor.getAccelX(), y = sensor.getAccelY(), z = sensor.getAccelZ();
|
||||
sensor->updateAccel();
|
||||
int x = sensor->getAccelX(),
|
||||
y = sensor->getAccelY(),
|
||||
z = sensor->getAccelZ();
|
||||
printf("accelerometer is: %d, %d, %d\n", x, y, z);
|
||||
|
||||
sensor.updateGyro();
|
||||
int a = sensor.getGyroX(), b = sensor.getGyroY(), c = sensor.getGyroZ();
|
||||
sensor->updateGyro();
|
||||
int a = sensor->getGyroX(),
|
||||
b = sensor->getGyroY(),
|
||||
c = sensor->getGyroZ();
|
||||
printf("gyroscope is: %d, %d, %d\n", a, b, c);
|
||||
|
||||
int axis, direction;
|
||||
sensor.enableShockDetection(true);
|
||||
for (int i = 0; i < 300; i++) {
|
||||
if (sensor.isShockDetected()) {
|
||||
sensor.getNextShock();
|
||||
axis = sensor.getAxis();
|
||||
direction = sensor.getDirection();
|
||||
printf("shock data is: %d, %d\n", axis, direction);
|
||||
}
|
||||
upm_delay_us(10000);
|
||||
sensor->enableShockDetection(true);
|
||||
for(int i=0; i<300; i++) {
|
||||
if (sensor->isShockDetected()) {
|
||||
sensor->getNextShock();
|
||||
axis = sensor->getAxis();
|
||||
direction = sensor->getDirection();
|
||||
printf("shock data is: %d, %d\n", axis, direction);
|
||||
}
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
sensor.updateMotion();
|
||||
int m = sensor.getAccelX(), n = sensor.getAccelY(), o = sensor.getAccelZ(),
|
||||
p = sensor.getGyroX(), q = sensor.getGyroY(), r = sensor.getGyroZ();
|
||||
sensor->updateMotion();
|
||||
int m = sensor->getAccelX(),
|
||||
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);
|
||||
|
||||
delete sensor;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
|
@ -22,57 +22,61 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "cwlsxxa.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Initializing..." << endl;
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||
// humidity and A2 for temperature
|
||||
upm::CWLSXXA sensor(0, 1, 2);
|
||||
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||
// humidity and A2 for temperature
|
||||
upm::CWLSXXA *sensor = new upm::CWLSXXA(0, 1, 2);
|
||||
|
||||
// update and print available values every second
|
||||
while (shouldRun) {
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
// update and print available values every second
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Temperature: " << sensor.getTemperature() << " C / " << sensor.getTemperature(true)
|
||||
<< " F" << endl;
|
||||
// we show both C and F for temperature
|
||||
cout << "Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << "Humidity: " << sensor.getHumidity() << " %" << endl;
|
||||
cout << "Humidity: " << sensor->getHumidity()
|
||||
<< " %" << endl;
|
||||
|
||||
cout << "CO2: " << sensor.getCO2() << " ppm" << endl;
|
||||
cout << "CO2: " << sensor->getCO2()
|
||||
<< " ppm" << endl;
|
||||
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
//! [Interesting]
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,53 +22,60 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "dfrec.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a DFRobot EC sensor on analog pin A0, with a ds18b20
|
||||
// temperature sensor connected to UART 0, and a device index (for
|
||||
// the ds1820b uart bus) of 0, and an analog reference voltage of
|
||||
// 5.0.
|
||||
upm::DFREC sensor(0, 0, 0, 5.0);
|
||||
// Instantiate a DFRobot EC sensor on analog pin A0, with a ds18b20
|
||||
// temperature sensor connected to UART 0, and a device index (for
|
||||
// the ds1820b uart bus) of 0, and an analog reference voltage of
|
||||
// 5.0.
|
||||
upm::DFREC *sensor = new upm::DFREC(0, 0, 0, 5.0);
|
||||
|
||||
// Every 2 seconds, update and print values
|
||||
while (shouldRun) {
|
||||
sensor.update();
|
||||
// Every 2 seconds, update and print values
|
||||
while (shouldRun)
|
||||
{
|
||||
sensor->update();
|
||||
|
||||
cout << "EC = " << sensor.getEC() << " ms/cm" << endl;
|
||||
cout << "EC = "
|
||||
<< sensor->getEC()
|
||||
<< " ms/cm"
|
||||
<< endl;
|
||||
|
||||
cout << "Volts = " << sensor.getVolts() << ", Temperature = " << sensor.getTemperature()
|
||||
<< " C" << endl;
|
||||
cout << "Volts = "
|
||||
<< sensor->getVolts()
|
||||
<< ", Temperature = "
|
||||
<< sensor->getTemperature()
|
||||
<< " C"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
|
||||
upm_delay(2);
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,63 +22,66 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "dfrorp.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a DFRobot ORP sensor on analog pin A0 with an analog
|
||||
// reference voltage of 5.0.
|
||||
upm::DFRORP sensor(0, 5.0);
|
||||
// Instantiate a DFRobot ORP sensor on analog pin A0 with an analog
|
||||
// reference voltage of 5.0.
|
||||
upm::DFRORP *sensor = new upm::DFRORP(0, 5.0);
|
||||
|
||||
// To calibrate:
|
||||
//
|
||||
// Disconnect the sensor probe (but leave the sensor interface board
|
||||
// connected). Then run one of the examples while holding down the
|
||||
// 'calibrate' button on the device. Read the ORP value reported
|
||||
// (it should be fairly small).
|
||||
//
|
||||
// This value is what you should supply to setCalibrationOffset().
|
||||
// Then reconnect the probe to the interface board and you should be
|
||||
// ready to go.
|
||||
//
|
||||
// DO NOT press the calibrate button on the interface board while
|
||||
// the probe is attached or you can permanently damage the probe.
|
||||
sensor.setCalibrationOffset(0.97);
|
||||
// To calibrate:
|
||||
//
|
||||
// Disconnect the sensor probe (but leave the sensor interface board
|
||||
// connected). Then run one of the examples while holding down the
|
||||
// 'calibrate' button on the device. Read the ORP value reported
|
||||
// (it should be fairly small).
|
||||
//
|
||||
// This value is what you should supply to setCalibrationOffset().
|
||||
// Then reconnect the probe to the interface board and you should be
|
||||
// ready to go.
|
||||
//
|
||||
// DO NOT press the calibrate button on the interface board while
|
||||
// the probe is attached or you can permanently damage the probe.
|
||||
sensor->setCalibrationOffset(0.97);
|
||||
|
||||
// Every second, update and print values
|
||||
while (shouldRun) {
|
||||
sensor.update();
|
||||
// Every second, update and print values
|
||||
while (shouldRun)
|
||||
{
|
||||
sensor->update();
|
||||
|
||||
cout << "ORP: " << sensor.getORP() << " mV" << endl;
|
||||
cout << "ORP: "
|
||||
<< sensor->getORP()
|
||||
<< " mV"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,55 +22,55 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "dfrph.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
#define DFRPH_AREF 5.0
|
||||
#define DFRPH_AREF 5.0
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a DFRPH sensor on analog pin A0, with an analog
|
||||
// reference voltage of DFRPH_AREF
|
||||
upm::DFRPH sensor(0, DFRPH_AREF);
|
||||
// Instantiate a DFRPH sensor on analog pin A0, with an analog
|
||||
// reference voltage of DFRPH_AREF
|
||||
upm::DFRPH *sensor = new upm::DFRPH(0, DFRPH_AREF);
|
||||
|
||||
|
||||
// After calibration, set the offset (based on calibration with a pH
|
||||
// 7.0 buffer solution). See the UPM sensor documentation for
|
||||
// calibrations instructions.
|
||||
sensor.setOffset(0.065);
|
||||
// After calibration, set the offset (based on calibration with a pH
|
||||
// 7.0 buffer solution). See the UPM sensor documentation for
|
||||
// calibrations instructions.
|
||||
sensor->setOffset(0.065);
|
||||
|
||||
// Every second, sample the pH and output it's corresponding
|
||||
// analog voltage.
|
||||
// Every second, sample the pH and output it's corresponding
|
||||
// analog voltage.
|
||||
|
||||
while (shouldRun) {
|
||||
cout << "Detected volts: " << sensor.volts() << endl;
|
||||
cout << "pH value: " << sensor.pH() << endl;
|
||||
cout << endl;
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Detected volts: " << sensor->volts() << endl;
|
||||
cout << "pH value: " << sensor->pH() << endl;
|
||||
cout << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,54 +22,56 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "ds1307.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
printTime(upm::DS1307& rtc)
|
||||
void printTime(upm::DS1307 *rtc)
|
||||
{
|
||||
cout << "The time is: " << rtc.month << "/" << rtc.dayOfMonth << "/" << rtc.year << " "
|
||||
<< rtc.hours << ":" << rtc.minutes << ":" << rtc.seconds;
|
||||
cout << "The time is: " <<
|
||||
rtc->month << "/" << rtc->dayOfMonth << "/" << rtc->year << " "
|
||||
<< rtc->hours << ":" << rtc->minutes << ":" << rtc->seconds;
|
||||
|
||||
if (rtc.amPmMode)
|
||||
cout << ((rtc.pm) ? " PM " : " AM ");
|
||||
if (rtc->amPmMode)
|
||||
cout << ((rtc->pm) ? " PM " : " AM ");
|
||||
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
|
||||
cout << "Clock is in " << ((rtc.amPmMode) ? "AM/PM mode" : "24hr mode") << endl;
|
||||
cout << "Clock is in " << ((rtc->amPmMode) ? "AM/PM mode" : "24hr mode")
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a DS1037 on I2C bus 0
|
||||
upm::DS1307 rtc(0);
|
||||
|
||||
// always do this first
|
||||
cout << "Loading the current time... " << endl;
|
||||
if (!rtc.loadTime()) {
|
||||
cerr << "rtc.loadTime() failed." << endl;
|
||||
return 0;
|
||||
//! [Interesting]
|
||||
// Instantiate a DS1037 on I2C bus 0
|
||||
upm::DS1307 *rtc = new upm::DS1307(0);
|
||||
|
||||
// always do this first
|
||||
cout << "Loading the current time... " << endl;
|
||||
if (!rtc->loadTime())
|
||||
{
|
||||
cerr << "rtc->loadTime() failed." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
printTime(rtc);
|
||||
|
||||
printTime(rtc);
|
||||
// set the year as an example
|
||||
cout << "setting the year to 50" << endl;
|
||||
rtc->year = 50;
|
||||
|
||||
// set the year as an example
|
||||
cout << "setting the year to 50" << endl;
|
||||
rtc.year = 50;
|
||||
rtc->setTime();
|
||||
|
||||
rtc.setTime();
|
||||
// reload the time and print it
|
||||
rtc->loadTime();
|
||||
printTime(rtc);
|
||||
|
||||
// reload the time and print it
|
||||
rtc.loadTime();
|
||||
printTime(rtc);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
//! [Interesting]
|
||||
|
||||
delete rtc;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,41 +1,43 @@
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "ds1808lc.hpp"
|
||||
|
||||
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||
|
||||
void
|
||||
printState(upm::ILightController& lightController)
|
||||
void printState(upm::ILightController &lightController)
|
||||
{
|
||||
if (lightController.isPowered()) {
|
||||
std::cout << "Light is powered, brightness = " << lightController.getBrightness()
|
||||
<< std::endl;
|
||||
} else {
|
||||
if (lightController.isPowered())
|
||||
{
|
||||
std::cout << "Light is powered, brightness = " << lightController.getBrightness() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Light is not powered." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::DS1808LC lightController(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||
std::cout << "Existing state: ";
|
||||
printState(lightController);
|
||||
if (argc == 2) {
|
||||
std::cout << "Existing state: "; printState(lightController);
|
||||
if (argc == 2)
|
||||
{
|
||||
std::string arg = argv[1];
|
||||
int brightness = ::atoi(argv[1]);
|
||||
if (brightness > 0) {
|
||||
if (brightness > 0)
|
||||
{
|
||||
lightController.setPowerOn();
|
||||
lightController.setBrightness(brightness);
|
||||
} else
|
||||
}
|
||||
else
|
||||
lightController.setPowerOff();
|
||||
}
|
||||
std::cout << "Now: ";
|
||||
printState(lightController);
|
||||
std::cout << "Now: ";printState(lightController);
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,61 +22,65 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ds18b20.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Initializing..." << endl;
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an DS18B20 instance using the default values (uart 0)
|
||||
upm::DS18B20 sensor;
|
||||
// Instantiate an DS18B20 instance using the default values (uart 0)
|
||||
upm::DS18B20 sensor;
|
||||
|
||||
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
|
||||
cout << endl;
|
||||
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
|
||||
cout << endl;
|
||||
|
||||
// bail if we didn't find anything
|
||||
if (!sensor.devicesFound())
|
||||
return 1;
|
||||
// bail if we didn't find anything
|
||||
if (!sensor.devicesFound())
|
||||
return 1;
|
||||
|
||||
// update and print available values every 2 seconds
|
||||
while (shouldRun) {
|
||||
// update our values for all of the detected sensors
|
||||
sensor.update(-1);
|
||||
// update and print available values every 2 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values for all of the detected sensors
|
||||
sensor.update(-1);
|
||||
|
||||
// we show both C and F for temperature for the sensors
|
||||
int i;
|
||||
for (i = 0; i < sensor.devicesFound(); i++) {
|
||||
cout << "Device " << i << ": Temperature: " << sensor.getTemperature(i) << " C / "
|
||||
<< sensor.getTemperature(i, true) << " F" << endl;
|
||||
}
|
||||
cout << endl;
|
||||
// we show both C and F for temperature for the sensors
|
||||
int i;
|
||||
for (i=0; i<sensor.devicesFound(); i++)
|
||||
{
|
||||
cout << "Device "
|
||||
<< i
|
||||
<< ": Temperature: "
|
||||
<< sensor.getTemperature(i)
|
||||
<< " C / " << sensor.getTemperature(i, true) << " F"
|
||||
<< endl;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
upm_delay(2);
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,37 +22,38 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ds2413.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a DS2413 Module on a Dallas 1-wire bus connected to UART 0
|
||||
upm::DS2413 sensor(0);
|
||||
//! [Interesting]
|
||||
// Instantiate a DS2413 Module on a Dallas 1-wire bus connected to UART 0
|
||||
upm::DS2413* sensor = new upm::DS2413(0);
|
||||
|
||||
// find all of the DS2413 devices present on the bus
|
||||
sensor.init();
|
||||
// find all of the DS2413 devices present on the bus
|
||||
sensor->init();
|
||||
|
||||
// how many devices were found?
|
||||
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
|
||||
// how many devices were found?
|
||||
cout << "Found "<< sensor->devicesFound() << " device(s)" << endl;
|
||||
|
||||
// read the gpio and latch values from the first device
|
||||
// the lower 4 bits are of the form:
|
||||
// <gpioB latch> <gpioB value> <gpioA latch> <gpioA value>
|
||||
cout << "GPIO device 0 values: " << sensor.readGpios(0) << endl;
|
||||
// read the gpio and latch values from the first device
|
||||
// the lower 4 bits are of the form:
|
||||
// <gpioB latch> <gpioB value> <gpioA latch> <gpioA value>
|
||||
cout << "GPIO device 0 values: " << sensor->readGpios(0) << endl;
|
||||
|
||||
// set the gpio latch values of the first device
|
||||
cout << "Setting GPIO latches to on" << endl;
|
||||
sensor.writeGpios(0, 0x03);
|
||||
// set the gpio latch values of the first device
|
||||
cout << "Setting GPIO latches to on" << endl;
|
||||
sensor->writeGpios(0, 0x03);
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
delete sensor;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,84 +22,91 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <string>
|
||||
|
||||
#include "e50hx.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// You will need to edit this example to conform to your site and your
|
||||
// devices, specifically the Device Object Instance ID passed to the
|
||||
// constructor, and the arguments to initMaster() that are
|
||||
// appropriate for your BACnet network.
|
||||
//! [Interesting]
|
||||
// You will need to edit this example to conform to your site and your
|
||||
// devices, specifically the Device Object Instance ID passed to the
|
||||
// constructor, and the arguments to initMaster() that are
|
||||
// appropriate for your BACnet network.
|
||||
|
||||
string defaultDev = "/dev/ttyUSB0";
|
||||
string defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (argc > 1)
|
||||
defaultDev = string(argv[1]);
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (argc > 1)
|
||||
defaultDev = string(argv[1]);
|
||||
|
||||
cout << "Using device " << defaultDev << endl;
|
||||
cout << "Initializing..." << endl;
|
||||
cout << "Using device " << defaultDev << endl;
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an E50HX object for an E50HX device that has 1075425
|
||||
// as it's unique Device Object Instance ID. NOTE: You will
|
||||
// certainly want to change this to the correct value for your
|
||||
// device(s).
|
||||
E50HX sensor(1075425);
|
||||
// Instantiate an E50HX object for an E50HX device that has 1075425
|
||||
// as it's unique Device Object Instance ID. NOTE: You will
|
||||
// certainly want to change this to the correct value for your
|
||||
// device(s).
|
||||
E50HX *sensor = new E50HX(1075425);
|
||||
|
||||
// Initialize our BACnet master, if it has not already been
|
||||
// initialized, with the device and baudrate, choosing 1000001 as
|
||||
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||
// using default values for maxMaster and maxInfoFrames
|
||||
sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||
// Initialize our BACnet master, if it has not already been
|
||||
// initialized, with the device and baudrate, choosing 1000001 as
|
||||
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||
// using default values for maxMaster and maxInfoFrames
|
||||
sensor->initMaster(defaultDev, 38400, 1000001, 2);
|
||||
|
||||
// Uncomment to enable debugging output
|
||||
// sensor.setDebug(true);
|
||||
// Uncomment to enable debugging output
|
||||
// sensor->setDebug(true);
|
||||
|
||||
cout << endl;
|
||||
cout << "Device Description: " << sensor.getDeviceDescription() << endl;
|
||||
cout << "Device Location: " << sensor.getDeviceLocation() << endl;
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
cout << "Device Description: " << sensor->getDeviceDescription() << endl;
|
||||
cout << "Device Location: " << sensor->getDeviceLocation() << endl;
|
||||
cout << endl;
|
||||
|
||||
// update and print a few values every 5 seconds
|
||||
while (shouldRun) {
|
||||
cout << "System Voltage: " << sensor.getAnalogValue(E50HX::AV_System_Voltage) << " "
|
||||
<< sensor.getAnalogValueUnits(E50HX::AV_System_Voltage) << endl;
|
||||
// update and print a few values every 5 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "System Voltage: "
|
||||
<< sensor->getAnalogValue(E50HX::AV_System_Voltage)
|
||||
<< " " << sensor->getAnalogValueUnits(E50HX::AV_System_Voltage)
|
||||
<< endl;
|
||||
|
||||
cout << "System Type: " << sensor.getAnalogValue(E50HX::AV_System_Type) << endl;
|
||||
cout << "System Type: "
|
||||
<< sensor->getAnalogValue(E50HX::AV_System_Type)
|
||||
<< endl;
|
||||
|
||||
cout << "Energy Consumption: " << sensor.getAnalogInput(E50HX::AI_Energy) << " "
|
||||
<< sensor.getAnalogInputUnits(E50HX::AI_Energy) << endl;
|
||||
cout << "Energy Consumption: " << sensor->getAnalogInput(E50HX::AI_Energy)
|
||||
<< " " << sensor->getAnalogInputUnits(E50HX::AI_Energy)
|
||||
<< endl;
|
||||
|
||||
cout << "Power Up Counter: " << sensor.getAnalogInput(E50HX::AI_Power_Up_Count) << endl;
|
||||
cout << "Power Up Counter: "
|
||||
<< sensor->getAnalogInput(E50HX::AI_Power_Up_Count)
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
upm_delay(5);
|
||||
cout << endl;
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
//! [Interesting]
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,44 +22,51 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <ecezo.hpp>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
#include <ecezo.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
upm::ECEZO sensor(0, 9600, false);
|
||||
upm::ECEZO *sensor = new upm::ECEZO(0, 9600, false);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// upm::ECEZO sensor(0, 0x64, true);
|
||||
// upm::ECEZO *sensor = new upm::ECEZO(0, 0x64, true);
|
||||
|
||||
while (shouldRun) {
|
||||
while (shouldRun)
|
||||
{
|
||||
// this will take about 1 second to complete
|
||||
sensor.update();
|
||||
sensor->update();
|
||||
|
||||
cout << "EC " << sensor.getEC() << " uS/cm, TDS " << sensor.getTDS() << " mg/L, Salinity "
|
||||
<< sensor.getSalinity() << " PSS-78, SG " << sensor.getSG() << endl;
|
||||
cout << "EC "
|
||||
<< sensor->getEC()
|
||||
<< " uS/cm, TDS "
|
||||
<< sensor->getTDS()
|
||||
<< " mg/L, Salinity "
|
||||
<< sensor->getSalinity()
|
||||
<< " PSS-78, SG "
|
||||
<< sensor->getSG()
|
||||
<< endl;
|
||||
|
||||
upm_delay(5);
|
||||
}
|
||||
@ -68,5 +75,7 @@ main()
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,13 +22,14 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ecs1030.hpp"
|
||||
|
||||
int is_running = 0;
|
||||
upm::ECS1030 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
@ -41,20 +42,20 @@ sig_handler(int signo)
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
upm::ECS1030 sensor(0);
|
||||
sensor = new upm::ECS1030(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!is_running) {
|
||||
std::cout << "I = " << sensor.getCurrency_A() << ", Power = " << sensor.getPower_A()
|
||||
<< std::endl;
|
||||
std::cout << "I = " << sensor.getCurrency_B() << ", Power = " << sensor.getPower_B()
|
||||
<< std::endl;
|
||||
std::cout << "I = " << sensor->getCurrency_A () << ", Power = " << sensor->getPower_A () << std::endl;
|
||||
std::cout << "I = " << sensor->getCurrency_B () << ", Power = " << sensor->getPower_B () << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,57 +22,57 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ehr.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Ear-clip Heart Rate sensor on digital pin D2
|
||||
upm::EHR heart(2);
|
||||
//! [Interesting]
|
||||
// Instantiate a Ear-clip Heart Rate sensor on digital pin D2
|
||||
upm::EHR* heart = new upm::EHR(2);
|
||||
|
||||
// set the beat counter to 0, init the clock and start counting beats
|
||||
heart->clearBeatCounter();
|
||||
heart->initClock();
|
||||
heart->startBeatCounter();
|
||||
|
||||
// set the beat counter to 0, init the clock and start counting beats
|
||||
heart.clearBeatCounter();
|
||||
heart.initClock();
|
||||
heart.startBeatCounter();
|
||||
while (shouldRun)
|
||||
{
|
||||
// we grab these just for display purposes in this example
|
||||
uint32_t millis = heart->getMillis();
|
||||
uint32_t beats = heart->beatCounter();
|
||||
|
||||
while (shouldRun) {
|
||||
// we grab these just for display purposes in this example
|
||||
uint32_t millis = heart.getMillis();
|
||||
uint32_t beats = heart.beatCounter();
|
||||
// heartRate() requires that at least 5 seconds pass before
|
||||
// returning anything other than 0
|
||||
int hr = heart->heartRate();
|
||||
|
||||
// heartRate() requires that at least 5 seconds pass before
|
||||
// returning anything other than 0
|
||||
int hr = heart.heartRate();
|
||||
// output milliseconds passed, beat count, and computed heart rate
|
||||
cout << "Millis: " << millis << " Beats: " << beats;
|
||||
cout << " Heart Rate: " << hr << endl;
|
||||
|
||||
// output milliseconds passed, beat count, and computed heart rate
|
||||
cout << "Millis: " << millis << " Beats: " << beats;
|
||||
cout << " Heart Rate: " << hr << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
heart.stopBeatCounter();
|
||||
//! [Interesting]
|
||||
heart->stopBeatCounter();
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
delete heart;
|
||||
return 0;
|
||||
}
|
@ -22,46 +22,45 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "eldriver.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// This was tested with the El Driver Module
|
||||
// Instantiate an El Driver on digital pin D2
|
||||
upm::ElDriver eldriver(2);
|
||||
//! [Interesting]
|
||||
// The was tested with the El Driver Module
|
||||
// Instantiate a El Driver on digital pin D2
|
||||
upm::ElDriver* eldriver = new upm::ElDriver(2);
|
||||
|
||||
bool lightState = true;
|
||||
bool lightState = true;
|
||||
|
||||
while (shouldRun) {
|
||||
if (lightState)
|
||||
eldriver.on();
|
||||
else
|
||||
eldriver.off();
|
||||
lightState = !lightState;
|
||||
upm_delay(1);
|
||||
}
|
||||
while (shouldRun)
|
||||
{
|
||||
if (lightState)
|
||||
eldriver->on();
|
||||
else
|
||||
eldriver->off();
|
||||
lightState = !lightState;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
eldriver.off();
|
||||
cout << "Exiting" << endl;
|
||||
//! [Interesting]
|
||||
eldriver->off();
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete eldriver;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,60 +22,58 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include "electromagnet.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
float
|
||||
get_time()
|
||||
float get_time()
|
||||
{
|
||||
return ((float) (clock())) / CLOCKS_PER_SEC;
|
||||
return ((float)(clock()))/CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Electromagnetic Module
|
||||
// Instantiate a Electromagnet on digital pin D2
|
||||
upm::Electromagnet magnet(2);
|
||||
cout << "Starting up magnet...." << endl;
|
||||
magnet.off();
|
||||
//! [Interesting]
|
||||
// The was tested with the Electromagnetic Module
|
||||
// Instantiate a Electromagnet on digital pin D2
|
||||
upm::Electromagnet* magnet = new upm::Electromagnet(2);
|
||||
cout << "Starting up magnet...." << endl;
|
||||
magnet->off();
|
||||
|
||||
bool magnetState = false;
|
||||
float time_passed = get_time();
|
||||
bool magnetState = false;
|
||||
float time_passed = get_time();
|
||||
|
||||
// Turn magnet on and off every 5 seconds
|
||||
while (shouldRun) {
|
||||
if ((get_time() - time_passed) > 5.0) {
|
||||
magnetState = !magnetState;
|
||||
if (magnetState)
|
||||
magnet.on();
|
||||
else
|
||||
magnet.off();
|
||||
cout << "Turning magnet " << ((magnetState) ? "on" : "off") << endl;
|
||||
time_passed = get_time();
|
||||
}
|
||||
}
|
||||
// Turn magnet on and off every 5 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
if ((get_time() - time_passed) > 5.0)
|
||||
{
|
||||
magnetState = !magnetState;
|
||||
if (magnetState)
|
||||
magnet->on();
|
||||
else
|
||||
magnet->off();
|
||||
cout << "Turning magnet " << ((magnetState) ? "on" : "off") << endl;
|
||||
time_passed = get_time();
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
magnet.off();
|
||||
cout << "Exiting" << endl;
|
||||
//! [Interesting]
|
||||
magnet->off();
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete magnet;
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,41 +21,40 @@
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "emg.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the EMG Muscle Signal Reader Sensor Module
|
||||
// Instantiate a EMG on analog pin A0
|
||||
upm::EMG emg(0);
|
||||
cout << "Calibrating...." << endl;
|
||||
emg.calibrate();
|
||||
//! [Interesting]
|
||||
// The was tested with the EMG Muscle Signal Reader Sensor Module
|
||||
// Instantiate a EMG on analog pin A0
|
||||
upm::EMG *emg = new upm::EMG(0);
|
||||
cout << "Calibrating...." << endl;
|
||||
emg->calibrate();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << emg->value() << endl;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
while (shouldRun) {
|
||||
cout << emg.value() << endl;
|
||||
upm_delay_us(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
return 0;
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
delete emg;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,11 +22,10 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "enc03r.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -35,43 +34,47 @@ bool shouldRun = true;
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define CALIBRATION_SAMPLES 1000
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a ENC03R on analog pin A0
|
||||
upm::ENC03R gyro(0);
|
||||
upm::ENC03R *gyro = new upm::ENC03R(0);
|
||||
|
||||
// The first thing we need to do is calibrate the sensor.
|
||||
cout << "Please place the sensor in a stable location, and do not" << endl;
|
||||
cout << "move it while calibration takes place." << endl;
|
||||
cout << "This may take a couple of minutes." << endl;
|
||||
|
||||
gyro.calibrate(CALIBRATION_SAMPLES);
|
||||
cout << "Calibration complete. Reference value: " << gyro.calibrationValue() << endl;
|
||||
gyro->calibrate(CALIBRATION_SAMPLES);
|
||||
cout << "Calibration complete. Reference value: "
|
||||
<< gyro->calibrationValue() << endl;
|
||||
|
||||
// Read the input and print both the raw value and the angular velocity,
|
||||
// waiting 0.1 seconds between readings
|
||||
while (shouldRun) {
|
||||
gyro.update();
|
||||
while (shouldRun)
|
||||
{
|
||||
gyro->update();
|
||||
|
||||
cout << "Angular velocity: " << gyro.angularVelocity() << " deg/s" << endl;
|
||||
cout << "Angular velocity: "
|
||||
<< gyro->angularVelocity()
|
||||
<< " deg/s"
|
||||
<< endl;
|
||||
|
||||
upm_delay_us(100000);
|
||||
usleep(100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete gyro;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,46 +22,45 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "flex.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with a Spectra Symbol flex sensor.
|
||||
// We attached a 22K resistor to a breadboard,
|
||||
// with 1 end attached to GND and the other connected to
|
||||
// both the flex sensor and A0.
|
||||
// The flex sensor was connected on 1 pin to the 22K resistor and A0
|
||||
// and on the other pin to 5V.
|
||||
//! [Interesting]
|
||||
// The was tested with a Spectra Symbol flex sensor.
|
||||
// We attached a 22K resistor to a breadboard,
|
||||
// with 1 end attached to GND and the other connected to
|
||||
// both the flex sensor and A0.
|
||||
// The flex sensor was connected on 1 pin to the 22K resistor and A0
|
||||
// and on the other pin to 5V.
|
||||
|
||||
// Instantiate a Flex sensor on analog pin A0
|
||||
upm::Flex flex(0);
|
||||
|
||||
while (shouldRun) {
|
||||
cout << "Flex value: " << flex.value() << endl;
|
||||
upm_delay(1);
|
||||
// Instantiate a Flex sensor on analog pin A0
|
||||
upm::Flex *flex = new upm::Flex(0);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Flex value: " << flex->value() << endl;
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete flex;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,16 +22,16 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gas.hpp"
|
||||
#include "mq2.hpp"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer[128];
|
||||
uint16_t buffer [128];
|
||||
upm::MQ2 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
@ -44,26 +44,26 @@ sig_handler(int signo)
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Attach gas sensor to A0
|
||||
upm::MQ2 sensor(0);
|
||||
sensor = new upm::MQ2(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 milliseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of the averages using a resolution of 5
|
||||
while (!is_running) {
|
||||
int len = sensor.getSampledWindow(2, 128, buffer);
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
||||
sensor.printGraph(&ctx, 5);
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
@ -72,6 +72,8 @@ main(int argc, char** argv)
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,16 +22,16 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gas.hpp"
|
||||
#include "mq3.hpp"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer[128];
|
||||
uint16_t buffer [128];
|
||||
upm::MQ3 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
@ -44,26 +44,26 @@ sig_handler(int signo)
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Attach gas sensor to A0
|
||||
upm::MQ3 sensor(0);
|
||||
sensor = new upm::MQ3(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 milliseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of the averages using a resolution of 5
|
||||
while (!is_running) {
|
||||
int len = sensor.getSampledWindow(2, 128, buffer);
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
||||
sensor.printGraph(&ctx, 5);
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
@ -72,6 +72,8 @@ main(int argc, char** argv)
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,12 +22,12 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gas.hpp"
|
||||
#include "mq4.hpp"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -36,43 +36,46 @@ using namespace std;
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
{
|
||||
shouldRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Attach gas sensor to Analog A0
|
||||
upm::MQ4 sensor(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
// Attach gas sensor to Analog A0
|
||||
upm::MQ4 *sensor = new upm::MQ4(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
uint16_t buffer [128];
|
||||
|
||||
uint16_t buffer[128];
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asteriskss as averages
|
||||
while (shouldRun) {
|
||||
int len = sensor.getSampledWindow(2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
||||
sensor.printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asteriskss as averages
|
||||
while (shouldRun)
|
||||
{
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,16 +22,16 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gas.hpp"
|
||||
#include "mq5.hpp"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer[128];
|
||||
uint16_t buffer [128];
|
||||
upm::MQ5 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
@ -44,21 +44,21 @@ sig_handler(int signo)
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
upm::MQ5 sensor(0);
|
||||
sensor = new upm::MQ5(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
while (!is_running) {
|
||||
int len = sensor.getSampledWindow(2, 128, buffer);
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
||||
sensor.printGraph(&ctx, 7);
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 7);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
@ -67,6 +67,8 @@ main(int argc, char** argv)
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,12 +22,12 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gas.hpp"
|
||||
#include "mq6.hpp"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -36,43 +36,46 @@ using namespace std;
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
{
|
||||
shouldRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Attach gas sensor to Analog A0
|
||||
upm::MQ6 sensor(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
// Attach gas sensor to Analog A0
|
||||
upm::MQ6 *sensor = new upm::MQ6(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
uint16_t buffer [128];
|
||||
|
||||
uint16_t buffer[128];
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asteriskss as averages
|
||||
while (shouldRun) {
|
||||
int len = sensor.getSampledWindow(2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
||||
sensor.printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asteriskss as averages
|
||||
while (shouldRun)
|
||||
{
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,12 +22,12 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gas.hpp"
|
||||
#include "mq7.hpp"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -36,43 +36,46 @@ using namespace std;
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
{
|
||||
shouldRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Attach gas sensor to Analog A0
|
||||
upm::MQ7 sensor(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
// Attach gas sensor to Analog A0
|
||||
upm::MQ7 *sensor = new upm::MQ7(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
uint16_t buffer [128];
|
||||
|
||||
uint16_t buffer[128];
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asteriskss as averages
|
||||
while (shouldRun) {
|
||||
int len = sensor.getSampledWindow(2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
||||
sensor.printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asteriskss as averages
|
||||
while (shouldRun)
|
||||
{
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,12 +22,12 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gas.hpp"
|
||||
#include "mq8.hpp"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -36,43 +36,46 @@ using namespace std;
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
{
|
||||
shouldRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Attach gas sensor to Analog A0
|
||||
upm::MQ8 sensor(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
// Attach gas sensor to Analog A0
|
||||
upm::MQ8 *sensor = new upm::MQ8(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
uint16_t buffer [128];
|
||||
|
||||
uint16_t buffer[128];
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asteriskss as averages
|
||||
while (shouldRun) {
|
||||
int len = sensor.getSampledWindow(2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
||||
sensor.printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asteriskss as averages
|
||||
while (shouldRun)
|
||||
{
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,16 +22,16 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gas.hpp"
|
||||
#include "mq9.hpp"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer[128];
|
||||
uint16_t buffer [128];
|
||||
upm::MQ9 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
@ -44,21 +44,21 @@ sig_handler(int signo)
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
upm::MQ9 sensor(0);
|
||||
sensor = new upm::MQ9(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
while (!is_running) {
|
||||
int len = sensor.getSampledWindow(2, 128, buffer);
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
||||
sensor.printGraph(&ctx, 5);
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
@ -67,6 +67,8 @@ main(int argc, char** argv)
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,13 +22,10 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "tp401.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -37,41 +34,37 @@ using namespace std;
|
||||
std::string
|
||||
airQuality(uint16_t value)
|
||||
{
|
||||
if (value < 50)
|
||||
return "Fresh Air";
|
||||
if (value < 200)
|
||||
return "Normal Indoor Air";
|
||||
if (value < 400)
|
||||
return "Low Pollution";
|
||||
if (value < 600)
|
||||
return "High Pollution - Action Recommended";
|
||||
if(value < 50) return "Fresh Air";
|
||||
if(value < 200) return "Normal Indoor Air";
|
||||
if(value < 400) return "Low Pollution";
|
||||
if(value < 600) return "High Pollution - Action Recommended";
|
||||
return "Very High Pollution - Take Action Immediately";
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main ()
|
||||
{
|
||||
upm::TP401 airSensor(0);
|
||||
upm::TP401* airSensor = new upm::TP401(0); // Instantiate new grove air quality sensor on analog pin A0
|
||||
|
||||
cout << airSensor.name() << endl;
|
||||
cout << airSensor->name() << endl;
|
||||
|
||||
fprintf(stdout, "Heating sensor for 3 minutes...\n");
|
||||
// wait 3 minutes for sensor to warm up
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (i) {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(i) {
|
||||
fprintf(stdout, "Please wait, %d minute(s) passed..\n", i);
|
||||
}
|
||||
upm_delay(60);
|
||||
sleep(60);
|
||||
}
|
||||
fprintf(stdout, "Sensor ready!\n");
|
||||
|
||||
while (true) {
|
||||
uint16_t value = airSensor.getSample(); // Read raw value
|
||||
float ppm = airSensor.getPPM(); // Read CO ppm (can vary slightly from previous read)
|
||||
while(true) {
|
||||
uint16_t value = airSensor->getSample(); // Read raw value
|
||||
float ppm = airSensor->getPPM(); // Read CO ppm (can vary slightly from previous read)
|
||||
fprintf(stdout, "raw: %4d ppm: %5.2f %s\n", value, ppm, airQuality(value).c_str());
|
||||
upm_delay_us(2500000); // Sleep for 2.5s
|
||||
usleep(2500000); // Sleep for 2.5s
|
||||
}
|
||||
|
||||
delete airSensor;
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -22,52 +22,52 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "gp2y0a.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define GP2Y0A_AREF 5.0
|
||||
#define GP2Y0A_AREF 5.0
|
||||
#define SAMPLES_PER_QUERY 20
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Note, for the Grove 80cm version of this sensor, due to the way
|
||||
// it is wired, you need to plug this into the A0 port, where it
|
||||
// will use the available A1 pin for data.
|
||||
//! [Interesting]
|
||||
// Note, for the Grove 80cm version of this sensor, due to the way
|
||||
// it is wired, you need to plug this into the A0 port, where it
|
||||
// will use the available A1 pin for data.
|
||||
|
||||
// Instantiate a GP2Y0A on analog pin A1
|
||||
upm::GP2Y0A volts(1);
|
||||
|
||||
// The higher the voltage (closer to AREF) the closer the object is. NOTE:
|
||||
// the measured voltage will probably not exceed 3.3 volts.
|
||||
// Every second, print the averaged voltage value (averaged over 20 samples).
|
||||
while (shouldRun) {
|
||||
cout << "AREF: " << GP2Y0A_AREF << ", Voltage value (higher means closer): "
|
||||
<< volts.value(GP2Y0A_AREF, SAMPLES_PER_QUERY) << endl;
|
||||
|
||||
upm_delay(1);
|
||||
// Instantiate a GP2Y0A on analog pin A1
|
||||
upm::GP2Y0A *volts = new upm::GP2Y0A(1);
|
||||
|
||||
// The higher the voltage (closer to AREF) the closer the object is. NOTE:
|
||||
// the measured voltage will probably not exceed 3.3 volts.
|
||||
// Every second, print the averaged voltage value (averaged over 20 samples).
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "AREF: " << GP2Y0A_AREF
|
||||
<< ", Voltage value (higher means closer): "
|
||||
<< volts->value(GP2Y0A_AREF, SAMPLES_PER_QUERY) << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete volts;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,81 +22,90 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "gprs.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
void
|
||||
printUsage(char* progname)
|
||||
void printUsage(char *progname)
|
||||
{
|
||||
cout << "Usage: " << progname << " [AT command]" << endl;
|
||||
cout << endl;
|
||||
cout << "Usage: " << progname << " [AT command]" << endl;
|
||||
cout << endl;
|
||||
|
||||
cout << "If an argument is supplied on the command line, that argument is" << endl;
|
||||
cout << "sent to the module and the response is printed out." << endl;
|
||||
cout << endl;
|
||||
cout << "If no argument is used, then the manufacturer and the current" << endl;
|
||||
cout << "saved profiles are queried and the results printed out." << endl;
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
cout << "If an argument is supplied on the command line, that argument is"
|
||||
<< endl;
|
||||
cout << "sent to the module and the response is printed out." << endl;
|
||||
cout << endl;
|
||||
cout << "If no argument is used, then the manufacturer and the current"
|
||||
<< endl;
|
||||
cout << "saved profiles are queried and the results printed out." << endl;
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
// simple helper function to send a command and wait for a response
|
||||
void
|
||||
sendCommand(upm::GPRS& sensor, string cmd)
|
||||
void sendCommand(upm::GPRS* sensor, string cmd)
|
||||
{
|
||||
// commands need to be terminated with a carriage return
|
||||
cmd += "\r";
|
||||
// commands need to be terminated with a carriage return
|
||||
cmd += "\r";
|
||||
|
||||
sensor.writeDataStr(cmd);
|
||||
|
||||
// wait up to 1 second
|
||||
if (sensor.dataAvailable(1000)) {
|
||||
cout << "Returned: " << sensor.readDataStr(1024) << endl;
|
||||
} else {
|
||||
cerr << "Timed out waiting for response" << endl;
|
||||
sensor->writeDataStr(cmd);
|
||||
|
||||
// wait up to 1 second
|
||||
if (sensor->dataAvailable(1000))
|
||||
{
|
||||
cout << "Returned: " << sensor->readDataStr(1024) << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Timed out waiting for response" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a GPRS Module on UART 0
|
||||
upm::GPRS sensor(0);
|
||||
// Instantiate a GPRS Module on UART 0
|
||||
upm::GPRS* sensor = new upm::GPRS(0);
|
||||
|
||||
// Set the baud rate, 19200 baud is the default.
|
||||
if (sensor.setBaudRate(19200) != 0) {
|
||||
cerr << "Failed to set tty baud rate" << endl;
|
||||
return 1;
|
||||
// Set the baud rate, 19200 baud is the default.
|
||||
if (sensor->setBaudRate(19200) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << "Failed to set tty baud rate" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
printUsage(argv[0]);
|
||||
printUsage(argv[0]);
|
||||
|
||||
if (argc > 1) {
|
||||
cout << "Sending command line argument (" << argv[1] << ")..." << endl;
|
||||
sendCommand(sensor, argv[1]);
|
||||
} else {
|
||||
// query the module manufacturer
|
||||
cout << "Querying module manufacturer (AT+CGMI)..." << endl;
|
||||
sendCommand(sensor, "AT+CGMI");
|
||||
if (argc > 1)
|
||||
{
|
||||
cout << "Sending command line argument (" << argv[1] << ")..." << endl;
|
||||
sendCommand(sensor, argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// query the module manufacturer
|
||||
cout << "Querying module manufacturer (AT+CGMI)..." << endl;
|
||||
sendCommand(sensor, "AT+CGMI");
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
|
||||
// query the saved profiles
|
||||
cout << "Querying the saved profiles (AT&V)..." << endl;
|
||||
sendCommand(sensor, "AT&V");
|
||||
// query the saved profiles
|
||||
cout << "Querying the saved profiles (AT&V)..." << endl;
|
||||
sendCommand(sensor, "AT&V");
|
||||
|
||||
// A comprehensive list is available from the datasheet at:
|
||||
// http://www.seeedstudio.com/wiki/images/7/72/AT_Commands_v1.11.pdf
|
||||
// A comprehensive list is available from the datasheet at:
|
||||
// http://www.seeedstudio.com/wiki/images/7/72/AT_Commands_v1.11.pdf
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
@ -22,29 +22,28 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "grovebutton.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// This example uses GPIO 0
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Create the button object using GPIO pin 0
|
||||
upm::GroveButton button(0);
|
||||
upm::GroveButton* button = new upm::GroveButton(0);
|
||||
|
||||
// Read the input and print, waiting one second between readings
|
||||
while (1) {
|
||||
std::cout << button.name() << " value is " << button.value() << std::endl;
|
||||
upm_delay(1);
|
||||
while( 1 ) {
|
||||
std::cout << button->name() << " value is " << button->value() << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the button object
|
||||
//! [Interesting]
|
||||
delete button;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,47 +22,47 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "groveled.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include "grove.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a grove LED on D2. Here we are controlling a Grove
|
||||
// Multi-color flash LED. We just just need to turn it on - it will
|
||||
// then cycle through various colors (red, green, blue, purple) on it's
|
||||
// own until turned off.
|
||||
upm::GroveLed led(2);
|
||||
// Instantiate a grove LED on D2. Here we are controlling a Grove
|
||||
// Multi-color flash LED. We just just need to turn it on - it will
|
||||
// then cycle through various colors (red, green, blue, purple) on it's
|
||||
// own until turned off.
|
||||
upm::GroveLed* led = new upm::GroveLed(2);
|
||||
|
||||
// start the light show
|
||||
led.on();
|
||||
// start the light show
|
||||
led->on();
|
||||
|
||||
// just upm_delay until interrupted
|
||||
while (shouldRun)
|
||||
upm_delay(1);
|
||||
// just sleep until interrupted
|
||||
while (shouldRun)
|
||||
sleep(1);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
//! [Interesting]
|
||||
led->off();
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
led.off();
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
delete led;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,34 +23,33 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "groveled.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Create the Grove LED object using GPIO pin 2
|
||||
upm::GroveLed led(2);
|
||||
upm::GroveLed* led = new upm::GroveLed(2);
|
||||
|
||||
// Print the name
|
||||
std::cout << led.name() << std::endl;
|
||||
std::cout << led->name() << std::endl;
|
||||
|
||||
// Turn the LED on and off 10 times, pausing one second
|
||||
// between transitions
|
||||
for (int i = 0; i < 10; i++) {
|
||||
led.on();
|
||||
upm_delay(1);
|
||||
led.off();
|
||||
upm_delay(1);
|
||||
for (int i=0; i < 10; i++) {
|
||||
led->on();
|
||||
sleep(1);
|
||||
led->off();
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the Grove LED object
|
||||
//! [Interesting]
|
||||
delete led;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,28 +23,27 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "grovelight.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
// Create the light sensor object using AIO pin 0
|
||||
upm::GroveLight light(0);
|
||||
upm::GroveLight* light = new upm::GroveLight(0);
|
||||
|
||||
// Read the input and print both the raw value and a rough lux value,
|
||||
// waiting one second between readings
|
||||
while (1) {
|
||||
std::cout << light.name() << " raw value is " << light.raw_value() << ", which is roughly "
|
||||
<< light.value() << " lux" << std::endl;
|
||||
upm_delay(1);
|
||||
while( 1 ) {
|
||||
std::cout << light->name() << " raw value is " << light->raw_value() <<
|
||||
", which is roughly " << light->value() << " lux" << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the light sensor object
|
||||
//! [Interesting]
|
||||
delete light;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,38 +22,37 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "groverelay.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// This example uses GPIO 0
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Create the relay switch object using GPIO pin 0
|
||||
upm::GroveRelay relay(0);
|
||||
upm::GroveRelay* relay = new upm::GroveRelay(0);
|
||||
|
||||
// Close and then open the relay switch 3 times,
|
||||
// waiting one second each time. The LED on the relay switch
|
||||
// will light up when the switch is on (closed).
|
||||
// The switch will also make a noise between transitions.
|
||||
for (int i = 0; i < 3; i++) {
|
||||
relay.on();
|
||||
if (relay.isOn())
|
||||
std::cout << relay.name() << " is on" << std::endl;
|
||||
upm_delay(1);
|
||||
relay.off();
|
||||
if (relay.isOff())
|
||||
std::cout << relay.name() << " is off" << std::endl;
|
||||
upm_delay(1);
|
||||
for ( int i = 0; i < 3; i++ ) {
|
||||
relay->on();
|
||||
if ( relay->isOn() )
|
||||
std::cout << relay->name() << " is on" << std::endl;
|
||||
sleep(1);
|
||||
relay->off();
|
||||
if ( relay->isOff() )
|
||||
std::cout << relay->name() << " is off" << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the relay switch object
|
||||
//! [Interesting]
|
||||
delete relay;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,46 +22,36 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "groverotary.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include <iomanip>
|
||||
#include "grove.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
int main ()
|
||||
{
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
// Instantiate a rotary sensor on analog pin A0
|
||||
upm::GroveRotary knob(0);
|
||||
upm::GroveRotary* knob = new upm::GroveRotary(0);
|
||||
|
||||
// Print sensor name to confirm it initialized properly
|
||||
cout << knob.name() << endl;
|
||||
cout << knob->name() << endl;
|
||||
|
||||
while (true) {
|
||||
float abs_value = knob.abs_value(); // Absolute raw value
|
||||
float abs_deg = knob.abs_deg(); // Absolute degrees
|
||||
float abs_rad = knob.abs_rad(); // Absolute radians
|
||||
float rel_value = knob.rel_value(); // Relative raw value
|
||||
float rel_deg = knob.rel_deg(); // Relative degrees
|
||||
float rel_rad = knob.rel_rad(); // Relative radians
|
||||
while(true) {
|
||||
float abs_value = knob->abs_value(); // Absolute raw value
|
||||
float abs_deg = knob->abs_deg(); // Absolute degrees
|
||||
float abs_rad = knob->abs_rad(); // Absolute radians
|
||||
float rel_value = knob->rel_value(); // Relative raw value
|
||||
float rel_deg = knob->rel_deg(); // Relative degrees
|
||||
float rel_rad = knob->rel_rad(); // Relative radians
|
||||
|
||||
fprintf(stdout,
|
||||
"Absolute: %4d raw %5.2f deg = %3.2f rad Relative: %4d raw %5.2f "
|
||||
"deg %3.2f rad\n",
|
||||
(int16_t) abs_value,
|
||||
abs_deg,
|
||||
abs_rad,
|
||||
(int16_t) rel_value,
|
||||
rel_deg,
|
||||
rel_rad);
|
||||
fprintf(stdout, "Absolute: %4d raw %5.2f deg = %3.2f rad Relative: %4d raw %5.2f deg %3.2f rad\n",
|
||||
(int16_t)abs_value, abs_deg, abs_rad, (int16_t)rel_value, rel_deg, rel_rad);
|
||||
|
||||
upm_delay_us(2500000); // Sleep for 2.5s
|
||||
usleep(2500000); // Sleep for 2.5s
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
delete knob;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,31 +22,29 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "groveslide.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "grove.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
int main ()
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::GroveSlide slide(0);
|
||||
//! [Interesting]
|
||||
upm::GroveSlide* slide = new upm::GroveSlide(0); // Instantiate new grove slide potentiometer on analog pin A0
|
||||
|
||||
cout << slide.name() << endl;
|
||||
cout << slide->name() << endl;
|
||||
|
||||
while (true) {
|
||||
float adc_value = slide.raw_value(); // Read raw value
|
||||
float volts = slide.voltage_value(); // Read voltage, board reference set at 5.0V
|
||||
fprintf(stdout, "%4d = %.2f V\n", (uint16_t) adc_value, volts);
|
||||
while(true) {
|
||||
float adc_value = slide->raw_value(); // Read raw value
|
||||
float volts = slide->voltage_value(); // Read voltage, board reference set at 5.0V
|
||||
fprintf(stdout, "%4d = %.2f V\n", (uint16_t)adc_value, volts);
|
||||
|
||||
upm_delay_us(2500000); // Sleep for 2.5s
|
||||
usleep(2500000); // Sleep for 2.5s
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
delete slide;
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,33 +23,33 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "grovetemp.hpp"
|
||||
#include "upm_utilities.h"
|
||||
#include <iomanip>
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Create the temperature sensor object using AIO pin 0
|
||||
upm::GroveTemp temp(0);
|
||||
std::cout << temp.name() << std::endl;
|
||||
upm::GroveTemp* temp = new upm::GroveTemp(0);
|
||||
std::cout << temp->name() << std::endl;
|
||||
|
||||
// Read the temperature ten times, printing both the Celsius and
|
||||
// equivalent Fahrenheit temperature, waiting one second between readings
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int celsius = temp.value();
|
||||
int fahrenheit = (int) (celsius * 9.0 / 5.0 + 32.0);
|
||||
printf("%d degrees Celsius, or %d degrees Fahrenheit\n", celsius, fahrenheit);
|
||||
upm_delay(1);
|
||||
for (int i=0; i < 10; i++) {
|
||||
int celsius = temp->value();
|
||||
int fahrenheit = (int) (celsius * 9.0/5.0 + 32.0);
|
||||
printf("%d degrees Celsius, or %d degrees Fahrenheit\n",
|
||||
celsius, fahrenheit);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the temperature sensor object
|
||||
//! [Interesting]
|
||||
delete temp;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,45 +22,48 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "grovecollision.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove Collision Sensor
|
||||
// Instantiate a Grove Collision on digital pin D2
|
||||
upm::GroveCollision collision(2);
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove Collision Sensor
|
||||
// Instantiate a Grove Collision on digital pin D2
|
||||
upm::GroveCollision* collision = new upm::GroveCollision(2);
|
||||
|
||||
bool collisionState = false;
|
||||
cout << "No collision" << endl;
|
||||
while (shouldRun) {
|
||||
if (collision.isColliding() && !collisionState) {
|
||||
cout << "Collision!" << endl;
|
||||
collisionState = true;
|
||||
} else if (collisionState) {
|
||||
cout << "No collision" << endl;
|
||||
collisionState = false;
|
||||
}
|
||||
}
|
||||
bool collisionState = false;
|
||||
cout << "No collision" << endl;
|
||||
while (shouldRun)
|
||||
{
|
||||
if (collision->isColliding() && !collisionState)
|
||||
{
|
||||
cout << "Collision!" << endl;
|
||||
collisionState = true;
|
||||
}
|
||||
else if (collisionState)
|
||||
{
|
||||
cout << "No collision" << endl;
|
||||
collisionState = false;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete collision;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,57 +22,57 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "groveehr.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Ear-clip Heart Rate sensor on digital pin D2
|
||||
upm::GroveEHR heart(2);
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Ear-clip Heart Rate sensor on digital pin D2
|
||||
upm::GroveEHR* heart = new upm::GroveEHR(2);
|
||||
|
||||
// set the beat counter to 0, init the clock and start counting beats
|
||||
heart->clearBeatCounter();
|
||||
heart->initClock();
|
||||
heart->startBeatCounter();
|
||||
|
||||
// set the beat counter to 0, init the clock and start counting beats
|
||||
heart.clearBeatCounter();
|
||||
heart.initClock();
|
||||
heart.startBeatCounter();
|
||||
while (shouldRun)
|
||||
{
|
||||
// we grab these just for display purposes in this example
|
||||
uint32_t millis = heart->getMillis();
|
||||
uint32_t beats = heart->beatCounter();
|
||||
|
||||
while (shouldRun) {
|
||||
// we grab these just for display purposes in this example
|
||||
uint32_t millis = heart.getMillis();
|
||||
uint32_t beats = heart.beatCounter();
|
||||
// heartRate() requires that at least 5 seconds pass before
|
||||
// returning anything other than 0
|
||||
int hr = heart->heartRate();
|
||||
|
||||
// heartRate() requires that at least 5 seconds pass before
|
||||
// returning anything other than 0
|
||||
int hr = heart.heartRate();
|
||||
// output milliseconds passed, beat count, and computed heart rate
|
||||
cout << "Millis: " << millis << " Beats: " << beats;
|
||||
cout << " Heart Rate: " << hr << endl;
|
||||
|
||||
// output milliseconds passed, beat count, and computed heart rate
|
||||
cout << "Millis: " << millis << " Beats: " << beats;
|
||||
cout << " Heart Rate: " << hr << endl;
|
||||
|
||||
upm_delay(1);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
heart.stopBeatCounter();
|
||||
//! [Interesting]
|
||||
heart->stopBeatCounter();
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
delete heart;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,46 +22,45 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "groveeldriver.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove El Driver Module
|
||||
// Instantiate a Grove El Driver on digital pin D2
|
||||
upm::GroveElDriver eldriver(2);
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove El Driver Module
|
||||
// Instantiate a Grove El Driver on digital pin D2
|
||||
upm::GroveElDriver* eldriver = new upm::GroveElDriver(2);
|
||||
|
||||
bool lightState = true;
|
||||
bool lightState = true;
|
||||
|
||||
while (shouldRun) {
|
||||
if (lightState)
|
||||
eldriver.on();
|
||||
else
|
||||
eldriver.off();
|
||||
lightState = !lightState;
|
||||
upm_delay(1);
|
||||
}
|
||||
while (shouldRun)
|
||||
{
|
||||
if (lightState)
|
||||
eldriver->on();
|
||||
else
|
||||
eldriver->off();
|
||||
lightState = !lightState;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
eldriver.off();
|
||||
cout << "Exiting" << endl;
|
||||
//! [Interesting]
|
||||
eldriver->off();
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete eldriver;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,60 +22,58 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include "groveelectromagnet.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
float
|
||||
get_time()
|
||||
float get_time()
|
||||
{
|
||||
return ((float) (clock())) / CLOCKS_PER_SEC;
|
||||
return ((float)(clock()))/CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove Electromagnetic Module
|
||||
// Instantiate a Grove Electromagnet on digital pin D2
|
||||
upm::GroveElectromagnet magnet(2);
|
||||
cout << "Starting up magnet...." << endl;
|
||||
magnet.off();
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove Electromagnetic Module
|
||||
// Instantiate a Grove Electromagnet on digital pin D2
|
||||
upm::GroveElectromagnet* magnet = new upm::GroveElectromagnet(2);
|
||||
cout << "Starting up magnet...." << endl;
|
||||
magnet->off();
|
||||
|
||||
bool magnetState = false;
|
||||
float time_passed = get_time();
|
||||
bool magnetState = false;
|
||||
float time_passed = get_time();
|
||||
|
||||
// Turn magnet on and off every 5 seconds
|
||||
while (shouldRun) {
|
||||
if ((get_time() - time_passed) > 5.0) {
|
||||
magnetState = !magnetState;
|
||||
if (magnetState)
|
||||
magnet.on();
|
||||
else
|
||||
magnet.off();
|
||||
cout << "Turning magnet " << ((magnetState) ? "on" : "off") << endl;
|
||||
time_passed = get_time();
|
||||
}
|
||||
}
|
||||
// Turn magnet on and off every 5 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
if ((get_time() - time_passed) > 5.0)
|
||||
{
|
||||
magnetState = !magnetState;
|
||||
if (magnetState)
|
||||
magnet->on();
|
||||
else
|
||||
magnet->off();
|
||||
cout << "Turning magnet " << ((magnetState) ? "on" : "off") << endl;
|
||||
time_passed = get_time();
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
magnet.off();
|
||||
cout << "Exiting" << endl;
|
||||
//! [Interesting]
|
||||
magnet->off();
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
delete magnet;
|
||||
return 0;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user