mirror of
https://github.com/eclipse/upm.git
synced 2025-07-07 20:31:13 +03:00
Compare commits
81 Commits
Author | SHA1 | Date | |
---|---|---|---|
39c55b23d9 | |||
09b0f0adaa | |||
00b0092fc1 | |||
ec85072011 | |||
60221dbcd6 | |||
a35e58c54c | |||
1b8cb1361c | |||
aeb948282a | |||
1b649021f1 | |||
10d784ea7e | |||
a48f457057 | |||
d8fc664178 | |||
83b0512ffb | |||
3e7fca21ee | |||
8c7d6483d3 | |||
22636fb47a | |||
fb5c809ff8 | |||
0d20cdb25a | |||
f2b10afa35 | |||
56e1d2214f | |||
e80e1bda2c | |||
98f9dc54ff | |||
611f72c491 | |||
6f68e07aa5 | |||
be34f53a51 | |||
7a133cf891 | |||
49611e5ac0 | |||
e5385eb510 | |||
de1a46aa59 | |||
7e402ede34 | |||
4381f8bd2e | |||
757104e013 | |||
6c08313cb7 | |||
6d4714df3c | |||
75e42c6731 | |||
5a5637a431 | |||
e062b9b85c | |||
b778476597 | |||
9fb4be1b44 | |||
42ff8b3a6e | |||
a8d96bd2d9 | |||
f3a2e0d77c | |||
a348f23a3b | |||
efe80a4450 | |||
411656d965 | |||
c007385847 | |||
8490a63309 | |||
2331548f25 | |||
777f081f84 | |||
56666872d9 | |||
c16f80f226 | |||
ee8433d92a | |||
dd3e88fa59 | |||
224fe03d98 | |||
9e7eae070a | |||
9bc3d2ded0 | |||
f268437cd5 | |||
aff6e9c77f | |||
d642d63d21 | |||
17fd502cb5 | |||
b08da722f7 | |||
4220dd25b4 | |||
bbdbe56355 | |||
e7a5118f86 | |||
fe8906fb51 | |||
f35f6cc064 | |||
389bd32f81 | |||
f2b8921f1e | |||
6f080db5cb | |||
4aeccf7714 | |||
33734dc2e2 | |||
1f1a1bce8e | |||
bd7930f249 | |||
d183c9574d | |||
63066bcc0b | |||
15d91d4797 | |||
031ed7bf95 | |||
1aa445b74e | |||
e6ad752a2c | |||
144937995c | |||
0b49cbab9b |
33
.travis.yml
33
.travis.yml
@ -1,21 +1,38 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
compiler:
|
env:
|
||||||
- gcc
|
- CC=gcc CXX=gcc
|
||||||
- clang
|
- CC=clang CXX=clang++
|
||||||
|
- NODE4=true
|
||||||
|
- NODE5=true
|
||||||
|
- NODE012=true
|
||||||
install:
|
install:
|
||||||
- sudo add-apt-repository --yes ppa:kalakris/cmake
|
|
||||||
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
||||||
- sudo apt-get update -qq
|
- sudo apt-get update -qq
|
||||||
- sudo apt-get install -y -qq swig3.0 python git cmake
|
- sudo apt-get install -y -qq swig3.0 git
|
||||||
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
||||||
- sudo update-java-alternatives -s java-8-oracle
|
- sudo update-java-alternatives -s java-8-oracle
|
||||||
before_script:
|
before_script:
|
||||||
|
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36"
|
||||||
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
|
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
|
||||||
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
||||||
|
- if [ "${NODE4}" ]; then nvm install 4.1; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
|
- if [ "${NODE5}" ]; then nvm install 5; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
|
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
script:
|
script:
|
||||||
- git clone --branch=master https://github.com/intel-iot-devkit/mraa.git
|
- git clone https://github.com/intel-iot-devkit/mraa.git
|
||||||
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include .. && make && make install
|
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=OFF -DFIRMATA=ON -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. .. && make && make install
|
||||||
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
|
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
|
||||||
- export CPLUS_INCLUDE_PATH=$PWD/include
|
- export CPLUS_INCLUDE_PATH=$PWD/include
|
||||||
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
|
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
|
||||||
- cd ../.. && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
- cd ../.. && mkdir build && cd build && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-precise-3.6
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
- george-edison55-precise-backports
|
||||||
|
packages:
|
||||||
|
- clang-3.6
|
||||||
|
- g++-4.8
|
||||||
|
- cmake
|
||||||
|
- cmake-data
|
||||||
|
@ -25,7 +25,7 @@ include (GetGitRevisionDescription)
|
|||||||
git_describe (VERSION "--tags")
|
git_describe (VERSION "--tags")
|
||||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
||||||
message (WARNING " - Install git to compile a production UPM!")
|
message (WARNING " - Install git to compile a production UPM!")
|
||||||
set (VERSION "v0.5.1-dirty")
|
set (VERSION "v0.6.0-dirty")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
message (INFO " - UPM Version ${VERSION}")
|
message (INFO " - UPM Version ${VERSION}")
|
||||||
@ -51,13 +51,15 @@ set (CMAKE_SWIG_FLAGS "")
|
|||||||
option (BUILDDOC "Build all doc." OFF)
|
option (BUILDDOC "Build all doc." OFF)
|
||||||
option (BUILDSWIG "Build swig modules." ON)
|
option (BUILDSWIG "Build swig modules." ON)
|
||||||
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
||||||
|
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
|
||||||
option (BUILDSWIGNODE "Build swig node modules." ON)
|
option (BUILDSWIGNODE "Build swig node modules." ON)
|
||||||
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
||||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
||||||
option (IPK "Generate IPK using CPack" OFF)
|
option (IPK "Generate IPK using CPack" OFF)
|
||||||
option (RPM "Generate RPM using CPack" OFF)
|
option (RPM "Generate RPM using CPack" OFF)
|
||||||
option (BUILDTESTS "Generate check-ups for upm" OFF)
|
option (BUILDTESTS "Generate check-ups for upm" ON)
|
||||||
|
option (ENABLECXX11 "Enable C++11 standards support" ON)
|
||||||
|
|
||||||
# Find swig
|
# Find swig
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIG)
|
||||||
@ -76,6 +78,27 @@ include (TargetArch)
|
|||||||
target_architecture (DETECTED_ARCH)
|
target_architecture (DETECTED_ARCH)
|
||||||
message( INFO " - Target arch is ${DETECTED_ARCH}")
|
message( INFO " - Target arch is ${DETECTED_ARCH}")
|
||||||
|
|
||||||
|
# enable c++11 standards support
|
||||||
|
if (ENABLECXX11)
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||||
|
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||||
|
if (COMPILER_SUPPORTS_CXX11)
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
elseif (COMPILER_SUPPORTS_CXX0X)
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
else()
|
||||||
|
message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please update your C++ compiler.")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
# 3.1+ uses this generic method to enable c++11
|
||||||
|
set (CMAKE_CXX_STANDARD 11)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "Some modules require C++11 support, and may not build without it.")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (BUILDDOC)
|
if (BUILDDOC)
|
||||||
# Add a target to generate API documentation with Doxygen
|
# Add a target to generate API documentation with Doxygen
|
||||||
find_package (Doxygen)
|
find_package (Doxygen)
|
||||||
@ -99,7 +122,7 @@ if (BUILDDOC)
|
|||||||
find_package (Sphinx)
|
find_package (Sphinx)
|
||||||
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
|
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
|
||||||
# Python required for Sphinx build
|
# Python required for Sphinx build
|
||||||
find_package (PythonLibs)
|
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
||||||
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
||||||
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
||||||
@ -156,7 +179,7 @@ if (IPK)
|
|||||||
endif ()
|
endif ()
|
||||||
message (INFO " - Package arch is ${TARGET_ARCH}")
|
message (INFO " - Package arch is ${TARGET_ARCH}")
|
||||||
|
|
||||||
set(CPACK_GENERATOR "DEB" "TGZ")
|
set(CPACK_GENERATOR "DEB")
|
||||||
set(OPKG_ARCH ${TARGET_ARCH})
|
set(OPKG_ARCH ${TARGET_ARCH})
|
||||||
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
||||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
||||||
@ -182,10 +205,9 @@ if (RPM)
|
|||||||
message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
|
message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
|
||||||
set(CPACK_PACKAGE_VERSION ${VERSION})
|
set(CPACK_PACKAGE_VERSION ${VERSION})
|
||||||
set(CPACK_GENERATOR "RPM")
|
set(CPACK_GENERATOR "RPM")
|
||||||
set(CPACK_PACKAGE_NAME "libupm${upm_VERSION_MAJOR}")
|
set(CPACK_PACKAGE_NAME "upm")
|
||||||
set(CPACK_PACKAGE_RELEASE 1)
|
|
||||||
set(CPACK_PACKAGE_VERSION
|
set(CPACK_PACKAGE_VERSION
|
||||||
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}-${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}.${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
||||||
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
|
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
|
||||||
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
|
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
|
||||||
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
|
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
|
||||||
@ -196,7 +218,7 @@ if (RPM)
|
|||||||
COMMAND tr \\n \\t
|
COMMAND tr \\n \\t
|
||||||
COMMAND sed -e s/\\t//
|
COMMAND sed -e s/\\t//
|
||||||
OUTPUT_VARIABLE DIST_TAG)
|
OUTPUT_VARIABLE DIST_TAG)
|
||||||
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
|
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${DIST_TAG}.${DETECTED_ARCH}")
|
||||||
include(CPack)
|
include(CPack)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -210,10 +232,16 @@ if(BUILDJAVAEXAMPLES)
|
|||||||
add_subdirectory (examples/java)
|
add_subdirectory (examples/java)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(BUILDTESTS)
|
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||||
find_package (PythonInterp REQUIRED)
|
if (BUILDPYTHON3)
|
||||||
if (${PYTHONINTERP_FOUND})
|
set (PYTHONBUILD_VERSION 3)
|
||||||
|
else ()
|
||||||
|
set (PYTHONBUILD_VERSION 2.7)
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (BUILDTESTS)
|
||||||
|
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
enable_testing ()
|
enable_testing ()
|
||||||
add_subdirectory (tests)
|
add_subdirectory (tests)
|
||||||
endif ()
|
|
||||||
endif()
|
endif()
|
||||||
|
19
README.md
19
README.md
@ -12,6 +12,19 @@ to provide identification/pin location on the board.
|
|||||||
Typically an update() function will be called in order to get new data from the
|
Typically an update() function will be called in order to get new data from the
|
||||||
sensor in order to reduce load when doing multiple reads to sensor data.
|
sensor in order to reduce load when doing multiple reads to sensor data.
|
||||||
|
|
||||||
|
Although implementation and API design is up to the developer, C++ interfaces have
|
||||||
|
been defined for the following sensor/actuator types and developers are encouraged to
|
||||||
|
implement them. Interface header files are in the src/upm folder.
|
||||||
|
|
||||||
|
* Light controller
|
||||||
|
* Light sensor
|
||||||
|
* Temperature sensor
|
||||||
|
* Humidity sensor
|
||||||
|
* Pressure sensor
|
||||||
|
* Analog to digital converter
|
||||||
|
|
||||||
|
Feedback on interface design and additions for new types are welcome
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer API):
|
A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer API):
|
||||||
@ -51,10 +64,6 @@ A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
However implementation and API design is completely up to the developer, some
|
|
||||||
enumerable sensors for example may provide much clever instantiation. Displays
|
|
||||||
may also create more complex structures in order to interface with them.
|
|
||||||
|
|
||||||
Browse through the list of all [examples](https://github.com/intel-iot-devkit/upm/tree/master/examples).
|
Browse through the list of all [examples](https://github.com/intel-iot-devkit/upm/tree/master/examples).
|
||||||
|
|
||||||
Multi-sensor samples for the starter and specialized kits can be found in the
|
Multi-sensor samples for the starter and specialized kits can be found in the
|
||||||
@ -81,7 +90,7 @@ See building documentation [here](docs/building.md).
|
|||||||
|
|
||||||
Porting [link](docs/porting.md) has more information on making new UPM modules.
|
Porting [link](docs/porting.md) has more information on making new UPM modules.
|
||||||
|
|
||||||
There is also an example available for max31855 [sensor](docs/max31855.md).
|
There is also an example available gfor max31855 [sensor](docs/max31855.md).
|
||||||
|
|
||||||
Guide on creating Java [bindings](docs/creating_java_bindings.md).
|
Guide on creating Java [bindings](docs/creating_java_bindings.md).
|
||||||
|
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
find_program (NODE_EXECUTABLE NAMES node
|
# 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})
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
|
find_program (NODEJS_EXECUTABLE NAMES node nodejs
|
||||||
HINTS
|
HINTS
|
||||||
$ENV{NODE_DIR}
|
$ENV{NODE_DIR}
|
||||||
PATH_SUFFIXES bin
|
PATH_SUFFIXES bin
|
||||||
@ -7,26 +15,50 @@ find_program (NODE_EXECUTABLE NAMES node
|
|||||||
|
|
||||||
include (FindPackageHandleStandardArgs)
|
include (FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
|
# If compat-libuv package exists, it must be at start of include path
|
||||||
PATHS /usr/include/nodejs /usr/local/include/nodejs)
|
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})
|
||||||
|
endif()
|
||||||
|
|
||||||
set (NODE_INCLUDE_DIRS
|
# Now look for node. Flag an error if not found
|
||||||
${NODE_ROOT_DIR}/src
|
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
|
||||||
${NODE_ROOT_DIR}/node
|
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
||||||
${NODE_ROOT_DIR}/deps/v8/include
|
if (NODE_ROOT_DIR)
|
||||||
${NODE_ROOT_DIR}/deps/uv/include
|
add_include_dir(${NODE_ROOT_DIR}/include/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}/include/deps/uv/include)
|
||||||
|
else()
|
||||||
|
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")
|
||||||
|
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")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package_handle_standard_args (Nodejs DEFAULT_MSG
|
||||||
|
NODEJS_EXECUTABLE
|
||||||
|
NODEJS_INCLUDE_DIRS
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package_handle_standard_args (Node DEFAULT_MSG
|
if (NODEJS_EXECUTABLE)
|
||||||
NODE_EXECUTABLE
|
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
|
||||||
NODE_INCLUDE_DIRS
|
|
||||||
)
|
|
||||||
|
|
||||||
if (NODE_EXECUTABLE)
|
|
||||||
execute_process(COMMAND ${NODE_EXECUTABLE} --version
|
|
||||||
OUTPUT_VARIABLE _VERSION
|
OUTPUT_VARIABLE _VERSION
|
||||||
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
||||||
execute_process(COMMAND ${NODE_EXECUTABLE} -e "console.log(process.versions.v8)"
|
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
|
||||||
OUTPUT_VARIABLE _V8_VERSION
|
OUTPUT_VARIABLE _V8_VERSION
|
||||||
RESULT_VARIABLE _V8_RESULT)
|
RESULT_VARIABLE _V8_RESULT)
|
||||||
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
||||||
@ -55,7 +87,11 @@ if (NODE_EXECUTABLE)
|
|||||||
set (V8_VERSION_STRING "3.28.72")
|
set (V8_VERSION_STRING "3.28.72")
|
||||||
message ("defaulted to node 0.10.30")
|
message ("defaulted to node 0.10.30")
|
||||||
endif ()
|
endif ()
|
||||||
message ("INFO - Node version is " ${NODE_VERSION_STRING} "INFO - Node using v8 " ${V8_VERSION_STRING})
|
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
|
||||||
|
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
|
||||||
|
message ("INFO - Node version is " ${NODE_VERSION_STRING})
|
||||||
|
message ("INFO - Node using v8 " ${V8_VERSION_STRING})
|
||||||
|
mark_as_advanced (NODEJS_EXECUTABLE)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
mark_as_advanced (NODE_EXECUTABLE)
|
mark_as_advanced (NODE_EXECUTABLE)
|
||||||
|
@ -4,6 +4,19 @@ Changelog {#changelog}
|
|||||||
Here's a list summarizing some of the key undergoing changes to our library
|
Here's a list summarizing some of the key undergoing changes to our library
|
||||||
from earlier versions:
|
from earlier versions:
|
||||||
|
|
||||||
|
### v0.6.0
|
||||||
|
|
||||||
|
* Introduced C++ Interfaces for several sensor categories that will help
|
||||||
|
consolidate the sensor APIs with uniform function names upon implementation
|
||||||
|
* Greatly improved Node.js detection and handling during build and install,
|
||||||
|
and should be now compatible with all major versions
|
||||||
|
* Added a driver for the Curie IMU (accelerometer + gyroscope) that works with
|
||||||
|
the new Firmata support implemented by MRAA
|
||||||
|
* Continued to provide several JAVA fixes and examples
|
||||||
|
* Many new industrial and maker sensors: cwlsxxa, teams, tex00, h803x, apa102,
|
||||||
|
smartdrive, bmi160, bme280, ds1808lc, hlg150, lp8860, max44009, si1132, t6713,
|
||||||
|
si7005, ssd1351
|
||||||
|
|
||||||
### v0.5.1
|
### v0.5.1
|
||||||
|
|
||||||
* Updated the API and added new functionality for the MY9221 class and derived
|
* Updated the API and added new functionality for the MY9221 class and derived
|
||||||
|
BIN
docs/images/apa102.jpg
Normal file
BIN
docs/images/apa102.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 72 KiB |
BIN
docs/images/ssd1351.jpg
Normal file
BIN
docs/images/ssd1351.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
@ -859,7 +859,7 @@ EXCLUDE_SYMLINKS = NO
|
|||||||
# Note that the wildcards are matched against the file with absolute path, so to
|
# Note that the wildcards are matched against the file with absolute path, so to
|
||||||
# exclude all test directories for example use the pattern */test/*
|
# exclude all test directories for example use the pattern */test/*
|
||||||
|
|
||||||
EXCLUDE_PATTERNS =
|
EXCLUDE_PATTERNS = bosch_*
|
||||||
|
|
||||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||||
|
@ -48,7 +48,7 @@ mpu9150.cxx MPU9150Sample.java
|
|||||||
mq2.cxx MQ2Sample.java
|
mq2.cxx MQ2Sample.java
|
||||||
mq303a.cxx MQ303ASample.java
|
mq303a.cxx MQ303ASample.java
|
||||||
mq5.cxx MQ5Sample.java
|
mq5.cxx MQ5Sample.java
|
||||||
my9221-ledbar.cxx MY9221_ledbarSample.java
|
groveledbar GroveLEDBar
|
||||||
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
|
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
|
||||||
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
|
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
|
||||||
nunchuck.cxx NUNCHUCKSample.java
|
nunchuck.cxx NUNCHUCKSample.java
|
||||||
|
@ -234,11 +234,30 @@ if (MODBUS_FOUND)
|
|||||||
include_directories(${MODBUS_INCLUDE_DIRS})
|
include_directories(${MODBUS_INCLUDE_DIRS})
|
||||||
add_example (t3311)
|
add_example (t3311)
|
||||||
add_example (hwxpxx)
|
add_example (hwxpxx)
|
||||||
|
add_example (h803x)
|
||||||
endif()
|
endif()
|
||||||
add_example (hdxxvxta)
|
add_example (hdxxvxta)
|
||||||
add_example (rhusb)
|
add_example (rhusb)
|
||||||
add_example (apds9930)
|
add_example (apds9930)
|
||||||
add_example (kxcjk1013)
|
add_example (kxcjk1013)
|
||||||
|
add_example (ssd1351)
|
||||||
|
add_example (bme280)
|
||||||
|
add_example (ds1808lc)
|
||||||
|
add_example (hlg150h)
|
||||||
|
add_example (lp8860)
|
||||||
|
add_example (max44009)
|
||||||
|
add_example (si1132)
|
||||||
|
add_example (si7005)
|
||||||
|
add_example (t6713)
|
||||||
|
add_example (cwlsxxa)
|
||||||
|
add_example (teams)
|
||||||
|
add_example (apa102)
|
||||||
|
add_example (tex00)
|
||||||
|
add_example (bmi160)
|
||||||
|
add_example (smartdrive)
|
||||||
|
if (HAVE_FIRMATA)
|
||||||
|
add_example (curieimu)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# These are special cases where you specify example binary, source file and module(s)
|
# These are special cases where you specify example binary, source file and module(s)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||||
@ -257,3 +276,10 @@ add_custom_example (ak8975-example ak8975.cxx mpu9150)
|
|||||||
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
|
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
|
||||||
add_custom_example (groveledbar-example groveledbar.cxx my9221)
|
add_custom_example (groveledbar-example groveledbar.cxx my9221)
|
||||||
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)
|
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)
|
||||||
|
add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bmp180;bme280")
|
||||||
|
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bme280")
|
||||||
|
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmp180;bme280")
|
||||||
|
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
||||||
|
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
|
||||||
|
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
||||||
|
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
||||||
|
80
examples/c++/adc-sensor.cxx
Normal file
80
examples/c++/adc-sensor.cxx
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "ads1015.h"
|
||||||
|
#include "mraa/gpio.hpp"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
|
||||||
|
//! [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()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
51
examples/c++/apa102.cxx
Normal file
51
examples/c++/apa102.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "apa102.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a strip of 30 LEDs on SPI bus 0
|
||||||
|
upm::APA102* ledStrip = new upm::APA102(800, 0);
|
||||||
|
|
||||||
|
// Set all LEDs to Red
|
||||||
|
ledStrip->setAllLeds(31, 255, 0, 0);
|
||||||
|
|
||||||
|
// Set a section (10 to 20) to blue
|
||||||
|
ledStrip->setLeds(10, 20, 31, 0, 0, 255);
|
||||||
|
|
||||||
|
// Set a single LED to green
|
||||||
|
ledStrip->setLed(15, 31, 0, 255, 0);
|
||||||
|
|
||||||
|
delete ledStrip;
|
||||||
|
//! [Interesting]
|
||||||
|
return 0;
|
||||||
|
}
|
51
examples/c++/bme280.cxx
Normal file
51
examples/c++/bme280.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "bme280.h"
|
||||||
|
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
upm::BME280* bme280 = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
while (true) {
|
||||||
|
int temperature = bme280->getTemperatureCelcius();
|
||||||
|
int humidity = bme280->getHumidityRelative();
|
||||||
|
int pressure = bme280->getPressurePa();
|
||||||
|
std::cout << "Temperature = " << temperature << "C" << std::endl;
|
||||||
|
std::cout << "Humidity = " << humidity << "%" << std::endl;
|
||||||
|
std::cout << "Pressure = " << pressure << "Pa" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete bme280;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
82
examples/c++/bmi160.cxx
Normal file
82
examples/c++/bmi160.cxx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "bmi160.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
float dataX, dataY, dataZ;
|
||||||
|
|
||||||
|
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->getMagnetometer(&dataX, &dataY, &dataZ);
|
||||||
|
cout << "Magnetometer: ";
|
||||||
|
cout << "MX: " << dataX << " MY: " << dataY << " MZ: "
|
||||||
|
<< dataZ << endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
71
examples/c++/co2-sensor.cxx
Normal file
71
examples/c++/co2-sensor.cxx
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "t6713.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ICO2Sensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ICO2Sensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::ICO2Sensor* getCO2Sensor()
|
||||||
|
{
|
||||||
|
upm::ICO2Sensor* cO2Sensor = NULL;
|
||||||
|
try {
|
||||||
|
cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return cO2Sensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "T6713: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return cO2Sensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::ICO2Sensor* cO2Sensor = getCO2Sensor();
|
||||||
|
if (cO2Sensor == NULL) {
|
||||||
|
std::cout << "CO2 sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "CO2 sensor " << cO2Sensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
uint16_t value = cO2Sensor->getPpm();
|
||||||
|
std::cout << "CO2 level = " << value << " ppm" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete cO2Sensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
81
examples/c++/curieimu.cxx
Normal file
81
examples/c++/curieimu.cxx
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Author: Justin Zemlyansky (@JustInDevelopment)
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
#include "mraa.h"
|
||||||
|
#include "mraa/firmata.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
mraa_init();
|
||||||
|
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||||
|
|
||||||
|
upm::CurieImu* sensor = new upm::CurieImu();
|
||||||
|
|
||||||
|
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();
|
||||||
|
printf("accelerometer is: %d, %d, %d\n", x, y, z);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
usleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
82
examples/c++/cwlsxxa.cxx
Normal file
82
examples/c++/cwlsxxa.cxx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "cwlsxxa.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Temperature: " << sensor->getTemperature()
|
||||||
|
<< " C / " << sensor->getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Humidity: " << sensor->getHumidity()
|
||||||
|
<< " %" << endl;
|
||||||
|
|
||||||
|
cout << "CO2: " << sensor->getCO2()
|
||||||
|
<< " ppm" << endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
51
examples/c++/ds1808lc.cxx
Normal file
51
examples/c++/ds1808lc.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "ds1808lc.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||||
|
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||||
|
|
||||||
|
void printState(upm::ILightController *lightController)
|
||||||
|
{
|
||||||
|
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 status = 0;
|
||||||
|
upm::ILightController* lightController;
|
||||||
|
|
||||||
|
try {
|
||||||
|
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
std::cout << "Existing state: "; printState(lightController);
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";printState(lightController);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete lightController;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
149
examples/c++/h803x.cxx
Normal file
149
examples/c++/h803x.cxx
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "h803x.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
string defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
||||||
|
// default comm parameters (9600, 8, N, 2)
|
||||||
|
upm::H803X *sensor = new upm::H803X(defaultDev, 1);
|
||||||
|
|
||||||
|
// output the Slave ID string
|
||||||
|
cout << "Slave ID: " << sensor->getSlaveID() << endl;
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor->update();
|
||||||
|
|
||||||
|
// H8035 / H8036
|
||||||
|
cout << "Consumption (kWh): " << sensor->getConsumption() << endl;
|
||||||
|
cout << "Real Power (kW): " << sensor->getRealPower() << endl;
|
||||||
|
|
||||||
|
if (sensor->isH8036())
|
||||||
|
{
|
||||||
|
// The H8036 has much more data available...
|
||||||
|
|
||||||
|
cout << "Reactive Power (kVAR): " << sensor->getReactivePower()
|
||||||
|
<< endl;
|
||||||
|
cout << "Apparent Power (kVA): " << sensor->getApparentPower()
|
||||||
|
<< endl;
|
||||||
|
cout << "Power Factor: " << sensor->getPowerFactor()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Line to Line: " << sensor->getVoltsLineToLine()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Line to Neutral: " << sensor->getVoltsLineToNeutral()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Current: " << sensor->getCurrent()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Real Power Phase A (kW): " << sensor->getRealPowerPhaseA()
|
||||||
|
<< endl;
|
||||||
|
cout << "Real Power Phase B (kW): " << sensor->getRealPowerPhaseB()
|
||||||
|
<< endl;
|
||||||
|
cout << "Real Power Phase C (kW): " << sensor->getRealPowerPhaseC()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Power Factor Phase A: " << sensor->getPowerFactorPhaseA()
|
||||||
|
<< endl;
|
||||||
|
cout << "Power Factor Phase B: " << sensor->getPowerFactorPhaseB()
|
||||||
|
<< endl;
|
||||||
|
cout << "Power Factor Phase C: " << sensor->getPowerFactorPhaseC()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Volts Phase A to B: " << sensor->getVoltsPhaseAToB()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase B to C: " << sensor->getVoltsPhaseBToC()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase A to C: " << sensor->getVoltsPhaseAToC()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase A to Neutral: "
|
||||||
|
<< sensor->getVoltsPhaseAToNeutral()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase B to Neutral: "
|
||||||
|
<< sensor->getVoltsPhaseBToNeutral()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase C to Neutral: "
|
||||||
|
<< sensor->getVoltsPhaseCToNeutral()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Current Phase A: " << sensor->getCurrentPhaseA()
|
||||||
|
<< endl;
|
||||||
|
cout << "Current Phase B: " << sensor->getCurrentPhaseB()
|
||||||
|
<< endl;
|
||||||
|
cout << "Current Phase C: " << sensor->getCurrentPhaseC()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Avg Real Power (kW): " << sensor->getAvgRealPower()
|
||||||
|
<< endl;
|
||||||
|
cout << "Min Real Power (kW): " << sensor->getMinRealPower()
|
||||||
|
<< endl;
|
||||||
|
cout << "Max Real Power (kW): " << sensor->getMaxRealPower()
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
51
examples/c++/hlg150h.cxx
Normal file
51
examples/c++/hlg150h.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "hlg150h.h"
|
||||||
|
|
||||||
|
#define HLG150H_GPIO_RELAY 21
|
||||||
|
#define HLG150H_GPIO_PWM 22
|
||||||
|
|
||||||
|
void printState(upm::ILightController *lightController)
|
||||||
|
{
|
||||||
|
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 status = 0;
|
||||||
|
upm::ILightController* lightController;
|
||||||
|
|
||||||
|
try {
|
||||||
|
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
|
||||||
|
std::cout << "Existing state: "; printState(lightController);
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";printState(lightController);
|
||||||
|
delete lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
82
examples/c++/humidity-sensor.cxx
Normal file
82
examples/c++/humidity-sensor.cxx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "si7005.h"
|
||||||
|
#include "bme280.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ILightSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::IHumiditySensor* getHumiditySensor()
|
||||||
|
{
|
||||||
|
upm::IHumiditySensor* humiditySensor = NULL;
|
||||||
|
try {
|
||||||
|
humiditySensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return humiditySensor ;
|
||||||
|
} catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr <<"BME280: "<<e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
humiditySensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
|
return humiditySensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI7005: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return humiditySensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::IHumiditySensor* humiditySensor = getHumiditySensor();
|
||||||
|
if (humiditySensor == NULL) {
|
||||||
|
std::cout << "Humidity sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "Humidity sensor " << humiditySensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
int value = humiditySensor->getHumidityRelative();
|
||||||
|
std::cout << "Humidity = " << value << "%" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete humiditySensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
98
examples/c++/light-controller.cxx
Normal file
98
examples/c++/light-controller.cxx
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "lp8860.h"
|
||||||
|
#include "ds1808lc.h"
|
||||||
|
#include "hlg150h.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||||
|
#define GPIO_SI7005_CS 20 // Edison GP12
|
||||||
|
#define HLG150H_GPIO_RELAY 21
|
||||||
|
#define HLG150H_GPIO_PWM 22
|
||||||
|
#define LP8860_GPIO_PWR 45 // Edison GP45
|
||||||
|
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||||
|
#define DS1808_GPIO_EDISON_LIVE 36 // Edison GP14
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightController to determine
|
||||||
|
// which controller is present and return its name.
|
||||||
|
// ILightController is then used to get readings from sensor
|
||||||
|
|
||||||
|
upm::ILightController* getLightController()
|
||||||
|
{
|
||||||
|
upm::ILightController* lightController = NULL;
|
||||||
|
try {
|
||||||
|
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "LP8860: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "DS1808LC: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "HLG150H: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return lightController;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printState(upm::ILightController *lightController)
|
||||||
|
{
|
||||||
|
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 status = 0;
|
||||||
|
// MraaUtils::setGpio(GPIO_SI7005_CS, 1);
|
||||||
|
|
||||||
|
upm::ILightController *lightController = getLightController();
|
||||||
|
if (lightController != NULL)
|
||||||
|
{
|
||||||
|
std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Error. Unsupported platform." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::cout << "Existing state: "; printState(lightController);
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";printState(lightController);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete lightController;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
78
examples/c++/light-sensor.cxx
Normal file
78
examples/c++/light-sensor.cxx
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "max44009.h"
|
||||||
|
#include "si1132.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ILightSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::ILightSensor* getLightSensor()
|
||||||
|
{
|
||||||
|
upm::ILightSensor* lightSensor = NULL;
|
||||||
|
try {
|
||||||
|
lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI1132: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
|
||||||
|
return lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "MAX44009: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return lightSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::ILightSensor* lightSensor = getLightSensor();
|
||||||
|
if (lightSensor == NULL) {
|
||||||
|
std::cout << "Light sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "Light sensor " << lightSensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
float value = lightSensor->getVisibleLux();
|
||||||
|
std::cout << "Light level = " << value << " lux" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete lightSensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
52
examples/c++/lp8860.cxx
Normal file
52
examples/c++/lp8860.cxx
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "lp8860.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||||
|
#define LP8860_GPIO_PWR 45 // Edison GP45
|
||||||
|
|
||||||
|
|
||||||
|
void printState(upm::ILightController *lightController)
|
||||||
|
{
|
||||||
|
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 status = 0;
|
||||||
|
upm::LP8860* lightController;
|
||||||
|
|
||||||
|
try {
|
||||||
|
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
std::cout << "Existing state: "; printState(lightController);
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";printState(lightController);
|
||||||
|
delete lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
46
examples/c++/max44009.cxx
Normal file
46
examples/c++/max44009.cxx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "max44009.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
upm::MAX44009* lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
|
||||||
|
while (true) {
|
||||||
|
float value = lightSensor->getVisibleLux();
|
||||||
|
std::cout << "Light level = " << value << " lux" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
81
examples/c++/pressure-sensor.cxx
Normal file
81
examples/c++/pressure-sensor.cxx
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "bmp180.h"
|
||||||
|
#include "bme280.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ILightSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::IPressureSensor* getPressureSensor()
|
||||||
|
{
|
||||||
|
upm::IPressureSensor* pressureSensor = NULL;
|
||||||
|
try {
|
||||||
|
pressureSensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return pressureSensor ;
|
||||||
|
} catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr <<"BME280: "<<e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
pressureSensor = new upm::BMP180(EDISON_I2C_BUS);
|
||||||
|
return pressureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BMP180: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return pressureSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::IPressureSensor* pressureSensor = getPressureSensor();
|
||||||
|
if (pressureSensor == NULL) {
|
||||||
|
std::cout << "Pressure sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "Pressure sensor " << pressureSensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
int value = pressureSensor->getPressurePa();
|
||||||
|
std::cout << "Pressure = " << value << " Pa" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete pressureSensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
46
examples/c++/si1132.cxx
Normal file
46
examples/c++/si1132.cxx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "si1132.h"
|
||||||
|
|
||||||
|
#define FT4222_I2C_BUS 1
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
upm::SI1132* lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
while (true) {
|
||||||
|
float value = lightSensor->getVisibleLux();
|
||||||
|
std::cout << "Light level = " << value << " lux" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
51
examples/c++/si7005.cxx
Normal file
51
examples/c++/si7005.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "si7005.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
upm::SI7005* sensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
|
while (true) {
|
||||||
|
int temperature = sensor->getTemperatureCelcius();
|
||||||
|
int humidity = sensor->getHumidityRelative();
|
||||||
|
std::cout << "Temperature = " << temperature << "C" << std::endl;
|
||||||
|
std::cout << "Humidity = " << humidity << "%" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete sensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
75
examples/c++/smartdrive.cxx
Normal file
75
examples/c++/smartdrive.cxx
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Author: Oussema Harbi <oussema.elharbi@gmail.com>
|
||||||
|
* Copyright (c) <2016> <Oussema Harbi>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "smartdrive.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
upm::SmartDrive *drive = NULL;
|
||||||
|
|
||||||
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
|
{
|
||||||
|
printf("got signal\n");
|
||||||
|
if (signo == SIGINT) {
|
||||||
|
printf("exiting application\n");
|
||||||
|
if (drive != NULL)
|
||||||
|
delete drive;
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
float voltage = 0;
|
||||||
|
|
||||||
|
std::cout << "SmartDrive demo is starting. Please make sure drive is connected to board" << std::endl;
|
||||||
|
sleep(2); //Wait for 2 seconds in case you want to fix your h/w setup
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a SmartDrive connected to /dev/i2c-0 bus, using DefaultAddress
|
||||||
|
drive = new upm::SmartDrive(0);
|
||||||
|
|
||||||
|
std::cout << "Battery Voltage before motor run : " << drive->GetBattVoltage() << std::endl;
|
||||||
|
//Set motor M1 to run for 120 seconds, with speed of 15RPM, waith for it to finish and then Brake It
|
||||||
|
drive->Run_Seconds(SmartDrive_Motor_ID_1, SmartDrive_Dir_Forward, 15, 120, true, SmartDrive_Action_Brake);
|
||||||
|
std::cout << "Battery Voltage after motor run : " << drive->GetBattVoltage() << std::endl;
|
||||||
|
//Rotate motor M2 2270 degrees, in reverse sense, with speed of 10RPM, return immediately from function call
|
||||||
|
drive->Run_Degrees(SmartDrive_Motor_ID_2, SmartDrive_Dir_Reverse, 10, 2270, false, SmartDrive_Action_Float);
|
||||||
|
//While motor is running, Display its status
|
||||||
|
drive->PrintMotorStatus(SmartDrive_Motor_ID_2);
|
||||||
|
sleep(2); //Sleep for 2 seconds
|
||||||
|
//Stop motor M2 and then finish program
|
||||||
|
drive->StopMotor(SmartDrive_Motor_ID_2, SmartDrive_Action_BrakeHold);
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
std::cout << "Demo complete. GoodBye" << std::endl;
|
||||||
|
|
||||||
|
delete drive;
|
||||||
|
drive = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
61
examples/c++/ssd1351.cxx
Normal file
61
examples/c++/ssd1351.cxx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "mraa.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "ssd1351.h"
|
||||||
|
|
||||||
|
#define BLACK 0x0000
|
||||||
|
#define WHITE 0xFFFF
|
||||||
|
#define INTEL_BLUE 0x0BF8
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Define colors (16-bit RGB on 5/6/5 bits)
|
||||||
|
int colors[] = {0x0000, 0x000F, 0x03E0, 0x03EF,
|
||||||
|
0x7800, 0x780F, 0x7BE0, 0xC618,
|
||||||
|
0x7BEF, 0x001F, 0x07E0, 0x07FF,
|
||||||
|
0xF800, 0xF81F, 0xFFE0, 0xFFFF};
|
||||||
|
//! [Interesting]
|
||||||
|
// Initialize display with pins
|
||||||
|
// oc = 0, dc = 1, r = 2, si = 11, cl = 13
|
||||||
|
upm::SSD1351* display = new upm::SSD1351(0, 1, 2);
|
||||||
|
|
||||||
|
// Test lines pixel by pixel
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT; i++) {
|
||||||
|
for(int j = 0; j < SSD1351WIDTH; j++) {
|
||||||
|
display->drawPixel(i, j, colors[i/8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test rectangles
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
|
||||||
|
for (int j = 0; j < SSD1351WIDTH/32; j++) {
|
||||||
|
display->fillRect(i * 32, j * 32, 32, 32, colors[i * 4 + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test circles
|
||||||
|
display->fillScreen(0x2104);
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
|
||||||
|
for (int j = 0; j < SSD1351WIDTH/32; j++) {
|
||||||
|
display->drawCircle(i * 32 + 15, j * 32 + 15, 15, colors[i * 4 + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test Text
|
||||||
|
display->fillScreen(INTEL_BLUE);
|
||||||
|
display->setTextColor(WHITE, INTEL_BLUE);
|
||||||
|
display->setTextSize(4);
|
||||||
|
display->setCursor(7, 30);
|
||||||
|
display->print("Intel");
|
||||||
|
display->setCursor(5, 70);
|
||||||
|
display->print("IoTDK");
|
||||||
|
display->refresh();
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
48
examples/c++/t6713.cxx
Normal file
48
examples/c++/t6713.cxx
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "t6713.h"
|
||||||
|
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
upm::T6713* cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
while (true) {
|
||||||
|
uint16_t value = cO2Sensor->getPpm();
|
||||||
|
std::cout << "CO2 level = " << value << " ppm" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete cO2Sensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
84
examples/c++/teams.cxx
Normal file
84
examples/c++/teams.cxx
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "teams.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// Instantiate an TEAMS instance, using A0 for temperature, and
|
||||||
|
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
||||||
|
// interface)
|
||||||
|
upm::TEAMS *sensor = new upm::TEAMS(0, 165.0);
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor->update();
|
||||||
|
|
||||||
|
// is the sensor connected? (current >= 4ma)
|
||||||
|
cout << "Is Connected: " << sensor->isConnected() << endl;
|
||||||
|
|
||||||
|
// print computed current on the loop. This includes the offset,
|
||||||
|
// if one was set by setOffsetMilliamps().
|
||||||
|
cout << "Milliamps: " << sensor->getRawMilliamps() << endl;
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Temperature: " << sensor->getTemperature()
|
||||||
|
<< " C / " << sensor->getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
90
examples/c++/temperature-sensor.cxx
Normal file
90
examples/c++/temperature-sensor.cxx
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "si7005.h"
|
||||||
|
#include "bmp180.h"
|
||||||
|
#include "bme280.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ITemperatureSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ITemperatureSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::ITemperatureSensor* getTemperatureSensor()
|
||||||
|
{
|
||||||
|
upm::ITemperatureSensor* temperatureSensor = NULL;
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr <<"BME280: "<<e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI7005: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::BMP180(EDISON_I2C_BUS);
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BMP180: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return temperatureSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::ITemperatureSensor* temperatureSensor = getTemperatureSensor();
|
||||||
|
if (temperatureSensor == NULL) {
|
||||||
|
std::cout << "Temperature sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
int value = temperatureSensor->getTemperatureCelcius();
|
||||||
|
std::cout << "Temperature = " << value << "C" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete temperatureSensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
91
examples/c++/tex00.cxx
Normal file
91
examples/c++/tex00.cxx
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "tex00.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
||||||
|
// this example, we are using a 10K Ohm balance resistor and a TED
|
||||||
|
// (10k type 2) thermistor.
|
||||||
|
upm::TEX00 *sensor = new upm::TEX00(0, 10000,
|
||||||
|
upm::TEX00::STYPE_THERMISTOR_TED);
|
||||||
|
|
||||||
|
cout << "Minimum temperature: " << sensor->getTemperatureRangeMin()
|
||||||
|
<< " C" << endl;
|
||||||
|
cout << "Maximum temperature: " << sensor->getTemperatureRangeMax()
|
||||||
|
<< " C" << endl;
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor->update();
|
||||||
|
|
||||||
|
if (sensor->isOutOfRange())
|
||||||
|
{
|
||||||
|
cout << "Temperature out of range" << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Temperature: " << sensor->getTemperature()
|
||||||
|
<< " C / " << sensor->getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
examples/java/APA102Sample.java
Normal file
44
examples/java/APA102Sample.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class APA102Sample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Instantiate a strip of 30 LEDs on SPI bus 0
|
||||||
|
upm_apa102.APA102 ledStrip =
|
||||||
|
new upm_apa102.APA102(30, (short)0, false, (byte)-1);
|
||||||
|
|
||||||
|
System.out.println("Set all LEDs to blue");
|
||||||
|
ledStrip.setAllLeds((short)31, (short)0, (short)0, (short)255);
|
||||||
|
|
||||||
|
System.out.println("Set LEDs between 10 and 20 to green");
|
||||||
|
ledStrip.setLeds(10, 20, (short)31, (short)0, (short)255, (short)0);
|
||||||
|
|
||||||
|
System.out.println("Set a single LED to red at index 15");
|
||||||
|
ledStrip.setLed(15, (short)31, (short)255, (short)0, (short)0);
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
50
examples/java/Ad8232Example.java
Normal file
50
examples/java/Ad8232Example.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
import upm_ad8232.AD8232;
|
||||||
|
|
||||||
|
public class Ad8232Example {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
|
||||||
|
// and an analog pin, 0 (OUTPUT)
|
||||||
|
AD8232 ad8232 = new AD8232(10, 11, 0);
|
||||||
|
while(true){
|
||||||
|
// 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.
|
||||||
|
System.out.println(ad8232.value());
|
||||||
|
try {
|
||||||
|
Thread.sleep(1);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following error has occured: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
78
examples/java/BMI160_Example.java
Normal file
78
examples/java/BMI160_Example.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_bmi160.BMI160;
|
||||||
|
|
||||||
|
public class BMI160_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate a BMI160 instance using default i2c bus and address
|
||||||
|
BMI160 sensor = new BMI160();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
float dataA[] = sensor.getAccelerometer();
|
||||||
|
|
||||||
|
System.out.println("Accelerometer: "
|
||||||
|
+ "AX: "
|
||||||
|
+ dataA[0]
|
||||||
|
+ " AY: "
|
||||||
|
+ dataA[1]
|
||||||
|
+ " AZ: "
|
||||||
|
+ dataA[2]);
|
||||||
|
|
||||||
|
float dataG[] = sensor.getGyroscope();
|
||||||
|
|
||||||
|
System.out.println("Gryoscope: "
|
||||||
|
+ "GX: "
|
||||||
|
+ dataG[0]
|
||||||
|
+ " GY: "
|
||||||
|
+ dataG[1]
|
||||||
|
+ " GZ: "
|
||||||
|
+ dataG[2]);
|
||||||
|
|
||||||
|
float dataM[] = sensor.getMagnetometer();
|
||||||
|
|
||||||
|
System.out.println("Magnetometer: "
|
||||||
|
+ "MX: "
|
||||||
|
+ dataM[0]
|
||||||
|
+ " MY: "
|
||||||
|
+ dataM[1]
|
||||||
|
+ " MZ: "
|
||||||
|
+ dataM[2]);
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
@ -101,7 +101,18 @@ add_example(WaterLevelSensor waterlevel)
|
|||||||
add_example(WT5001Sample wt5001)
|
add_example(WT5001Sample wt5001)
|
||||||
add_example(YG1006Sample yg1006)
|
add_example(YG1006Sample yg1006)
|
||||||
add_example(ZFM20Sample zfm20)
|
add_example(ZFM20Sample zfm20)
|
||||||
|
add_example(Ad8232Example ad8232)
|
||||||
|
add_example(Gp2y0aExample gp2y0a)
|
||||||
|
add_example(Th02Example th02)
|
||||||
|
add_example(FlexSensorExample flex)
|
||||||
|
add_example(CWLSXXA_Example cwlsxxa)
|
||||||
|
add_example(TEAMS_Example teams)
|
||||||
|
add_example(APA102Sample apa102)
|
||||||
|
add_example(TEX00_Example tex00)
|
||||||
|
add_example(BMI160_Example bmi160)
|
||||||
|
if (MODBUS_FOUND)
|
||||||
|
add_example(H803X_Example h803x)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
|
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
|
||||||
add_example_with_path(Jhd1313m1Sample lcd/upm_i2clcd.jar)
|
add_example_with_path(Jhd1313m1Sample lcd/upm_i2clcd.jar)
|
||||||
|
62
examples/java/CWLSXXA_Example.java
Normal file
62
examples/java/CWLSXXA_Example.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_cwlsxxa.CWLSXXA;
|
||||||
|
|
||||||
|
public class CWLSXXA_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||||
|
// humidity and A2 for temperature
|
||||||
|
CWLSXXA sensor = new CWLSXXA(0, 1, 2);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
System.out.println("Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
|
||||||
|
System.out.println("Humidity: "
|
||||||
|
+ sensor.getHumidity()
|
||||||
|
+ " %");
|
||||||
|
|
||||||
|
System.out.println("CO2: "
|
||||||
|
+ sensor.getCO2()
|
||||||
|
+ " ppm");
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
41
examples/java/FlexSensorExample.java
Normal file
41
examples/java/FlexSensorExample.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import upm_flex.Flex;
|
||||||
|
|
||||||
|
public class FlexSensorExample {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_flex");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [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
|
||||||
|
Flex flex = new Flex(0);
|
||||||
|
while(true){
|
||||||
|
System.out.println("Flex Sensor value is: "+flex.value());
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
68
examples/java/Gp2y0aExample.java
Normal file
68
examples/java/Gp2y0aExample.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
import upm_gp2y0a.GP2Y0A;
|
||||||
|
|
||||||
|
public class Gp2y0aExample {
|
||||||
|
|
||||||
|
public static final float GP2Y0A_AREF = 5;
|
||||||
|
public static final short SAMPLES_PER_QUERY = 20;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_gp2y0a");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [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
|
||||||
|
GP2Y0A gp2y0a = new 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(true){
|
||||||
|
System.out.println("AREF: " + GP2Y0A_AREF + "\t, Voltage Value (Higher means Closer): "+ gp2y0a.value(GP2Y0A_AREF, SAMPLES_PER_QUERY));
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception occured: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
123
examples/java/H803X_Example.java
Normal file
123
examples/java/H803X_Example.java
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_h803x.H803X;
|
||||||
|
|
||||||
|
public class H803X_Example
|
||||||
|
{
|
||||||
|
private static String defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
if (args.length > 0)
|
||||||
|
defaultDev = args[0];
|
||||||
|
System.out.println("Using device " + defaultDev);
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
||||||
|
// default comm parameters (9600, 8, N, 2)
|
||||||
|
H803X sensor = new H803X(defaultDev, 1);
|
||||||
|
|
||||||
|
// output the Slave ID (manufacturer, model, serno)
|
||||||
|
System.out.println("Slave ID: " + sensor.getSlaveID());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// H8035 / H8036
|
||||||
|
System.out.println("Consumption (kWh): "
|
||||||
|
+ sensor.getConsumption());
|
||||||
|
System.out.println("Real Power (kW): "
|
||||||
|
+ sensor.getRealPower());
|
||||||
|
|
||||||
|
if (sensor.isH8036())
|
||||||
|
{
|
||||||
|
// The H8036 has much more data available...
|
||||||
|
|
||||||
|
System.out.println("Reactive Power (kVAR): "
|
||||||
|
+ sensor.getReactivePower());
|
||||||
|
System.out.println("Apparent Power (kVA): "
|
||||||
|
+ sensor.getApparentPower());
|
||||||
|
System.out.println("Power Factor: "
|
||||||
|
+ sensor.getPowerFactor());
|
||||||
|
System.out.println("Volts Line to Line: "
|
||||||
|
+ sensor.getVoltsLineToLine());
|
||||||
|
System.out.println("Volts Line to Neutral: "
|
||||||
|
+ sensor.getVoltsLineToNeutral());
|
||||||
|
|
||||||
|
System.out.println("Current: " + sensor.getCurrent());
|
||||||
|
|
||||||
|
System.out.println("Real Power Phase A (kW): "
|
||||||
|
+ sensor.getRealPowerPhaseA());
|
||||||
|
System.out.println("Real Power Phase B (kW): "
|
||||||
|
+ sensor.getRealPowerPhaseB());
|
||||||
|
System.out.println("Real Power Phase C (kW): "
|
||||||
|
+ sensor.getRealPowerPhaseC());
|
||||||
|
|
||||||
|
System.out.println("Power Factor Phase A: "
|
||||||
|
+ sensor.getPowerFactorPhaseA());
|
||||||
|
System.out.println("Power Factor Phase B: "
|
||||||
|
+ sensor.getPowerFactorPhaseB());
|
||||||
|
System.out.println("Power Factor Phase C: "
|
||||||
|
+ sensor.getPowerFactorPhaseC());
|
||||||
|
|
||||||
|
System.out.println("Volts Phase A to B: "
|
||||||
|
+ sensor.getVoltsPhaseAToB());
|
||||||
|
System.out.println("Volts Phase B to C: "
|
||||||
|
+ sensor.getVoltsPhaseBToC());
|
||||||
|
System.out.println("Volts Phase A to C: "
|
||||||
|
+ sensor.getVoltsPhaseAToC());
|
||||||
|
System.out.println("Volts Phase A to Neutral: "
|
||||||
|
+ sensor.getVoltsPhaseAToNeutral());
|
||||||
|
System.out.println("Volts Phase B to Neutral: "
|
||||||
|
+ sensor.getVoltsPhaseBToNeutral());
|
||||||
|
System.out.println("Volts Phase C to Neutral: "
|
||||||
|
+ sensor.getVoltsPhaseCToNeutral());
|
||||||
|
|
||||||
|
System.out.println("Current Phase A: "
|
||||||
|
+ sensor.getCurrentPhaseA());
|
||||||
|
System.out.println("Current Phase B: "
|
||||||
|
+ sensor.getCurrentPhaseB());
|
||||||
|
System.out.println("Current Phase C: "
|
||||||
|
+ sensor.getCurrentPhaseC());
|
||||||
|
|
||||||
|
System.out.println("Avg Real Power (kW): "
|
||||||
|
+ sensor.getAvgRealPower());
|
||||||
|
System.out.println("Min Real Power (kW): "
|
||||||
|
+ sensor.getMinRealPower());
|
||||||
|
System.out.println("Max Real Power (kW): "
|
||||||
|
+ sensor.getMaxRealPower());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
64
examples/java/TEAMS_Example.java
Normal file
64
examples/java/TEAMS_Example.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_teams.TEAMS;
|
||||||
|
|
||||||
|
public class TEAMS_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an TEAMS instance, using A0 for temperature, and
|
||||||
|
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
||||||
|
// interface)
|
||||||
|
TEAMS sensor = new TEAMS(0, 165.0f);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// is the sensor connected? (current >= 4ma)
|
||||||
|
System.out.println("Is Connected: " + sensor.isConnected());
|
||||||
|
|
||||||
|
// print computed current on the loop. This includes
|
||||||
|
// the offset, if one was set by setOffsetMilliamps().
|
||||||
|
System.out.println("Milliamps: " + sensor.getRawMilliamps());
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
System.out.println("Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
71
examples/java/TEX00_Example.java
Normal file
71
examples/java/TEX00_Example.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_tex00.TEX00;
|
||||||
|
|
||||||
|
public class TEX00_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
||||||
|
// this example, we are using a 10K Ohm balance resistor and a TED
|
||||||
|
// (10k type 2) thermistor.
|
||||||
|
TEX00 sensor = new TEX00(0, 10000.0f,
|
||||||
|
TEX00.SENSOR_TYPES_T.STYPE_THERMISTOR_TED);
|
||||||
|
|
||||||
|
System.out.println("Minimum temperature: "
|
||||||
|
+ sensor.getTemperatureRangeMin());
|
||||||
|
System.out.println("Maximum temperature: "
|
||||||
|
+ sensor.getTemperatureRangeMax());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
if (sensor.isOutOfRange())
|
||||||
|
{
|
||||||
|
System.out.println("Temperature out of range");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we show both C and F for temperature
|
||||||
|
System.out.println("Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
47
examples/java/Th02Example.java
Normal file
47
examples/java/Th02Example.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
import upm_th02.TH02;
|
||||||
|
|
||||||
|
public class Th02Example {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
float temperature = 0;
|
||||||
|
float humidity = 0;
|
||||||
|
|
||||||
|
TH02 sensor = new TH02();
|
||||||
|
while(true){
|
||||||
|
temperature = sensor.getTemperature();
|
||||||
|
humidity = sensor.getHumidity();
|
||||||
|
System.out.println("Temperature = "+temperature+", Humidity = "+humidity);
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception has occured: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
44
examples/javascript/apa102.js
Normal file
44
examples/javascript/apa102.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var lib = require('jsupm_apa102');
|
||||||
|
|
||||||
|
// Instantiate a strip of 30 LEDs on SPI Bus 0
|
||||||
|
var ledStrip = new lib.APA102(30, 0);
|
||||||
|
|
||||||
|
// Set all LEDs to blue
|
||||||
|
ledStrip.setAllLeds(31, 0, 0, 255);
|
||||||
|
|
||||||
|
// Set a mid-section to red
|
||||||
|
ledStrip.setLeds(10,20, 31, 255, 0, 0);
|
||||||
|
|
||||||
|
// Set a single led to green
|
||||||
|
ledStrip.setLed(15, 31, 0, 255, 0);
|
||||||
|
|
||||||
|
|
||||||
|
// Exit
|
||||||
|
ledStrip = null;
|
||||||
|
process.exit(0);
|
51
examples/javascript/bme280.js
Normal file
51
examples/javascript/bme280.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var bme280pkg = require('jsupm_bme280');
|
||||||
|
|
||||||
|
// Instantiate a BME280 Sensor on I2C sub-platform bus 0
|
||||||
|
var bme280 = new bme280pkg.BME280(512);
|
||||||
|
|
||||||
|
// update every second and print the values
|
||||||
|
var myInterval = setInterval(function()
|
||||||
|
{
|
||||||
|
// print detected value
|
||||||
|
console.log("Temperature: " + bme280.getTemperatureCelcius() + "C");
|
||||||
|
console.log("Humidity: " + bme280.getHumidityRelative() + "%");
|
||||||
|
console.log("Pressure: " + bme280.getPressurePa() + "Pa");
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
// When exiting: clear interval and print message
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
clearInterval(myInterval);
|
||||||
|
bme280 = null
|
||||||
|
bme280pkg = null;
|
||||||
|
console.log("Exiting");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
71
examples/javascript/bmi160.js
Normal file
71
examples/javascript/bmi160.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_bmi160');
|
||||||
|
|
||||||
|
// Instantiate a BMI160 instance using default i2c bus and address
|
||||||
|
var sensor = new sensorObj.BMI160();
|
||||||
|
|
||||||
|
var x = new sensorObj.new_floatp();
|
||||||
|
var y = new sensorObj.new_floatp();
|
||||||
|
var z = new sensorObj.new_floatp();
|
||||||
|
|
||||||
|
// Output data every half second until interrupted
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
sensor.getAccelerometer(x, y, z);
|
||||||
|
console.log("Accelerometer: AX: " + sensorObj.floatp_value(x) +
|
||||||
|
" AY: " + sensorObj.floatp_value(y) +
|
||||||
|
" AZ: " + sensorObj.floatp_value(z));
|
||||||
|
|
||||||
|
sensor.getGyroscope(x, y, z);
|
||||||
|
console.log("Gyroscope: GX: " + sensorObj.floatp_value(x) +
|
||||||
|
" AY: " + sensorObj.floatp_value(y) +
|
||||||
|
" AZ: " + sensorObj.floatp_value(z));
|
||||||
|
|
||||||
|
sensor.getMagnetometer(x, y, z);
|
||||||
|
console.log("Magnetometer: MX: " + sensorObj.floatp_value(x) +
|
||||||
|
" MY: " + sensorObj.floatp_value(y) +
|
||||||
|
" MZ: " + sensorObj.floatp_value(z));
|
||||||
|
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
// exit on ^C
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting.");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
52
examples/javascript/curieimu.js
Normal file
52
examples/javascript/curieimu.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
/*
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var mraa = require('mraa');
|
||||||
|
console.log('MRAA Version: ' + mraa.getVersion());
|
||||||
|
|
||||||
|
// open connection to Firmata
|
||||||
|
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||||
|
|
||||||
|
var curieImu = require('jsupm_curieimu');
|
||||||
|
var myCurie = new curieImu.CurieImu();
|
||||||
|
|
||||||
|
var outputStr;
|
||||||
|
var myInterval = setInterval(function()
|
||||||
|
{
|
||||||
|
myCurie.updateAccel();
|
||||||
|
outputStr = "accel: x " + myCurie.getAccelX()
|
||||||
|
+ " - y " + myCurie.getAccelY()
|
||||||
|
+ " - z " + myCurie.getAccelZ();
|
||||||
|
console.log(outputStr);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
// Print message when exiting
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
clearInterval(myInterval);
|
||||||
|
console.log("Exiting");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
66
examples/javascript/cwlsxxa.js
Normal file
66
examples/javascript/cwlsxxa.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_cwlsxxa');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||||
|
// humidity and A2 for temperature
|
||||||
|
var sensor = new sensorObj.CWLSXXA(0, 1, 2);
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
console.log("Temperature:", sensor.getTemperature(),
|
||||||
|
"C /", sensor.getTemperature(true), "F");
|
||||||
|
|
||||||
|
console.log("Humidity:", sensor.getHumidity(), "%");
|
||||||
|
|
||||||
|
console.log("CO2:", sensor.getCO2(), "ppm");
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
115
examples/javascript/h803x.js
Normal file
115
examples/javascript/h803x.js
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_h803x');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
var defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
// if an argument was specified, use it as the device instead
|
||||||
|
if (process.argv.length > 2)
|
||||||
|
{
|
||||||
|
defaultDev = process.argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Using device " + defaultDev);
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
||||||
|
// default comm parameters (9600, 8, N, 2)
|
||||||
|
var sensor = new sensorObj.H803X(defaultDev, 1);
|
||||||
|
|
||||||
|
// output the Slave ID (manufacturer, model, serno)
|
||||||
|
console.log("Slave ID:", sensor.getSlaveID());
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// H8035 / H8036
|
||||||
|
console.log("Consumption (kWh):", sensor.getConsumption());
|
||||||
|
console.log("Real Power (kW):", sensor.getRealPower());
|
||||||
|
|
||||||
|
if (sensor.isH8036())
|
||||||
|
{
|
||||||
|
// The H8036 has much more data available...
|
||||||
|
|
||||||
|
console.log("Reactive Power (kVAR):", sensor.getReactivePower());
|
||||||
|
console.log("Apparent Power (kVA):", sensor.getApparentPower());
|
||||||
|
console.log("Power Factor:", sensor.getPowerFactor());
|
||||||
|
console.log("Volts Line to Line:", sensor.getVoltsLineToLine());
|
||||||
|
console.log("Volts Line to Neutral:", sensor.getVoltsLineToNeutral());
|
||||||
|
|
||||||
|
console.log("Current:", sensor.getCurrent());
|
||||||
|
|
||||||
|
console.log("Real Power Phase A (kW):", sensor.getRealPowerPhaseA());
|
||||||
|
console.log("Real Power Phase B (kW):", sensor.getRealPowerPhaseB());
|
||||||
|
console.log("Real Power Phase C (kW):", sensor.getRealPowerPhaseC());
|
||||||
|
|
||||||
|
console.log("Power Factor Phase A:", sensor.getPowerFactorPhaseA());
|
||||||
|
console.log("Power Factor Phase B:", sensor.getPowerFactorPhaseB());
|
||||||
|
console.log("Power Factor Phase C:", sensor.getPowerFactorPhaseC());
|
||||||
|
|
||||||
|
console.log("Volts Phase A to B:", sensor.getVoltsPhaseAToB());
|
||||||
|
console.log("Volts Phase B to C:", sensor.getVoltsPhaseBToC());
|
||||||
|
console.log("Volts Phase A to C:", sensor.getVoltsPhaseAToC());
|
||||||
|
console.log("Volts Phase A to Neutral: ",
|
||||||
|
sensor.getVoltsPhaseAToNeutral());
|
||||||
|
console.log("Volts Phase B to Neutral: ",
|
||||||
|
sensor.getVoltsPhaseBToNeutral());
|
||||||
|
console.log("Volts Phase C to Neutral: ",
|
||||||
|
sensor.getVoltsPhaseCToNeutral());
|
||||||
|
|
||||||
|
console.log("Current Phase A:", sensor.getCurrentPhaseA());
|
||||||
|
console.log("Current Phase B:", sensor.getCurrentPhaseB());
|
||||||
|
console.log("Current Phase C:", sensor.getCurrentPhaseC());
|
||||||
|
|
||||||
|
console.log("Avg Real Power (kW):", sensor.getAvgRealPower());
|
||||||
|
console.log("Min Real Power (kW):", sensor.getMinRealPower());
|
||||||
|
console.log("Max Real Power (kW):", sensor.getMaxRealPower());
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
70
examples/javascript/teams.js
Normal file
70
examples/javascript/teams.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_teams');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an TEAMS instance, using A0 for temperature, and
|
||||||
|
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
||||||
|
// interface)
|
||||||
|
var sensor = new sensorObj.TEAMS(0, 165.0);
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// is the sensor connected? (current >= 4ma)
|
||||||
|
console.log("Is Connected:", sensor.isConnected());
|
||||||
|
|
||||||
|
// print computed current on the loop. This includes the offset,
|
||||||
|
// if one was set by setOffsetMilliamps().
|
||||||
|
console.log("Milliamps:", sensor.getRawMilliamps());
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
console.log("Temperature:", sensor.getTemperature(),
|
||||||
|
"C /", sensor.getTemperature(true), "F");
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
77
examples/javascript/tex00.js
Normal file
77
examples/javascript/tex00.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_tex00');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
||||||
|
// this example, we are using a 10K Ohm balance resistor and a TED
|
||||||
|
// (10k type 2) thermistor.
|
||||||
|
var sensor = new sensorObj.TEX00(0, 10000,
|
||||||
|
sensorObj.TEX00.STYPE_THERMISTOR_TED);
|
||||||
|
|
||||||
|
console.log("Minimum temperature:", sensor.getTemperatureRangeMin(),
|
||||||
|
"C");
|
||||||
|
console.log("Maximum temperature:", sensor.getTemperatureRangeMax(),
|
||||||
|
"C");
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
if (sensor.isOutOfRange())
|
||||||
|
{
|
||||||
|
console.log("Temperature out of range");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we show both C and F for temperature
|
||||||
|
console.log("Temperature:", sensor.getTemperature(),
|
||||||
|
"C /", sensor.getTemperature(true), "F");
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
48
examples/python/apa102.py
Normal file
48
examples/python/apa102.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
# Copyright (c) 2016 Yannick Adam
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_apa102 as mylib
|
||||||
|
|
||||||
|
# Instantiate a strip of 30 LEDs on SPI bus 0
|
||||||
|
ledStrip = mylib.APA102(30, 0, False)
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
print "Setting all LEDs to Green"
|
||||||
|
ledStrip.setAllLeds(31, 0, 255, 0)
|
||||||
|
|
||||||
|
print "Setting LEDs between 10 and 20 to Red"
|
||||||
|
ledStrip.setLeds(10, 20, 31, 255, 0, 0)
|
||||||
|
|
||||||
|
print "Setting LED 15 to Blue"
|
||||||
|
ledStrip.setLed(15, 31, 0, 0, 255)
|
||||||
|
|
||||||
|
|
66
examples/python/bmi160.py
Normal file
66
examples/python/bmi160.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_bmi160 as sensorObj
|
||||||
|
|
||||||
|
# Instantiate a BMI160 instance using default i2c bus and address
|
||||||
|
sensor = sensorObj.BMI160()
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
x = sensorObj.new_floatp()
|
||||||
|
y = sensorObj.new_floatp()
|
||||||
|
z = sensorObj.new_floatp()
|
||||||
|
|
||||||
|
while (1):
|
||||||
|
sensor.update()
|
||||||
|
sensor.getAccelerometer(x, y, z)
|
||||||
|
print "Accelerometer: AX: ", sensorObj.floatp_value(x),
|
||||||
|
print " AY: ", sensorObj.floatp_value(y),
|
||||||
|
print " AZ: ", sensorObj.floatp_value(z)
|
||||||
|
|
||||||
|
sensor.getGyroscope(x, y, z)
|
||||||
|
print "Gyroscope: GX: ", sensorObj.floatp_value(x),
|
||||||
|
print " GY: ", sensorObj.floatp_value(y),
|
||||||
|
print " GZ: ", sensorObj.floatp_value(z)
|
||||||
|
|
||||||
|
sensor.getMagnetometer(x, y, z)
|
||||||
|
print "Magnetometer: MX: ", sensorObj.floatp_value(x),
|
||||||
|
print " MY: ", sensorObj.floatp_value(y),
|
||||||
|
print " MZ: ", sensorObj.floatp_value(z)
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(.5)
|
56
examples/python/curieimu.py
Normal file
56
examples/python/curieimu.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# Author: Ron Evans (@deadprogram)
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||||
|
|
||||||
|
import mraa
|
||||||
|
print (mraa.getVersion())
|
||||||
|
|
||||||
|
# open connection to Firmata
|
||||||
|
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0")
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_curieimu as curieimu
|
||||||
|
sensor = curieimu.CurieImu()
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
sensor.updateAccel();
|
||||||
|
|
||||||
|
outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
|
||||||
|
sensor.getAccelX(), sensor.getAccelY(),
|
||||||
|
sensor.getAccelZ())
|
||||||
|
print outputStr
|
||||||
|
|
||||||
|
time.sleep(1)
|
61
examples/python/cwlsxxa.py
Normal file
61
examples/python/cwlsxxa.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_cwlsxxa as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||||
|
# humidity and A2 for temperature
|
||||||
|
sensor = sensorObj.CWLSXXA(0, 1, 2)
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
# update our values from the sensor
|
||||||
|
sensor.update()
|
||||||
|
|
||||||
|
# we show both C and F for temperature
|
||||||
|
print "Temperature:", sensor.getTemperature(), "C /",
|
||||||
|
print sensor.getTemperature(True), "F"
|
||||||
|
|
||||||
|
print "Humidity:", sensor.getHumidity(), "%"
|
||||||
|
|
||||||
|
print "CO2:", sensor.getCO2(), "ppm"
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(1)
|
106
examples/python/h803x.py
Normal file
106
examples/python/h803x.py
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_h803x as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting..."
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
defaultDev = "/dev/ttyUSB0"
|
||||||
|
|
||||||
|
# if an argument was specified, use it as the device instead
|
||||||
|
if (len(sys.argv) > 1):
|
||||||
|
defaultDev = sys.argv[1]
|
||||||
|
|
||||||
|
print "Using device", defaultDev
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an H803X instance, using MODBUS slave address 1, and
|
||||||
|
# default comm parameters (9600, 8, N, 2)
|
||||||
|
sensor = sensorObj.H803X(defaultDev, 1)
|
||||||
|
|
||||||
|
# output the serial number and firmware revision
|
||||||
|
print "Slave ID:", sensor.getSlaveID()
|
||||||
|
|
||||||
|
print
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
# update our values from the sensor
|
||||||
|
sensor.update()
|
||||||
|
|
||||||
|
# H8035 / H8036
|
||||||
|
print "Consumption (kWh):", sensor.getConsumption()
|
||||||
|
print "Real Power (kW):", sensor.getRealPower()
|
||||||
|
|
||||||
|
if (sensor.isH8036()):
|
||||||
|
# The H8036 has much more data available...
|
||||||
|
|
||||||
|
print "Reactive Power (kVAR):", sensor.getReactivePower()
|
||||||
|
print "Apparent Power (kVA):", sensor.getApparentPower()
|
||||||
|
print "Power Factor:", sensor.getPowerFactor()
|
||||||
|
print "Volts Line to Line:", sensor.getVoltsLineToLine()
|
||||||
|
print "Volts Line to Neutral:", sensor.getVoltsLineToNeutral()
|
||||||
|
|
||||||
|
print "Current:", sensor.getCurrent()
|
||||||
|
|
||||||
|
print "Real Power Phase A (kW):", sensor.getRealPowerPhaseA()
|
||||||
|
print "Real Power Phase B (kW):", sensor.getRealPowerPhaseB()
|
||||||
|
print "Real Power Phase C (kW):", sensor.getRealPowerPhaseC()
|
||||||
|
|
||||||
|
print "Power Factor Phase A:", sensor.getPowerFactorPhaseA()
|
||||||
|
print "Power Factor Phase B:", sensor.getPowerFactorPhaseB()
|
||||||
|
print "Power Factor Phase C:", sensor.getPowerFactorPhaseC()
|
||||||
|
|
||||||
|
print "Volts Phase A to B:", sensor.getVoltsPhaseAToB()
|
||||||
|
print "Volts Phase B to C:", sensor.getVoltsPhaseBToC()
|
||||||
|
print "Volts Phase A to C:", sensor.getVoltsPhaseAToC()
|
||||||
|
print "Volts Phase A to Neutral: ",
|
||||||
|
print sensor.getVoltsPhaseAToNeutral()
|
||||||
|
print "Volts Phase B to Neutral: ",
|
||||||
|
print sensor.getVoltsPhaseBToNeutral()
|
||||||
|
print "Volts Phase C to Neutral: ",
|
||||||
|
print sensor.getVoltsPhaseCToNeutral()
|
||||||
|
|
||||||
|
print "Current Phase A:", sensor.getCurrentPhaseA()
|
||||||
|
print "Current Phase B:", sensor.getCurrentPhaseB()
|
||||||
|
print "Current Phase C:", sensor.getCurrentPhaseC()
|
||||||
|
|
||||||
|
print "Avg Real Power (kW):", sensor.getAvgRealPower()
|
||||||
|
print "Min Real Power (kW):", sensor.getMinRealPower()
|
||||||
|
print "Max Real Power (kW):", sensor.getMaxRealPower()
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(2)
|
65
examples/python/teams.py
Normal file
65
examples/python/teams.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_teams as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an TEAMS instance, using A0 for temperature, and
|
||||||
|
# 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
||||||
|
# interface)
|
||||||
|
sensor = sensorObj.TEAMS(0, 165.0)
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
# update our values from the sensor
|
||||||
|
sensor.update()
|
||||||
|
|
||||||
|
# is the sensor connected? (current >= 4ma)
|
||||||
|
print "Is Connected:", sensor.isConnected()
|
||||||
|
|
||||||
|
# print computed current on the loop. This includes the offset,
|
||||||
|
# if one was set by setOffsetMilliamps().
|
||||||
|
print "Milliamps:", sensor.getRawMilliamps()
|
||||||
|
|
||||||
|
# we show both C and F for temperature
|
||||||
|
print "Temperature:", sensor.getTemperature(), "C /",
|
||||||
|
print sensor.getTemperature(True), "F"
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(1)
|
65
examples/python/tex00.py
Normal file
65
examples/python/tex00.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_tex00 as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an TEX00 instance, using A0 for the analog input. In
|
||||||
|
# this example, we are using a 10K Ohm balance resistor and a TED
|
||||||
|
# (10k type 2) thermistor.
|
||||||
|
sensor = sensorObj.TEX00(0, 10000, sensorObj.TEX00.STYPE_THERMISTOR_TED)
|
||||||
|
|
||||||
|
print "Minimum temperature:", sensor.getTemperatureRangeMin(), "C"
|
||||||
|
print "Maximum temperature:", sensor.getTemperatureRangeMax(), "C"
|
||||||
|
print
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
# update our values from the sensor
|
||||||
|
sensor.update()
|
||||||
|
|
||||||
|
if (sensor.isOutOfRange()):
|
||||||
|
print "Temperature out of range"
|
||||||
|
else:
|
||||||
|
# we show both C and F for temperature
|
||||||
|
print "Temperature:", sensor.getTemperature(), "C /",
|
||||||
|
print sensor.getTemperature(True), "F"
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(1)
|
@ -28,6 +28,7 @@ endmacro (upm_CREATE_INSTALL_PKGCONFIG)
|
|||||||
|
|
||||||
macro(upm_SWIG_PYTHON)
|
macro(upm_SWIG_PYTHON)
|
||||||
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
||||||
|
|
||||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
|
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
|
||||||
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
||||||
@ -46,16 +47,30 @@ endmacro()
|
|||||||
|
|
||||||
macro(upm_SWIG_NODE)
|
macro(upm_SWIG_NODE)
|
||||||
if (BUILDSWIGNODE AND BUILDSWIG)
|
if (BUILDSWIGNODE AND BUILDSWIG)
|
||||||
|
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is
|
||||||
|
# required. This hardcodes V8_VERSION to be <10 but I assume that's not going
|
||||||
|
# to be a problem for a little while! SWIG uses a padded SWIG_V8 version which
|
||||||
|
# we hack together from our findnode module.
|
||||||
|
set (V8_VERSION_HEX 0x0${V8_VERSION_MAJOR}${V8_VERSION_MINOR}${V8_VERSION_PATCH})
|
||||||
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
||||||
|
while (V8_VERSION_HEX_length LESS 8)
|
||||||
|
set (V8_VERSION_HEX "${V8_VERSION_HEX}0")
|
||||||
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
||||||
|
endwhile ()
|
||||||
|
|
||||||
|
# include_directories (${NODE_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
|
||||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node")
|
|
||||||
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
|
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
|
||||||
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||||
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${NODE_INCLUDE_DIRS}"
|
"${NODE_INCLUDE_DIRS}"
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties (jsupm_${libname} PROPERTIES
|
set_target_properties (jsupm_${libname} PROPERTIES
|
||||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=0x0${V8_DEFINE_STRING}"
|
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}"
|
||||||
PREFIX ""
|
PREFIX ""
|
||||||
SUFFIX ".node"
|
SUFFIX ".node"
|
||||||
)
|
)
|
||||||
@ -65,12 +80,29 @@ macro(upm_SWIG_NODE)
|
|||||||
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
|
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (NOT ENABLECXX11)
|
||||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
||||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
|
||||||
|
message (FATAL_ERROR " FATAL ERROR: GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
|
||||||
|
endif ()
|
||||||
|
set (UPM_CXX11_WORKAROUND_OPTION "-std=gnu++11")
|
||||||
|
else ()
|
||||||
|
set (UPM_CXX11_WORKAROUND_OPTION "-std=c++11")
|
||||||
|
endif ()
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UPM_CXX11_WORKAROUND_OPTION} ")
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
createpackagejson(${libname})
|
createpackagejson(${libname})
|
||||||
|
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
|
||||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
|
||||||
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
|
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
@ -139,30 +171,30 @@ macro(upm_doxygen)
|
|||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
if (SWIG_FOUND)
|
if (SWIG_FOUND)
|
||||||
if(BUILDSWIGPYTHON)
|
if (BUILDSWIGPYTHON)
|
||||||
find_package (PythonLibs)
|
if(NOT PYTHONLIBS_FOUND)
|
||||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
endif()
|
||||||
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
endif()
|
||||||
endif(BUILDSWIGPYTHON)
|
if (BUILDSWIGNODE)
|
||||||
if(BUILDSWIGNODE)
|
|
||||||
if(NOT NODE_FOUND)
|
if(NOT NODE_FOUND)
|
||||||
find_package(Node)
|
find_package(Node)
|
||||||
endif()
|
endif()
|
||||||
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
|
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
|
||||||
message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
|
message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
|
||||||
endif()
|
endif()
|
||||||
find_path (NODE_ROOT_DIR "node/node.h")
|
find_path (NODE_ROOT_DIR "include/node/node.h")
|
||||||
set (NODE_INCLUDE_DIRS
|
set (NODE_INCLUDE_DIRS
|
||||||
${NODE_ROOT_DIR}/src
|
${NODE_ROOT_DIR}/include/src
|
||||||
${NODE_ROOT_DIR}/node
|
${NODE_ROOT_DIR}/include/node
|
||||||
${NODE_ROOT_DIR}/deps/v8/include
|
${NODE_ROOT_DIR}/include/deps/v8/include
|
||||||
${NODE_ROOT_DIR}/deps/uv/include
|
${NODE_ROOT_DIR}/include/deps/uv/include
|
||||||
)
|
)
|
||||||
macro(createpackagejson)
|
macro(createpackagejson)
|
||||||
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
|
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
|
||||||
|
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
|
||||||
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
|
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
endif(BUILDSWIGNODE)
|
endif(BUILDSWIGNODE)
|
||||||
|
@ -30,15 +30,63 @@ ADS1015::setSPS(ADSSAMPLERATE rate){
|
|||||||
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
ADS1015::ADS1015(int bus, uint8_t address) : ADS1X15(bus, address) {
|
ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
|
||||||
m_name = "ADS1015";
|
m_name = "ADS1015";
|
||||||
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
||||||
m_bitShift = 4;
|
m_bitShift = 4;
|
||||||
ADS1X15::getCurrentConfig();
|
ADS1X15::getCurrentConfig();
|
||||||
|
if (vref < 0.0 || vref > 6.144)
|
||||||
|
UPM_THROW("vref out of range");
|
||||||
|
else if (vref > 4.096)
|
||||||
|
setGain(GAIN_TWOTHIRDS);
|
||||||
|
else if (vref > 2.048)
|
||||||
|
setGain(GAIN_ONE);
|
||||||
|
else if (vref > 1.024)
|
||||||
|
setGain(GAIN_TWO);
|
||||||
|
else if (vref > 0.512)
|
||||||
|
setGain(GAIN_FOUR);
|
||||||
|
else if (vref > 0.256)
|
||||||
|
setGain(GAIN_EIGHT);
|
||||||
|
else
|
||||||
|
setGain(GAIN_SIXTEEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
ADS1015::~ADS1015(){};
|
ADS1015::~ADS1015(){};
|
||||||
|
|
||||||
|
const char*
|
||||||
|
ADS1015::getModuleName() {
|
||||||
|
return m_name.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
ADS1015::getNumInputs() {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
ADS1015::getResolutionInBits() {
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t
|
||||||
|
ADS1015::getRawValue(unsigned int input) {
|
||||||
|
ADS1X15::ADSMUXMODE mode = getMuxMode(input);
|
||||||
|
updateConfigRegister((m_config_reg & ~ADS1X15_MUX_MASK) | mode, true);
|
||||||
|
usleep(m_conversionDelay);
|
||||||
|
uint16_t value = i2c->readWordReg(ADS1X15_REG_POINTER_CONVERT);
|
||||||
|
value = value >> m_bitShift;
|
||||||
|
return swapWord(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
float
|
||||||
|
ADS1015::getVoltage(unsigned int input) {
|
||||||
|
ADSMUXMODE mode = getMuxMode(input);
|
||||||
|
return getSample(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Private functions
|
//Private functions
|
||||||
float
|
float
|
||||||
ADS1015::getMultiplier(void){
|
ADS1015::getMultiplier(void){
|
||||||
@ -99,4 +147,20 @@ ADS1015::setDelay(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ADS1X15::ADSMUXMODE
|
||||||
|
ADS1015::getMuxMode(unsigned int input) {
|
||||||
|
ADS1X15::ADSMUXMODE mode;
|
||||||
|
switch (input) {
|
||||||
|
case 0:
|
||||||
|
return SINGLE_0;
|
||||||
|
case 1:
|
||||||
|
return SINGLE_1;
|
||||||
|
case 2:
|
||||||
|
return SINGLE_2;
|
||||||
|
case 3:
|
||||||
|
return SINGLE_3;
|
||||||
|
default:
|
||||||
|
UPM_THROW("Invalid input");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ads1x15.h"
|
#include "ads1x15.h"
|
||||||
|
#include "upm/iADC.h"
|
||||||
|
|
||||||
|
#define ADS1015_VREF 2.048
|
||||||
|
|
||||||
/*=========================================================================
|
/*=========================================================================
|
||||||
CONVERSION DELAY (in microS)
|
CONVERSION DELAY (in microS)
|
||||||
@ -82,7 +83,7 @@ namespace upm {
|
|||||||
* @image html ads1015.jpg
|
* @image html ads1015.jpg
|
||||||
* @snippet ads1x15.cxx Interesting
|
* @snippet ads1x15.cxx Interesting
|
||||||
*/
|
*/
|
||||||
class ADS1015 : public ADS1X15 {
|
class ADS1015 : public ADS1X15, public IADC {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -111,12 +112,16 @@ namespace upm {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADS1X15 constructor
|
* ADS1015 constructor
|
||||||
|
*
|
||||||
|
* This constructor includes a vref parameter that can be used
|
||||||
|
* to set gain so it matches full scale value of input
|
||||||
*
|
*
|
||||||
* @param bus i2c bus the sensor is attached to.
|
* @param bus i2c bus the sensor is attached to.
|
||||||
* @param address. Device address. Default is 0x48.
|
* @param address. Optional device address. Default is 0x48.
|
||||||
|
* @param vref. Optional reference (i.e. half full swing) voltage. Default is 2.048V
|
||||||
*/
|
*/
|
||||||
ADS1015 (int bus, uint8_t address = 0x48);
|
ADS1015 (int bus, uint8_t address = 0x48, float vref = ADS1015_VREF);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADS1X15 destructor
|
* ADS1X15 destructor
|
||||||
@ -132,9 +137,48 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
void setSPS(ADSSAMPLERATE rate = SPS_1600);
|
void setSPS(ADSSAMPLERATE rate = SPS_1600);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of inputs
|
||||||
|
*
|
||||||
|
* @return number of inputs
|
||||||
|
*/
|
||||||
|
unsigned int getNumInputs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read current value for current single ended analogue input
|
||||||
|
*
|
||||||
|
* @return current conversion value
|
||||||
|
*/
|
||||||
|
uint16_t getRawValue(unsigned int input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read current voltage for current single ended analogue input
|
||||||
|
*
|
||||||
|
* @return current voltage
|
||||||
|
*/
|
||||||
|
float getVoltage(unsigned int input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read current voltage for current single ended analogue input
|
||||||
|
*
|
||||||
|
* @return current voltage
|
||||||
|
*/
|
||||||
|
unsigned int getResolutionInBits();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns module name
|
||||||
|
*
|
||||||
|
* @return modulename as const char*
|
||||||
|
*/
|
||||||
|
const char* getModuleName();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float getMultiplier(void);
|
float getMultiplier(void);
|
||||||
void setDelay(void);
|
void setDelay(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ADS1X15::ADSMUXMODE getMuxMode(unsigned int input);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,8 @@ AM2315::i2cWriteReg(uint8_t reg, uint8_t* data, uint8_t ilen)
|
|||||||
uint8_t
|
uint8_t
|
||||||
AM2315::i2cReadReg(int reg, uint8_t* data, int ilen)
|
AM2315::i2cReadReg(int reg, uint8_t* data, int ilen)
|
||||||
{
|
{
|
||||||
uint8_t tdata[16] = { AM2315_READ, reg, ilen };
|
uint8_t tdata[16] = { AM2315_READ, static_cast<uint8_t>(reg),
|
||||||
|
static_cast<uint8_t>(ilen) };
|
||||||
|
|
||||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||||
int iLoops = 5;
|
int iLoops = 5;
|
||||||
|
5
src/apa102/CMakeLists.txt
Normal file
5
src/apa102/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
set (libname "apa102")
|
||||||
|
set (libdescription "upm apa102 led strip spi output module")
|
||||||
|
set (module_src ${libname}.cxx)
|
||||||
|
set (module_h ${libname}.h)
|
||||||
|
upm_module_init()
|
166
src/apa102/apa102.cxx
Normal file
166
src/apa102/apa102.cxx
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "apa102.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
APA102::APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode, int8_t csn)
|
||||||
|
: m_ledCount(ledCount), m_batchMode(batchMode)
|
||||||
|
{
|
||||||
|
mraa::Result res = mraa::SUCCESS;
|
||||||
|
m_leds = NULL;
|
||||||
|
|
||||||
|
// Optional chip select pin
|
||||||
|
m_csnPinCtx = NULL;
|
||||||
|
if (csn > -1) {
|
||||||
|
m_csnPinCtx = new mraa::Gpio(csn);
|
||||||
|
res = m_csnPinCtx->dir(mraa::DIR_OUT);
|
||||||
|
if (res != mraa::SUCCESS) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": GPIO failed to set direction");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CSOff();
|
||||||
|
// Initialize SPI
|
||||||
|
m_spi = new mraa::Spi(spiBus);
|
||||||
|
|
||||||
|
// Initialize LED array
|
||||||
|
uint16_t endFrameLength = (m_ledCount + 15) / 16; // End frame should be (leds/2) bits
|
||||||
|
m_frameLength = endFrameLength + (m_ledCount + 1) * 4;
|
||||||
|
if ((m_leds = (uint8_t*) malloc(m_frameLength))) {
|
||||||
|
memset(m_leds, 0x00, m_frameLength - 4); // Clear state
|
||||||
|
memset(&m_leds[m_frameLength - endFrameLength], 0xFF, endFrameLength); // Frame End
|
||||||
|
|
||||||
|
// Need to set the brightness to "0" for each Led
|
||||||
|
for (int i = 1; i <= m_ledCount; i++) {
|
||||||
|
m_leds[i * 4] = 224;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": Failed to allocate memory for LED Strip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
APA102::~APA102()
|
||||||
|
{
|
||||||
|
// Clear leds
|
||||||
|
if (m_leds) {
|
||||||
|
free(m_leds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear SPI
|
||||||
|
if (m_spi) {
|
||||||
|
delete m_spi;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear GPIO
|
||||||
|
if (m_csnPinCtx) {
|
||||||
|
delete m_csnPinCtx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
setLeds(ledIdx, ledIdx, brightness, r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
setLeds(0, m_ledCount - 1, brightness, r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
uint16_t s_idx = (startIdx + 1) * 4;
|
||||||
|
uint16_t e_idx = (endIdx + 1) * 4;
|
||||||
|
|
||||||
|
for (uint16_t i = s_idx; i <= e_idx; i += 4) {
|
||||||
|
m_leds[i] = brightness | 224;
|
||||||
|
m_leds[i + 1] = b;
|
||||||
|
m_leds[i + 2] = g;
|
||||||
|
m_leds[i + 3] = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_batchMode) {
|
||||||
|
pushState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors)
|
||||||
|
{
|
||||||
|
uint16_t s_idx = (startIdx + 1) * 4;
|
||||||
|
memcpy(&m_leds[s_idx], colors, (endIdx - startIdx + 1) * 4);
|
||||||
|
|
||||||
|
if (!m_batchMode) {
|
||||||
|
pushState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::pushState(void)
|
||||||
|
{
|
||||||
|
CSOn();
|
||||||
|
m_spi->write(m_leds, m_frameLength);
|
||||||
|
CSOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* **************
|
||||||
|
* private area
|
||||||
|
* **************
|
||||||
|
*/
|
||||||
|
|
||||||
|
mraa::Result
|
||||||
|
APA102::CSOn()
|
||||||
|
{
|
||||||
|
if (m_csnPinCtx) {
|
||||||
|
return m_csnPinCtx->write(HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mraa::ERROR_FEATURE_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
mraa::Result
|
||||||
|
APA102::CSOff()
|
||||||
|
{
|
||||||
|
if (m_csnPinCtx) {
|
||||||
|
return m_csnPinCtx->write(LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mraa::ERROR_FEATURE_NOT_SUPPORTED;
|
||||||
|
}
|
143
src/apa102/apa102.h
Normal file
143
src/apa102/apa102.h
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mraa/gpio.hpp>
|
||||||
|
#include <mraa/spi.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define HIGH 1
|
||||||
|
#define LOW 0
|
||||||
|
|
||||||
|
namespace upm
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief APA102 RGB LED Strip driver library
|
||||||
|
* @defgroup apa102 libupm-apa102
|
||||||
|
* @ingroup spi led
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @library apa102
|
||||||
|
* @sensor apa102
|
||||||
|
* @comname APA102/DotStar LED Strip
|
||||||
|
* @type led
|
||||||
|
* @man adafruit
|
||||||
|
* @con spi
|
||||||
|
*
|
||||||
|
* @brief API for controlling APA102/DotStar RGB LED Strips
|
||||||
|
*
|
||||||
|
* APA102 LED Strips provide individually controllable LEDs through a SPI interface.
|
||||||
|
* For each LED, brightness (0-31) and RGB (0-255) values can be set.
|
||||||
|
*
|
||||||
|
* @image html apa102.jpg
|
||||||
|
* @snippet apa102.cxx Interesting
|
||||||
|
*/
|
||||||
|
class APA102
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Instantiates a new APA102 LED Strip
|
||||||
|
*
|
||||||
|
* @param ledCount Number of APA102 leds in the strip
|
||||||
|
* @param spiBus SPI Bus number
|
||||||
|
* @param batchMode (optional) Immediatly write to SPI (false, default) or wait for a pushState
|
||||||
|
* call (true)
|
||||||
|
* @param csn (optional) Chip Select Pin
|
||||||
|
*/
|
||||||
|
APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode = false, int8_t csn = -1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APA102 destructor
|
||||||
|
*/
|
||||||
|
~APA102();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the color for a single led
|
||||||
|
*
|
||||||
|
* @param ledIdx Index of the LED in the strip (0 based)
|
||||||
|
* @param brightness Brightness value (0-31)
|
||||||
|
* @param r Red component (0-255)
|
||||||
|
* @param g Green component (0-255)
|
||||||
|
* @param b Blue component (0-255)
|
||||||
|
*/
|
||||||
|
void setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the color for all leds
|
||||||
|
*
|
||||||
|
* @param brightness Brightness value (0-31)
|
||||||
|
* @param r Red component (0-255)
|
||||||
|
* @param g Green component (0-255)
|
||||||
|
* @param b Blue component (0-255)
|
||||||
|
*/
|
||||||
|
void setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the color for a range of leds
|
||||||
|
*
|
||||||
|
* @param startIdx Start index of the range of LEDs in the strip (0 based)
|
||||||
|
* @param endIdx End index of the range of LEDs in the strip (0 based)
|
||||||
|
* @param brightness Brightness value (0-31)
|
||||||
|
* @param r Red component (0-255)
|
||||||
|
* @param g Green component (0-255)
|
||||||
|
* @param b Blue component (0-255)
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Advanced) Manually control the colors of a range of LEDS
|
||||||
|
* Best used to maximize performance
|
||||||
|
*
|
||||||
|
* @param startIdx Start index of the range of LEDs to update (0 based)
|
||||||
|
* @param endIdx End index of the range of LEDs to update (0 based)
|
||||||
|
* @param colors Pointer to an array of bytes. Each color is described as the following:
|
||||||
|
* B1: Brightness (224-255) B2: Blue (0-255) B3: Green (0-255) B4: Red
|
||||||
|
*(0-255)
|
||||||
|
* No check done on the boundaries
|
||||||
|
*/
|
||||||
|
void setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outputs the current LED data to the SPI bus
|
||||||
|
* Note: Only required if batch mode is set to TRUE
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void pushState();
|
||||||
|
|
||||||
|
private:
|
||||||
|
mraa::Spi* m_spi;
|
||||||
|
mraa::Gpio* m_csnPinCtx;
|
||||||
|
|
||||||
|
uint16_t m_ledCount;
|
||||||
|
uint8_t* m_leds;
|
||||||
|
uint16_t m_frameLength;
|
||||||
|
|
||||||
|
bool m_batchMode;
|
||||||
|
|
||||||
|
mraa::Result CSOn();
|
||||||
|
mraa::Result CSOff();
|
||||||
|
};
|
||||||
|
}
|
30
src/apa102/javaupm_apa102.i
Normal file
30
src/apa102/javaupm_apa102.i
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
%module javaupm_apa102
|
||||||
|
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "typemaps.i"
|
||||||
|
|
||||||
|
%typemap(jtype) (uint8_t *colors) "byte[]"
|
||||||
|
%typemap(jstype) (uint8_t *colors) "byte[]"
|
||||||
|
%typemap(jni) (uint8_t *colors) "jbyteArray"
|
||||||
|
%typemap(javain) (uint8_t *colors) "$javainput"
|
||||||
|
|
||||||
|
%typemap(in) (uint8_t *colors) {
|
||||||
|
$1 = (uint8_t*)JCALL2(GetByteArrayElements, jenv, $input, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "apa102.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "apa102.h"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_apa102");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
19
src/apa102/jsupm_apa102.i
Normal file
19
src/apa102/jsupm_apa102.i
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
%module jsupm_apa102
|
||||||
|
|
||||||
|
%include "../upm.i"
|
||||||
|
%inline %{
|
||||||
|
#include <node_buffer.h>
|
||||||
|
%}
|
||||||
|
|
||||||
|
%typemap(in) (uint8_t *colors) {
|
||||||
|
if (!node::Buffer::HasInstance($input)) {
|
||||||
|
SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer");
|
||||||
|
}
|
||||||
|
$1 = (uint8_t*) node::Buffer::Data($input);
|
||||||
|
}
|
||||||
|
|
||||||
|
%include "apa102.h"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "apa102.h"
|
||||||
|
%}
|
25
src/apa102/pyupm_apa102.i
Normal file
25
src/apa102/pyupm_apa102.i
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Include doxygen-generated documentation
|
||||||
|
%include "pyupm_doxy2swig.i"
|
||||||
|
|
||||||
|
%module pyupm_apa102
|
||||||
|
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
// setLeds
|
||||||
|
%typemap(in) (uint8_t *colors) {
|
||||||
|
if (PyByteArray_Check($input)) {
|
||||||
|
$1 = (uint8_t*) PyByteArray_AsString($input);
|
||||||
|
} else {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "bytearray expected");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%include "apa102.h"
|
||||||
|
|
||||||
|
%{
|
||||||
|
|
||||||
|
#include "apa102.h"
|
||||||
|
%}
|
6
src/bme280/CMakeLists.txt
Normal file
6
src/bme280/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include_directories(..)
|
||||||
|
set (libname "bme280")
|
||||||
|
set (libdescription "upm bme280 temperature humidity pressure sensor module")
|
||||||
|
set (module_src ${libname}.cxx bme280driver.cxx)
|
||||||
|
set (module_h ${libname}.h bme280driver.h)
|
||||||
|
upm_module_init()
|
485
src/bme280/bme280.cxx
Normal file
485
src/bme280/bme280.cxx
Normal file
@ -0,0 +1,485 @@
|
|||||||
|
/*
|
||||||
|
* Author: Aditya Nagal <adityax.nagal@intel.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "bme280.h"
|
||||||
|
#include "bme280driver.h"
|
||||||
|
/************** I2C buffer length ******/
|
||||||
|
#define I2C_BUFFER_LEN 26
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*
|
||||||
|
* struct bme280_t parameters can be accessed by using bme280
|
||||||
|
* bme280_t having the following parameters
|
||||||
|
* Bus write function pointer: BME280_WR_FUNC_PTR
|
||||||
|
Bus read function pointer: BME280_RD_FUNC_PTR
|
||||||
|
* Delay function pointer: delay_msec
|
||||||
|
* I2C address: dev_addr
|
||||||
|
* Chip id of the sensor: chip_id
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct bme280_t bme280;
|
||||||
|
|
||||||
|
static struct bme280_t *p_bme280; /**< pointer to BME280 */
|
||||||
|
mraa::I2c* BME280::m_i2c = NULL;
|
||||||
|
int BME280::m_bus = 0;
|
||||||
|
|
||||||
|
BME280::BME280 (int bus, int devAddr) {
|
||||||
|
m_bus = bus;
|
||||||
|
if( m_i2c == NULL)
|
||||||
|
{
|
||||||
|
m_i2c = new mraa::I2c(m_bus);
|
||||||
|
m_i2c->address(BME280_I2C_ADDRESS1);
|
||||||
|
//Based on the requirement, configure I2C interface.
|
||||||
|
I2C_routine();
|
||||||
|
/*--------------------------------------------------------------------------*
|
||||||
|
* This function used to assign the value/reference of
|
||||||
|
* the following parameters
|
||||||
|
* I2C address
|
||||||
|
* Bus Write
|
||||||
|
* Bus read
|
||||||
|
* Chip id
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
bme280_init(&bme280);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BME280::~BME280() {
|
||||||
|
delete m_i2c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This function is an example for reading sensor temperature
|
||||||
|
* \param: None
|
||||||
|
* \return: compensated temperature
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32_t BME280::getTemperatureInternal(void)
|
||||||
|
{
|
||||||
|
/* The variable used to read uncompensated temperature*/
|
||||||
|
int32_t v_data_uncomp_tem_int32 = getTemperatureRawInternal();
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*
|
||||||
|
************ START READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY DATA ********
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
/* API is used to read the true temperature*/
|
||||||
|
/* Input value as uncompensated temperature and output format*/
|
||||||
|
int32_t v_actual_temp_int32 = bme280_compensate_temperature_int32(v_data_uncomp_tem_int32);
|
||||||
|
/*--------------------------------------------------------------------*
|
||||||
|
************ END READ TRUE TEMPERATURE ********
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
return v_actual_temp_int32;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This function is an example for reading sensor pressure
|
||||||
|
* \param: None
|
||||||
|
* \return: compensated pressure
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32_t BME280::getPressureInternal(void)
|
||||||
|
{
|
||||||
|
/* The variable used to read uncompensated pressure*/
|
||||||
|
int32_t v_data_uncomp_pres_int32 = getPressureRawInternal();
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*
|
||||||
|
************ START READ TRUE PRESSURE DATA ********
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
/* API is used to read the true pressure*/
|
||||||
|
/* Input value as uncompensated pressure */
|
||||||
|
uint32_t v_actual_press_uint32 = bme280_compensate_pressure_int32(v_data_uncomp_pres_int32);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*
|
||||||
|
************ END READ TRUE PRESSURE ********
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
return v_actual_press_uint32;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* This function is an example for reading sensor humidity
|
||||||
|
* \param: None
|
||||||
|
* \return: compensated humidity
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32_t BME280::getHumidityInternal(void)
|
||||||
|
{
|
||||||
|
/* The variable used to read uncompensated pressure*/
|
||||||
|
int32_t v_data_uncomp_hum_int32 = getHumidityRawInternal();
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*
|
||||||
|
************ START READ TRUE HUMIDITY DATA ********
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
/* API is used to read the true humidity*/
|
||||||
|
/* Input value as uncompensated humidity and output format*/
|
||||||
|
uint32_t v_actual_humity_uint32 = bme280_compensate_humidity_int32(v_data_uncomp_hum_int32);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*
|
||||||
|
************ END READ TRUE HUMIDITY ********
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
return v_actual_humity_uint32;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* This function is an example for reading sensor temperature
|
||||||
|
* \param: None
|
||||||
|
* \return: uncompensated temperature
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32_t BME280::getTemperatureRawInternal(void)
|
||||||
|
{
|
||||||
|
/* The variable used to read uncompensated temperature*/
|
||||||
|
int32_t v_data_uncomp_tem_int32 = BME280_INIT_VALUE;
|
||||||
|
|
||||||
|
/* For initialization it is required to set the mode of
|
||||||
|
* the sensor as "NORMAL"
|
||||||
|
* data acquisition/read/write is possible in this mode
|
||||||
|
* by using the below API able to set the power mode as NORMAL*/
|
||||||
|
/* Set the power mode as NORMAL*/
|
||||||
|
bme280_set_power_mode(BME280_NORMAL_MODE);
|
||||||
|
/* For reading the temperature data it is required to
|
||||||
|
* set the OSS setting of temperature
|
||||||
|
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
||||||
|
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
||||||
|
* the "BME280_CTRLMEAS_REG" register in the function*/
|
||||||
|
|
||||||
|
/* set the temperature oversampling*/
|
||||||
|
bme280_set_oversamp_temperature(BME280_OVERSAMP_4X);
|
||||||
|
|
||||||
|
/************************* END INITIALIZATION *************************/
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*
|
||||||
|
************ START READ UNCOMPENSATED TEMPERATURE DATA ********
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
/* API is used to read the uncompensated temperature*/
|
||||||
|
bme280_read_uncomp_temperature(&v_data_uncomp_tem_int32);
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*
|
||||||
|
************ END READ UNCOMPENSATED TEMPERATURE ********
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*
|
||||||
|
************************* START DE-INITIALIZATION ***********************
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
/* For de-initialization it is required to set the mode of
|
||||||
|
* the sensor as "SLEEP"
|
||||||
|
* the device reaches the lowest power consumption only
|
||||||
|
* In SLEEP mode no measurements are performed
|
||||||
|
* All registers are accessible
|
||||||
|
* by using the below API able to set the power mode as SLEEP*/
|
||||||
|
/* Set the power mode as SLEEP*/
|
||||||
|
bme280_set_power_mode(BME280_SLEEP_MODE);
|
||||||
|
/*---------------------------------------------------------------------*
|
||||||
|
************************* END DE-INITIALIZATION **********************
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
return v_data_uncomp_tem_int32;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This function is an example for reading sensor pressure
|
||||||
|
* \param: None
|
||||||
|
* \return: uncompensated pressure
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32_t BME280::getPressureRawInternal(void)
|
||||||
|
{
|
||||||
|
/* The variable used to read uncompensated pressure*/
|
||||||
|
int32_t v_data_uncomp_pres_int32 = BME280_INIT_VALUE;
|
||||||
|
|
||||||
|
|
||||||
|
/* For initialization it is required to set the mode of
|
||||||
|
* the sensor as "NORMAL"
|
||||||
|
* data acquisition/read/write is possible in this mode
|
||||||
|
* by using the below API able to set the power mode as NORMAL*/
|
||||||
|
/* Set the power mode as NORMAL*/
|
||||||
|
bme280_set_power_mode(BME280_NORMAL_MODE);
|
||||||
|
/* For reading the pressure data it is required to
|
||||||
|
* set the OSS setting of humidity, pressure and temperature
|
||||||
|
* The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
|
||||||
|
* data acquisition options of the device.
|
||||||
|
* changes to this registers only become effective after a write operation to
|
||||||
|
* "BME280_CTRLMEAS_REG" register.
|
||||||
|
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
||||||
|
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
||||||
|
* the "BME280_CTRLMEAS_REG" register in the function*/
|
||||||
|
|
||||||
|
/* set the pressure oversampling*/
|
||||||
|
bme280_set_oversamp_pressure(BME280_OVERSAMP_2X);
|
||||||
|
|
||||||
|
/************************* END INITIALIZATION *************************/
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*
|
||||||
|
************ START READ UNCOMPENSATED PRESSURE DATA ********
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* API is used to read the uncompensated pressure*/
|
||||||
|
bme280_read_uncomp_pressure(&v_data_uncomp_pres_int32);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*
|
||||||
|
************ END READ UNCOMPENSATED PRESSURE ********
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*
|
||||||
|
************************* START DE-INITIALIZATION ***********************
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
/* For de-initialization it is required to set the mode of
|
||||||
|
* the sensor as "SLEEP"
|
||||||
|
* the device reaches the lowest power consumption only
|
||||||
|
* In SLEEP mode no measurements are performed
|
||||||
|
* All registers are accessible
|
||||||
|
* by using the below API able to set the power mode as SLEEP*/
|
||||||
|
/* Set the power mode as SLEEP*/
|
||||||
|
bme280_set_power_mode(BME280_SLEEP_MODE);
|
||||||
|
/*---------------------------------------------------------------------*
|
||||||
|
************************* END DE-INITIALIZATION **********************
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
return v_data_uncomp_pres_int32;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* This function is an example for reading sensor humidity
|
||||||
|
* \param: None
|
||||||
|
* \return: uncompensated humidity
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32_t BME280::getHumidityRawInternal(void)
|
||||||
|
{
|
||||||
|
/* The variable used to read uncompensated pressure*/
|
||||||
|
int32_t v_data_uncomp_hum_int32 = BME280_INIT_VALUE;
|
||||||
|
|
||||||
|
/* For initialization it is required to set the mode of
|
||||||
|
* the sensor as "NORMAL"
|
||||||
|
* data acquisition/read/write is possible in this mode
|
||||||
|
* by using the below API able to set the power mode as NORMAL*/
|
||||||
|
/* Set the power mode as NORMAL*/
|
||||||
|
bme280_set_power_mode(BME280_NORMAL_MODE);
|
||||||
|
/* For reading humidity data it is required to
|
||||||
|
* set the OSS setting of humidity
|
||||||
|
* The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
|
||||||
|
* data acquisition options of the device.
|
||||||
|
* changes to this registers only become effective after a write operation to
|
||||||
|
* "BME280_CTRLMEAS_REG" register.
|
||||||
|
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
||||||
|
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
||||||
|
* the "BME280_CTRLMEAS_REG" register in the function*/
|
||||||
|
bme280_set_oversamp_humidity(BME280_OVERSAMP_1X);
|
||||||
|
|
||||||
|
|
||||||
|
/************************* END INITIALIZATION *************************/
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*
|
||||||
|
************ START READ HUMIDITY DATA ********
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
/* API is used to read the uncompensated humidity*/
|
||||||
|
bme280_read_uncomp_humidity(&v_data_uncomp_hum_int32);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------*
|
||||||
|
************ END READ UNCOMPENSATED PRESSURE AND TEMPERATURE********
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*
|
||||||
|
************************* START DE-INITIALIZATION ***********************
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
/* For de-initialization it is required to set the mode of
|
||||||
|
* the sensor as "SLEEP"
|
||||||
|
* the device reaches the lowest power consumption only
|
||||||
|
* In SLEEP mode no measurements are performed
|
||||||
|
* All registers are accessible
|
||||||
|
* by using the below API able to set the power mode as SLEEP*/
|
||||||
|
/* Set the power mode as SLEEP*/
|
||||||
|
bme280_set_power_mode(BME280_SLEEP_MODE);
|
||||||
|
/*---------------------------------------------------------------------*
|
||||||
|
************************* END DE-INITIALIZATION **********************
|
||||||
|
*---------------------------------------------------------------------*/
|
||||||
|
return v_data_uncomp_hum_int32;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*
|
||||||
|
* The following function is used to map the I2C bus read, write, delay and
|
||||||
|
* device address with global structure bme280
|
||||||
|
*-------------------------------------------------------------------------*/
|
||||||
|
int8_t BME280::I2C_routine()
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------*
|
||||||
|
* By using bme280 the following structure parameter can be accessed
|
||||||
|
* Bus write function pointer: BME280_WR_FUNC_PTR
|
||||||
|
* Bus read function pointer: BME280_RD_FUNC_PTR
|
||||||
|
* Delay function pointer: delay_msec
|
||||||
|
* I2C address: dev_addr
|
||||||
|
*--------------------------------------------------------------------------*/
|
||||||
|
// bme280.bus_write = &BME280::BME280_I2C_bus_write;
|
||||||
|
bme280.bus_write = BME280_I2C_bus_write;
|
||||||
|
|
||||||
|
//bme280.bus_write = BME280_I2C_bus_write_dummy;
|
||||||
|
bme280.bus_read = BME280_I2C_bus_read;
|
||||||
|
bme280.dev_addr = BME280_I2C_ADDRESS1;
|
||||||
|
bme280.delay_msec = BME280_delay_msek;
|
||||||
|
|
||||||
|
return BME280_INIT_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------*
|
||||||
|
* The device address defined in the bme280.h file
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
int32_t BME280::i2c_write_string(uint8_t dev_addr,uint8_t* ptr, uint8_t cnt)
|
||||||
|
{
|
||||||
|
mraa::Result ret;
|
||||||
|
m_i2c->address(dev_addr);
|
||||||
|
|
||||||
|
if((ret = m_i2c->write((const uint8_t*) (ptr), cnt)) != 0)
|
||||||
|
{
|
||||||
|
UPM_THROW("I2C write error");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* \Brief: The function is used as I2C bus write
|
||||||
|
* \Return : Status of the I2C write
|
||||||
|
* \param dev_addr : The device address of the sensor
|
||||||
|
* \param reg_addr : Address of the first register, will data is going to be written
|
||||||
|
* \param reg_data : It is a value hold in the array,
|
||||||
|
* will be used for write the value into the register
|
||||||
|
* \param cnt : The no of byte of data to be write
|
||||||
|
*/
|
||||||
|
|
||||||
|
int8_t BME280::BME280_I2C_bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
|
||||||
|
|
||||||
|
{
|
||||||
|
int32_t iError = BME280_INIT_VALUE;
|
||||||
|
static uint8_t array[I2C_BUFFER_LEN];
|
||||||
|
for (int i=0; i<I2C_BUFFER_LEN; i++) array[i]=0;
|
||||||
|
|
||||||
|
uint8_t stringpos = BME280_INIT_VALUE;
|
||||||
|
array[BME280_INIT_VALUE] = reg_addr;
|
||||||
|
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
|
||||||
|
array[stringpos + BME280_ONE_U8X] = *(reg_data + stringpos);
|
||||||
|
}
|
||||||
|
iError = i2c_write_string(dev_addr,array, cnt+1);
|
||||||
|
return (int8_t)iError;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t BME280::i2c_write_read_string(uint8_t dev_addr,uint8_t reg_addr , uint8_t * ptr, uint8_t cnt)
|
||||||
|
{
|
||||||
|
mraa::Result ret;
|
||||||
|
|
||||||
|
m_i2c->address(dev_addr);
|
||||||
|
|
||||||
|
if( m_i2c->readBytesReg(reg_addr, ptr, cnt) != cnt)
|
||||||
|
{
|
||||||
|
UPM_THROW("bme280 register read failed");
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* \Brief: The function is used as I2C bus read
|
||||||
|
* \Return : Status of the I2C read
|
||||||
|
* \param dev_addr : The device address of the sensor
|
||||||
|
* \param reg_addr : Address of the first register, will data is going to be read
|
||||||
|
* \param reg_data : This data read from the sensor, which is hold in an array
|
||||||
|
* \param cnt : The no of data byte of to be read
|
||||||
|
*/
|
||||||
|
int8_t BME280::BME280_I2C_bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
|
||||||
|
{
|
||||||
|
int32_t iError = BME280_INIT_VALUE;
|
||||||
|
uint8_t array[I2C_BUFFER_LEN] = {BME280_INIT_VALUE};
|
||||||
|
uint8_t stringpos = BME280_INIT_VALUE;
|
||||||
|
array[BME280_INIT_VALUE] = reg_addr;
|
||||||
|
i2c_write_read_string(dev_addr,reg_addr,array,cnt);
|
||||||
|
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
|
||||||
|
*(reg_data + stringpos) = array[stringpos];
|
||||||
|
}
|
||||||
|
return (int8_t)iError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Brief : The delay routine
|
||||||
|
* \param : delay in ms
|
||||||
|
*/
|
||||||
|
void BME280::BME280_delay_msek(uint16_t mseconds)
|
||||||
|
{
|
||||||
|
struct timespec sleepTime;
|
||||||
|
|
||||||
|
sleepTime.tv_sec = mseconds / 1000; // Number of seconds
|
||||||
|
sleepTime.tv_nsec = ( mseconds % 1000 ) * 1000000; // Convert fractional seconds to nanoseconds
|
||||||
|
|
||||||
|
// Iterate nanosleep in a loop until the total sleep time is the original
|
||||||
|
// value of the seconds parameter
|
||||||
|
while ( ( nanosleep( &sleepTime, &sleepTime ) != 0 ) && ( errno == EINTR ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get temperature measurement.
|
||||||
|
*/
|
||||||
|
uint16_t BME280::getTemperatureRaw (){ return BME280::getTemperatureRawInternal(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get temperature measurement.
|
||||||
|
*/
|
||||||
|
int BME280::getTemperatureCelcius (){ return (BME280::getTemperatureInternal() + 50) /100; }
|
||||||
|
/**
|
||||||
|
* Get relative humidity measurement.
|
||||||
|
*/
|
||||||
|
uint16_t BME280::getHumidityRaw (){ return BME280::getHumidityRawInternal(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get relative humidity measurement.
|
||||||
|
*/
|
||||||
|
int BME280::getHumidityRelative (){ return (BME280::getHumidityInternal() + 500) / 1000; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return pressure
|
||||||
|
*/
|
||||||
|
uint32_t BME280::getPressureRaw(){ return BME280::getPressureRawInternal(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return calculated pressure (Pa)
|
||||||
|
*/
|
||||||
|
int BME280::getPressurePa(){ return BME280::getPressureInternal(); }
|
||||||
|
|
||||||
|
|
||||||
|
|
141
src/bme280/bme280.h
Normal file
141
src/bme280/bme280.h
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
#include <mraa/i2c.hpp>
|
||||||
|
#include "upm/iPressureSensor.h"
|
||||||
|
#include "upm/iTemperatureSensor.h"
|
||||||
|
#include "upm/iHumiditySensor.h"
|
||||||
|
#ifndef __BME280_H__
|
||||||
|
#define __BME280_H__
|
||||||
|
|
||||||
|
|
||||||
|
//#define BME280_MDELAY_DATA_TYPE uint32_t
|
||||||
|
|
||||||
|
/****************************************************/
|
||||||
|
/**\name I2C ADDRESS DEFINITIONS */
|
||||||
|
/***************************************************/
|
||||||
|
#define BME280_I2C_ADDRESS1 (0x76)
|
||||||
|
#define BME280_I2C_ADDRESS2 (0x77)
|
||||||
|
#define BME280_ONE_U8X (1)
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BME280 : public ITemperatureSensor, public IHumiditySensor, public IPressureSensor {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instanciates a BME280 object
|
||||||
|
*
|
||||||
|
* @param bus number of used bus
|
||||||
|
* @param devAddr address of used i2c device
|
||||||
|
* @param mode BME280 mode
|
||||||
|
*/
|
||||||
|
BME280 (int bus, int devAddr = BME280_I2C_ADDRESS1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BME280 object destructor, basicaly it close i2c connection.
|
||||||
|
*/
|
||||||
|
~BME280 ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get temperature measurement.
|
||||||
|
*/
|
||||||
|
uint16_t getTemperatureRaw ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get temperature measurement.
|
||||||
|
*/
|
||||||
|
int getTemperatureCelcius ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get relative humidity measurement.
|
||||||
|
*/
|
||||||
|
uint16_t getHumidityRaw ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get relative humidity measurement.
|
||||||
|
*/
|
||||||
|
int getHumidityRelative ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns sensor module name
|
||||||
|
*/
|
||||||
|
const char* getModuleName() { return "BME280"; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return pressure
|
||||||
|
*/
|
||||||
|
uint32_t getPressureRaw();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return calculated pressure (Pa)
|
||||||
|
*/
|
||||||
|
int getPressurePa();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return temperature
|
||||||
|
*/
|
||||||
|
int32_t getTemperatureInternal(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return pressure
|
||||||
|
*/
|
||||||
|
int32_t getPressureInternal(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return humidity
|
||||||
|
*/
|
||||||
|
int32_t getHumidityInternal(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return temperature
|
||||||
|
*/
|
||||||
|
int32_t getTemperatureRawInternal(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return pressure
|
||||||
|
*/
|
||||||
|
int32_t getPressureRawInternal(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return humidity
|
||||||
|
*/
|
||||||
|
int32_t getHumidityRawInternal(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the correct chip is present at the given address.
|
||||||
|
*/
|
||||||
|
bool isAvailable();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**************************************************************/
|
||||||
|
/**\name STRUCTURE DEFINITIONS */
|
||||||
|
/**************************************************************/
|
||||||
|
/*!
|
||||||
|
* @brief This structure holds all device specific calibration parameters
|
||||||
|
*/
|
||||||
|
|
||||||
|
static mraa::I2c* m_i2c;
|
||||||
|
static int m_bus;
|
||||||
|
|
||||||
|
static int32_t i2c_write_string(uint8_t dev_addr,uint8_t* ptr, uint8_t cnt);
|
||||||
|
static int32_t i2c_write_read_string(uint8_t dev_addr,uint8_t reg_addr , uint8_t * ptr, uint8_t cnt);
|
||||||
|
static int8_t I2C_routine();
|
||||||
|
static int8_t BME280_I2C_bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt);
|
||||||
|
static void BME280_delay_msek(uint16_t msek);
|
||||||
|
static int8_t BME280_I2C_bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
2212
src/bme280/bme280driver.cxx
Normal file
2212
src/bme280/bme280driver.cxx
Normal file
File diff suppressed because it is too large
Load Diff
1704
src/bme280/bme280driver.h
Normal file
1704
src/bme280/bme280driver.h
Normal file
File diff suppressed because it is too large
Load Diff
23
src/bme280/javaupm_bme280.i
Normal file
23
src/bme280/javaupm_bme280.i
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
%module javaupm_bme280
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "arrays_java.i";
|
||||||
|
%include "../java_buffer.i"
|
||||||
|
%include "cpointer.i"
|
||||||
|
%include "typemaps.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "bme280.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "bme280.h"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_bme280");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
8
src/bme280/jsupm_bme280.i
Normal file
8
src/bme280/jsupm_bme280.i
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
%module jsupm_bme280
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "bme280.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "bme280.h"
|
10
src/bme280/pyupm_bme280.i
Normal file
10
src/bme280/pyupm_bme280.i
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
%module pyupm_bme280
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%include "stdint.i"
|
||||||
|
|
||||||
|
%include "bme280.h"
|
||||||
|
%{
|
||||||
|
#include "bme280.h"
|
||||||
|
%}
|
||||||
|
|
5
src/bmi160/CMakeLists.txt
Normal file
5
src/bmi160/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
set (libname "bmi160")
|
||||||
|
set (libdescription "Bosch BMI160 Accelerometer, Gyroscope and BMM150 Magnetometer")
|
||||||
|
set (module_src ${libname}.cxx bosch_bmi160.c)
|
||||||
|
set (module_h ${libname}.h)
|
||||||
|
upm_module_init()
|
433
src/bmi160/bmi160.cxx
Normal file
433
src/bmi160/bmi160.cxx
Normal file
@ -0,0 +1,433 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// we have to do it the old skool way
|
||||||
|
#include <mraa/i2c.h>
|
||||||
|
|
||||||
|
#include "bmi160.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "bosch_bmi160.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
// We do not need this define anyway. It conflicts with mraa::SUCCESS.
|
||||||
|
#undef SUCCESS
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
static mraa_i2c_context i2cContext = NULL;
|
||||||
|
|
||||||
|
// Our bmi160 info structure
|
||||||
|
struct bmi160_t s_bmi160;
|
||||||
|
|
||||||
|
// bus read and write functions for use with the bmi driver code
|
||||||
|
s8 bmi160_i2c_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
|
||||||
|
{
|
||||||
|
if (!i2cContext)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": i2c context is NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
int retries = 10;
|
||||||
|
|
||||||
|
// There seems to be some occasional flakyness with reads when
|
||||||
|
// moving the sensor around
|
||||||
|
while (retries >= 0)
|
||||||
|
{
|
||||||
|
int rv = mraa_i2c_read_bytes_data(i2cContext, reg_addr, reg_data, cnt);
|
||||||
|
|
||||||
|
if (rv < 0)
|
||||||
|
{
|
||||||
|
usleep(100000);
|
||||||
|
retries--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": mraa_i2c_read_bytes_data() failed");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
s8 bmi160_i2c_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
|
||||||
|
{
|
||||||
|
if (!i2cContext)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": i2c context is NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME fprintf(stderr, "%s: %02x: cnt %d\n", __FUNCTION__, reg_addr, cnt);
|
||||||
|
uint8_t buffer[cnt + 1];
|
||||||
|
|
||||||
|
buffer[0] = reg_addr;
|
||||||
|
for (int i=0; i<cnt; i++)
|
||||||
|
buffer[i+1] = reg_data[i];
|
||||||
|
|
||||||
|
mraa_result_t rv = mraa_i2c_write(i2cContext, buffer, cnt+1);
|
||||||
|
|
||||||
|
if (rv != MRAA_SUCCESS)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": mraa_i2c_write() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// delay for some milliseconds
|
||||||
|
void bmi160_delay_ms(u32 msek)
|
||||||
|
{
|
||||||
|
usleep(msek * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMI160::BMI160(int bus, uint8_t address)
|
||||||
|
{
|
||||||
|
m_addr = address;
|
||||||
|
|
||||||
|
// We need to use the C MRAA interface to avoid issue with C++ <-> C
|
||||||
|
// calling convention issues, also we need a global
|
||||||
|
// mraa_i2c_context
|
||||||
|
|
||||||
|
if (!(i2cContext = mraa_i2c_init(bus)))
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_i2c_init() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mraa_i2c_address(i2cContext, m_addr) != MRAA_SUCCESS)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": mraa_i2c_address() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// init the driver interface functions
|
||||||
|
s_bmi160.bus_write = bmi160_i2c_bus_write;
|
||||||
|
s_bmi160.bus_read = bmi160_i2c_bus_read;
|
||||||
|
s_bmi160.delay_msec = bmi160_delay_ms;
|
||||||
|
s_bmi160.dev_addr = m_addr;
|
||||||
|
|
||||||
|
// Init our driver interface pointers
|
||||||
|
bmi160_init(&s_bmi160);
|
||||||
|
|
||||||
|
m_accelX = 0.0;
|
||||||
|
m_accelY = 0.0;
|
||||||
|
m_accelZ = 0.0;
|
||||||
|
|
||||||
|
m_gyroX = 0.0;
|
||||||
|
m_gyroY = 0.0;
|
||||||
|
m_gyroZ = 0.0;
|
||||||
|
|
||||||
|
m_magX = 0.0;
|
||||||
|
m_magY = 0.0;
|
||||||
|
m_magZ = 0.0;
|
||||||
|
|
||||||
|
m_accelScale = 1.0;
|
||||||
|
m_gyroScale = 1.0;
|
||||||
|
|
||||||
|
m_magEnabled = false;
|
||||||
|
|
||||||
|
if (!init())
|
||||||
|
{
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": init() failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BMI160::~BMI160()
|
||||||
|
{
|
||||||
|
mraa_i2c_stop(i2cContext);
|
||||||
|
i2cContext = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BMI160::init()
|
||||||
|
{
|
||||||
|
// This should be interesting...
|
||||||
|
const u32 C_BMI160_THIRTY_U8X = 30;
|
||||||
|
|
||||||
|
enableMagnetometer(true);
|
||||||
|
|
||||||
|
/*Set the accel mode as Normal write in the register 0x7E*/
|
||||||
|
bmi160_set_command_register(ACCEL_MODE_NORMAL);
|
||||||
|
|
||||||
|
/* bmi160_delay_ms in ms*/
|
||||||
|
bmi160_delay_ms(C_BMI160_THIRTY_U8X);
|
||||||
|
|
||||||
|
/*Set the gyro mode as Normal write in the register 0x7E*/
|
||||||
|
bmi160_set_command_register(GYRO_MODE_NORMAL);
|
||||||
|
|
||||||
|
/* bmi160_delay_ms in ms*/
|
||||||
|
bmi160_delay_ms(C_BMI160_THIRTY_U8X);
|
||||||
|
|
||||||
|
/* Set the accel bandwidth as OSRS4 */
|
||||||
|
bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
|
||||||
|
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
||||||
|
|
||||||
|
/* Set the gryo bandwidth as Normal */
|
||||||
|
bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
|
||||||
|
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
||||||
|
|
||||||
|
/* set gyro data rate as 200Hz*/
|
||||||
|
bmi160_set_gyro_output_data_rate(BMI160_GYRO_OUTPUT_DATA_RATE_200HZ);
|
||||||
|
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
||||||
|
|
||||||
|
/* set accel data rate as 200Hz*/
|
||||||
|
bmi160_set_accel_output_data_rate(BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ,
|
||||||
|
BMI160_ACCEL_OSR4_AVG1);
|
||||||
|
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
||||||
|
|
||||||
|
setAccelerometerScale(ACCEL_RANGE_2G);
|
||||||
|
setGyroscopeScale(GYRO_RANGE_125);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BMI160::update()
|
||||||
|
{
|
||||||
|
struct bmi160_gyro_t gyroxyz;
|
||||||
|
struct bmi160_accel_t accelxyz;
|
||||||
|
struct bmi160_mag_xyz_s32_t magxyz;
|
||||||
|
|
||||||
|
// read gyro data
|
||||||
|
bmi160_read_gyro_xyz(&gyroxyz);
|
||||||
|
|
||||||
|
// read accel data
|
||||||
|
bmi160_read_accel_xyz(&accelxyz);
|
||||||
|
|
||||||
|
// read mag data
|
||||||
|
if (m_magEnabled)
|
||||||
|
bmi160_bmm150_mag_compensate_xyz(&magxyz);
|
||||||
|
|
||||||
|
// read the sensor time
|
||||||
|
u32 v_sensor_time;
|
||||||
|
bmi160_get_sensor_time(&v_sensor_time);
|
||||||
|
m_sensorTime = (unsigned int)v_sensor_time;
|
||||||
|
|
||||||
|
m_accelX = float(accelxyz.x);
|
||||||
|
m_accelY = float(accelxyz.y);
|
||||||
|
m_accelZ = float(accelxyz.z);
|
||||||
|
|
||||||
|
m_gyroX = float(gyroxyz.x);
|
||||||
|
m_gyroY = float(gyroxyz.y);
|
||||||
|
m_gyroZ = float(gyroxyz.z);
|
||||||
|
|
||||||
|
if (m_magEnabled)
|
||||||
|
{
|
||||||
|
m_magX = float(magxyz.x);
|
||||||
|
m_magY = float(magxyz.y);
|
||||||
|
m_magZ = float(magxyz.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMI160::setAccelerometerScale(ACCEL_RANGE_T scale)
|
||||||
|
{
|
||||||
|
s8 v_range = BMI160_ACCEL_RANGE_2G;
|
||||||
|
// store scaling factor
|
||||||
|
|
||||||
|
switch (scale)
|
||||||
|
{
|
||||||
|
case ACCEL_RANGE_2G:
|
||||||
|
v_range = BMI160_ACCEL_RANGE_2G;
|
||||||
|
m_accelScale = 16384.0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACCEL_RANGE_4G:
|
||||||
|
v_range = BMI160_ACCEL_RANGE_4G;
|
||||||
|
m_accelScale = 8192.0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACCEL_RANGE_8G:
|
||||||
|
v_range = BMI160_ACCEL_RANGE_8G;
|
||||||
|
m_accelScale = 4096.0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACCEL_RANGE_16G:
|
||||||
|
v_range = BMI160_ACCEL_RANGE_16G;
|
||||||
|
m_accelScale = 2048.0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: // should never occur, but...
|
||||||
|
m_accelScale = 1.0; // set a safe, though incorrect value
|
||||||
|
throw std::logic_error(string(__FUNCTION__) +
|
||||||
|
": internal error, unsupported scale");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bmi160_set_accel_range(v_range);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMI160::setGyroscopeScale(GYRO_RANGE_T scale)
|
||||||
|
{
|
||||||
|
u8 v_range = BMI160_GYRO_RANGE_2000_DEG_SEC;
|
||||||
|
|
||||||
|
// store scaling factor
|
||||||
|
|
||||||
|
switch (scale)
|
||||||
|
{
|
||||||
|
case GYRO_RANGE_125:
|
||||||
|
v_range = BMI160_GYRO_RANGE_125_DEG_SEC;
|
||||||
|
m_gyroScale = 262.4;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GYRO_RANGE_250:
|
||||||
|
v_range = BMI160_GYRO_RANGE_250_DEG_SEC;
|
||||||
|
m_gyroScale = 131.2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GYRO_RANGE_500:
|
||||||
|
v_range = BMI160_GYRO_RANGE_500_DEG_SEC;
|
||||||
|
m_gyroScale = 65.6;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GYRO_RANGE_1000:
|
||||||
|
v_range = BMI160_GYRO_RANGE_1000_DEG_SEC;
|
||||||
|
m_gyroScale = 32.8;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GYRO_RANGE_2000:
|
||||||
|
v_range = BMI160_GYRO_RANGE_2000_DEG_SEC;
|
||||||
|
m_gyroScale = 16.4;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: // should never occur, but...
|
||||||
|
m_gyroScale = 1.0; // set a safe, though incorrect value
|
||||||
|
throw std::logic_error(string(__FUNCTION__) +
|
||||||
|
": internal error, unsupported scale");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bmi160_set_gyro_range(v_range);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMI160::getAccelerometer(float *x, float *y, float *z)
|
||||||
|
{
|
||||||
|
if (x)
|
||||||
|
*x = m_accelX / m_accelScale;
|
||||||
|
|
||||||
|
if (y)
|
||||||
|
*y = m_accelY / m_accelScale;
|
||||||
|
|
||||||
|
if (z)
|
||||||
|
*z = m_accelZ / m_accelScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMI160::getGyroscope(float *x, float *y, float *z)
|
||||||
|
{
|
||||||
|
if (x)
|
||||||
|
*x = m_gyroX / m_gyroScale;
|
||||||
|
|
||||||
|
if (y)
|
||||||
|
*y = m_gyroY / m_gyroScale;
|
||||||
|
|
||||||
|
if (z)
|
||||||
|
*z = m_gyroZ / m_gyroScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMI160::getMagnetometer(float *x, float *y, float *z)
|
||||||
|
{
|
||||||
|
if (x)
|
||||||
|
*x = m_magX;
|
||||||
|
|
||||||
|
if (y)
|
||||||
|
*y = m_magY;
|
||||||
|
|
||||||
|
if (z)
|
||||||
|
*z = m_magZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
float *BMI160::getAccelerometer()
|
||||||
|
{
|
||||||
|
float *values = new float[3]; // x, y, and then z
|
||||||
|
|
||||||
|
getAccelerometer(&values[0], &values[1], &values[2]);
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
float *BMI160::getGyroscope()
|
||||||
|
{
|
||||||
|
float *values = new float[3]; // x, y, and then z
|
||||||
|
|
||||||
|
getGyroscope(&values[0], &values[1], &values[2]);
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
float *BMI160::getMagnetometer()
|
||||||
|
{
|
||||||
|
float *values = new float[3]; // x, y, and then z
|
||||||
|
|
||||||
|
getMagnetometer(&values[0], &values[1], &values[2]);
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMI160::enableMagnetometer(bool enable)
|
||||||
|
{
|
||||||
|
// butchered from support example
|
||||||
|
if (!enable)
|
||||||
|
{
|
||||||
|
bmi160_set_bmm150_mag_and_secondary_if_power_mode(MAG_SUSPEND_MODE);
|
||||||
|
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
||||||
|
bmi160_set_if_mode(0x00);
|
||||||
|
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
||||||
|
|
||||||
|
m_magEnabled = false;
|
||||||
|
m_magX = 0;
|
||||||
|
m_magY = 0;
|
||||||
|
m_magZ = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u8 v_bmm_chip_id_u8 = BMI160_INIT_VALUE;
|
||||||
|
/* Init the magnetometer */
|
||||||
|
bmi160_bmm150_mag_interface_init(&v_bmm_chip_id_u8);
|
||||||
|
|
||||||
|
/* bmi160_delay_ms in ms*/
|
||||||
|
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
||||||
|
|
||||||
|
m_magEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int BMI160::getSensorTime()
|
||||||
|
{
|
||||||
|
return m_sensorTime;
|
||||||
|
}
|
251
src/bmi160/bmi160.h
Normal file
251
src/bmi160/bmi160.h
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define BMI160_I2C_BUS 0
|
||||||
|
#define BMI160_DEFAULT_I2C_ADDR 0x69
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief BMI160 3-axis Accelerometer, Gyroscope and Magnetometer
|
||||||
|
* @defgroup bmi160 libupm-bmi160
|
||||||
|
* @ingroup i2c accelerometer compass
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @library bmi160
|
||||||
|
* @sensor bmi160
|
||||||
|
* @comname UPM API for the BMI160 3-axis Accelerometer, Gyroscope
|
||||||
|
* and Magnetometer
|
||||||
|
* @type accelerometer compass
|
||||||
|
* @man mouser
|
||||||
|
* @con i2c
|
||||||
|
* @web http://www.mouser.com/ProductDetail/Bosch-Sensortec/0330SB2187/?qs=sGAEpiMZZMvi6wO7nhr1L9JELKA6cYRX60mAGNTn0fQ%3d
|
||||||
|
*
|
||||||
|
* @brief UPM API for the BMI160 3-axis Accelerometer, Gyroscope and
|
||||||
|
* Magnetometer
|
||||||
|
*
|
||||||
|
* The Bosch BMI160 is a 3-axis Accelerometer and Gyroscope.
|
||||||
|
* Additionally it supports an external Magnetometer, accessed
|
||||||
|
* through the BMI160's register interface. This driver was
|
||||||
|
* developed with a BMI160 "Shuttle" board, which included a BMM150
|
||||||
|
* Magnetometer.
|
||||||
|
*
|
||||||
|
* The device is driven by either 1.8v or 3.3vdc. This driver
|
||||||
|
* incorporates the Bosch BMI160 driver code at
|
||||||
|
* https://github.com/BoschSensortec/BMI160_driver .
|
||||||
|
*
|
||||||
|
* While not all of the functionality of this device is supported
|
||||||
|
* initially, the inclusion of the Bosch driver in the source code
|
||||||
|
* makes it possible to support whatever features are required that
|
||||||
|
* the driver can support.
|
||||||
|
*
|
||||||
|
* @snippet bmi160.cxx Interesting
|
||||||
|
*/
|
||||||
|
class BMI160 {
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ACCEL_RANGE_2G = 0, // 2 Gravities
|
||||||
|
ACCEL_RANGE_4G,
|
||||||
|
ACCEL_RANGE_8G,
|
||||||
|
ACCEL_RANGE_16G
|
||||||
|
} ACCEL_RANGE_T;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GYRO_RANGE_125 = 0, // 125 degrees/sec
|
||||||
|
GYRO_RANGE_250,
|
||||||
|
GYRO_RANGE_500,
|
||||||
|
GYRO_RANGE_1000,
|
||||||
|
GYRO_RANGE_2000
|
||||||
|
} GYRO_RANGE_T;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bmi160 constructor
|
||||||
|
*
|
||||||
|
* @param bus i2c bus to use
|
||||||
|
* @param address the address for this device
|
||||||
|
*/
|
||||||
|
BMI160(int bus=BMI160_I2C_BUS, uint8_t address=BMI160_DEFAULT_I2C_ADDR);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BMI160 Destructor
|
||||||
|
*/
|
||||||
|
~BMI160();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take a measurement and store the current sensor values
|
||||||
|
* internally. This function must be called prior to retrieving
|
||||||
|
* any sensor values, for example getAccelerometer().
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void update();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the scaling mode of the accelerometer
|
||||||
|
*
|
||||||
|
* @param scale one of the ACCEL_RANGE_T values
|
||||||
|
*/
|
||||||
|
void setAccelerometerScale(ACCEL_RANGE_T scale);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the scaling mode of the gyroscope
|
||||||
|
*
|
||||||
|
* @param scale one of the GYRO_RANGE_T values
|
||||||
|
*/
|
||||||
|
void setGyroscopeScale(GYRO_RANGE_T scale);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Accelerometer values. This function returns a pointer
|
||||||
|
* to 3 floating point values: X, Y, and Z, in that order. The
|
||||||
|
* values returned are in gravities. update() must have been
|
||||||
|
* called prior to calling this method.
|
||||||
|
*
|
||||||
|
* The caller is reponsible for freeing the returned pointer.
|
||||||
|
*
|
||||||
|
* @return Pointer to 3 floating point values: X, Y, and Z in
|
||||||
|
* gravities.
|
||||||
|
*/
|
||||||
|
float *getAccelerometer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Accelerometer values. The values returned are in
|
||||||
|
* gravities. update() must have been called prior to calling
|
||||||
|
* this method.
|
||||||
|
*
|
||||||
|
* @param x A pointer into which the X value will be returned
|
||||||
|
* @param y A pointer into which the Y value will be returned
|
||||||
|
* @param z A pointer into which the Z value will be returned
|
||||||
|
*/
|
||||||
|
void getAccelerometer(float *x, float *y, float *z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Gyroscope values. This function returns a pointer to 3
|
||||||
|
* floating point values: X, Y, and Z, in that order. The values
|
||||||
|
* values returned are in degrees per second. update() must have
|
||||||
|
* been called prior to calling this method.
|
||||||
|
*
|
||||||
|
* The caller is reponsible for freeing the returned pointer.
|
||||||
|
*
|
||||||
|
* @return Pointer to 3 floating point values: X, Y, and Z in
|
||||||
|
* degrees per second.
|
||||||
|
*/
|
||||||
|
float *getGyroscope();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Gyroscope values. The values returned are in degrees
|
||||||
|
* per second. update() must have been called prior to calling
|
||||||
|
* this method.
|
||||||
|
*
|
||||||
|
* @param x A pointer into which the X value will be returned
|
||||||
|
* @param y A pointer into which the Y value will be returned
|
||||||
|
* @param z A pointer into which the Z value will be returned
|
||||||
|
*/
|
||||||
|
void getGyroscope(float *x, float *y, float *z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Magnetometer values. This function returns a pointer
|
||||||
|
* to 3 floating point values: X, Y, and Z, in that order. The
|
||||||
|
* values values returned are in micro Teslas. update() must have
|
||||||
|
* been called prior to calling this method. If the Magnetometer
|
||||||
|
* has been disabled, the return values will always be 0, 0, and
|
||||||
|
* 0.
|
||||||
|
*
|
||||||
|
* The caller is reponsible for freeing the returned pointer.
|
||||||
|
*
|
||||||
|
* @return Pointer to 3 floating point values: X, Y, and Z in
|
||||||
|
* micro Teslas.
|
||||||
|
*/
|
||||||
|
float *getMagnetometer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Magnetometer values. The values returned are in micro
|
||||||
|
* Teslas. update() must have been called prior to calling this
|
||||||
|
* method.
|
||||||
|
*
|
||||||
|
* @param x A pointer into which the X value will be returned
|
||||||
|
* @param y A pointer into which the Y value will be returned
|
||||||
|
* @param z A pointer into which the Z value will be returned
|
||||||
|
*/
|
||||||
|
void getMagnetometer(float *x, float *y, float *z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable the Magnetometer. By default, the
|
||||||
|
* magnetometer is enabled.
|
||||||
|
*
|
||||||
|
* @param enable true to enable the magnetometer, false to disable.
|
||||||
|
*/
|
||||||
|
void enableMagnetometer(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the sensor time. This is a 24bit value that increments
|
||||||
|
* every 39us. It will wrap around once the 24b resolution is
|
||||||
|
* exceeded.
|
||||||
|
*
|
||||||
|
* @return The current sensor time.
|
||||||
|
*/
|
||||||
|
unsigned int getSensorTime();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// uncompensated accelerometer and gyroscope values
|
||||||
|
float m_accelX;
|
||||||
|
float m_accelY;
|
||||||
|
float m_accelZ;
|
||||||
|
|
||||||
|
float m_gyroX;
|
||||||
|
float m_gyroY;
|
||||||
|
float m_gyroZ;
|
||||||
|
|
||||||
|
float m_magX;
|
||||||
|
float m_magY;
|
||||||
|
float m_magZ;
|
||||||
|
|
||||||
|
unsigned int m_sensorTime;
|
||||||
|
|
||||||
|
// accelerometer and gyro scaling factors, depending on their Full
|
||||||
|
// Scale (Range) settings.
|
||||||
|
float m_accelScale;
|
||||||
|
float m_gyroScale;
|
||||||
|
|
||||||
|
// is the magnetometer enabled?
|
||||||
|
bool m_magEnabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set up initial values and start operation
|
||||||
|
*
|
||||||
|
* @return true if successful
|
||||||
|
*/
|
||||||
|
virtual bool init();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// due to the way we need to 'hook' into the bmi driver, the i2c
|
||||||
|
// context is a static variable defined in the .cxx implmentation.
|
||||||
|
|
||||||
|
uint8_t m_addr;
|
||||||
|
};
|
||||||
|
}
|
20467
src/bmi160/bosch_bmi160.c
Normal file
20467
src/bmi160/bosch_bmi160.c
Normal file
File diff suppressed because it is too large
Load Diff
12045
src/bmi160/bosch_bmi160.h
Normal file
12045
src/bmi160/bosch_bmi160.h
Normal file
File diff suppressed because it is too large
Load Diff
41
src/bmi160/javaupm_bmi160.i
Normal file
41
src/bmi160/javaupm_bmi160.i
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
%module javaupm_bmi160
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "typemaps.i"
|
||||||
|
%include "arrays_java.i"
|
||||||
|
%include "../java_buffer.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "bmi160.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%typemap(jni) float * "jfloatArray"
|
||||||
|
%typemap(jstype) float * "float[]"
|
||||||
|
%typemap(jtype) float * "float[]"
|
||||||
|
|
||||||
|
%typemap(javaout) float * {
|
||||||
|
return $jnicall;
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) float * {
|
||||||
|
$result = JCALL1(NewFloatArray, jenv, 3);
|
||||||
|
JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1);
|
||||||
|
delete [] $1;
|
||||||
|
}
|
||||||
|
|
||||||
|
%ignore getAccelerometer(float *, float *, float *);
|
||||||
|
%ignore getGyroscope(float *, float *, float *);
|
||||||
|
%ignore getMagnetometer(float *, float *, float *);
|
||||||
|
|
||||||
|
%include "bmi160.h"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_bmi160");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
10
src/bmi160/jsupm_bmi160.i
Normal file
10
src/bmi160/jsupm_bmi160.i
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
%module jsupm_bmi160
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "cpointer.i"
|
||||||
|
|
||||||
|
%pointer_functions(float, floatp);
|
||||||
|
|
||||||
|
%include "bmi160.h"
|
||||||
|
%{
|
||||||
|
#include "bmi160.h"
|
||||||
|
%}
|
55
src/bmi160/license.txt
Normal file
55
src/bmi160/license.txt
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/** \mainpage
|
||||||
|
*
|
||||||
|
****************************************************************************
|
||||||
|
* Copyright (C) 2014 Bosch Sensortec GmbH
|
||||||
|
*
|
||||||
|
* File : bmi160.h
|
||||||
|
*
|
||||||
|
* Date : 2014/10/27
|
||||||
|
*
|
||||||
|
* Revision : 2.0.6 $
|
||||||
|
*
|
||||||
|
* Usage: Sensor Driver for BMI160 sensor
|
||||||
|
*
|
||||||
|
****************************************************************************
|
||||||
|
*
|
||||||
|
* \section License
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* Neither the name of the copyright holder nor the names of the
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
|
||||||
|
* OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||||
|
* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||||
|
*
|
||||||
|
* The information provided is believed to be accurate and reliable.
|
||||||
|
* The copyright holder assumes no responsibility
|
||||||
|
* for the consequences of use
|
||||||
|
* of such information nor for any infringement of patents or
|
||||||
|
* other rights of third parties which may result from its use.
|
||||||
|
* No license is granted by implication or otherwise under any patent or
|
||||||
|
* patent rights of the copyright holder.
|
||||||
|
**************************************************************************/
|
16
src/bmi160/pyupm_bmi160.i
Normal file
16
src/bmi160/pyupm_bmi160.i
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Include doxygen-generated documentation
|
||||||
|
%include "pyupm_doxy2swig.i"
|
||||||
|
%module pyupm_bmi160
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "cpointer.i"
|
||||||
|
|
||||||
|
%include "stdint.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
%pointer_functions(float, floatp);
|
||||||
|
|
||||||
|
%include "bmi160.h"
|
||||||
|
%{
|
||||||
|
#include "bmi160.h"
|
||||||
|
%}
|
6
src/bmp180/CMakeLists.txt
Normal file
6
src/bmp180/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include_directories(..)
|
||||||
|
set (libname "bmp180")
|
||||||
|
set (libdescription "upm BMP180")
|
||||||
|
set (module_src ${libname}.cxx)
|
||||||
|
set (module_h ${libname}.h)
|
||||||
|
upm_module_init()
|
286
src/bmp180/bmp180.cxx
Normal file
286
src/bmp180/bmp180.cxx
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "bmp180.h"
|
||||||
|
|
||||||
|
/* CALIBRATION */
|
||||||
|
#define BMP180_PROM_START_ADDR (0xAA)
|
||||||
|
#define BMP180_PROM_DATA_LEN (22)
|
||||||
|
|
||||||
|
#define BMP180_CALIB_DATA_SIZE (22)
|
||||||
|
#define BMP180_CALIB_PARAM_AC1_MSB (0)
|
||||||
|
#define BMP180_CALIB_PARAM_AC1_LSB (1)
|
||||||
|
#define BMP180_CALIB_PARAM_AC2_MSB (2)
|
||||||
|
#define BMP180_CALIB_PARAM_AC2_LSB (3)
|
||||||
|
#define BMP180_CALIB_PARAM_AC3_MSB (4)
|
||||||
|
#define BMP180_CALIB_PARAM_AC3_LSB (5)
|
||||||
|
#define BMP180_CALIB_PARAM_AC4_MSB (6)
|
||||||
|
#define BMP180_CALIB_PARAM_AC4_LSB (7)
|
||||||
|
#define BMP180_CALIB_PARAM_AC5_MSB (8)
|
||||||
|
#define BMP180_CALIB_PARAM_AC5_LSB (9)
|
||||||
|
#define BMP180_CALIB_PARAM_AC6_MSB (10)
|
||||||
|
#define BMP180_CALIB_PARAM_AC6_LSB (11)
|
||||||
|
#define BMP180_CALIB_PARAM_B1_MSB (12)
|
||||||
|
#define BMP180_CALIB_PARAM_B1_LSB (13)
|
||||||
|
#define BMP180_CALIB_PARAM_B2_MSB (14)
|
||||||
|
#define BMP180_CALIB_PARAM_B2_LSB (15)
|
||||||
|
#define BMP180_CALIB_PARAM_MB_MSB (16)
|
||||||
|
#define BMP180_CALIB_PARAM_MB_LSB (17)
|
||||||
|
#define BMP180_CALIB_PARAM_MC_MSB (18)
|
||||||
|
#define BMP180_CALIB_PARAM_MC_LSB (19)
|
||||||
|
#define BMP180_CALIB_PARAM_MD_MSB (20)
|
||||||
|
#define BMP180_CALIB_PARAM_MD_LSB (21)
|
||||||
|
|
||||||
|
/* REGISTERS */
|
||||||
|
#define BMP180_TEMPERATURE_DATA_LENGTH ((uint8_t)2)
|
||||||
|
#define BMP180_PRESSURE_DATA_LENGTH ((uint8_t)3)
|
||||||
|
|
||||||
|
#define BMP180_CHIP_ID_REG (0xD0)
|
||||||
|
#define BMP180_VERSION_REG (0xD1)
|
||||||
|
|
||||||
|
#define BMP180_CTRL_MEAS_REG (0xF4)
|
||||||
|
#define BMP180_ADC_OUT_MSB_REG (0xF6)
|
||||||
|
#define BMP180_ADC_OUT_LSB_REG (0xF7)
|
||||||
|
|
||||||
|
#define BMP180_SOFT_RESET_REG (0xE0)
|
||||||
|
|
||||||
|
/* temperature measurement */
|
||||||
|
#define BMP180_T_MEASURE (0x2E)
|
||||||
|
|
||||||
|
/* pressure measurement*/
|
||||||
|
#define BMP180_P_MEASURE (0x34)
|
||||||
|
|
||||||
|
#define BMP180_TEMPERATURE_DATA_BYTES (2)
|
||||||
|
#define BMP180_PRESSURE_DATA_BYTES (3)
|
||||||
|
#define BMP180_TEMPERATURE_LSB_DATA (1)
|
||||||
|
#define BMP180_TEMPERATURE_MSB_DATA (0)
|
||||||
|
#define BMP180_PRESSURE_MSB_DATA (0)
|
||||||
|
#define BMP180_PRESSURE_LSB_DATA (1)
|
||||||
|
#define BMP180_PRESSURE_XLSB_DATA (2)
|
||||||
|
|
||||||
|
#define BMP180_PARAM_MG (3038)
|
||||||
|
#define BMP180_PARAM_MH (-7357)
|
||||||
|
#define BMP180_PARAM_MI (3791)
|
||||||
|
|
||||||
|
/* ID */
|
||||||
|
#define BMP180_ID (0x55)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
BMP180::BMP180 (int bus, int devAddr, uint8_t mode) {
|
||||||
|
m_name = "BMP180";
|
||||||
|
m_controlAddr = devAddr;
|
||||||
|
m_bus = bus;
|
||||||
|
|
||||||
|
m_i2c = new mraa::I2c(m_bus);
|
||||||
|
|
||||||
|
// Set mode
|
||||||
|
if (mode > BMP180_ULTRAHIGHRES) {
|
||||||
|
mode = BMP180_ULTRAHIGHRES;
|
||||||
|
}
|
||||||
|
oversampling = mode;
|
||||||
|
|
||||||
|
// Check this is a BMP180 chip and get calibration data
|
||||||
|
if (!isAvailable() || !getCalibrationData())
|
||||||
|
UPM_THROW("Init failed");
|
||||||
|
|
||||||
|
getTemperatureCelcius();
|
||||||
|
}
|
||||||
|
|
||||||
|
BMP180::~BMP180() {
|
||||||
|
delete m_i2c;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
BMP180::getPressurePa () {
|
||||||
|
int pressure;
|
||||||
|
int32_t x1, x2, x3, b3, b6, value;
|
||||||
|
uint32_t b4, b7;
|
||||||
|
uint32_t raw_pressure = getPressureRaw();
|
||||||
|
|
||||||
|
/*****calculate B6************/
|
||||||
|
b6 = b5 - 4000;
|
||||||
|
|
||||||
|
/*****calculate B3************/
|
||||||
|
x1 = (b6 * b6) >> 12;
|
||||||
|
x1 *= b2;
|
||||||
|
x1 >>= 11;
|
||||||
|
|
||||||
|
x2 = (ac2 * b6);
|
||||||
|
x2 >>= 11;
|
||||||
|
|
||||||
|
x3 = x1 + x2;
|
||||||
|
b3 = (((((int32_t) ac1) * 4 + x3) << oversampling) + 2) >> 2;
|
||||||
|
|
||||||
|
/*****calculate B4************/
|
||||||
|
x1 = (ac3 * b6) >> 13;
|
||||||
|
x2 = (b1 * ((b6 * b6) >> 12)) >> 16;
|
||||||
|
x3 = ((x1 + x2) + 2) >> 2;
|
||||||
|
b4 = (ac4 * (uint32_t)(x3 + 32768)) >> 15;
|
||||||
|
b7 = ((uint32_t)(raw_pressure - b3) * (50000 >> oversampling));
|
||||||
|
|
||||||
|
if (b4 == 0)
|
||||||
|
UPM_THROW("b4 == 0");
|
||||||
|
|
||||||
|
if (b7 < 0x80000000)
|
||||||
|
pressure = (b7 << 1) / b4;
|
||||||
|
else
|
||||||
|
pressure = (b7 / b4) << 1;
|
||||||
|
|
||||||
|
x1 = pressure >> 8;
|
||||||
|
x1 *= x1;
|
||||||
|
x1 = (x1 * BMP180_PARAM_MG) >> 16;
|
||||||
|
x2 = (pressure * BMP180_PARAM_MH) >> 16;
|
||||||
|
|
||||||
|
/*pressure in Pa*/
|
||||||
|
pressure += (x1 + x2 + BMP180_PARAM_MI) >> 4;
|
||||||
|
return pressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
BMP180::getTemperatureCelcius () {
|
||||||
|
uint32_t temp;
|
||||||
|
int32_t x1, x2;
|
||||||
|
|
||||||
|
temp = (uint32_t) getTemperatureRaw();
|
||||||
|
|
||||||
|
/* calculate temperature*/
|
||||||
|
x1 = (((int32_t) temp - (int32_t) ac6) * (int32_t) ac5) >> 15;
|
||||||
|
|
||||||
|
// Check divisor
|
||||||
|
if (x1 == 0 && md == 0)
|
||||||
|
UPM_THROW("x1 == 0 && md == 0");
|
||||||
|
|
||||||
|
x2 = ((int32_t) mc << 11) / (x1 + md);
|
||||||
|
b5 = x1 + x2;
|
||||||
|
|
||||||
|
int value = ((b5 + 8) >> 4);
|
||||||
|
return (value + 5) / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
BMP180::getPressureRaw () {
|
||||||
|
uint8_t data[BMP180_PRESSURE_DATA_BYTES];
|
||||||
|
|
||||||
|
m_i2c->address(m_controlAddr);
|
||||||
|
status = m_i2c->writeReg(BMP180_CTRL_MEAS_REG, BMP180_P_MEASURE + (oversampling << 6));
|
||||||
|
if (status != mraa::SUCCESS)
|
||||||
|
UPM_THROW("BMP180_CTRL_MEAS_REG write failed");
|
||||||
|
|
||||||
|
if (oversampling == BMP180_ULTRALOWPOWER) {
|
||||||
|
usleep(5000);
|
||||||
|
} else if (oversampling == BMP180_STANDARD) {
|
||||||
|
usleep(8000);
|
||||||
|
} else if (oversampling == BMP180_HIGHRES) {
|
||||||
|
usleep(14000);
|
||||||
|
} else {
|
||||||
|
usleep(26000);
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = m_i2c->readBytesReg(BMP180_ADC_OUT_MSB_REG, data, BMP180_PRESSURE_DATA_LENGTH);
|
||||||
|
if (length != BMP180_PRESSURE_DATA_LENGTH)
|
||||||
|
UPM_THROW("BMP180_ADC_OUT_MSB_REG read failed");
|
||||||
|
|
||||||
|
return (uint32_t)((((uint32_t)data[BMP180_PRESSURE_MSB_DATA] << 16)
|
||||||
|
| ((uint32_t) data[BMP180_PRESSURE_LSB_DATA] << 8)
|
||||||
|
| (uint32_t) data[BMP180_PRESSURE_XLSB_DATA]) >> (8 - oversampling));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t
|
||||||
|
BMP180::getTemperatureRaw () {
|
||||||
|
uint8_t data[BMP180_TEMPERATURE_DATA_BYTES];
|
||||||
|
|
||||||
|
m_i2c->address(m_controlAddr);
|
||||||
|
status = m_i2c->writeReg(BMP180_CTRL_MEAS_REG, BMP180_T_MEASURE);
|
||||||
|
if (status != mraa::SUCCESS)
|
||||||
|
UPM_THROW("BMP180_CTRL_MEAS_REG write failed");
|
||||||
|
|
||||||
|
usleep(5000);
|
||||||
|
|
||||||
|
int length = m_i2c->readBytesReg(BMP180_ADC_OUT_MSB_REG, data, BMP180_TEMPERATURE_DATA_LENGTH);
|
||||||
|
if (length != BMP180_TEMPERATURE_DATA_LENGTH)
|
||||||
|
UPM_THROW("BMP180_ADC_OUT_MSB_REG read failed");
|
||||||
|
|
||||||
|
return (uint16_t)((((int32_t)((int8_t)data[BMP180_TEMPERATURE_MSB_DATA])) << 8)
|
||||||
|
| (data[BMP180_TEMPERATURE_LSB_DATA]));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
BMP180::getCalibrationData() {
|
||||||
|
|
||||||
|
// Holds calibration data
|
||||||
|
uint8_t calibration_data[BMP180_CALIB_DATA_SIZE];
|
||||||
|
|
||||||
|
/* Read calibration data */
|
||||||
|
m_i2c->address(m_controlAddr);
|
||||||
|
int length = m_i2c->readBytesReg(BMP180_PROM_START_ADDR, calibration_data, BMP180_PROM_DATA_LEN);
|
||||||
|
|
||||||
|
// Check we read all calibration data
|
||||||
|
if(length != BMP180_PROM_DATA_LEN) { return false; }
|
||||||
|
|
||||||
|
ac1 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_AC1_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_AC1_LSB]);
|
||||||
|
ac2 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_AC2_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_AC2_LSB]);
|
||||||
|
ac3 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_AC3_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_AC3_LSB]);
|
||||||
|
ac4 = (uint16_t)(((uint32_t)((uint8_t)calibration_data[BMP180_CALIB_PARAM_AC4_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_AC4_LSB]);
|
||||||
|
ac5 = (uint16_t)(((uint32_t)((uint8_t)calibration_data[BMP180_CALIB_PARAM_AC5_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_AC5_LSB]);
|
||||||
|
ac6 = (uint16_t)(((uint32_t)((uint8_t)calibration_data[BMP180_CALIB_PARAM_AC6_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_AC6_LSB]);
|
||||||
|
|
||||||
|
b1 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_B1_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_B1_LSB]);
|
||||||
|
b2 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_B2_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_B2_LSB]);
|
||||||
|
|
||||||
|
mb = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_MB_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_MB_LSB]);
|
||||||
|
mc = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_MC_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_MC_LSB]);
|
||||||
|
md = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_MD_MSB] << 8))
|
||||||
|
| calibration_data[BMP180_CALIB_PARAM_MD_LSB]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
BMP180::isAvailable() {
|
||||||
|
m_i2c->address(m_controlAddr);
|
||||||
|
if (m_i2c->readReg(BMP180_CHIP_ID_REG) != BMP180_ID) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
126
src/bmp180/bmp180.h
Normal file
126
src/bmp180/bmp180.h
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Contributions: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Credits to Adafruit.
|
||||||
|
* Based on Adafruit BMP180 library.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mraa/i2c.hpp>
|
||||||
|
#include "upm/iPressureSensor.h"
|
||||||
|
#include "upm/iTemperatureSensor.h"
|
||||||
|
|
||||||
|
#define BMP180_ADDR 0x77 // device address
|
||||||
|
|
||||||
|
/* MODES */
|
||||||
|
#define BMP180_ULTRALOWPOWER 0
|
||||||
|
#define BMP180_STANDARD 1
|
||||||
|
#define BMP180_HIGHRES 2
|
||||||
|
#define BMP180_ULTRAHIGHRES 3
|
||||||
|
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief BPM180 atmospheric pressure sensor library
|
||||||
|
* @defgroup BMP180 libupm-BMP180
|
||||||
|
* @ingroup bosch seeed adafruit sparkfun i2c pressure ipressuresensor
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief API for Bosch BMP180 Pressure Sensor
|
||||||
|
*
|
||||||
|
* The Bosch BMP180 is a high precision, ultra-low
|
||||||
|
* power consumption pressure sensor. It has a range of between
|
||||||
|
* 30,000 and 110,000 Pa.
|
||||||
|
*
|
||||||
|
* @library BMP180
|
||||||
|
* @sensor BMP180
|
||||||
|
* @comname Bosch BMP Atmospheric Pressure Sensor
|
||||||
|
* @altname BMP180
|
||||||
|
* @type pressure
|
||||||
|
* @man bosch adafruit sparkfun
|
||||||
|
* @con i2c
|
||||||
|
* @if ipressuresensor
|
||||||
|
*
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
class BMP180 : public IPressureSensor, public ITemperatureSensor {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Instanciates a BMP180 object
|
||||||
|
*
|
||||||
|
* @param bus number of used bus
|
||||||
|
* @param devAddr address of used i2c device
|
||||||
|
* @param mode BMP180 mode
|
||||||
|
*/
|
||||||
|
BMP180 (int bus, int devAddr=BMP180_ADDR, uint8_t mode=BMP180_ULTRAHIGHRES);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BMP180 object destructor, basicaly it close i2c connection.
|
||||||
|
*/
|
||||||
|
~BMP180 ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return pressure
|
||||||
|
*/
|
||||||
|
uint32_t getPressureRaw();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return calculated pressure (Pa)
|
||||||
|
*/
|
||||||
|
int getPressurePa();
|
||||||
|
|
||||||
|
uint16_t getTemperatureRaw();
|
||||||
|
/**
|
||||||
|
* Return latest calculated temperature value in Celcius
|
||||||
|
*/
|
||||||
|
int getTemperatureCelcius();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the correct chip is present at the given address.
|
||||||
|
*/
|
||||||
|
bool isAvailable();
|
||||||
|
const char* getModuleName() { return m_name.c_str(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_name;
|
||||||
|
|
||||||
|
int m_controlAddr;
|
||||||
|
int m_bus;
|
||||||
|
mraa::I2c* m_i2c;
|
||||||
|
mraa::Result status;
|
||||||
|
|
||||||
|
uint8_t oversampling;
|
||||||
|
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
|
||||||
|
uint16_t ac4, ac5, ac6;
|
||||||
|
|
||||||
|
int32_t b5;
|
||||||
|
|
||||||
|
bool getCalibrationData();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
23
src/bmp180/javaupm_bmp180.i
Normal file
23
src/bmp180/javaupm_bmp180.i
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
%module javaupm_bmp180
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "arrays_java.i";
|
||||||
|
%include "../java_buffer.i"
|
||||||
|
%include "cpointer.i"
|
||||||
|
%include "typemaps.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "bmp180.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "bmp180.h"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_bmp180");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
8
src/bmp180/jsupm_bmp180.i
Normal file
8
src/bmp180/jsupm_bmp180.i
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
%module jsupm_bmp180
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "bmp180.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "bmp180.h"
|
10
src/bmp180/pyupm_bmp180.i
Normal file
10
src/bmp180/pyupm_bmp180.i
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
%module pyupm_bmp180
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%include "stdint.i"
|
||||||
|
|
||||||
|
%include "bmp180.h"
|
||||||
|
%{
|
||||||
|
#include "bmp180.h"
|
||||||
|
%}
|
||||||
|
|
@ -93,7 +93,8 @@ BMPX8X::getPressure () {
|
|||||||
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
|
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
|
||||||
|
|
||||||
if (B7 < 0x80000000) {
|
if (B7 < 0x80000000) {
|
||||||
p = (B7 * 2) / B4;
|
p = (B7 * 2) / B4
|
||||||
|
;
|
||||||
} else {
|
} else {
|
||||||
p = (B7 / B4) * 2;
|
p = (B7 / B4) * 2;
|
||||||
}
|
}
|
||||||
@ -169,6 +170,18 @@ BMPX8X::getAltitude (float sealevelPressure) {
|
|||||||
return altitude;
|
return altitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
BMPX8X::getTemperatureCelcius() {
|
||||||
|
return static_cast<int>(getTemperature() + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
BMPX8X::getModuleName() {
|
||||||
|
return m_name.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t
|
int32_t
|
||||||
BMPX8X::computeB5(int32_t UT) {
|
BMPX8X::computeB5(int32_t UT) {
|
||||||
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
|
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <mraa/i2c.hpp>
|
#include <mraa/i2c.hpp>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include "upm/iTemperatureSensor.h"
|
||||||
|
|
||||||
#define ADDR 0x77 // device address
|
#define ADDR 0x77 // device address
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ namespace upm {
|
|||||||
* @snippet bmpx8x.cxx Interesting
|
* @snippet bmpx8x.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BMPX8X {
|
class BMPX8X : public ITemperatureSensor {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Instantiates a BMPX8X object
|
* Instantiates a BMPX8X object
|
||||||
@ -141,6 +142,19 @@ class BMPX8X {
|
|||||||
*/
|
*/
|
||||||
float getAltitude (float sealevelPressure = 101325);
|
float getAltitude (float sealevelPressure = 101325);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return latest calculated temperature value in Celcius
|
||||||
|
* See ITemperatureSensor
|
||||||
|
*/
|
||||||
|
int getTemperatureCelcius();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns name of module. This is the string in library name after libupm_
|
||||||
|
|
||||||
|
* @return name of module
|
||||||
|
*/
|
||||||
|
const char* getModuleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates B5 (check the spec for more information)
|
* Calculates B5 (check the spec for more information)
|
||||||
*
|
*
|
||||||
|
11
src/curieimu/CMakeLists.txt
Normal file
11
src/curieimu/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
include (CheckFunctionExists)
|
||||||
|
include (CheckLibraryExists)
|
||||||
|
include (CheckIncludeFiles)
|
||||||
|
check_library_exists (${MRAA_LIBRARIES} mraa_firmata_init "" HAVE_FIRMATA)
|
||||||
|
if (HAVE_FIRMATA)
|
||||||
|
set (libname "curieimu")
|
||||||
|
set (libdescription "upm Curie IMU via Firmata")
|
||||||
|
set (module_src ${libname}.cpp)
|
||||||
|
set (module_h ${libname}.hpp)
|
||||||
|
upm_module_init ()
|
||||||
|
endif ()
|
458
src/curieimu/curieimu.cpp
Normal file
458
src/curieimu/curieimu.cpp
Normal file
@ -0,0 +1,458 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Author: Justin Zemlyansky (@JustInDevelopment)
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
static CurieImu* awaitingReponse;
|
||||||
|
|
||||||
|
CurieImu::CurieImu (int subplatformoffset)
|
||||||
|
{
|
||||||
|
m_firmata = mraa_firmata_init(FIRMATA_CURIE_IMU);
|
||||||
|
if (m_firmata == NULL) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_firmata_init() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pthread_mutex_init(&m_responseLock, NULL)) {
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": pthread_mutex_init(m_responseLock) failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pthread_cond_init(&m_responseCond, NULL)) {
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": pthread_cond_init(m_responseCond) failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurieImu::~CurieImu()
|
||||||
|
{
|
||||||
|
pthread_mutex_destroy(&m_responseLock);
|
||||||
|
pthread_cond_destroy(&m_responseCond);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::lock()
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&m_responseLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::unlock()
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(&m_responseLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::waitForResponse()
|
||||||
|
{
|
||||||
|
awaitingReponse = this;
|
||||||
|
pthread_cond_wait(&m_responseCond, &m_responseLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::proceed()
|
||||||
|
{
|
||||||
|
pthread_cond_broadcast(&m_responseCond);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::setResults(uint8_t* buf, int length)
|
||||||
|
{
|
||||||
|
m_results = new char(length);
|
||||||
|
memcpy((void*)m_results, (void*)buf, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handles a single syncronous response being returned from Firmata
|
||||||
|
*
|
||||||
|
* @param buffer the data beinig returned from Firmata
|
||||||
|
* @param length length of results buffer
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
handleSyncResponse(uint8_t* buf, int length)
|
||||||
|
{
|
||||||
|
awaitingReponse->setResults(buf, length);
|
||||||
|
awaitingReponse->proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handles asyncronous responses being returned from Firmata
|
||||||
|
*
|
||||||
|
* @param buffer the data beinig returned from Firmata
|
||||||
|
* @param length length of results buffer
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
handleAsyncResponses(uint8_t* buf, int length)
|
||||||
|
{
|
||||||
|
awaitingReponse->setResults(buf, length);
|
||||||
|
awaitingReponse->processResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::processResponse()
|
||||||
|
{
|
||||||
|
switch(m_results[2]) {
|
||||||
|
case FIRMATA_CURIE_IMU_SHOCK_DETECT:
|
||||||
|
{
|
||||||
|
IMUDataItem* item = new IMUDataItem();
|
||||||
|
item->axis = m_results[3];
|
||||||
|
item->direction = m_results[4];
|
||||||
|
m_shockData.push(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FIRMATA_CURIE_IMU_STEP_COUNTER:
|
||||||
|
{
|
||||||
|
int count = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
m_stepData.push(count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FIRMATA_CURIE_IMU_TAP_DETECT:
|
||||||
|
{
|
||||||
|
IMUDataItem* item = new IMUDataItem();
|
||||||
|
item->axis = m_results[3];
|
||||||
|
item->direction = m_results[4];
|
||||||
|
m_tapData.push(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getAccel()
|
||||||
|
{
|
||||||
|
return &m_accel[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelX()
|
||||||
|
{
|
||||||
|
return m_accel[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelY()
|
||||||
|
{
|
||||||
|
return m_accel[Y];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelZ()
|
||||||
|
{
|
||||||
|
return m_accel[Z];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getGyro()
|
||||||
|
{
|
||||||
|
return &m_gyro[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroX()
|
||||||
|
{
|
||||||
|
return m_gyro[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroY()
|
||||||
|
{
|
||||||
|
return m_gyro[Y];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroZ()
|
||||||
|
{
|
||||||
|
return m_gyro[Z];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getMotion()
|
||||||
|
{
|
||||||
|
return &m_motion[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::updateAccel()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_ACCEL;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
m_accel[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
m_accel[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
|
m_accel[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::updateGyro()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_GYRO;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
m_gyro[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
m_gyro[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
|
m_gyro[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::updateMotion()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_MOTION;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
m_motion[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
m_motion[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
|
m_motion[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
m_motion[3] = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
|
||||||
|
m_motion[4] = ((m_results[11] & 0x7f) | ((m_results[12] & 0x7f) << 7));
|
||||||
|
m_motion[5] = ((m_results[13] & 0x7f) | ((m_results[13] & 0x7f) << 7));
|
||||||
|
|
||||||
|
for (int i=0; i<3; i++)
|
||||||
|
m_accel[i] = m_motion[i];
|
||||||
|
|
||||||
|
for (int i=0; i<3; i++)
|
||||||
|
m_gyro[i] = m_motion[i+3];
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getTemperature()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_TEMP;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
int16_t result;
|
||||||
|
result = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
result += ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7)) << 8;
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAxis()
|
||||||
|
{
|
||||||
|
return m_axis;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getDirection()
|
||||||
|
{
|
||||||
|
return m_direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::enableShockDetection(bool enable)
|
||||||
|
{
|
||||||
|
char message[5];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_SHOCK_DETECT;
|
||||||
|
message[3] = enable;
|
||||||
|
message[4] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleAsyncResponses);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
|
||||||
|
|
||||||
|
awaitingReponse = this;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CurieImu::isShockDetected()
|
||||||
|
{
|
||||||
|
return (m_shockData.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::getNextShock()
|
||||||
|
{
|
||||||
|
if (m_shockData.size() > 0) {
|
||||||
|
IMUDataItem* item = m_shockData.front();
|
||||||
|
m_axis = item->axis;
|
||||||
|
m_direction = item->direction;
|
||||||
|
m_shockData.pop();
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::enableStepCounter(bool enable)
|
||||||
|
{
|
||||||
|
char message[5];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_STEP_COUNTER;
|
||||||
|
message[3] = enable;
|
||||||
|
message[4] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleAsyncResponses);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
|
||||||
|
|
||||||
|
awaitingReponse = this;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CurieImu::isStepDetected()
|
||||||
|
{
|
||||||
|
return (m_stepData.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getStepCount()
|
||||||
|
{
|
||||||
|
int16_t count = 0;
|
||||||
|
if (m_stepData.size() > 0) {
|
||||||
|
count = m_stepData.front();
|
||||||
|
m_stepData.pop();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::enableTapDetection(bool enable)
|
||||||
|
{
|
||||||
|
char message[5];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_TAP_DETECT;
|
||||||
|
message[3] = enable;
|
||||||
|
message[4] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleAsyncResponses);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
|
||||||
|
|
||||||
|
awaitingReponse = this;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CurieImu::isTapDetected()
|
||||||
|
{
|
||||||
|
return (m_tapData.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::getNextTap()
|
||||||
|
{
|
||||||
|
if (m_tapData.size() > 0) {
|
||||||
|
IMUDataItem* item = m_tapData.front();
|
||||||
|
m_axis = item->axis;
|
||||||
|
m_direction = item->direction;
|
||||||
|
m_tapData.pop();
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
307
src/curieimu/curieimu.hpp
Normal file
307
src/curieimu/curieimu.hpp
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Author: Justin Zemlyansky (@JustInDevelopment)
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mraa/firmata.h>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CurieIMU sensor for Genuino 101 running Firmata
|
||||||
|
* @defgroup curieimu libupm-curieimu
|
||||||
|
* @ingroup firmata
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @library curieimu
|
||||||
|
* @sensor curieimu
|
||||||
|
* @comname Curie IMU sensor over Genuino 101 running Firmata
|
||||||
|
* @altname Curie Firmata IMU
|
||||||
|
* @type firmata
|
||||||
|
* @man firmata imu genuino
|
||||||
|
* @con firmata
|
||||||
|
*
|
||||||
|
* @brief API for the Curie IMU via Firmata
|
||||||
|
*
|
||||||
|
* Curie IMU is a 6-axxis acclerometer
|
||||||
|
*
|
||||||
|
* This module has been tested on an Genuino 101 running ConfigurableFirmata with CurieIMU
|
||||||
|
*
|
||||||
|
* @snippet curieimu.cxx Interesting
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define FIRMATA_START_SYSEX 0xF0
|
||||||
|
#define FIRMATA_END_SYSEX 0xF7
|
||||||
|
#define FIRMATA_CURIE_IMU 0x11
|
||||||
|
#define FIRMATA_CURIE_IMU_READ_ACCEL 0x00
|
||||||
|
#define FIRMATA_CURIE_IMU_READ_GYRO 0x01
|
||||||
|
#define FIRMATA_CURIE_IMU_READ_TEMP 0x02
|
||||||
|
#define FIRMATA_CURIE_IMU_SHOCK_DETECT 0x03
|
||||||
|
#define FIRMATA_CURIE_IMU_STEP_COUNTER 0x04
|
||||||
|
#define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
|
||||||
|
#define FIRMATA_CURIE_IMU_READ_MOTION 0x06
|
||||||
|
|
||||||
|
#define X 0
|
||||||
|
#define Y 1
|
||||||
|
#define Z 2
|
||||||
|
|
||||||
|
struct IMUDataItem {
|
||||||
|
int axis;
|
||||||
|
int direction;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CurieImu {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a CurieImu object
|
||||||
|
*
|
||||||
|
* @param subplatformoffset Subplatform offset
|
||||||
|
*/
|
||||||
|
CurieImu (int subplatform_offset=512);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for CurieImu object
|
||||||
|
*/
|
||||||
|
~CurieImu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the latest accelerometer readings by calling Firmata
|
||||||
|
*/
|
||||||
|
void updateAccel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the latest gyroscope readings by calling Firmata
|
||||||
|
*/
|
||||||
|
void updateGyro();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the both the latest accelerometer & gyroscope readings
|
||||||
|
* by calling Firmata
|
||||||
|
*/
|
||||||
|
void updateMotion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading X, Y, and Z axis
|
||||||
|
*
|
||||||
|
* @return pointer to array with X-axis, Y-axis & Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t* getAccel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading X axis
|
||||||
|
*
|
||||||
|
* @return X-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading Y axis
|
||||||
|
*
|
||||||
|
* @return Y-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading Z axis
|
||||||
|
*
|
||||||
|
* @return Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelZ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read gyroscope X, Y, and Z axis
|
||||||
|
*
|
||||||
|
* @return pointer to array with X-axis, Y-axis & Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t* getGyro();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading X axis
|
||||||
|
*
|
||||||
|
* @return X-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading Y axis
|
||||||
|
*
|
||||||
|
* @return Y-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading Z axis
|
||||||
|
*
|
||||||
|
* @return Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroZ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the internal temperature
|
||||||
|
*
|
||||||
|
* @return 16-bit integer containing the scaled temperature reading
|
||||||
|
*/
|
||||||
|
int16_t getTemperature();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the X, Y, and Z axis of both gyroscope and accelerometer
|
||||||
|
*
|
||||||
|
* @return pointer to array with X-axis, Y-axis & Z-axis values for
|
||||||
|
* accelerometer, and then X-axis, Y-axis & Z-axis values for
|
||||||
|
* gyroscope
|
||||||
|
*/
|
||||||
|
int16_t* getMotion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last shock or tap axis reading
|
||||||
|
*
|
||||||
|
* @return axis value
|
||||||
|
*/
|
||||||
|
int16_t getAxis();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last shock or tap direction reading
|
||||||
|
*
|
||||||
|
* @return direction value
|
||||||
|
*/
|
||||||
|
int16_t getDirection();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns shock detection notifications on/off
|
||||||
|
*
|
||||||
|
* @param enable enables/disables notifications
|
||||||
|
*/
|
||||||
|
void enableShockDetection(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has there been a shock detected?
|
||||||
|
*
|
||||||
|
* @return true if any unprocessed shock notifications are in the queue
|
||||||
|
*/
|
||||||
|
bool isShockDetected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets shock detect data from queue. Then m_axis gets axis data, and
|
||||||
|
* m_direction gets direction data
|
||||||
|
*/
|
||||||
|
void getNextShock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns step counter notifications on/off
|
||||||
|
*
|
||||||
|
* @param enable enables/disables notifications
|
||||||
|
*/
|
||||||
|
void enableStepCounter(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has there been a step detected?
|
||||||
|
*
|
||||||
|
* @return true if any unprocessed step notifications are in the queue
|
||||||
|
*/
|
||||||
|
bool isStepDetected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets step count data from queue
|
||||||
|
*
|
||||||
|
* @return the total number of steps taken
|
||||||
|
*/
|
||||||
|
int16_t getStepCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns tap detection notifications on/off
|
||||||
|
*
|
||||||
|
* @param enable enables/disables notifications
|
||||||
|
*/
|
||||||
|
void enableTapDetection(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has there been a tap detected?
|
||||||
|
*
|
||||||
|
* @return true if any unprocessed tap notifications are in the queue
|
||||||
|
*/
|
||||||
|
bool isTapDetected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tap detect data from queue. Then m_axis gets axis data, and
|
||||||
|
* m_direction gets direction data
|
||||||
|
*/
|
||||||
|
void getNextTap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locks responses from Firmata
|
||||||
|
*/
|
||||||
|
void lock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlocks responses from Firmata
|
||||||
|
*/
|
||||||
|
void unlock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for a response from Firmata before proceeding
|
||||||
|
*/
|
||||||
|
void waitForResponse();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proceed with original function call now that response
|
||||||
|
* from Firmata has been received
|
||||||
|
*/
|
||||||
|
void proceed();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set results being returned from Firmata for processing
|
||||||
|
*
|
||||||
|
* @param buf is the buffer
|
||||||
|
* @param length is the length of results buffer
|
||||||
|
*/
|
||||||
|
void setResults(uint8_t* buf, int length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes asyncronous responses returned from Firmata
|
||||||
|
*/
|
||||||
|
void processResponse();
|
||||||
|
|
||||||
|
private:
|
||||||
|
mraa_firmata_context m_firmata;
|
||||||
|
pthread_mutex_t m_responseLock;
|
||||||
|
pthread_cond_t m_responseCond;
|
||||||
|
char* m_results;
|
||||||
|
|
||||||
|
std::queue<IMUDataItem*> m_shockData;
|
||||||
|
std::queue<int> m_stepData;
|
||||||
|
std::queue<IMUDataItem*> m_tapData;
|
||||||
|
|
||||||
|
int16_t m_accel[3];
|
||||||
|
int16_t m_gyro[3];
|
||||||
|
int16_t m_motion[6];
|
||||||
|
|
||||||
|
int16_t m_axis;
|
||||||
|
int16_t m_direction;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
42
src/curieimu/javaupm_curieimu.i
Normal file
42
src/curieimu/javaupm_curieimu.i
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
%module javaupm_curieimu
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%typemap(jni) int16_t* "jshortArray"
|
||||||
|
%typemap(jstype) int16_t* "short[]"
|
||||||
|
%typemap(jtype) int16_t* "short[]"
|
||||||
|
|
||||||
|
%typemap(javaout) int16_t* {
|
||||||
|
return $jnicall;
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getAccel {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 3);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getGyro {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 3);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getMotion {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 6);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 6, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%include "curieimu.hpp"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_curieimu");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
15
src/curieimu/jsupm_curieimu.i
Normal file
15
src/curieimu/jsupm_curieimu.i
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
%module jsupm_curieimu
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "../carrays_int16_t.i"
|
||||||
|
|
||||||
|
// Adding this typemap because SWIG is converting int16 into a short by default
|
||||||
|
// This forces SWIG to convert it correctly
|
||||||
|
%typemap(out) int16_t* {
|
||||||
|
jsresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "curieimu.hpp"
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user