Compare commits
158 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 | |||
f1f9d9ec2e | |||
74d625c797 | |||
2695ef3361 | |||
a9548f3ff4 | |||
3ed0e14487 | |||
1a80400fa9 | |||
9845b24dea | |||
af7f544387 | |||
ac5c20afad | |||
9f3557aa20 | |||
d112266170 | |||
94fdd86896 | |||
c0c99fd87a | |||
684919f069 | |||
37add7eb33 | |||
e17dc9a22e | |||
84c3445412 | |||
6b2850557e | |||
f94ee6a388 | |||
cbb289438e | |||
71b0791239 | |||
757a2ce342 | |||
3fab5625c7 | |||
5324808e82 | |||
7d64e5458f | |||
ab15d1e98f | |||
d9b761469d | |||
2098449c56 | |||
63c75be370 | |||
03b4d24e64 | |||
9d1afd35f8 | |||
022b546003 | |||
1d085362d9 | |||
3504dc7246 | |||
5b7522bec4 | |||
828a9ce7d8 | |||
8cec2ad473 | |||
c3e3a6bb17 | |||
11b5d3bc58 | |||
3522e4ee8f | |||
0f548d367b | |||
1786017006 | |||
2d68d707f6 | |||
d7f4b76ed0 | |||
4a1b4f1dd4 | |||
ec75790516 | |||
fad4f72357 | |||
b3db180ffb | |||
a4f41c7cb5 | |||
40f9135412 | |||
46996e5251 | |||
2cd043c2a1 | |||
e1c66c351a | |||
a5fd4a2c10 | |||
fc7bfc113a | |||
bf82beaf9c | |||
5e37830bb7 | |||
4ff722ed2e | |||
52b0ef4b28 | |||
930ff6734d | |||
40be9b68a5 | |||
4259aeab7b | |||
d0cb2a032c | |||
4dc679af70 | |||
091bd9b381 | |||
d04f93ffca | |||
66aaa97955 | |||
387b2b86b0 | |||
e003a11723 | |||
d0504bb65b | |||
669fd317b6 | |||
af7d1d2611 | |||
1cbb486330 | |||
9516e0720c | |||
8273556539 | |||
5bc9353bb4 | |||
c8e80bf6a3 |
33
.travis.yml
@ -1,21 +1,38 @@
|
||||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
env:
|
||||
- CC=gcc CXX=gcc
|
||||
- CC=clang CXX=clang++
|
||||
- NODE4=true
|
||||
- NODE5=true
|
||||
- NODE012=true
|
||||
install:
|
||||
- sudo add-apt-repository --yes ppa:kalakris/cmake
|
||||
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
||||
- 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 update-java-alternatives -s java-8-oracle
|
||||
before_script:
|
||||
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36"
|
||||
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
|
||||
- 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:
|
||||
- git clone --branch=master 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
|
||||
- git clone https://github.com/intel-iot-devkit/mraa.git
|
||||
- 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 CPLUS_INCLUDE_PATH=$PWD/include
|
||||
- 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 .. && 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
|
||||
|
@ -10,7 +10,7 @@ find_package (PkgConfig REQUIRED)
|
||||
|
||||
# Force a libmraa search and minimum required version every time a config is generated
|
||||
unset(MRAA_FOUND CACHE)
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=0.8.0)
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=0.9.1)
|
||||
message (INFO " found mraa version: ${MRAA_VERSION}")
|
||||
|
||||
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
||||
@ -25,7 +25,7 @@ include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production UPM!")
|
||||
set (VERSION "v0.4.1-dirty")
|
||||
set (VERSION "v0.6.0-dirty")
|
||||
endif ()
|
||||
|
||||
message (INFO " - UPM Version ${VERSION}")
|
||||
@ -51,11 +51,15 @@ set (CMAKE_SWIG_FLAGS "")
|
||||
option (BUILDDOC "Build all doc." OFF)
|
||||
option (BUILDSWIG "Build swig 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 (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
option (RPM "Generate RPM using CPack" OFF)
|
||||
option (BUILDTESTS "Generate check-ups for upm" ON)
|
||||
option (ENABLECXX11 "Enable C++11 standards support" ON)
|
||||
|
||||
# Find swig
|
||||
if (BUILDSWIG)
|
||||
@ -74,6 +78,27 @@ include (TargetArch)
|
||||
target_architecture (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)
|
||||
# Add a target to generate API documentation with Doxygen
|
||||
find_package (Doxygen)
|
||||
@ -97,7 +122,7 @@ if (BUILDDOC)
|
||||
find_package (Sphinx)
|
||||
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
|
||||
# Python required for Sphinx build
|
||||
find_package (PythonLibs)
|
||||
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
||||
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
||||
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
||||
@ -154,7 +179,7 @@ if (IPK)
|
||||
endif ()
|
||||
message (INFO " - Package arch is ${TARGET_ARCH}")
|
||||
|
||||
set(CPACK_GENERATOR "DEB" "TGZ")
|
||||
set(CPACK_GENERATOR "DEB")
|
||||
set(OPKG_ARCH ${TARGET_ARCH})
|
||||
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
||||
@ -180,10 +205,9 @@ if (RPM)
|
||||
message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
|
||||
set(CPACK_PACKAGE_VERSION ${VERSION})
|
||||
set(CPACK_GENERATOR "RPM")
|
||||
set(CPACK_PACKAGE_NAME "libupm${upm_VERSION_MAJOR}")
|
||||
set(CPACK_PACKAGE_RELEASE 1)
|
||||
set(CPACK_PACKAGE_NAME "upm")
|
||||
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_VENDOR "Intel IoT-Devkit")
|
||||
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
|
||||
@ -194,7 +218,7 @@ if (RPM)
|
||||
COMMAND tr \\n \\t
|
||||
COMMAND sed -e s/\\t//
|
||||
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)
|
||||
endif()
|
||||
|
||||
@ -203,3 +227,21 @@ add_subdirectory (src)
|
||||
if(BUILDEXAMPLES)
|
||||
add_subdirectory (examples/c++)
|
||||
endif()
|
||||
|
||||
if(BUILDJAVAEXAMPLES)
|
||||
add_subdirectory (examples/java)
|
||||
endif()
|
||||
|
||||
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
if (BUILDPYTHON3)
|
||||
set (PYTHONBUILD_VERSION 3)
|
||||
else ()
|
||||
set (PYTHONBUILD_VERSION 2.7)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (BUILDTESTS)
|
||||
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif()
|
||||
|
21
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
|
||||
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
|
||||
|
||||
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).
|
||||
|
||||
Multi-sensor samples for the starter and specialized kits can be found in the
|
||||
@ -81,7 +90,9 @@ See building documentation [here](docs/building.md).
|
||||
|
||||
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).
|
||||
|
||||
### Naming conventions and rules for new UPM contributions
|
||||
|
||||
|
@ -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
|
||||
$ENV{NODE_DIR}
|
||||
PATH_SUFFIXES bin
|
||||
@ -7,26 +15,50 @@ find_program (NODE_EXECUTABLE NAMES node
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
|
||||
PATHS /usr/include/nodejs /usr/local/include/nodejs)
|
||||
# If compat-libuv package exists, it must be at start of include path
|
||||
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
|
||||
if (UV_ROOT_DIR)
|
||||
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
|
||||
add_include_dir(${UV_ROOT_DIR})
|
||||
endif()
|
||||
|
||||
set (NODE_INCLUDE_DIRS
|
||||
${NODE_ROOT_DIR}/src
|
||||
${NODE_ROOT_DIR}/node
|
||||
${NODE_ROOT_DIR}/deps/v8/include
|
||||
${NODE_ROOT_DIR}/deps/uv/include
|
||||
# Now look for node. Flag an error if not found
|
||||
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
|
||||
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
||||
if (NODE_ROOT_DIR)
|
||||
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
|
||||
NODE_EXECUTABLE
|
||||
NODE_INCLUDE_DIRS
|
||||
)
|
||||
|
||||
if (NODE_EXECUTABLE)
|
||||
execute_process(COMMAND ${NODE_EXECUTABLE} --version
|
||||
if (NODEJS_EXECUTABLE)
|
||||
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
|
||||
OUTPUT_VARIABLE _VERSION
|
||||
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
|
||||
RESULT_VARIABLE _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")
|
||||
message ("defaulted to node 0.10.30")
|
||||
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 ()
|
||||
|
||||
mark_as_advanced (NODE_EXECUTABLE)
|
||||
|
@ -5,12 +5,10 @@ UPM uses cmake in order to make compilation relatively painless. Cmake runs
|
||||
build out of tree so the recommended way is to clone from git and make a build/
|
||||
directory.
|
||||
|
||||
This project depends on libmraa, so that needs to be installed first. Use the
|
||||
following environment variables to configure the paths:
|
||||
This project depends on libmraa, so that needs to be installed first. Append
|
||||
the install location of mraa pkgconfig to the following environment variable:
|
||||
|
||||
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:.../mraa/build/lib/pkgconfig
|
||||
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:.../mraa/build/include
|
||||
LIBRARY_PATH=$LIBRARY_PATH:.../mraa/build/lib
|
||||
|
||||
UPM will attempt to build all directories inside src/ and they must contain
|
||||
individual CMakeLists.txt files.
|
||||
|
@ -4,6 +4,44 @@ Changelog {#changelog}
|
||||
Here's a list summarizing some of the key undergoing changes to our library
|
||||
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
|
||||
|
||||
* Updated the API and added new functionality for the MY9221 class and derived
|
||||
sensors: grovecircularled and groveledbar, along with new code samples that
|
||||
show these changes
|
||||
* Provided a fix for one JAVA example that uses interrupts and updated library
|
||||
install paths
|
||||
* Several documentation improvements and pictures were added for new sensors
|
||||
* A few other sensors received minor patches
|
||||
|
||||
### v0.5.0
|
||||
|
||||
* First implementations for industrial grade Modbus sensors, along with first
|
||||
sensor examples that use the new iio system driver in MRAA
|
||||
* Significant improvements to the stepmotor driver that will now allow precise
|
||||
control using any GPIO pin and extended the API with new functionality
|
||||
* Further improved JAVA bindings and sensor ISRs have been modified to
|
||||
implement Runnable objects
|
||||
* Improved Python typemaps and error checking, documentation now includes
|
||||
detailed function descriptions
|
||||
* Simplified the build process by eliminating the need to define redundant
|
||||
MRAA related environment variables
|
||||
* New sensors: nlgpio16, ads1x15, t3311, hdxxvxta, hwxpxx, rhusb, ili9341,
|
||||
apds9930, kxcjk1013
|
||||
|
||||
### v0.4.1
|
||||
|
||||
* Over 150 supported sensor drivers including some industrial grade devices
|
||||
@ -40,7 +78,7 @@ from earlier versions:
|
||||
includes last remaining images and grouping sensors by kits
|
||||
* Added support for Sparkfun Sensor Blocks (OLED & IMU)
|
||||
* Fully reworked API for at42qt1070, mpu9150 and lcd classes, while
|
||||
maintaining backwards compatibility for existing lcd displays.
|
||||
maintaining backwards compatibility for existing lcd displays
|
||||
* Extended doxygen tags for better integration with automated documentation
|
||||
generators
|
||||
* New sensors: rgbringcoder, hp20x, pn532, sainsmartks, lsm9ds0, eboled
|
||||
|
353
docs/creating_java_bindings.md
Normal file
@ -0,0 +1,353 @@
|
||||
Creating Java Bindings Guide
|
||||
==============
|
||||
* [Overview](#overview)
|
||||
* [Tools of trade](#tools-of-trade)
|
||||
* [Recommendations for the native API](#recommendations-for-the-native-api)
|
||||
* [Pointers](#pointers)
|
||||
* [Throwing Exceptions in Java](#throwing-exceptions-in-java)
|
||||
* [Caveats & Challenges](#caveats--challenges)
|
||||
* [Wrapping C arrays with Java arrays](#wrapping-c-arrays-with-java-arrays)
|
||||
* [Wrapping unbound C arrays with Java arrays if array is output](#wrapping-unbound-c-arrays-with-java-arrays-if-array-is-output)
|
||||
* [Wrapping unbound C arrays with Java arrays if array is input](#wrapping-unbound-c-arrays-with-java-arrays-if-array-is-input)
|
||||
* [Implementing callbacks in Java](#implementing-callbacks-in-java)
|
||||
|
||||
|
||||
##Overview
|
||||
|
||||
The "Creating Java Bindings Guide" serves as a basic tutorial for using the SWIG software development tool to create 'glue code' required for Java to call into C/C++ code. It contains: guides for dealing with type conversions, exception handling, callbacks; recommendations on how to write/modify the native API to avoid issues on the Java side, and also workarounds for those issues that can't be avoided.
|
||||
|
||||
This guide was created with the [upm](https://github.com/intel-iot-devkit/upm/) and [mraa](https://github.com/intel-iot-devkit/mraa) libraries in mind, and uses examples taken from these sources, but its usage can be extended to any project of creating Java bindings for C/C++ libraries.
|
||||
|
||||
##Tools of trade
|
||||
|
||||
[SWIG General Documentation](http://www.swig.org/Doc3.0/SWIGDocumentation.html)
|
||||
|
||||
[SWIG Java-specific Documentation](http://www.swig.org/Doc3.0/Java.html)
|
||||
|
||||
|
||||
##Recommendations for the native API
|
||||
|
||||
###Pointers
|
||||
As much as possible, avoid passing values/returning values through pointers given as as arguments to methods. As the Java language does not have pointers, SWIG provides a [workaround](http://www.swig.org/Doc3.0/Java.html#Java_tips_techniques) in the typemaps.i library.
|
||||
|
||||
####Alternatives:
|
||||
1. Functions that read data from a driver, return it through a pointer given as argument, and return a bool value, should be __replaced by__ functions that return the value directly and throw a std::runtime_error if a read error occurs. E.g.:
|
||||
```c++
|
||||
/*
|
||||
* Function reads from sensor, places read value in variable bar and
|
||||
* returns true if succesful. Function returns false if read failed.
|
||||
*/
|
||||
bool func(int *bar);
|
||||
```
|
||||
__Replaced by:__
|
||||
```c++
|
||||
/*
|
||||
* Function reads from sensor and returns read value.
|
||||
* Or throws std::runtime_error if a read error occurs
|
||||
*/
|
||||
int func();
|
||||
```
|
||||
|
||||
2. Functions that return multiple values through pointers, that make sense to be grouped together into an array<sup>1</sup> (e.g. speed values, acceleration values), should be __replaced by__ functions that return a pointer to an array in which the elements are the returned values. Afterwards, [wrap the C array with a Java array](#wrapping-unbound-c-arrays-with-java-arrays-if-array-is-output). E.g.:
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis in the given variables.
|
||||
*/
|
||||
void getAccel(int *accelX, int *accelY, int *accelZ);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis as elements of a 3-element array.
|
||||
*/
|
||||
int *getAccel();
|
||||
```
|
||||
|
||||
3. Functions that return N values through pointers, that do not make sense to grouped together (e.g. a general purpose function that returns both the light intensity and air pollution), should be __replaced by__ N functions (one for each value) that read only one specific value. E.g.:
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the light intensity and air pollution
|
||||
*/
|
||||
void getData(int *light, int *air);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
```c++
|
||||
int getLight();
|
||||
int getAir();
|
||||
```
|
||||
|
||||
4. Functions that return N values through pointers; values that do not make sense to be grouped together, but are time dependent, and make sense to be read at the same time. For example, a sensor that reads air humidity and temperature. A user may want to know the temperature value _temp_ read at the exact moment the humidity value _humid_ was read. These should be __replaced by__ N+1 functions: a _getData()_ function that reads all values at the same time and stores them in global variables; and N getter functions, one for each value. E.g.
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the light intensity and air pollution
|
||||
*/
|
||||
void getData(int *temp, int *humid);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
```c++
|
||||
void getData();
|
||||
int getTemp();
|
||||
int getHumid();
|
||||
```
|
||||
|
||||
<sup>1</sup>this depends on the interpretation of the returned data. For example, arguments that return the temperature and light intensity, don't make sense to be grouped into an array of size 2. But acceleration on the three axis can be grouped together in an array of size 3. where accelX is accel[0], accelY is accel[1], accelZ is accel[2].
|
||||
|
||||
__Notice:__
|
||||
Sometimes, you may be required to write JNI code. Be aware of the difference between the C JNI calling syntax and the C++ JNI calling syntax.The C++ calling syntax will not compile as C and also vice versa. It is however possible to write JNI calls which will compile under both C and C++ and is covered in the [Typemaps for both C and C++ compilation](http://www.swig.org/Doc3.0/Java.html#Java_typemaps_for_c_and_cpp) section of the SWIG Documentation.
|
||||
|
||||
|
||||
###Throwing Exceptions in Java
|
||||
####Language independent:
|
||||
The %exception directive allows you to define a general purpose exception handler. For example, you can specify the following:
|
||||
|
||||
```c++
|
||||
%exception [method_name] {
|
||||
try {
|
||||
$action
|
||||
}
|
||||
catch (std::invalid_argument& e) {
|
||||
... handle error ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If [method_name] is not specified then the directive is applied to all methods in its scope.
|
||||
|
||||
The usual thing you'd want to do is catch the C++ exception and throw an equivalent exception in your language.
|
||||
|
||||
The exception.i library file provides support for creating language independent exceptions in your interfaces. To use it, simply put an "%include exception.i" in your interface file. This provides a function SWIG_exception() that can be used to raise common language exceptions in a portable manner. For example :
|
||||
|
||||
|
||||
```c++
|
||||
// Language independent exception handler
|
||||
%include exception.i
|
||||
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch(OutOfMemory) {
|
||||
SWIG_exception(SWIG_MemoryError, "Out of memory");
|
||||
} catch(...) {
|
||||
SWIG_exception(SWIG_RuntimeError,"Unknown exception");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In the upm library, the upm_exception.i interface file provides the functionality to catch common exceptions and propagate them through SWIG. It uses the exception.i library file and is language independent.
|
||||
|
||||
The upm_exception.i interface file is included in the upm.i file, therefor SWIG wraps all generated methods' body in a try-catch statement for the following exceptions:
|
||||
|
||||
* std::invalid_argument
|
||||
* std::domain_error
|
||||
* std::overflow_error
|
||||
* std::out_of_range
|
||||
* std::length_error
|
||||
* std::logic_error
|
||||
* std::bad_alloc
|
||||
* std::runtime_error
|
||||
* std::exception
|
||||
|
||||
|
||||
####Java specific:
|
||||
To throw a specific Java exception:
|
||||
|
||||
```c++
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range &e) {
|
||||
jclass clazz = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(clazz, "Range error");
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Where FindClass and ThrowNew are [JNI functions](http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html).
|
||||
|
||||
Java defines two tipes of exceptions: checked exception and unchecked exceptions (errors and runtime exceptions). Checked exceptions are subject to the [Catch or Specify Requirement](https://docs.oracle.com/javase/tutorial/essential/exceptions/catchOrDeclare.html).
|
||||
|
||||
The C++ compiler does not force the code to catch any exception.
|
||||
|
||||
The %exception directive does not specify if a method throws a checked exception (does not add classes to the throws clause). For this, the %javaexception(classes) directive is used; where classes is a string containing one or more comma separated Java classes.
|
||||
|
||||
```c++
|
||||
%javaexception("java.lang.Exception") {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range &e) {
|
||||
jclass clazz = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(clazz, "Range error");
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In the upm library, the java_exceptions.i library file provides the functionality to catch exceptions and propagate them through SWIG as Java checked exceptions. The file provides SWIG wrappers, in the form of macros, that can be applied to methods.E.g. use the __READDATA_EXCEPTION(function)__ macro for functions that read data from a sensor and throw a std::runtime_error in case of a read failure. This will result in:
|
||||
|
||||
```java
|
||||
void function throws IOException ();
|
||||
```
|
||||
|
||||
##Caveats & Challenges
|
||||
|
||||
###Wrapping C arrays with Java arrays
|
||||
SWIG can wrap arrays in a more natural Java manner than the default by using the arrays_java.i library file. Just include this file into your SWIG interface file.
|
||||
|
||||
###Wrapping unbound C arrays with Java arrays if array is output
|
||||
Functions that return arrays, return a pointer to that array. E.g.:
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis as elements of a 3-element array.
|
||||
*/
|
||||
|
||||
int *getAccel();
|
||||
```
|
||||
|
||||
__SWIG:__
|
||||
```c++
|
||||
%typemap(jni) int* "jintArray"
|
||||
%typemap(jstype) int* "int[]"
|
||||
%typemap(jtype) int* "int[]"
|
||||
|
||||
%typemap(javaout) int* {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
%typemap(out) int *getAccel {
|
||||
$result = JCALL1(NewIntArray, jenv, 3);
|
||||
JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const signed int*)$1);
|
||||
}
|
||||
```
|
||||
|
||||
###Wrapping unbound C arrays with Java arrays if array is input
|
||||
In C, arrays are tipically passed as pointers, with an integer value representig the length of the array. In Java, the length of an array is always known, so the length argument is redundant. This example shows how to wrap the C array and also get rid the length argument. E.g.:
|
||||
|
||||
```c++
|
||||
void func(uint8_t *buffer, int length);
|
||||
```
|
||||
|
||||
__SWIG:__
|
||||
```c++
|
||||
%typemap(jtype) (uint8_t *buffer, int length) "byte[]"
|
||||
%typemap(jstype) (uint8_t *buffer, int length) "byte[]"
|
||||
%typemap(jni) (uint8_t *buffer, int length) "jbyteArray"
|
||||
%typemap(javain) (uint8_t *buffer, int length) "$javainput"
|
||||
|
||||
%typemap(in,numinputs=1) (uint8_t *buffer, int length) {
|
||||
$1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
|
||||
$2 = JCALL1(GetArrayLength, jenv, $input);
|
||||
}
|
||||
```
|
||||
|
||||
!!!! There is a difference between TYPE *name and TYPE * name in typemaps!!!!!
|
||||
|
||||
|
||||
###Implementing callbacks in Java
|
||||
Callbacks in the UPM Java library (as well as the MRAA Java library) make use of the _void mraa\_java\_isr\_callback(void\* data\)_ method from MRAA.
|
||||
|
||||
__Callbacks in the UPM Java library are implemented as follows (we use the a110x Hall Effect sensors as example):__
|
||||
|
||||
We extend the sensor class with another method, _installISR\(jobject runnable\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _mraa\_java\_isr\_callback\(\)_ method as the interrupt service routine \(ISR\) to be called, with _jobject runnable_ as argument.
|
||||
|
||||
SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _installISR\(jobject runnable\)_ method in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
|
||||
|
||||
```c++
|
||||
#if defined(SWIGJAVA)
|
||||
void A110X::installISR(jobject runnable)
|
||||
{
|
||||
installISR(mraa_java_isr_callback, runnable);
|
||||
}
|
||||
#endif
|
||||
```
|
||||
|
||||
We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(jobject runnable\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
|
||||
|
||||
```c++
|
||||
public:
|
||||
#if defined(SWIGJAVA)
|
||||
void installISR(jobject runnable);
|
||||
#else
|
||||
void installISR(void (*isr)(void *), void *arg);
|
||||
#endif
|
||||
private:
|
||||
#if defined(SWIGJAVA)
|
||||
void installISR(void (*isr)(void *), void *arg);
|
||||
#endif
|
||||
```
|
||||
|
||||
To use callback in java, we create a ISR class, which implements the Java Runnable interface, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
|
||||
|
||||
```java
|
||||
public class A110X_intrSample {
|
||||
public static int counter=0;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
upm_a110x.A110X hall = new upm_a110x.A110X(2);
|
||||
|
||||
A110XISR callback = new A110XISR();
|
||||
hall.installISR(callback);
|
||||
|
||||
while(true){
|
||||
System.out.println("Counter: " + counter);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class A110XISR implements Runnable {
|
||||
public A110XISR(){
|
||||
super();
|
||||
}
|
||||
public void run(){
|
||||
A110X_intrSample.counter++;
|
||||
}
|
||||
}
|
||||
```
|
||||
####Issues with java callbacks and workarounds
|
||||
|
||||
__SWIGJAVA not defined at compile time__
|
||||
|
||||
Consider the following files:
|
||||
* example.h - Header file for our source file
|
||||
* example.cxx - Source file containing the class Example, for which we build java bindings
|
||||
* example.i - The SWIG interface, that includes the example.h header file
|
||||
|
||||
The build process of a java module using SWIG is split into two steps:
|
||||
|
||||
1. Generating the intermediate files, from the SWIG interface file. This will produce the java class file (Example.java), the JNI file (exampleJNI.java) and wrapper file (example_wrap.cxx). The source file (example.cxx) is not needed in the first step.
|
||||
|
||||
```
|
||||
swig -c++ -java example.i
|
||||
```
|
||||
|
||||
2. Generating the shared library from the C++ sources and wrapper file
|
||||
```
|
||||
g++ -fPIC -c example.cxx example_wrap.cxx -I/usr/lib/jvm/java-1.8.0/include -I/usr/lib/jvm/java-1.8.0/include/linux
|
||||
g++ -shared example_wrap.o sensor.o -o libexample.so
|
||||
```
|
||||
|
||||
|
||||
SWIGJAVA is always defined when SWIG parses the interface file, meaning it will be defined when it parses the header file (example.h) that is included in the interface file (example.i).
|
||||
SWIG also adds the "#define SWIGJAVA" directive in the wrapper file (example_wrap.cxx).
|
||||
However, in generating the shared library the SWIGJAVA symbol is only defined in the example_wrap.cxx file, because of the added "#define SWIGJAVA" directive. But we have also used the "#if defined(SWIGJAVA)" check in the source file (example.cxx), and thus need to define SWIGJAVA for it too. If we define the SWIGJAVA symbol as a compile flag, when compiling the source code to object code, the SWIGJAVA compile flag and #define SWIGJAVA" directive will clash and give a double definition warning (only a warning).
|
||||
|
||||
In this example it is simple to compile the two source codes separately, one with the compile flag, the other without, and then create the shared library (libexample.so).
|
||||
But in a big automatic build like the java upm libraries, this may prove too hard or too complicated to do. A workaround to this would be to define a custom symbol (e.q. JAVACALLBACK in the upm library) and also test for it. In short, replace:
|
||||
```c++
|
||||
#if defined(SWIGJAVA)
|
||||
```
|
||||
by
|
||||
```c++
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
```
|
||||
|
@ -50,10 +50,12 @@ Here's an example (disregard the "@verbatim" tags in your actual code):
|
||||
library's "@defgroup", otherwise this is a new library name, generally the
|
||||
same as chip id. *Mandatory*
|
||||
- `<chip-id>` Usually the chip number used by the sensor. When this is not
|
||||
available or relevant, use a unique descriptor that makes sense. *Mandatory*
|
||||
- `<component-name>` A short name for your sensor, can include manufacturer
|
||||
name. *Mandatory*
|
||||
- `<alt-name>` Alternative names that your sensor driver might have. *Optional*
|
||||
available or relevant, use a unique descriptor that makes sense. Must match
|
||||
class name. *Mandatory*
|
||||
- `<component-name>` A short name for your sensor, try to avoid including the
|
||||
manufacturer's name here. *Mandatory*
|
||||
- `<alt-name>` Alternative names that your sensor driver might have. This may
|
||||
include manufacturer's name. *Optional*
|
||||
- `<alt-id>` Alternative chip-ids that your sensor driver supports. *Optional*
|
||||
- `<component-category>` Mention one or more categories the sensor fits in. Can
|
||||
be 'other'. *Mandatory*
|
||||
|
BIN
docs/images/ads1015.jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
docs/images/ads1115.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
docs/images/adxrs610.jpg
Normal file
After Width: | Height: | Size: 45 KiB |
BIN
docs/images/apa102.jpg
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
docs/images/bma220.jpg
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
docs/images/dfrph.jpg
Normal file
After Width: | Height: | Size: 96 KiB |
BIN
docs/images/eboled.jpg
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
docs/images/groveultrasonic.jpg
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
docs/images/ili9341.jpg
Normal file
After Width: | Height: | Size: 199 KiB |
BIN
docs/images/keypadlcd.jpg
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
docs/images/lm35.jpg
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
docs/images/lsm9ds0.jpg
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
docs/images/mg811.jpg
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
docs/images/mpu60x0.jpg
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
docs/images/mpu9250.jpg
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
docs/images/pn532.jpg
Normal file
After Width: | Height: | Size: 102 KiB |
BIN
docs/images/ssd1351.jpg
Normal file
After Width: | Height: | Size: 90 KiB |
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 198 KiB |
BIN
docs/images/urm37.jpg
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
docs/images/wheelencoder.jpg
Normal file
After Width: | Height: | Size: 43 KiB |
BIN
docs/images/xbee.jpg
Normal file
After Width: | Height: | Size: 176 KiB |
@ -7,6 +7,11 @@ such sensors and known workarounds if they exist.
|
||||
|
||||
#### Grove Sensors
|
||||
|
||||
* **Grove LCD RGB Backlit** (JHD1313M1) requires 5V and should be used with an
|
||||
external power supply connected to the board to function properly. Although
|
||||
some high powered USB ports might be enough, in most cases you will encounter
|
||||
dropped characters, washed out text and/or failed I2C writes while using USB
|
||||
power alone.
|
||||
* **Grove I2C Touch Sensor** (MPR121) v1.3 is incompatible with the Intel
|
||||
Edison using the Arduino board, but will work with the Mini-breakout if
|
||||
supplied with at least 4V. Revision v1.2 works well on all Intel boards.
|
||||
@ -14,8 +19,8 @@ such sensors and known workarounds if they exist.
|
||||
on the Intel Edison boards.
|
||||
* **Grove 3-Axis Digital Gyroscope** (ITG-3200) is not compatible with the
|
||||
Intel Edison Arduino board but will work with the Mini-breakout.
|
||||
* **Grove 3-Axis Digital Accelerometer** (ADXL345) only works with the Intel
|
||||
Edison Arduino board when powered from the 3.3V line.
|
||||
* **Grove 3-Axis Digital Accelerometer +/-16g** (ADXL345) only works with the
|
||||
Intel Edison Arduino board when powered from the 3.3V line.
|
||||
* **Grove 3-Axis Digital Compass** (HMC5883L) reports inaccurate values at 5V
|
||||
on the Intel Edison Arduino board and newer revisions might not work at all.
|
||||
Use 3.3V or the Mini-breakout.
|
||||
@ -26,21 +31,24 @@ such sensors and known workarounds if they exist.
|
||||
* **Grove Barometer** (BMP085) has an unstable connection on the Intel Edison
|
||||
using the Arduino breakout and may drop read data. The Xadow version of this
|
||||
sensor (BMP180) is also dropping data packets occasionally.
|
||||
* **Grove Digital Light Sensor** (TSL2561) occasionally drops I2C reads on the
|
||||
Intel Edison with the Arduino breakout. This might cause the sensor not to
|
||||
initialize properly. Works as expected with the Mini-breakout.
|
||||
* **Grove 6-Axis Accelerometer & Compass** (LSM303) fails to write to the
|
||||
configuration register properly and returns invalid data.
|
||||
* **Grove I2C ADC Converter** does not show up on the I2C bus on the Intel
|
||||
Edison with the Arduino board.
|
||||
* **Grove I2C Motor Driver** is not compatible with the Intel Galileo due to
|
||||
the inability to change the I2C bus speed to 100 KHz.
|
||||
* **Grove Digital Light Sensor** (TSL2561) may have an unstable connection on
|
||||
the Intel Edison using the Arduino breakout that results in missed I2C reads.
|
||||
This is usually applicable when the I2C lines are pulled-up to 5V. Works as
|
||||
expected with the Mini-breakout.
|
||||
* **Grove CO2 Sensor** will return zeroed data and is unusable on the Intel
|
||||
Galileo.
|
||||
* **Grove BLE** (HM-11) does not return data on the Intel Galileo board due to
|
||||
known UART limitation.
|
||||
* **Grove Hall Sensor** (A11X), if the base shield is set to 3V on Intel Edison,
|
||||
* **Grove Hall Sensor** (A11X) if the base shield is set to 3V on Intel Edison,
|
||||
it will trigger continous callbacks when the sensor is not reading anything.
|
||||
* **Grove RTC** (DS1307) is not compatible with the Intel Edison Arduino board
|
||||
but will work with the Mini-breakout.
|
||||
|
||||
#### Adafruit Sensors
|
||||
|
||||
|
@ -859,7 +859,7 @@ EXCLUDE_SYMLINKS = NO
|
||||
# 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_PATTERNS =
|
||||
EXCLUDE_PATTERNS = bosch_*
|
||||
|
||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||
|
@ -30,7 +30,7 @@ Multi-sensor samples for the starter and specialized kits can be found in the
|
||||
|
||||
Supported [sensor list](http://iotdk.intel.com/docs/master/upm/modules.html) from API documentation.
|
||||
|
||||
You can also refer to the [Intel® IoT Developer Zone](https://software.intel.com/iot/sensors).
|
||||
You can also refer to the [Intel IoT Developer Zone](https://software.intel.com/iot/sensors).
|
||||
|
||||
### IDE Compatibility
|
||||
|
||||
|
@ -1,40 +1,21 @@
|
||||
# Mapping C++ sample files to Java sample files
|
||||
a110x-intr.cxx A110X_intrSample.java
|
||||
a110x.cxx A110XSample.java
|
||||
ad8232.cxx AD8232Sample.java
|
||||
adc121c021.cxx ADC121C021Sample.java
|
||||
adis16448.cxx ADIS16448Sample.java
|
||||
adxl335.cxx ADXL335Sample.java
|
||||
adxl345.cxx Adxl345Sample.java
|
||||
ak8975.cxx AK8975Sample.java
|
||||
am2315.cxx AM2315Sample.java
|
||||
apds9002.cxx APDS9002Sample.java
|
||||
biss0001.cxx BISS0001Sample.java
|
||||
bmpx8x.cxx BMPX8XSample.java
|
||||
buzzer-sound.cxx Buzzer_soundSample.java
|
||||
cjq4435.cxx CJQ4435Sample.java
|
||||
ds1307.cxx DS1307Sample.java
|
||||
eboled.cxx EBOLEDSample.java
|
||||
ecs1030.cxx ECS1030Sample.java
|
||||
enc03r.cxx ENC03RSample.java
|
||||
es08a.cxx ES08ASample.java
|
||||
flex.cxx FlexSample.java
|
||||
gp2y0a.cxx GP2Y0ASample.java
|
||||
grovebutton.cxx GroveButtonSample.java
|
||||
grovecircularled.cxx GroveCircularLEDSample.java
|
||||
grovecollision.cxx GroveCollisionSample.java
|
||||
groveehr.cxx GroveEHRSample.java
|
||||
groveeldriver.cxx GroveElDriverSample.java
|
||||
groveelectromagnet.cxx GroveElectromagnetSample.java
|
||||
groveemg.cxx GroveEMGSample.java
|
||||
grovegprs.cxx GroveGPRSSample.java
|
||||
grovegsr.cxx GroveGSRSample.java
|
||||
groveled.cxx GroveLEDSample.java
|
||||
grovelinefinder.cxx GroveLineFinderSample.java
|
||||
grovelight.cxx GroveLightSample.java
|
||||
groveloudness.cxx GroveLoudnessSample.java
|
||||
grovemoisture.cxx GroveMoistureSample.java
|
||||
groveo2.cxx GroveO2Sample.java
|
||||
groverelay.cxx GroveRelaySample.java
|
||||
groverotary.cxx GroveRotarySample.java
|
||||
grovescam.cxx GROVESCAMSample.java
|
||||
@ -48,75 +29,45 @@ h3lis331dl.cxx H3LIS331DLSample.java
|
||||
hcsr04.cxx HCSR04Sample.java
|
||||
hm11.cxx HM11Sample.java
|
||||
hmc5883l.cxx Hmc5883lSample.java
|
||||
hp20x.cxx HP20XSample.java
|
||||
ht9170.cxx HT9170Sample.java
|
||||
htu21d.cxx HTU21DSample.java
|
||||
hx711.cxx HX711Sample.java
|
||||
hyld9767.cxx HYLD9767Sample.java
|
||||
ina132.cxx INA132Sample.java
|
||||
itg3200.cxx Itg3200Sample.java
|
||||
jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java
|
||||
joystick12-example.cxx Joystick12_exampleSample.java
|
||||
l298-stepper.cxx L298_stepperSample.java
|
||||
l298.cxx L298Sample.java
|
||||
lcm1602-lcd.cxx Lcm1602_lcdSample.java
|
||||
joystick12.cxx Joystick12Sample.java
|
||||
lcm1602-i2c.cxx Lcm1602_i2cSample.java
|
||||
ldt0028.cxx LDT0028Sample.java
|
||||
lol-example.cxx LoL_exampleSample.java
|
||||
lpd8806.cxx LPD8806Sample.java
|
||||
lol.cxx LoLSample.java
|
||||
lsm303.cxx LSM303Sample.java
|
||||
lsm9ds0.cxx LSM9DS0Sample.java
|
||||
m24lr64e.cxx M24LR64ESample.java
|
||||
max31723.cxx MAX31723Sample.java
|
||||
max31855.cxx MAX31855Sample.java
|
||||
max44000.cxx MAX44000Sample.java
|
||||
max5487.cxx MAX5487Sample.java
|
||||
maxds3231m.cxx MAXDS3231MSample.java
|
||||
mg811.cxx MG811Sample.java
|
||||
mic.cxx MicrophoneSample.java
|
||||
mlx90614.cxx MLX90614Sample.java
|
||||
mma7455.cxx MMA7455Sample.java
|
||||
mma7660.cxx MMA7660Sample.java
|
||||
mpl3115a2.cxx MPL3115A2Sample.java
|
||||
mpr121.cxx MPR121Sample.java
|
||||
mpu60x0.cxx MPU60X0Sample.java
|
||||
mpu9150.cxx MPU9150Sample.java
|
||||
mpu9250.cxx MPU9250Sample.java
|
||||
mq2.cxx MQ2Sample.java
|
||||
mq3.cxx MQ3Sample.java
|
||||
mq303a.cxx MQ303ASample.java
|
||||
mq5.cxx MQ5Sample.java
|
||||
mq9.cxx MQ9Sample.java
|
||||
my9221-ledbar.cxx MY9221_ledbarSample.java
|
||||
my9221-updown.cxx MY9221_updownSample.java
|
||||
nrf24l01-broadcast.cxx NRF24L01_broadcastSample.java
|
||||
groveledbar GroveLEDBar
|
||||
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
|
||||
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
|
||||
nunchuck.cxx NUNCHUCKSample.java
|
||||
otp538u.cxx OTP538USample.java
|
||||
pca9685.cxx PCA9685Sample.java
|
||||
pn532-writeurl.cxx PN532_writeurlSample.java
|
||||
pn532.cxx PN532Sample.java
|
||||
ppd42ns.cxx PPD42NSSample.java
|
||||
pulsensor.cxx PulsensorSample.java
|
||||
rfr359f.cxx RFR359FSample.java
|
||||
rgbringcoder.cxx RGBRingCoderSample.java
|
||||
rotaryencoder.cxx RotaryEncoderSample.java
|
||||
rpr220-intr.cxx RPR220_intrSample.java
|
||||
rpr220.cxx RPR220Sample.java
|
||||
sainsmartks.cxx SAINSMARTKSSample.java
|
||||
sm130.cxx SM130Sample.java
|
||||
ssd1306-oled.cxx SSD1306_oledSample.java
|
||||
ssd1308-oled.cxx SSD1308_oledSample.java
|
||||
ssd1327-oled.cxx SSD1327_oledSample.java
|
||||
st7735.cxx ST7735Sample.java
|
||||
stepmotor.cxx StepMotorSample.java
|
||||
ta12200.cxx TA12200Sample.java
|
||||
tm1637.cxx TM1637Sample.java
|
||||
tp401.cxx TP401Sample.java
|
||||
tsl2561.cxx TSL2561Sample.java
|
||||
ttp223.cxx TTP223Sample.java
|
||||
ublox6.cxx Ublox6Sample.java
|
||||
uln200xa.cxx ULN200XASample.java
|
||||
waterlevel.cxx WaterLevelSample.java
|
||||
wt5001.cxx WT5001Sample.java
|
||||
yg1006.cxx YG1006Sample.java
|
||||
|
@ -10,11 +10,10 @@ macro(get_module_name example_name module_name)
|
||||
elseif ((${example_name} MATCHES "^mq" AND ${length} EQUAL 3) OR ${example_name} STREQUAL "tp401")
|
||||
set (${module_name} "gas")
|
||||
else()
|
||||
set(${module_name} ${example_name})
|
||||
set(${module_name} ${example_name})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
# Set source file, include and linker settings for an example
|
||||
# If example cannot be built, example_bin is cleared
|
||||
macro(add_custom_example example_bin example_src example_module_list)
|
||||
@ -26,25 +25,25 @@ macro(add_custom_example example_bin example_src example_module_list)
|
||||
if (MODULE_LIST)
|
||||
list(FIND MODULE_LIST ${module} index)
|
||||
if (${index} EQUAL -1)
|
||||
set(found_all_modules FALSE)
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if (found_all_modules)
|
||||
add_executable (${example_bin} ${example_src})
|
||||
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
|
||||
foreach (module ${example_module_list})
|
||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
|
||||
include_directories (${module_dir})
|
||||
if (${module} STREQUAL "lcd")
|
||||
set(module "i2clcd")
|
||||
set(module "i2clcd")
|
||||
endif()
|
||||
target_link_libraries (${example_bin} ${module})
|
||||
target_link_libraries (${example_bin} ${module})
|
||||
endforeach()
|
||||
else()
|
||||
MESSAGE(INFO " Ignored ${example_bin}")
|
||||
set (example_bin "")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
@ -57,13 +56,13 @@ macro(add_example example_name)
|
||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
|
||||
AND EXISTS ${module_dir}
|
||||
AND IS_DIRECTORY ${module_dir})
|
||||
AND IS_DIRECTORY ${module_dir})
|
||||
add_custom_example(${example_bin} ${example_src} ${module_name})
|
||||
if ((NOT ${example_bin} STREQUAL "") AND (${module_name} STREQUAL "grove"))
|
||||
set(grove_module_path "${PROJECT_SOURCE_DIR}/src/${example_name}")
|
||||
if (EXISTS ${grove_module_path})
|
||||
include_directories(${grove_module_path})
|
||||
target_link_libraries (${example_bin} ${example_name})
|
||||
target_link_libraries (${example_bin} ${example_name})
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
@ -74,6 +73,10 @@ endmacro()
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
||||
|
||||
# Set the mraa include and link directories prior to adding examples
|
||||
include_directories (${MRAA_INCLUDE_DIRS})
|
||||
link_directories (${MRAA_LIBDIR})
|
||||
|
||||
# If your sample source file matches the name of the module it tests, add it here
|
||||
# Exceptions are as follows:
|
||||
# string after first '-' is ignored (e.g. nrf24l01-transmitter maps to nrf24l01)
|
||||
@ -88,8 +91,6 @@ add_example (grovebutton)
|
||||
add_example (groverotary)
|
||||
add_example (groveslide)
|
||||
add_example (buzzer-sound)
|
||||
add_example (my9221-ledbar)
|
||||
add_example (my9221-updown)
|
||||
add_example (nrf24l01-transmitter)
|
||||
add_example (nrf24l01-receiver)
|
||||
add_example (nrf24l01-broadcast)
|
||||
@ -200,7 +201,6 @@ add_example (h3lis331dl)
|
||||
add_example (ad8232)
|
||||
add_example (grovescam)
|
||||
add_example (m24lr64e)
|
||||
add_example (grovecircularled)
|
||||
add_example (rgbringcoder)
|
||||
add_example (hp20x)
|
||||
add_example (pn532)
|
||||
@ -223,10 +223,41 @@ add_example (mcp9808)
|
||||
add_example (groveultrasonic)
|
||||
add_example (sx1276-lora)
|
||||
add_example (sx1276-fsk)
|
||||
add_example (ili9341)
|
||||
if (OPENZWAVE_FOUND)
|
||||
include_directories(${OPENZWAVE_INCLUDE_DIRS})
|
||||
add_example (ozw)
|
||||
endif()
|
||||
add_example (nlgpio16)
|
||||
add_example (ads1x15)
|
||||
if (MODBUS_FOUND)
|
||||
include_directories(${MODBUS_INCLUDE_DIRS})
|
||||
add_example (t3311)
|
||||
add_example (hwxpxx)
|
||||
add_example (h803x)
|
||||
endif()
|
||||
add_example (hdxxvxta)
|
||||
add_example (rhusb)
|
||||
add_example (apds9930)
|
||||
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)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
@ -243,3 +274,12 @@ add_custom_example (eboled-example eboled.cxx lcd)
|
||||
add_custom_example (mpu60x0-example mpu60x0.cxx mpu9150)
|
||||
add_custom_example (ak8975-example ak8975.cxx mpu9150)
|
||||
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
|
||||
add_custom_example (groveledbar-example groveledbar.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
@ -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]
|
320
examples/c++/ads1x15.cxx
Normal file
@ -0,0 +1,320 @@
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* 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 "mraa.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include "ads1015.h"
|
||||
#include "ads1115.h"
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
int command;
|
||||
//Select the device you are testing here and adjust case 6 for the correct sample rates.
|
||||
//upm::ADS1015 *ads = new upm::ADS1015(1);
|
||||
upm::ADS1115 *ads = new upm::ADS1115(1, 0x49);
|
||||
float inputVoltage;
|
||||
int ans;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
cout << endl;
|
||||
cout << "1 - get Conversion \t" ;
|
||||
cout << "2 - get last conversion" << endl;
|
||||
cout << "3 - get Gain \t\t";
|
||||
cout << "4 - set Gain" << endl;;
|
||||
cout << "5 - get Data Rate \t";
|
||||
cout << "6 - set Data Rate" << endl;
|
||||
cout << "7 - Set Upper Threshold \t" ;
|
||||
cout << "8 - Set Lower Threshold \t";
|
||||
cout << "9 - Display Thresholds \t";
|
||||
cout << "10 - Set Default Thresholds \t";
|
||||
cout << "11 - Set conversion ready" << endl;
|
||||
cout << "12 - get Comp Que \t" ;
|
||||
cout << "13 - set Comp Que" << endl;
|
||||
cout << "14 - get Comp Pol \t";
|
||||
cout << "15 - set Comp Pol" << endl;
|
||||
cout << "16 - get Comp mode \t";
|
||||
cout << "17 - set Comp mode " << endl;
|
||||
cout << "18 - get Comp Latch\t";
|
||||
cout << "19 - set Comp Latch " << endl;
|
||||
cout << "20 - get Continuous \t";
|
||||
cout << "21 - set Continuous \t" << endl;
|
||||
cout << "-1 - exit" << endl;
|
||||
cout << "Enter a command: ";
|
||||
cin >> command;
|
||||
|
||||
|
||||
switch(command)
|
||||
{
|
||||
case 2:
|
||||
cout << ads->getLastSample() << endl;
|
||||
break;
|
||||
case 3:
|
||||
cout << std::hex << ads->getGain() << endl;
|
||||
break;
|
||||
case 5:
|
||||
cout << std::hex << ads->getSPS() << endl;
|
||||
break;
|
||||
case 4:
|
||||
int gain;
|
||||
ADS1015::ADSGAIN set_gain;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> gain 2/3 \t 2 -> gain1 \t 3 -> gain 2" << endl;
|
||||
cout << "4 -> gain 4 \t 5 -> gain 8 \t 6 -> gain 15" << endl;
|
||||
cin >> gain;
|
||||
switch(gain){
|
||||
case 1:
|
||||
set_gain = ADS1X15::GAIN_TWOTHIRDS;
|
||||
break;
|
||||
case 2:
|
||||
set_gain = ADS1X15::GAIN_ONE;
|
||||
break;
|
||||
case 3:
|
||||
set_gain = ADS1X15::GAIN_TWO;
|
||||
break;
|
||||
case 4:
|
||||
set_gain = ADS1X15::GAIN_FOUR;
|
||||
break;
|
||||
case 5:
|
||||
set_gain = ADS1X15::GAIN_EIGHT;
|
||||
break;
|
||||
case 6:
|
||||
set_gain = ADS1X15::GAIN_SIXTEEN;
|
||||
break;
|
||||
default:
|
||||
set_gain = ADS1X15::GAIN_ONE;
|
||||
}
|
||||
ads->setGain(set_gain);
|
||||
break;
|
||||
case 6:
|
||||
int rate;
|
||||
/*ADS1015::ADSDATARATE set_rate;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> SPS_120 \t 2 -> SPS_250 \t 3 -> SPS_490 \t 4 -> SPS_920" << endl;
|
||||
cout << "5 -> SPS_1600 \t 6 -> SPS_2400 \t 7 -> SPS_3300" << endl;
|
||||
cin >> rate;
|
||||
switch(rate){
|
||||
case 1:
|
||||
set_rate = ADS1015::SPS_128;
|
||||
break;
|
||||
case 2:
|
||||
set_rate = ADS1015::SPS_250;
|
||||
break;
|
||||
case 3:
|
||||
set_rate = ADS1015::SPS_490;
|
||||
break;
|
||||
case 4:
|
||||
set_rate = ADS1015::SPS_920;
|
||||
break;
|
||||
case 5:
|
||||
set_rate = ADS1015::SPS_1600;
|
||||
break;
|
||||
case 6:
|
||||
set_rate = ADS1015::SPS_2400;
|
||||
break;
|
||||
case 7:
|
||||
set_rate = ADS1015::SPS_3300;
|
||||
break;
|
||||
default:
|
||||
set_rate = ADS1015::SPS_1600;
|
||||
} */
|
||||
ADS1115::ADSDATARATE set_rate;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> SPS_8 \t 2 -> SPS_16 \t 3 -> SPS_32 \t 4 -> SPS_64" << endl;
|
||||
cout << "5 -> SPS_128 \t 6 -> SPS_250 \t 7 -> SPS_475 \t 8-> SPS_860" << endl;
|
||||
cin >> rate;
|
||||
switch(rate){
|
||||
case 1:
|
||||
set_rate = ADS1115::SPS_8;
|
||||
break;
|
||||
case 2:
|
||||
set_rate = ADS1115::SPS_16;
|
||||
break;
|
||||
case 3:
|
||||
set_rate = ADS1115::SPS_32;
|
||||
break;
|
||||
case 4:
|
||||
set_rate = ADS1115::SPS_64;
|
||||
break;
|
||||
case 5:
|
||||
set_rate = ADS1115::SPS_128;
|
||||
break;
|
||||
case 6:
|
||||
set_rate = ADS1115::SPS_250;
|
||||
break;
|
||||
case 7:
|
||||
set_rate = ADS1115::SPS_475;
|
||||
break;
|
||||
case 8:
|
||||
set_rate = ADS1115::SPS_860;
|
||||
break;
|
||||
default:
|
||||
set_rate = ADS1115::SPS_128;
|
||||
}
|
||||
|
||||
ads->setSPS(set_rate);
|
||||
break;
|
||||
case 1:
|
||||
int mode;
|
||||
ADS1X15::ADSMUXMODE set_mode;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> MUX_0_1 \t 2 -> MUX_0_3 \t 3 -> MUX_1_3 \t 4 -> MUX_2_3" << endl;
|
||||
cout << "5 -> SINGLE_0 \t 6 -> SINGLE_1 \t 7 -> SINGLE_2 \t 8 -> SINGLE_3" << endl;
|
||||
cin >> mode;
|
||||
switch(mode){
|
||||
case 1:
|
||||
set_mode = ADS1X15::DIFF_0_1;
|
||||
break;
|
||||
case 2:
|
||||
set_mode = ADS1X15::DIFF_0_3;
|
||||
break;
|
||||
case 3:
|
||||
set_mode = ADS1X15::DIFF_1_3;
|
||||
break;
|
||||
case 4:
|
||||
set_mode = ADS1X15::DIFF_2_3;
|
||||
break;
|
||||
case 5:
|
||||
set_mode = ADS1X15::SINGLE_0;
|
||||
break;
|
||||
case 6:
|
||||
set_mode = ADS1X15::SINGLE_1;
|
||||
break;
|
||||
case 7:
|
||||
set_mode = ADS1X15::SINGLE_2;
|
||||
break;
|
||||
case 8:
|
||||
set_mode = ADS1X15::SINGLE_3;
|
||||
break;
|
||||
default:
|
||||
set_mode = ADS1X15::DIFF_0_1;
|
||||
break;
|
||||
}
|
||||
cout << ads->getSample(set_mode) << endl;
|
||||
break;
|
||||
case 7:
|
||||
cout << " enter a float value: " ;
|
||||
cin >> inputVoltage;
|
||||
ads->setThresh(ADS1115::THRESH_HIGH, inputVoltage);
|
||||
break;
|
||||
case 8:
|
||||
cout << " enter a float value: " ;
|
||||
cin >> inputVoltage;
|
||||
ads->setThresh(ADS1115::THRESH_LOW, inputVoltage);
|
||||
break;
|
||||
case 9:
|
||||
cout << "Upper " << ads->getThresh(ADS1X15::THRESH_HIGH) << endl;
|
||||
cout << "Lower " << ads->getThresh(ADS1X15::THRESH_LOW) << endl;
|
||||
break;
|
||||
case 10:
|
||||
ads->setThresh(ADS1115::THRESH_DEFAULT);
|
||||
break;
|
||||
case 11:
|
||||
ads->setThresh(ADS1015::CONVERSION_RDY);
|
||||
break;
|
||||
case 12:
|
||||
cout << ads->getCompQue() << endl;
|
||||
break;
|
||||
case 13:
|
||||
int que;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> CQUE_1CONV \t 2 -> CQUE_2CONV \t 3 -> CQUE_3CONV \t 4 -> CQUE_NONE" << endl;
|
||||
cin >> que;
|
||||
switch(que){
|
||||
case 1:
|
||||
ads->setCompQue(ADS1X15::CQUE_1CONV);
|
||||
break;
|
||||
case 2:
|
||||
ads->setCompQue(ADS1X15::CQUE_2CONV);
|
||||
break;
|
||||
case 3:
|
||||
ads->setCompQue(ADS1X15::CQUE_4CONV);
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
ads->setCompQue(ADS1X15::CQUE_NONE);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
cout << ads->getCompPol() << endl;
|
||||
break;
|
||||
case 15:
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> active high \t 2 -> active low" << endl;
|
||||
cin >> ans;
|
||||
if(ans == 1) ads->setCompPol(true);
|
||||
else ads->setCompPol(false);
|
||||
break;
|
||||
case 16:
|
||||
cout << ads->getCompMode() << endl;
|
||||
break;
|
||||
case 17:
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> Window \t 2 -> Traditional (default)" << endl;
|
||||
cin >> ans;
|
||||
if(ans == 1) ads->setCompMode(true);
|
||||
else ads->setCompMode();
|
||||
break;
|
||||
case 18:
|
||||
cout << ads->getCompLatch() << cout;
|
||||
break;
|
||||
case 19:
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> Latching \t 2 -> Non-latching (default)" << endl;
|
||||
cin >> ans;
|
||||
if(ans == 1) ads->setCompLatch(true);
|
||||
else ads->setCompLatch();
|
||||
break;
|
||||
case 20:
|
||||
cout << ads->getContinuous() << cout;
|
||||
break;
|
||||
case 21:
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> Power Down (default) \t 2 -> Continuous" << endl;
|
||||
cin >> ans;
|
||||
if(ans == 1) ads->setContinuous(true);
|
||||
else ads->setContinuous();
|
||||
break;
|
||||
case -1:
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}while (command != -1 );
|
||||
|
||||
delete ads;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* 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
|
||||
@ -22,42 +22,30 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include "apa102.h"
|
||||
#include <iostream>
|
||||
#include "my9221.h"
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int running = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::MY9221 *bar = new upm::MY9221(8, 9);
|
||||
// Instantiate a strip of 30 LEDs on SPI bus 0
|
||||
upm::APA102* ledStrip = new upm::APA102(800, 0);
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
// Set all LEDs to Red
|
||||
ledStrip->setAllLeds(31, 255, 0, 0);
|
||||
|
||||
while (!running) {
|
||||
for (int idx = 1; idx < 11; idx++) {
|
||||
bar->setBarLevel (idx);
|
||||
usleep(1000);
|
||||
}
|
||||
}
|
||||
// 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]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete bar;
|
||||
|
||||
return 0;
|
||||
}
|
63
examples/c++/apds9930.cxx
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Author: Lay, Kuan Loon <kuan.loon.lay@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 <signal.h>
|
||||
#include "apds9930.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
// Instantiate a Digital Proximity and Ambient Light sensor on iio device 4
|
||||
upm::APDS9930* light_proximity = new upm::APDS9930(4);
|
||||
|
||||
while (shouldRun) {
|
||||
float lux = light_proximity->getAmbient();
|
||||
cout << "Luminance value is " << lux << endl;
|
||||
float proximity = light_proximity->getProximity();
|
||||
cout << "Proximity value is " << proximity << endl;
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete light_proximity;
|
||||
|
||||
return 0;
|
||||
}
|
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
@ -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
@ -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
@ -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
@ -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
@ -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;
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,9 @@ int main()
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a Grove Circular LED on gpio pins 5 and 4
|
||||
// Instantiate a Grove Circular LED on D9 for data, D8 for clock
|
||||
|
||||
upm::GroveCircularLED *circle = new upm::GroveCircularLED(5, 4);
|
||||
upm::GroveCircularLED *circle = new upm::GroveCircularLED(9, 8);
|
||||
|
||||
int level = 0;
|
||||
while (shouldRun)
|
||||
@ -54,6 +54,7 @@ int main()
|
||||
level = (level + 1) % 24;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "my9221.h"
|
||||
#include "groveledbar.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -42,28 +42,27 @@ int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MY9221, we use D2 for the data, and D3 for the
|
||||
// data clock. This was tested with a Grove LED bar.
|
||||
// Instantiate a GroveLEDBar, we use D8 for the data, and D9 for the
|
||||
// clock. This was tested with a Grove LED bar.
|
||||
upm::GroveLEDBar* bar = new upm::GroveLEDBar(8, 9);
|
||||
|
||||
upm::MY9221* bar = new upm::MY9221(2, 3);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// count up from green to red
|
||||
for (int i=1; i<=10; i++)
|
||||
for (int i=0; i<=10; i++)
|
||||
{
|
||||
bar->setBarLevel(i, true);
|
||||
usleep(50000);
|
||||
usleep(100000);
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
// count down from red to green
|
||||
for (int i=1; i<=10; i++)
|
||||
for (int i=0; i<=10; i++)
|
||||
{
|
||||
bar->setBarLevel(i, false);
|
||||
usleep(50000);
|
||||
usleep(100000);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
@ -71,7 +70,7 @@ int main ()
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
// turn off the LED's
|
||||
bar->setBarLevel(0, true);
|
||||
bar->setBarLevel(0);
|
||||
|
||||
delete bar;
|
||||
return 0;
|
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;
|
||||
}
|
79
examples/c++/hdxxvxta.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 "hdxxvxta.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 HDXXVXTA instance, using A1 for humidity and A0
|
||||
// for temperature
|
||||
upm::HDXXVXTA *sensor = new upm::HDXXVXTA(1, 0);
|
||||
|
||||
// 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 << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
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
@ -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]
|
102
examples/c++/hwxpxx.cxx
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 "hwxpxx.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 HWXPXX instance, using MODBUS slave address 3, and
|
||||
// default comm parameters (19200, 8, N, 2)
|
||||
upm::HWXPXX *sensor = new upm::HWXPXX(defaultDev, 3);
|
||||
|
||||
// output the Slave ID (manufacturer, model, serno)
|
||||
cout << "Slave ID: " << sensor->getSlaveID() << endl;
|
||||
|
||||
// stored temperature and humidity offsets
|
||||
cout << "Temperature Offset: " << sensor->getTemperatureOffset()
|
||||
<< endl;
|
||||
cout << "Humidity Offset: " << sensor->getHumidityOffset()
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
// 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 << "Slider: " << sensor->getSlider() << " %" << endl;
|
||||
|
||||
cout << "Override Switch Status: " << sensor->getOverrideSwitchStatus()
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
84
examples/c++/ili9341.cxx
Normal file
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Author: Shawn Hymel
|
||||
* Copyright (c) 2016 SparkFun Electronics
|
||||
*
|
||||
* 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 "ili9341.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
//! [Interesting]
|
||||
|
||||
// Pins (Edison)
|
||||
// CS_LCD GP44 (MRAA 31)
|
||||
// CS_SD GP43 (MRAA 38) unused
|
||||
// DC GP12 (MRAA 20)
|
||||
// RESEST GP13 (MRAA 14)
|
||||
upm::ILI9341 * lcd = new upm::ILI9341(31, 38, 20, 14);
|
||||
|
||||
// Fill the screen with a solid color
|
||||
lcd->fillScreen(lcd->color565(0, 40, 16));
|
||||
|
||||
// Draw some shapes
|
||||
lcd->drawFastVLine(10, 10, 100, ILI9341_RED);
|
||||
lcd->drawFastHLine(20, 10, 50, ILI9341_CYAN);
|
||||
lcd->drawLine(160, 30, 200, 60, ILI9341_GREEN);
|
||||
lcd->fillRect(20, 30, 75, 60, ILI9341_ORANGE);
|
||||
lcd->drawCircle(70, 50, 20, ILI9341_PURPLE);
|
||||
lcd->fillCircle(120, 50, 20, ILI9341_PURPLE);
|
||||
lcd->drawTriangle(50, 100, 10, 140, 90, 140, ILI9341_YELLOW);
|
||||
lcd->fillTriangle(150, 100, 110, 140, 190, 140, ILI9341_YELLOW);
|
||||
lcd->drawRoundRect(20, 150, 50, 30, 10, ILI9341_RED);
|
||||
lcd->drawRoundRect(130, 150, 50, 30, 10, ILI9341_RED);
|
||||
lcd->fillRoundRect(75, 150, 50, 30, 10, ILI9341_RED);
|
||||
|
||||
// Write some text
|
||||
lcd->setCursor(0, 200);
|
||||
lcd->setTextColor(ILI9341_LIGHTGREY);
|
||||
lcd->setTextWrap(true);
|
||||
lcd->setTextSize(1);
|
||||
lcd->print("Text 1\n");
|
||||
lcd->setTextSize(2);
|
||||
lcd->print("Text 2\n");
|
||||
lcd->setTextSize(3);
|
||||
lcd->print("Text 3\n");
|
||||
lcd->setTextSize(4);
|
||||
lcd->print("Text 4\n");
|
||||
|
||||
// Test screen rotation
|
||||
for(int r = 0; r < 4; r++) {
|
||||
lcd->setRotation(r);
|
||||
lcd->fillRect(0, 0, 5, 5, ILI9341_WHITE);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Invert colors, wait, then revert back
|
||||
lcd->invertDisplay(true);
|
||||
sleep(2);
|
||||
lcd->invertDisplay(false);
|
||||
|
||||
// Don't forget to free up that memory!
|
||||
delete lcd;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
75
examples/c++/kxcjk1013.cxx
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: Lay, Kuan Loon <kuan.loon.lay@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 <signal.h>
|
||||
#include "kxcjk1013.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
upm::KXCJK1013* accelerometer;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
void
|
||||
data_callback(char* data)
|
||||
{
|
||||
float x, y, z;
|
||||
accelerometer->extract3Axis(data, &x, &y, &z);
|
||||
printf("%.1f %.1f %.1f\n", x, y, z);
|
||||
// usleep(100);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
// Instantiate a KXCJK1013 Accelerometer Sensor on iio device 0
|
||||
accelerometer = new upm::KXCJK1013(0);
|
||||
accelerometer->setScale(0.019163);
|
||||
accelerometer->setSamplingFrequency(25.0);
|
||||
accelerometer->enable3AxisChannel();
|
||||
accelerometer->installISR(data_callback, NULL);
|
||||
accelerometer->enableBuffer(16);
|
||||
|
||||
while (shouldRun) {
|
||||
sleep(1);
|
||||
}
|
||||
accelerometer->disableBuffer();
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete accelerometer;
|
||||
|
||||
return 0;
|
||||
}
|
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
@ -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
@ -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
@ -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;
|
||||
}
|
52
examples/c++/nlgpio16.cxx
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.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 <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "nlgpio16.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Instantiate a NLGPIO16 Module on the default UART (/dev/ttyACM0)
|
||||
upm::NLGPIO16* sensor = new upm::NLGPIO16();
|
||||
|
||||
// get the Version
|
||||
cout << "Device Version: " << sensor->getVersion() << endl;
|
||||
// read the gpio at pin 3
|
||||
cout << "GPIO 3 Value: " << sensor->gpioRead(3) << endl;
|
||||
// read the analog voltage at pin 5
|
||||
cout << "Analog 5 Voltage: " << sensor->analogReadVolts(5) << endl;
|
||||
// set the gpio at pin 14 to HIGH
|
||||
sensor->gpioSet(14);
|
||||
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
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]
|
@ -27,6 +27,8 @@
|
||||
#include "pulsensor.h"
|
||||
#include <signal.h>
|
||||
|
||||
using namespace upm;
|
||||
|
||||
int doWork = 0;
|
||||
|
||||
void
|
||||
|
88
examples/c++/rhusb.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 "rhusb.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 RHUSB instance on defaultDev
|
||||
upm::RHUSB sensor(defaultDev);
|
||||
|
||||
// output the firmware ID
|
||||
cout << "Firmware ID: " << sensor.getFirmwareID() << endl;
|
||||
cout << endl;
|
||||
|
||||
// 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 << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
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
@ -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
@ -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
@ -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]
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -22,13 +23,14 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "stepmotor.h"
|
||||
#include <signal.h>
|
||||
#include "stepmotor.h"
|
||||
|
||||
int doWork = 0;
|
||||
using namespace std;
|
||||
|
||||
int doWork = 1;
|
||||
upm::StepMotor *sensor = NULL;
|
||||
|
||||
void
|
||||
@ -37,7 +39,7 @@ sig_handler(int signo)
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
doWork = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,26 +47,29 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::StepMotor(4, 6);
|
||||
sensor = new upm::StepMotor(2, 3);
|
||||
|
||||
while (!doWork) {
|
||||
sensor->setSpeed (500);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
while (doWork) {
|
||||
cout << "1 Revolution forward and back at 60 rpm" << endl;
|
||||
sensor->setSpeed(60);
|
||||
sensor->stepForward(200);
|
||||
usleep(1000000);
|
||||
sensor->stepBackward(200);
|
||||
usleep(1000000);
|
||||
|
||||
sensor->setSpeed (750);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
cout << "1 Revolution forward and back at 150 rpm" << endl;
|
||||
sensor->setSpeed(150);
|
||||
sensor->stepForward(200);
|
||||
usleep(1000000);
|
||||
sensor->stepBackward(200);
|
||||
usleep(1000000);
|
||||
|
||||
sensor->setSpeed (1000);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
cout << "1 Revolution forward and back at 300 rpm" << endl;
|
||||
sensor->setSpeed(300);
|
||||
sensor->stepForward(200);
|
||||
usleep (1000000);
|
||||
sensor->stepBackward(200);
|
||||
usleep (1000000);
|
||||
}
|
||||
|
||||
delete sensor;
|
||||
|
115
examples/c++/t3311.cxx
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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 "t3311.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 << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an T3311 instance, using MODBUS slave address 1, and
|
||||
// default comm parameters (9600, 8, N, 2)
|
||||
upm::T3311 *sensor = new upm::T3311(defaultDev, 1);
|
||||
|
||||
// output the serial number and firmware revision
|
||||
cout << "Serial Number: " << sensor->getSerialNumber() << endl;
|
||||
cout << "Firmware Revision: " << sensor->getFirmwareMajor()
|
||||
<< "." << sensor->getFirmwareMinor() << endl;
|
||||
cout << endl;
|
||||
|
||||
// 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;
|
||||
|
||||
// this value depends on the sensor configuration -- by default
|
||||
// it is the dew point temperature
|
||||
cout << "Computed Value: " << sensor->getComputedValue() << endl;
|
||||
|
||||
// with FW revisions > 2.44, extended computed data is available
|
||||
if (sensor->extendedDataAvailable())
|
||||
{
|
||||
cout << "Dew Point Temperature: " << sensor->getDewPointTemperature()
|
||||
<< " C / " << sensor->getDewPointTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << "Absolute Humidity: " << sensor->getAbsoluteHumidity()
|
||||
<< " g/m3" << endl;
|
||||
|
||||
cout << "Specific Humidity: " << sensor->getSpecificHumidity()
|
||||
<< " g/kg" << endl;
|
||||
|
||||
cout << "Mixing Ratio: " << sensor->getMixingRatio()
|
||||
<< " g/kg" << endl;
|
||||
|
||||
cout << "Specific Enthalpy: " << sensor->getSpecificEnthalpy()
|
||||
<< " kJ/kg" << endl;
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
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
@ -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
@ -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
@ -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;
|
||||
}
|
@ -40,4 +40,4 @@ public class A110XSample {
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_a110x.IsrCallback;
|
||||
|
||||
public class A110X_intrSample {
|
||||
|
||||
public static int counter=0;
|
||||
@ -38,7 +36,7 @@ public class A110X_intrSample {
|
||||
// is detected. This could be used to measure the rotations per
|
||||
// minute (RPM) of a rotor for example.
|
||||
|
||||
IsrCallback callback = new A110XISR();
|
||||
A110XISR callback = new A110XISR();
|
||||
hall.installISR(callback);
|
||||
|
||||
while(true){
|
||||
@ -49,7 +47,7 @@ public class A110X_intrSample {
|
||||
}
|
||||
}
|
||||
|
||||
class A110XISR extends IsrCallback {
|
||||
class A110XISR implements Runnable {
|
||||
public A110XISR(){
|
||||
super();
|
||||
}
|
||||
|
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
@ -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
@ -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]
|
||||
}
|
||||
}
|
123
examples/java/CMakeLists.txt
Normal file
@ -0,0 +1,123 @@
|
||||
find_package(Java REQUIRED)
|
||||
include(UseJava)
|
||||
|
||||
macro(add_example example_name jar_name)
|
||||
set(example_src "${example_name}.java")
|
||||
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_name}/upm_${jar_name}.jar")
|
||||
|
||||
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${example_jar})
|
||||
endmacro()
|
||||
|
||||
macro(add_example_with_path example_name jar_path)
|
||||
set(example_src "${example_name}.java")
|
||||
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_path}")
|
||||
|
||||
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${example_jar})
|
||||
endmacro()
|
||||
|
||||
add_example(A110X_intrSample a110x)
|
||||
add_example(A110XSample a110x)
|
||||
add_example(ADC121C021Sample adc121c021)
|
||||
add_example(Adxl345Sample adxl345)
|
||||
add_example(Apds9002 apds9002)
|
||||
add_example(BISS0001Sample biss0001)
|
||||
add_example(BMPX8XSample bmpx8x)
|
||||
add_example(BuzzerSample buzzer)
|
||||
add_example(Buzzer_soundSample buzzer)
|
||||
add_example(CJQ4435Sample cjq4435)
|
||||
add_example(DS1307Sample ds1307)
|
||||
add_example(ENC03RSample enc03r)
|
||||
add_example(ES08ASample servo)
|
||||
add_example(GroveButtonSample grove)
|
||||
add_example(GroveButton_intrSample grove)
|
||||
add_example(GroveCollision grovecollision)
|
||||
add_example(GroveEHRSample groveehr)
|
||||
add_example(GroveEmg groveemg)
|
||||
add_example(GroveGsr grovegsr)
|
||||
add_example(GroveLed_multiSample grove)
|
||||
add_example(GroveLEDSample grove)
|
||||
add_example(GroveLightSample grove)
|
||||
add_example(GroveLineFinderSample grovelinefinder)
|
||||
add_example(GroveMDSample grovemd)
|
||||
add_example(GroveMoistureSample grovemoisture)
|
||||
add_example(GroveMQ3 gas)
|
||||
add_example(GroveMQ9 gas)
|
||||
add_example(GroveO2Example groveo2)
|
||||
add_example(GroveQTouch at42qt1070)
|
||||
add_example(GroveRelaySample grove)
|
||||
add_example(GroveRotarySample grove)
|
||||
add_example(GROVESCAMSample grovescam)
|
||||
add_example(GroveSlideSample grove)
|
||||
add_example(GroveSpeakerSample grovespeaker)
|
||||
add_example(GroveTempSample grove)
|
||||
add_example(GroveVDivSample grovevdiv)
|
||||
add_example(GroveWaterSample grovewater)
|
||||
add_example(GroveWFSSample grovewfs)
|
||||
add_example(GUVAS12DSample guvas12d)
|
||||
add_example(H3LIS331DLSample h3lis331dl)
|
||||
add_example(HCSR04Sample hcsr04)
|
||||
add_example(HM11Sample hm11)
|
||||
add_example(Hmc5883lSample hmc5883l)
|
||||
add_example(HMTRPSample hmtrp)
|
||||
add_example(HP20xExample hp20x)
|
||||
add_example(HTU21DSample htu21d)
|
||||
add_example(Itg3200Sample itg3200)
|
||||
add_example(Joystick12Sample joystick12)
|
||||
add_example(LDT0028Sample ldt0028)
|
||||
add_example(LoLSample lol)
|
||||
add_example(LSM303Sample lsm303)
|
||||
add_example(M24LR64ESample m24lr64e)
|
||||
add_example(MAX44000Sample max44000)
|
||||
add_example(MHZ16Sample mhz16)
|
||||
add_example(MicrophoneSample mic)
|
||||
add_example(MMA7455Sample mma7455)
|
||||
add_example(MMA7660Sample mma7660)
|
||||
add_example(MPL3115A2Sample mpl3115a2)
|
||||
add_example(MPR121Sample mpr121)
|
||||
add_example(MPU9150Sample mpu9150)
|
||||
add_example(MQ2Sample gas)
|
||||
add_example(MQ303ASample mq303a)
|
||||
add_example(MQ5Sample gas)
|
||||
add_example(GroveLEDBar my9221)
|
||||
add_example(NRF24L01_receiverSample nrf24l01)
|
||||
add_example(NRF24L01_transmitterSample nrf24l01)
|
||||
add_example(NUNCHUCKSample nunchuck)
|
||||
add_example(OTP538USample otp538u)
|
||||
add_example(PPD42NSSample ppd42ns)
|
||||
add_example(PulsensorSample pulsensor)
|
||||
add_example(RFR359FSample rfr359f)
|
||||
add_example(RotaryEncoderSample rotaryencoder)
|
||||
add_example(RPR220_intrSample rpr220)
|
||||
add_example(RPR220Sample rpr220)
|
||||
add_example(ST7735Sample st7735)
|
||||
add_example(StepMotorSample stepmotor)
|
||||
add_example(TM1637Sample tm1637)
|
||||
add_example(TP401Sample gas)
|
||||
add_example(TSL2561Sample tsl2561)
|
||||
add_example(TTP223Sample ttp223)
|
||||
add_example(Ublox6Sample ublox6)
|
||||
add_example(ULN200XASample uln200xa)
|
||||
add_example(WaterLevelSensor waterlevel)
|
||||
add_example(WT5001Sample wt5001)
|
||||
add_example(YG1006Sample yg1006)
|
||||
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(Jhd1313m1Sample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(Lcm1602_i2cSample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(Lcm1602_parallelSample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(SSD1308_oledSample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(SSD1327_oledSample lcd/upm_i2clcd.jar)
|
||||
|
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
@ -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
@ -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]
|
||||
}
|
||||
|
||||
}
|
@ -22,9 +22,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_grove.IsrCallback;
|
||||
|
||||
//NOT TESTED!!!
|
||||
public class GroveButton_intrSample {
|
||||
|
||||
public static int counter = 0;
|
||||
@ -33,8 +30,8 @@ public class GroveButton_intrSample {
|
||||
// ! [Interesting]
|
||||
upm_grove.GroveButton b = new upm_grove.GroveButton(2);
|
||||
|
||||
IsrCallback callback = new ButtonISR();
|
||||
b.installISR(mraa.Edge.EDGE_RISING.swigValue(), callback);
|
||||
ButtonISR callback = new ButtonISR();
|
||||
b.installISR(2, callback);
|
||||
|
||||
while (true) {
|
||||
System.out.println("Counter: " + counter);
|
||||
@ -44,7 +41,7 @@ public class GroveButton_intrSample {
|
||||
}
|
||||
}
|
||||
|
||||
class ButtonISR extends IsrCallback {
|
||||
class ButtonISR implements Runnable {
|
||||
public ButtonISR() {
|
||||
super();
|
||||
}
|
||||
|
@ -27,13 +27,12 @@ import upm_grovecollision.*;
|
||||
public class GroveCollision {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
// Initializing the sensor on D2 on the Base Shield
|
||||
upm_grovecollision.GroveCollision collision = new upm_grovecollision.GroveCollision(2);
|
||||
boolean collisionState = false;
|
||||
|
||||
// ! [Interesting]
|
||||
while(shouldRun){
|
||||
while(true){
|
||||
if(collision.isColliding() && !collisionState){
|
||||
System.out.println("Collision!!");
|
||||
collisionState = true;
|
||||
@ -44,7 +43,6 @@ public class GroveCollision {
|
||||
}
|
||||
}
|
||||
// ! [Interesting]
|
||||
System.out.println("Exiting");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,20 +22,20 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MY9221_ledbarSample{
|
||||
public class GroveLEDBar {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
|
||||
upm_my9221.MY9221 bar = new upm_my9221.MY9221((short) 8, (short) 9);
|
||||
|
||||
while (true) {
|
||||
for (short idx = 1; idx < 11; idx++) {
|
||||
bar.setBarLevel(idx);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
}
|
||||
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
|
||||
upm_my9221.GroveLEDBar bar = new upm_my9221.GroveLEDBar((short) 8, (short) 9);
|
||||
|
||||
while (true) {
|
||||
for (short idx = 1; idx < 11; idx++) {
|
||||
bar.setBarLevel(idx);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
|
||||
}
|
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]
|
||||
}
|
||||
}
|
44
examples/java/Joystick12Sample.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||
*/
|
||||
|
||||
public class Joystick12Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate a joystick on analog pins A0 and A1
|
||||
upm_joystick12.Joystick12 joystick = new upm_joystick12.Joystick12(0,1);
|
||||
|
||||
// Print the X and Y input values every second
|
||||
while(true){
|
||||
float x = joystick.getXInput();
|
||||
float y = joystick.getYInput();
|
||||
|
||||
System.out.println("Driving X: " + x + " , and Y: " + y );
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
|
||||
}
|
@ -38,7 +38,7 @@ public class Lcm1602_parallelSample {
|
||||
// 10K trimmer potentiometer:
|
||||
// ends to +5V and ground
|
||||
// wiper to LCD VO pin (pin 3)
|
||||
upm_i2clcd.Lcm1602 lcd = new upm_i2clcd.Lcm1602(8, 13, 2, 3, 4, 5, 20, 2);
|
||||
upm_i2clcd.Lcm1602 lcd = new upm_i2clcd.Lcm1602((short) 8, (short) 13, (short) 2, (short) 3, (short) 4, (short) 5, (short) 20, (short) 2);
|
||||
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.write("Hello World");
|
||||
@ -49,4 +49,4 @@ public class Lcm1602_parallelSample {
|
||||
Thread.sleep(5000);
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,26 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MY9221Sample {
|
||||
//NOT TESTED!!!
|
||||
public class LoLSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
|
||||
upm_my9221.MY9221 bar = new upm_my9221.MY9221((short) 8, (short) 9);
|
||||
// ! [Interesting]
|
||||
upm_lol.LoL sensor = new upm_lol.LoL();
|
||||
|
||||
int x = 0, y = 0;
|
||||
while (true) {
|
||||
for (short idx = 1; idx < 11; idx++) {
|
||||
bar.setBarLevel(idx);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
// revert pixel
|
||||
sensor.setPixel(x, y, sensor.getPixel(x, y));
|
||||
|
||||
}
|
||||
if (++x == 13) {
|
||||
x = 0;
|
||||
y++;
|
||||
}
|
||||
if (y == 9)
|
||||
y = 0;
|
||||
Thread.sleep(10);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -22,8 +22,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_rpr220.IsrCallback;
|
||||
|
||||
public class RPR220_intrSample {
|
||||
|
||||
public static int counter = 0;
|
||||
@ -35,7 +33,7 @@ public class RPR220_intrSample {
|
||||
// Instantiate an RPR220 digital pin D2
|
||||
upm_rpr220.RPR220 sensor = new upm_rpr220.RPR220(2);
|
||||
|
||||
IsrCallback callback = new RPRISR();
|
||||
RPRISR callback = new RPRISR();
|
||||
sensor.installISR(callback);
|
||||
|
||||
while (true) {
|
||||
@ -46,7 +44,7 @@ public class RPR220_intrSample {
|
||||
}
|
||||
}
|
||||
|
||||
class RPRISR extends IsrCallback {
|
||||
class RPRISR implements Runnable {
|
||||
public RPRISR() {
|
||||
super();
|
||||
}
|
||||
|
@ -25,29 +25,32 @@
|
||||
//NOT TESTED!!!
|
||||
public class StepMotorSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
upm_stepmotor.StepMotor sensor = new upm_stepmotor.StepMotor(4, 6);
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
upm_stepmotor.StepMotor sensor = new upm_stepmotor.StepMotor(2, 3);
|
||||
|
||||
while (true) {
|
||||
sensor.setSpeed(500);
|
||||
sensor.stepForward(500);
|
||||
Thread.sleep(10);
|
||||
sensor.stepBackwards(500);
|
||||
Thread.sleep(10);
|
||||
while (true) {
|
||||
System.out.println("One complete rotation forward and back at 60 rpm.");
|
||||
sensor.setSpeed(60);
|
||||
sensor.stepForward(200);
|
||||
Thread.sleep(1000);
|
||||
sensor.stepBackward(200);
|
||||
Thread.sleep(1000);
|
||||
|
||||
sensor.setSpeed(750);
|
||||
sensor.stepForward(500);
|
||||
Thread.sleep(10);
|
||||
sensor.stepBackwards(500);
|
||||
Thread.sleep(10);
|
||||
System.out.println("One complete rotation forward and back at 150 rpm.");
|
||||
sensor.setSpeed(150);
|
||||
sensor.stepForward(200);
|
||||
Thread.sleep(1000);
|
||||
sensor.stepBackward(200);
|
||||
Thread.sleep(1000);
|
||||
|
||||
sensor.setSpeed(1000);
|
||||
sensor.stepForward(500);
|
||||
Thread.sleep(10);
|
||||
sensor.stepBackwards(500);
|
||||
Thread.sleep(10);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
System.out.println("One complete rotation forward and back at 300 rpm.");
|
||||
sensor.setSpeed(300);
|
||||
sensor.stepForward(200);
|
||||
Thread.sleep(1000);
|
||||
sensor.stepBackward(200);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
|
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
@ -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
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
46
examples/javascript/ads1x15.js
Normal file
@ -0,0 +1,46 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* 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.
|
||||
*/
|
||||
var mraa = require('mraa');
|
||||
var version = mraa.getVersion();
|
||||
|
||||
if (version >= 'v0.6.1') {
|
||||
console.log('mraa version (' + version + ') ok');
|
||||
}
|
||||
else {
|
||||
console.log('mraa version(' + version + ') is old - this code may not work');
|
||||
}
|
||||
|
||||
var ADS1X15 = require('jsupm_ads1x15');
|
||||
var ads1115 = new ADS1X15.ADS1115(1, 0x49);
|
||||
var ads1015 = new ADS1X15.ADS1015(1, 0x48);
|
||||
|
||||
setInterval(function(){
|
||||
console.log(ads1115.getSample());
|
||||
console.log(ads1015.getSample());
|
||||
console.log("*********************");
|
||||
}, 1000);
|
||||
|
||||
|
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
@ -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
@ -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
@ -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
@ -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);
|
||||
});
|
@ -25,9 +25,9 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Instantiate a Grove Circular LED on gpio pins 5 and 4
|
||||
var GCL = require("jsupm_grovecircularled");
|
||||
var circle = new GCL.GroveCircularLED(5, 4);
|
||||
// Instantiate a Grove Circular LED on gpio pins 9 and 8
|
||||
var GCL = require("jsupm_my9221");
|
||||
var circle = new GCL.GroveCircularLED(9, 8);
|
||||
var level = 0;
|
||||
|
||||
// Show a spinner.
|
||||
|
@ -26,9 +26,9 @@
|
||||
|
||||
var LEDBar = require("jsupm_my9221");
|
||||
|
||||
// Instantiate a MY9221, we use D2 for the data, and D3 for the
|
||||
// Instantiate a MY9221, we use D8 for the data, and D9 for the
|
||||
// data clock. This was tested with a Grove LED bar.
|
||||
var myLEDBar = new LEDBar.MY9221(2, 3);
|
||||
var myLEDBar = new LEDBar.GroveLEDBar(8, 9);
|
||||
|
||||
var directionBool = true;
|
||||
|