mirror of
https://github.com/eclipse/upm.git
synced 2025-07-06 20:01:12 +03:00
Compare commits
127 Commits
v1.2.0
...
iio_change
Author | SHA1 | Date | |
---|---|---|---|
93054c382b | |||
6ac2557b7d | |||
cc3721128e | |||
28380f2bfa | |||
303323fa3a | |||
0bf4a38f5e | |||
e441c343d8 | |||
60816d8f2a | |||
ef681a0ab5 | |||
f37236fa01 | |||
aa047d6b5c | |||
0345a8e9f1 | |||
5bdd7a4c03 | |||
3ca7889755 | |||
c5cdfc702c | |||
a99e32fc13 | |||
9e09f899cf | |||
ae77966204 | |||
b0a842229a | |||
0f3f0e02ae | |||
287d716401 | |||
db89d872b4 | |||
c46fb64cac | |||
1f97840fee | |||
7bee29ba62 | |||
24b6cbcc85 | |||
ab4eeea61e | |||
98811b0fb7 | |||
f92c0c120e | |||
01036f7dae | |||
5e7a8b41a3 | |||
f59f3131bb | |||
539fbe7c75 | |||
5a1f27a92d | |||
f4da94a06e | |||
e190bb9d60 | |||
bac9e3bbc0 | |||
1647d8bc08 | |||
6bfb07e46a | |||
c25fa47e2f | |||
7cd290901d | |||
aaf733f41b | |||
ac4a10e248 | |||
8a4e06d856 | |||
9482d6bb74 | |||
0cb93331ee | |||
f01c89b95a | |||
4344151405 | |||
74cb3504f3 | |||
ac031ba9a8 | |||
65726087bc | |||
dc03eec56f | |||
c1903b8c39 | |||
0cb7d3f9b4 | |||
874eacf12e | |||
3e6fb61a20 | |||
8e7ac713c4 | |||
54c1b0ce4b | |||
53456d9138 | |||
7ec1765766 | |||
bb122bfac4 | |||
0f8e578c62 | |||
dcee721cb3 | |||
b11ec1638e | |||
fb6ae47b6d | |||
be718d79af | |||
87ffc81b65 | |||
afd9dd07e4 | |||
ce9742b355 | |||
c402fbb5e8 | |||
b757ccc617 | |||
c5c57b523b | |||
bb4ce17d44 | |||
d4396c2ce3 | |||
780b5df024 | |||
60379fca37 | |||
b90c5a7710 | |||
28f964cb48 | |||
b68eb5f6a6 | |||
50bb4ae1be | |||
da18bac925 | |||
2b70bea44f | |||
c64d04d084 | |||
8186d093ec | |||
b2eb392a07 | |||
274fd9b608 | |||
27eec52e29 | |||
ee0aaa89eb | |||
886deabfbb | |||
e740349355 | |||
34f2799c53 | |||
a03d8eb52f | |||
07f3029f10 | |||
a56b83fa37 | |||
b4bc15201b | |||
c70f378f72 | |||
106b6c7062 | |||
6c3b161702 | |||
c484056cf0 | |||
2931a9c24d | |||
aeefc758ee | |||
21a1860ec2 | |||
c78da687d4 | |||
6c383dbd42 | |||
7688e5f230 | |||
1db6bd826a | |||
e7ca8cf18b | |||
cdb735c34e | |||
90e4b5d385 | |||
6a37edcdac | |||
563519ae4f | |||
7b812284c5 | |||
0082f54902 | |||
b32e4911ab | |||
fe9254c004 | |||
e3a8b2fc13 | |||
21ecbd90eb | |||
0bd68e4e2b | |||
b2aa2515b0 | |||
5cc4e2120a | |||
fe4e97f5dc | |||
6e4faefe15 | |||
460e9de94f | |||
1f5f466691 | |||
12c59a6aca | |||
19c58ebba2 | |||
d9fd1af272 |
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Dockerfile
|
||||||
|
docker-compose.yaml
|
||||||
|
build
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -11,3 +11,6 @@ build*/
|
|||||||
# Temp files
|
# Temp files
|
||||||
*.swp
|
*.swp
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
# Node modules
|
||||||
|
**/node_modules
|
||||||
|
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[submodule "doxy/doxygen2jsdoc"]
|
||||||
|
path = doxy/doxygen2jsdoc
|
||||||
|
url = https://github.com/intel-iot-devkit/doxygen2jsdoc
|
||||||
|
[submodule "doxy/doxyport"]
|
||||||
|
path = doxy/doxyport
|
||||||
|
url = https://github.com/intel-iot-devkit/doxyport
|
127
.travis.yml
127
.travis.yml
@ -1,48 +1,81 @@
|
|||||||
|
dist: trusty
|
||||||
|
sudo: required
|
||||||
|
|
||||||
language: cpp
|
language: cpp
|
||||||
env:
|
|
||||||
global:
|
services:
|
||||||
- MRAA_ROOT=/tmp/mraa
|
- docker
|
||||||
- MRAA_BUILD=$MRAA_ROOT/build
|
|
||||||
- UPM_ROOT=$TRAVIS_BUILD_DIR
|
before_install:
|
||||||
- UPM_BUILD=$UPM_ROOT/build
|
- sudo rm /usr/local/bin/docker-compose
|
||||||
- JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
- curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > docker-compose
|
||||||
matrix:
|
- chmod +x docker-compose
|
||||||
- NODE010=true
|
- sudo mv docker-compose /usr/local/bin
|
||||||
- NODE012=true
|
|
||||||
- NODE4=true
|
jobs:
|
||||||
- NODE5=true
|
fast_finish: true
|
||||||
compiler:
|
allow_failures:
|
||||||
- clang
|
- env: TARGET=ipk
|
||||||
- gcc
|
include:
|
||||||
install:
|
- &run-with-clang
|
||||||
- sudo add-apt-repository --yes ppa:rosmo/swig3.0.7
|
stage: Clang 3.8
|
||||||
- sudo apt-get update -qq
|
env: TARGET=python
|
||||||
- sudo apt-get install -y --force-yes -qq swig3.0 git
|
before_script: docker-compose pull ${TARGET}
|
||||||
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
script:
|
||||||
- sudo update-java-alternatives -s java-8-oracle
|
- export CC=clang-3.8 CXX=clang++-3.8
|
||||||
before_script:
|
- docker-compose run ${TARGET}
|
||||||
# Turn off JAVA SWIG for clang++, use 4.8 for all g++ builds
|
- <<: *run-with-clang
|
||||||
- if [ "$CC" == "gcc" ]; then export BUILDJAVA=ON; export CC=gcc-4.8; export CXX=g++-4.8; else export BUILDJAVA=OFF; fi
|
env: TARGET=node4
|
||||||
- if [ "${NODE012}" ]; then nvm install 0.12; fi
|
- <<: *run-with-clang
|
||||||
- if [ "${NODE4}" ]; then nvm install 4.1; fi
|
env: TARGET=node5
|
||||||
- if [ "${NODE5}" ]; then nvm install 5; fi
|
- <<: *run-with-clang
|
||||||
# Handle 0.10 NODE_ROOT_DIR differently than other versions
|
env: TARGET=node6
|
||||||
- if [ -z ${NODE010} ]; then export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; else export NODE_ROOT_DIR=/home/travis/.nvm/v0.10.36; fi
|
- <<: *run-with-clang
|
||||||
script:
|
env: TARGET=java
|
||||||
# Build/install MRAA
|
- &run-with-gcc-5
|
||||||
- echo "CC=$CC BUILDJAVA=$BUILDJAVA NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
|
stage: Gcc 5
|
||||||
- git clone https://github.com/intel-iot-devkit/mraa.git $MRAA_ROOT
|
env: TARGET=python
|
||||||
- mkdir -p $MRAA_BUILD && cd $_ && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=ON -DFIRMATA=ON -DENABLEEXAMPLES=OFF $MRAA_ROOT
|
before_script: docker-compose pull ${TARGET}
|
||||||
- sudo make install
|
script:
|
||||||
- sudo ldconfig
|
- export CC=gcc-5 CXX=g++-5
|
||||||
# Build/install UPM
|
- docker-compose run ${TARGET}
|
||||||
- cd $UPM_ROOT && mkdir $UPM_BUILD && cd $_ && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDTESTS=ON -DBUILDFTI=ON .. && sudo make install && sudo ldconfig && ctest --output-on-failure -E examplenames_js
|
- <<: *run-with-gcc-5
|
||||||
addons:
|
env: TARGET=node4
|
||||||
apt:
|
- <<: *run-with-gcc-5
|
||||||
sources:
|
env: TARGET=node5
|
||||||
- ubuntu-toolchain-r-test
|
- <<: *run-with-gcc-5
|
||||||
- george-edison55-precise-backports
|
env: TARGET=node6
|
||||||
packages:
|
- <<: *run-with-gcc-5
|
||||||
- cmake
|
env: TARGET=java
|
||||||
- cmake-data
|
- &run-with-gcc-6
|
||||||
- g++-4.8
|
stage: Gcc 6
|
||||||
|
env: TARGET=python
|
||||||
|
before_script: docker-compose pull ${TARGET}
|
||||||
|
script:
|
||||||
|
- export CC=gcc-6 CXX=g++-6
|
||||||
|
- docker-compose run ${TARGET}
|
||||||
|
- <<: *run-with-gcc-6
|
||||||
|
env: TARGET=node4
|
||||||
|
- <<: *run-with-gcc-6
|
||||||
|
env: TARGET=node5
|
||||||
|
- <<: *run-with-gcc-6
|
||||||
|
env: TARGET=node6
|
||||||
|
- <<: *run-with-gcc-6
|
||||||
|
env: TARGET=java
|
||||||
|
- &run-additional-jobs
|
||||||
|
stage: Additional Jobs
|
||||||
|
env: TARGET=doc
|
||||||
|
before_script: docker-compose pull ${TARGET}
|
||||||
|
script:
|
||||||
|
- export CC=clang-3.8 CXX=clang++-3.8
|
||||||
|
- docker-compose run ${TARGET}
|
||||||
|
- <<: *run-additional-jobs
|
||||||
|
env: TARGET=android
|
||||||
|
- <<: *run-additional-jobs
|
||||||
|
env: TARGET=sonar-scan
|
||||||
|
- <<: *run-additional-jobs
|
||||||
|
env: TARGET=ipk
|
||||||
|
- <<: *run-additional-jobs
|
||||||
|
env: TARGET=rpm
|
||||||
|
- <<: *run-additional-jobs
|
||||||
|
env: TARGET=npm
|
||||||
|
@ -95,7 +95,7 @@ set (C_CXX_WARNING_FLAGS -Wall -Wno-misleading-indentation -Wno-strict-aliasing)
|
|||||||
|
|
||||||
# Warnings as errors?
|
# Warnings as errors?
|
||||||
if (WERROR)
|
if (WERROR)
|
||||||
set (C_CXX_WARNING_FLAGS "-Werror ${C_CXX_WARNING_FLAGS}")
|
list (APPEND C_CXX_WARNING_FLAGS -Werror)
|
||||||
message (STATUS "Warnings as errors enabled (-Werror), disable with -DWERROR=off")
|
message (STATUS "Warnings as errors enabled (-Werror), disable with -DWERROR=off")
|
||||||
endif (WERROR)
|
endif (WERROR)
|
||||||
|
|
||||||
@ -113,15 +113,26 @@ upm_add_compile_flags(CXX ${C_CXX_WARNING_FLAGS}
|
|||||||
-Woverloaded-virtual
|
-Woverloaded-virtual
|
||||||
-Wreorder)
|
-Wreorder)
|
||||||
|
|
||||||
|
# Allow exception error handling for Android C++
|
||||||
|
if (ANDROID)
|
||||||
|
upm_add_compile_flags(CXX -fexceptions)
|
||||||
|
endif (ANDROID)
|
||||||
|
|
||||||
find_package (Threads REQUIRED)
|
find_package (Threads REQUIRED)
|
||||||
find_package (PkgConfig REQUIRED)
|
find_package (PkgConfig REQUIRED)
|
||||||
|
|
||||||
# Force a libmraa search and minimum required version every time a config is generated
|
# Force a libmraa search and minimum required version every time a config is generated
|
||||||
unset(MRAA_FOUND CACHE)
|
unset(MRAA_FOUND CACHE)
|
||||||
set(MRAA_MINIMUM 1.6.1)
|
set(MRAA_MINIMUM 1.8.0)
|
||||||
pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM})
|
pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM})
|
||||||
# Also, get full path to the mraa library
|
# Also, get full path to the mraa library
|
||||||
find_library(MRAA_LIBRARY NAMES mraa PATHS ${MRAA_LIBDIR} NO_DEFAULT_PATH)
|
find_library(MRAA_LIBRARY NAMES mraa HINTS ${MRAA_LIBDIR})
|
||||||
|
|
||||||
|
# Test MRAA for various compile options
|
||||||
|
include (CheckLibraryExists)
|
||||||
|
check_library_exists (${MRAA_LIBRARIES} mraa_iio_init "${MRAA_LIBDIR}" MRAA_IIO_FOUND)
|
||||||
|
check_library_exists (${MRAA_LIBRARIES} mraa_firmata_init "${MRAA_LIBDIR}" MRAA_FIRMATA_FOUND)
|
||||||
|
check_library_exists (${MRAA_LIBRARIES} mraa_uart_ow_init "${MRAA_LIBDIR}" MRAA_OW_FOUND)
|
||||||
|
|
||||||
# Check for BACNET
|
# Check for BACNET
|
||||||
pkg_check_modules (BACNET libbacnet)
|
pkg_check_modules (BACNET libbacnet)
|
||||||
@ -138,15 +149,23 @@ find_package (JPEG)
|
|||||||
# Find nodejs
|
# Find nodejs
|
||||||
if (BUILDSWIGNODE)
|
if (BUILDSWIGNODE)
|
||||||
find_package (Node REQUIRED)
|
find_package (Node REQUIRED)
|
||||||
|
if (BUILDTESTS)
|
||||||
|
find_package (Npm REQUIRED)
|
||||||
|
if(NPM_EXECUTABLE)
|
||||||
|
message(STATUS "NPM Executable found at: ${NPM_EXECUTABLE}")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Please install NPM first, you can't run tests without it")
|
||||||
|
endif()
|
||||||
|
endif (BUILDTESTS)
|
||||||
endif (BUILDSWIGNODE)
|
endif (BUILDSWIGNODE)
|
||||||
|
|
||||||
# Find JAVA/JNI
|
# Find JAVA/JNI
|
||||||
if (BUILDSWIGJAVA)
|
if (BUILDSWIGJAVA)
|
||||||
find_package (Java REQUIRED)
|
find_package (Java REQUIRED)
|
||||||
find_package (JNI REQUIRED)
|
find_package (JNI REQUIRED)
|
||||||
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
|
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=${MRAA_MINIMUM})
|
||||||
# Also, get full path to the mraajava library
|
# Also, get full path to the mraajava library
|
||||||
find_library(MRAAJAVA_LIBRARY NAMES mraajava PATHS ${MRAA_LIBDIR} NO_DEFAULT_PATH)
|
find_library(MRAAJAVA_LIBRARY NAMES mraajava HINTS ${MRAA_LIBDIR})
|
||||||
endif (BUILDSWIGJAVA)
|
endif (BUILDSWIGJAVA)
|
||||||
|
|
||||||
# Find swig if any wrapper is enabled
|
# Find swig if any wrapper is enabled
|
||||||
@ -197,7 +216,7 @@ include (GetGitRevisionDescription)
|
|||||||
git_describe (VERSION "--tags")
|
git_describe (VERSION "--tags")
|
||||||
# If git_describe fails, use a dirty version
|
# If git_describe fails, use a dirty version
|
||||||
if (${VERSION} MATCHES -NOTFOUND)
|
if (${VERSION} MATCHES -NOTFOUND)
|
||||||
set (VERSION "v1.2.0")
|
set (VERSION "v1.3.0")
|
||||||
message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
|
message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
|
||||||
"${VERSION}). Check that git is installed and this is a valid git repo.")
|
"${VERSION}). Check that git is installed and this is a valid git repo.")
|
||||||
endif ()
|
endif ()
|
||||||
@ -225,11 +244,6 @@ include (TargetArch)
|
|||||||
target_architecture (DETECTED_ARCH)
|
target_architecture (DETECTED_ARCH)
|
||||||
message (STATUS "Target arch is ${DETECTED_ARCH}")
|
message (STATUS "Target arch is ${DETECTED_ARCH}")
|
||||||
|
|
||||||
#-march=native for ARM when not defined/forced
|
|
||||||
if (DETECTED_ARCH MATCHES "arm.*" AND NOT CMAKE_CXX_FLAGS MATCHES "-march")
|
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# enable c++11 standards support unconditionally
|
# enable c++11 standards support unconditionally
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
if (CMAKE_VERSION VERSION_LESS "3.1")
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
@ -312,7 +326,7 @@ if (BUILDDOC)
|
|||||||
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if Sphinx is installed and add target to generate API documentationa
|
# Check if Sphinx is installed and add target to generate API documentation
|
||||||
# Currently, the per-module documentation for python is generated from the
|
# Currently, the per-module documentation for python is generated from the
|
||||||
# python2 modules.
|
# python2 modules.
|
||||||
if(BUILDSWIGPYTHON)
|
if(BUILDSWIGPYTHON)
|
||||||
@ -337,14 +351,10 @@ if (BUILDDOC)
|
|||||||
# Check if Yuidoc is installed and add target for API documentation
|
# Check if Yuidoc is installed and add target for API documentation
|
||||||
if(BUILDSWIGNODE)
|
if(BUILDSWIGNODE)
|
||||||
find_package(Yuidoc REQUIRED)
|
find_package(Yuidoc REQUIRED)
|
||||||
file(GLOB_RECURSE JSDOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/doxy/node doxy/node/*)
|
|
||||||
foreach(JSDOC_FILE ${JSDOC_FILES})
|
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy/node/${JSDOC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${JSDOC_FILE} COPYONLY)
|
|
||||||
endforeach()
|
|
||||||
add_custom_target(jsdoc ALL
|
add_custom_target(jsdoc ALL
|
||||||
COMMAND ${NODEJS_EXECUTABLE} docgen -m upm -i xml -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/docgen.js -m upm -i xml -o jsdoc -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
||||||
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers generators/yuidoc/helper.js --themedir generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
|
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers ${CMAKE_SOURCE_DIR}/doxy/node/generators/yuidoc/helper.js --themedir ${CMAKE_SOURCE_DIR}/doxy/node/generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
|
||||||
COMMAND ${NODEJS_EXECUTABLE} tolower -i html/node
|
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/tolower.js -i html/node
|
||||||
DEPENDS doc
|
DEPENDS doc
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
||||||
@ -415,9 +425,10 @@ if (RPM)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# UPM common headers
|
# UPM common headers
|
||||||
set (UPM_COMMON_HEADER_DIRS
|
set (UPM_COMMON_HEADER_DIRS ${CMAKE_HOME_DIRECTORY}/include)
|
||||||
${CMAKE_HOME_DIRECTORY}/include
|
|
||||||
${CMAKE_HOME_DIRECTORY}/include/fti)
|
# Generate a build-only C++ header to add functionality to SWIG'ed modules
|
||||||
|
configure_file (${PROJECT_SOURCE_DIR}/cmake/modules/version.hpp.in ${PROJECT_BINARY_DIR}/src/version.hpp @ONLY)
|
||||||
|
|
||||||
# UPM source
|
# UPM source
|
||||||
add_subdirectory (src)
|
add_subdirectory (src)
|
||||||
|
@ -23,13 +23,16 @@ if (UV_ROOT_DIR)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Now look for node. Flag an error if not found
|
# Now look for node. Flag an error if not found
|
||||||
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
|
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h" "src/node.h"
|
||||||
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
||||||
if (NODE_ROOT_DIR)
|
if (NODE_ROOT_DIR)
|
||||||
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/src)
|
||||||
add_include_dir(${NODE_ROOT_DIR}/include/node)
|
add_include_dir(${NODE_ROOT_DIR}/include/node)
|
||||||
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
|
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/deps/v8/include)
|
||||||
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
|
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/deps/uv/include)
|
||||||
else()
|
else()
|
||||||
unset(NODEJS_INCLUDE_DIRS)
|
unset(NODEJS_INCLUDE_DIRS)
|
||||||
message(ERROR " - node.h not found")
|
message(ERROR " - node.h not found")
|
||||||
|
13
cmake/modules/FindNpm.cmake
Normal file
13
cmake/modules/FindNpm.cmake
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Finding and pointing a variable to the npm executable if found
|
||||||
|
# Only works on Linux systems as of now
|
||||||
|
|
||||||
|
find_program(NPM_EXECUTABLE NAMES npm
|
||||||
|
HINTS
|
||||||
|
/usr
|
||||||
|
)
|
||||||
|
|
||||||
|
if(NPM_EXECUTABLE)
|
||||||
|
message(STATUS "NPM Executable found at ${NPM_EXECUTABLE}")
|
||||||
|
else()
|
||||||
|
message(ERROR "Unable to find NPM installation, please install NPM")
|
||||||
|
endif()
|
@ -1,4 +0,0 @@
|
|||||||
#include "version.h"
|
|
||||||
|
|
||||||
const char* gVERSION = "@VERSION@";
|
|
||||||
const char* gVERSION_SHORT = "@VERSION_SHORT@";
|
|
6
cmake/modules/version.hpp.in
Normal file
6
cmake/modules/version.hpp.in
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <string>
|
||||||
|
|
||||||
|
inline std::string getVersion()
|
||||||
|
{
|
||||||
|
return "@upm_VERSION_STRING@";
|
||||||
|
}
|
112
docker-compose.yaml
Normal file
112
docker-compose.yaml
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
version: '2.1'
|
||||||
|
|
||||||
|
services:
|
||||||
|
|
||||||
|
base:
|
||||||
|
image: dnoliver/upm-base
|
||||||
|
environment:
|
||||||
|
- http_proxy
|
||||||
|
- https_proxy
|
||||||
|
- no_proxy
|
||||||
|
- BUILDDOC=${BUILDDOC:-OFF}
|
||||||
|
- BUILDCPP=${BUILDCPP:-ON}
|
||||||
|
- BUILDFTI=${BUILDFTI:-ON}
|
||||||
|
- BUILDSWIGPYTHON=${BUILDSWIGPYTHON:-OFF}
|
||||||
|
- BUILDSWIGJAVA=${BUILDSWIGJAVA:-OFF}
|
||||||
|
- BUILDSWIGNODE=${BUILDSWIGNODE:-OFF}
|
||||||
|
- BUILDEXAMPLES=${BUILDEXAMPLES:-ON}
|
||||||
|
- IPK=${IPK:-OFF}
|
||||||
|
- RPM=${RPM:-OFF}
|
||||||
|
- NPM=${NPM:-OFF}
|
||||||
|
- BUILDTESTS=${BUILDTESTS:-ON}
|
||||||
|
- CC=${CC:-clang-3.8}
|
||||||
|
- CXX=${CXX:-clang++-3.8}
|
||||||
|
- NODE_VERSION=${NODE_VERSION:-v4.4.7}
|
||||||
|
- WERROR=${WERROR:-ON}
|
||||||
|
volumes:
|
||||||
|
- .:${UPM_SRC_DIR:-/usr/src/app}
|
||||||
|
|
||||||
|
doc:
|
||||||
|
extends: base
|
||||||
|
image: dnoliver/upm-all
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGPYTHON=ON
|
||||||
|
- BUILDSWIGJAVA=ON
|
||||||
|
- BUILDSWIGNODE=ON
|
||||||
|
- BUILDDOC=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && ./scripts/build-doc.sh"
|
||||||
|
|
||||||
|
ipk:
|
||||||
|
extends: base
|
||||||
|
environment:
|
||||||
|
- IPK=ON
|
||||||
|
- BUILDDOC=OFF
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
|
||||||
|
|
||||||
|
rpm:
|
||||||
|
extends: doc
|
||||||
|
environment:
|
||||||
|
- RPM=ON
|
||||||
|
- BUILDDOC=OFF
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
|
||||||
|
|
||||||
|
npm:
|
||||||
|
extends: doc
|
||||||
|
environment:
|
||||||
|
- NPM=ON
|
||||||
|
- BUILDDOC=OFF
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 npmpkg"
|
||||||
|
|
||||||
|
sonar-scan:
|
||||||
|
extends: base
|
||||||
|
image: dnoliver/upm-all
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGPYTHON=ON
|
||||||
|
- BUILDSWIGNODE=ON
|
||||||
|
- BUILDSWIGJAVA=ON
|
||||||
|
- BUILDSWIGEXAMPLES=ON
|
||||||
|
- SONAR_TOKEN
|
||||||
|
- SONAR_ORG
|
||||||
|
- SONAR_PROJ_KEY
|
||||||
|
- TRAVIS_BRANCH
|
||||||
|
- TRAVIS_PULL_REQUEST
|
||||||
|
- TRAVIS_REPO_SLUG
|
||||||
|
- TRAVIS_PULL_REQUEST_SLUG
|
||||||
|
- GITHUB_TOKEN
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && ../scripts/sonar-scan.sh"
|
||||||
|
|
||||||
|
python:
|
||||||
|
extends: base
|
||||||
|
image: dnoliver/upm-python
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGPYTHON=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
|
||||||
|
|
||||||
|
java:
|
||||||
|
extends: base
|
||||||
|
image: dnoliver/upm-java
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGJAVA=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
|
||||||
|
|
||||||
|
android:
|
||||||
|
extends: java
|
||||||
|
image: dnoliver/upm-android
|
||||||
|
environment:
|
||||||
|
- BUILDTESTS=OFF
|
||||||
|
command: bash -c "./scripts/build-android.sh"
|
||||||
|
|
||||||
|
node4:
|
||||||
|
extends: base
|
||||||
|
image: dnoliver/upm-node4
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGNODE=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure -E examplenames_js"
|
||||||
|
|
||||||
|
node5:
|
||||||
|
extends: node4
|
||||||
|
image: dnoliver/upm-node5
|
||||||
|
|
||||||
|
node6:
|
||||||
|
extends: node4
|
||||||
|
image: dnoliver/upm-node6
|
@ -4,11 +4,23 @@ API Changes {#apichanges}
|
|||||||
Here's a list of other API changes made to the library that break source/binary
|
Here's a list of other API changes made to the library that break source/binary
|
||||||
compatibility between releases:
|
compatibility between releases:
|
||||||
|
|
||||||
|
# v1.3.0
|
||||||
|
|
||||||
|
* **The lsm303 driver has been renamed** There are a variety of
|
||||||
|
LSM303 devices out there with various incompatibilities and differing
|
||||||
|
capabilities. The current lsm303 driver in UPM only supports the
|
||||||
|
LSM303DLH variant, so it has been renamed to lsm303dlh to avoid
|
||||||
|
confusion and to make it clear which variant is actually supported.
|
||||||
|
|
||||||
|
All examples and source files have been renamed, including header
|
||||||
|
files. In addition, the class name, LSM303, has been renamed to
|
||||||
|
LSM303DLH. No other functionality or behavior has been changed.
|
||||||
|
|
||||||
# v1.2.0
|
# v1.2.0
|
||||||
|
|
||||||
* **Note for all drivers ported to C** As a general note concerning
|
* **Note for all drivers ported to C** As a general note concerning
|
||||||
all of the drivers that have been ported to C: **external constants
|
all of the drivers that have been ported to C: **external constants
|
||||||
have likely been renamed**. Previously in C++, most these constants
|
have likely been renamed**. Previously in C++, most of these constants
|
||||||
were defined as enums in the *upm::classname* namespace.
|
were defined as enums in the *upm::classname* namespace.
|
||||||
|
|
||||||
For drivers written in C, all of these constants are no longer in
|
For drivers written in C, all of these constants are no longer in
|
||||||
|
102
docs/building.md
102
docs/building.md
@ -64,10 +64,6 @@ Building with an older version of swig (swig 2.0+) requires the disabling of jav
|
|||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
-DBUILDSWIGNODE=OFF
|
-DBUILDSWIGNODE=OFF
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
Generating python3 modules instead of python2.7
|
|
||||||
~~~~~~~~~~~~~
|
|
||||||
-DBUILDPYTHON3=ON
|
|
||||||
~~~~~~~~~~~~~
|
|
||||||
Disabling python module building
|
Disabling python module building
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
-DBUILDSWIGPYTHON=OFF
|
-DBUILDSWIGPYTHON=OFF
|
||||||
@ -130,3 +126,101 @@ autotools on linux.
|
|||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
pkg-config --cflags --libs upm-i2clcd
|
pkg-config --cflags --libs upm-i2clcd
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
## Building with Docker
|
||||||
|
|
||||||
|
You can use `docker` and `docker-compose` to generate a complete build environment
|
||||||
|
for upm without having to install any other tool.
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
* [docker](https://www.docker.com/get-docker) >= 1.12.6
|
||||||
|
* [docker-compose](https://docs.docker.com/compose/install/) >= 1.9.0
|
||||||
|
|
||||||
|
**NOTE:** docker-compose is an optional requirement. It actually make running complex
|
||||||
|
docker build and run command easier. But you can just use docker to build and run.
|
||||||
|
|
||||||
|
### Using Docker Images to build Upm
|
||||||
|
|
||||||
|
**tl;dr:** Just use this commands to build upm:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Build upm documentation
|
||||||
|
$ docker-compose run doc
|
||||||
|
# Build upm python2 and python3 packages and run python tests
|
||||||
|
$ docker-compose run python
|
||||||
|
# Build upm java package and run java tests
|
||||||
|
$ docker-compose run java
|
||||||
|
# Build upm node4 package and run node tests
|
||||||
|
$ docker-compose run node4
|
||||||
|
# Build upm node5 package and run node tests
|
||||||
|
$ docker-compose run node5
|
||||||
|
# Build upm node6 package and run node tests
|
||||||
|
$ docker-compose run node6
|
||||||
|
# Build upm for android things package
|
||||||
|
$ docker-compose run android
|
||||||
|
```
|
||||||
|
|
||||||
|
**docker-compose** will take a look at the `docker-compose.yaml` file in the repository
|
||||||
|
root directory, and run an specific command to build upm for the requested target.
|
||||||
|
Once the build is completed, you will have a `build/` folder in the repository root with all
|
||||||
|
the compiled code. This `build/` folder is created by using a docker volume. The `build\`
|
||||||
|
folder contents is reused each time you execute `docker-compose run [TARGET]`.
|
||||||
|
To know more about volumes in Docker, visit the [Docker Volume Documentation](https://docs.docker.com/engine/tutorials/dockervolumes/).
|
||||||
|
|
||||||
|
You can also start an interactive session inside the docker container if you need to run some
|
||||||
|
custom build commands:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Start an interactive bash shell inside the container
|
||||||
|
$ docker-compose run python bash
|
||||||
|
# From now, all the commands are executed inside the container
|
||||||
|
$ cd build && cmake -DBUILDSWIGPYTHON=ON .. && make clean all
|
||||||
|
```
|
||||||
|
|
||||||
|
If you don't want to use docker-compose, you can also use `docker run` to build upm.
|
||||||
|
For example, to build upm for python, you can do:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# From the repository root folder
|
||||||
|
$ docker run \
|
||||||
|
--volume=$(pwd):/usr/src/app \
|
||||||
|
--env BUILDSWIGPYTHON=ON \
|
||||||
|
--env BUILDSWIGJAVA=OFF \
|
||||||
|
--env BUILDSWIGNODE=OFF \
|
||||||
|
dnoliver/upm-python \
|
||||||
|
bash -c "./scripts/run-cmake.sh && make -Cbuild"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Proxy considerations
|
||||||
|
|
||||||
|
If, for some reason, you are behind a proxy, find below a list of common problems related
|
||||||
|
to proxy settings:
|
||||||
|
|
||||||
|
**docker cannot pull images from docker.io**
|
||||||
|
|
||||||
|
Visit [this link](https://docs.docker.com/engine/admin/systemd/#httphttps-proxy)
|
||||||
|
to configure docker daemon behind a proxy.
|
||||||
|
|
||||||
|
**docker run fails to access the internet**
|
||||||
|
|
||||||
|
docker-compose will automatically take `http_proxy`, `https_proxy`, and `no_proxy`
|
||||||
|
environment variables and use it as build arguments. Be sure to properly configure
|
||||||
|
this variables before building.
|
||||||
|
|
||||||
|
docker, unlinke docker-compose, do not take the proxy settings from the environment
|
||||||
|
automatically. You need to send them as environment arguments:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# From the repository root folder
|
||||||
|
$ docker run \
|
||||||
|
--volume=$(pwd):/usr/src/app \
|
||||||
|
--env BUILDSWIG=ON \
|
||||||
|
--env BUILDSWIGPYTHON=ON \
|
||||||
|
--env BUILDSWIGJAVA=OFF \
|
||||||
|
--env BUILDSWIGNODE=OFF \
|
||||||
|
--env http_proxy=$http_proxy \
|
||||||
|
--env https_proxy=$https_proxy \
|
||||||
|
--env no_proxy=$no_proxy \
|
||||||
|
dnoliver/upm-python \
|
||||||
|
bash -c "./scripts/run-cmake.sh && make -Cbuild"
|
||||||
|
```
|
||||||
|
@ -4,6 +4,17 @@ Changelog {#changelog}
|
|||||||
Here's a list summarizing some of the key undergoing changes to our library
|
Here's a list summarizing some of the key undergoing changes to our library
|
||||||
from earlier versions:
|
from earlier versions:
|
||||||
|
|
||||||
|
### v1.3.0
|
||||||
|
|
||||||
|
* Finalized all required build system and JAVA binding changes to release the
|
||||||
|
UPM libraries for Android Things targets
|
||||||
|
* Enhanced the modules for lsm303 and tmp006 to support newer variants of the
|
||||||
|
chips
|
||||||
|
* Fixed Node.js detection on Ubuntu when installed with apt using official
|
||||||
|
packages
|
||||||
|
* Minor documentation changes
|
||||||
|
* New sensors: lsm303agr, lsm303d, veml6070, tca9548a, rn2903
|
||||||
|
|
||||||
### v1.2.0
|
### v1.2.0
|
||||||
|
|
||||||
* Improved JAVA binding compiler compatibility and added JAVA interfaces that
|
* Improved JAVA binding compiler compatibility and added JAVA interfaces that
|
||||||
|
@ -108,13 +108,14 @@ commands below to generate collateral files for your new sensor library.
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
function make_new_sensor {
|
function make_new_sensor {
|
||||||
SensorName=$1
|
export SensorName=$1
|
||||||
|
# Get a lowercase version of the string
|
||||||
|
export sensorname=${SensorName,,}
|
||||||
|
|
||||||
# Make sure this is run from the root UPM directory
|
# Make sure this is run from the root UPM directory
|
||||||
if ! grep -q 'UPM ' README.md; then echo "Please run from the root UPM directory"; return -1; fi
|
if ! grep -q 'UPM ' README.md; then echo "Please run from the root UPM directory"; return -1; fi
|
||||||
|
|
||||||
# Copy/paste the below commands into a bash shell...
|
printf "Generating new sensor: ${SensorName}\n"
|
||||||
# Get a lowercase version of the string
|
|
||||||
sensorname=${SensorName,,}
|
|
||||||
# Copy sensortemplate files to ${sensorname}
|
# Copy sensortemplate files to ${sensorname}
|
||||||
find docs/ examples/ src/ -name '*sensortemplate*' -exec bash -c 'cp -r $0 ${0/sensortemplate/${sensorname}}' {} \;
|
find docs/ examples/ src/ -name '*sensortemplate*' -exec bash -c 'cp -r $0 ${0/sensortemplate/${sensorname}}' {} \;
|
||||||
# Copy SensorTemplate files to ${SensorName}
|
# Copy SensorTemplate files to ${SensorName}
|
||||||
|
BIN
docs/images/lidarlitev3.jpg
Normal file
BIN
docs/images/lidarlitev3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 156 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
BIN
docs/images/tca9548a.jpg
Normal file
BIN
docs/images/tca9548a.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 616 KiB |
@ -7,6 +7,9 @@ such sensors and known workarounds if they exist.
|
|||||||
|
|
||||||
#### Grove Sensors
|
#### Grove Sensors
|
||||||
|
|
||||||
|
* **RN2903** Click 2 version. This device will not work using the
|
||||||
|
Edison UART on the Arduino breakout. It does work on Edison using a
|
||||||
|
USB->serial interface.
|
||||||
* **Grove LCD RGB Backlit** (JHD1313M1) requires 5V and should be used with an
|
* **Grove LCD RGB Backlit** (JHD1313M1) requires 5V and should be used with an
|
||||||
external power supply connected to the board to function properly. Although
|
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
|
some high powered USB ports might be enough, in most cases you will encounter
|
||||||
@ -50,11 +53,11 @@ such sensors and known workarounds if they exist.
|
|||||||
* **Grove BLE** (HM-11) does not return data on the Intel Galileo board due to
|
* **Grove BLE** (HM-11) does not return data on the Intel Galileo board due to
|
||||||
known UART limitation.
|
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.
|
it will trigger continuous callbacks when the sensor is not reading anything.
|
||||||
* **Grove RTC** (DS1307) is not compatible with the Intel Edison Arduino board
|
* **Grove RTC** (DS1307) is not compatible with the Intel Edison Arduino board
|
||||||
but will work with the Mini-breakout.
|
but will work with the Mini-breakout.
|
||||||
* **Grove Tempture & Humidity (High-Accuracy & Mini) Sensor** (TH02) only works
|
* **Grove Temperature & Humidity (High-Accuracy & Mini) Sensor** (TH02) only
|
||||||
with the Intel Edison Arduino board when powered from the 3.3V rail.
|
works with the Intel Edison Arduino board when powered from the 3.3V rail.
|
||||||
|
|
||||||
#### Adafruit Sensors
|
#### Adafruit Sensors
|
||||||
|
|
||||||
@ -75,6 +78,8 @@ This affects the **DS18B20**, **DS2413** and **DFREC** drivers.
|
|||||||
|
|
||||||
#### Other Sensors
|
#### Other Sensors
|
||||||
|
|
||||||
|
* **HTU21D** is unstable on the Intel Edison with the Arduino breakout and
|
||||||
|
will throw an error when it can't complete an update call.
|
||||||
* **MLX90614** is not compatible with the Intel Galileo due to the inability
|
* **MLX90614** is not compatible with the Intel Galileo due to the inability
|
||||||
to change the I2C bus speed to 100 KHz.
|
to change the I2C bus speed to 100 KHz.
|
||||||
* **MICSV89** is not compatible with the Intel Galileo due to the inability to
|
* **MICSV89** is not compatible with the Intel Galileo due to the inability to
|
||||||
@ -89,10 +94,9 @@ This affects the **DS18B20**, **DS2413** and **DFREC** drivers.
|
|||||||
|
|
||||||
Some *I2C* sensors add too much capacitance to the SDA line of the Intel Edison
|
Some *I2C* sensors add too much capacitance to the SDA line of the Intel Edison
|
||||||
Arduino breakout board, thus the signal sticks to a logic 1. When this happens,
|
Arduino breakout board, thus the signal sticks to a logic 1. When this happens,
|
||||||
other sensors connected to the I2C bus are unusable. While there is no generic
|
other sensors connected to the I2C bus also become unusable. In order to solve
|
||||||
solution for this limitation, in most cases the sensor works on the Intel
|
this problem, an I2C repeater that isolates the capacitance on the bus, such as
|
||||||
Edison Mini-breakout. When this board is not an option, the sensor can be
|
the PCA9517 can be used.
|
||||||
sometimes replaced with the same model from a different vendor.
|
|
||||||
|
|
||||||
The Intel Edison *SPI* bus can corrupt data being sent across when certain
|
The Intel Edison *SPI* bus can corrupt data being sent across when certain
|
||||||
sensors are connected to it, if using an old image. This has been resolved with
|
sensors are connected to it, if using an old image. This has been resolved with
|
||||||
|
@ -129,8 +129,6 @@ ABBREVIATE_BRIEF = "The $name class" \
|
|||||||
|
|
||||||
ALWAYS_DETAILED_SEC = NO
|
ALWAYS_DETAILED_SEC = NO
|
||||||
|
|
||||||
DETAILS_AT_TOP = YES
|
|
||||||
|
|
||||||
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
|
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
|
||||||
# inherited members of a class in the documentation of that class as if those
|
# inherited members of a class in the documentation of that class as if those
|
||||||
# members were ordinary class members. Constructors, destructors and assignment
|
# members were ordinary class members. Constructors, destructors and assignment
|
||||||
@ -1861,18 +1859,6 @@ GENERATE_XML = YES
|
|||||||
|
|
||||||
XML_OUTPUT = xml
|
XML_OUTPUT = xml
|
||||||
|
|
||||||
# The XML_SCHEMA tag can be used to specify a XML schema, which can be used by a
|
|
||||||
# validating XML parser to check the syntax of the XML files.
|
|
||||||
# This tag requires that the tag GENERATE_XML is set to YES.
|
|
||||||
|
|
||||||
XML_SCHEMA =
|
|
||||||
|
|
||||||
# The XML_DTD tag can be used to specify a XML DTD, which can be used by a
|
|
||||||
# validating XML parser to check the syntax of the XML files.
|
|
||||||
# This tag requires that the tag GENERATE_XML is set to YES.
|
|
||||||
|
|
||||||
XML_DTD =
|
|
||||||
|
|
||||||
# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program
|
# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program
|
||||||
# listings (including syntax highlighting and cross-referencing information) to
|
# listings (including syntax highlighting and cross-referencing information) to
|
||||||
# the XML output. Note that enabling this will significantly increase the size
|
# the XML output. Note that enabling this will significantly increase the size
|
||||||
|
@ -129,8 +129,6 @@ ABBREVIATE_BRIEF = "The $name class" \
|
|||||||
|
|
||||||
ALWAYS_DETAILED_SEC = NO
|
ALWAYS_DETAILED_SEC = NO
|
||||||
|
|
||||||
DETAILS_AT_TOP = YES
|
|
||||||
|
|
||||||
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
|
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
|
||||||
# inherited members of a class in the documentation of that class as if those
|
# inherited members of a class in the documentation of that class as if those
|
||||||
# members were ordinary class members. Constructors, destructors and assignment
|
# members were ordinary class members. Constructors, destructors and assignment
|
||||||
@ -1818,18 +1816,6 @@ GENERATE_XML = YES
|
|||||||
|
|
||||||
XML_OUTPUT = xml
|
XML_OUTPUT = xml
|
||||||
|
|
||||||
# The XML_SCHEMA tag can be used to specify a XML schema, which can be used by a
|
|
||||||
# validating XML parser to check the syntax of the XML files.
|
|
||||||
# This tag requires that the tag GENERATE_XML is set to YES.
|
|
||||||
|
|
||||||
XML_SCHEMA =
|
|
||||||
|
|
||||||
# The XML_DTD tag can be used to specify a XML DTD, which can be used by a
|
|
||||||
# validating XML parser to check the syntax of the XML files.
|
|
||||||
# This tag requires that the tag GENERATE_XML is set to YES.
|
|
||||||
|
|
||||||
XML_DTD =
|
|
||||||
|
|
||||||
# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program
|
# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program
|
||||||
# listings (including syntax highlighting and cross-referencing information) to
|
# listings (including syntax highlighting and cross-referencing information) to
|
||||||
# the XML output. Note that enabling this will significantly increase the size
|
# the XML output. Note that enabling this will significantly increase the size
|
||||||
|
@ -15,7 +15,7 @@ sensor in order to reduce load when doing multiple reads to sensor data.
|
|||||||
### Example
|
### Example
|
||||||
|
|
||||||
A sensor/actuator is expected to work as such (here is the servo ES08A API):
|
A sensor/actuator is expected to work as such (here is the servo ES08A API):
|
||||||
@snippet es08a.cxx Interesting
|
@snippet servo-es08a.cxx Interesting
|
||||||
|
|
||||||
However implementation and API design is completely up to the developer, some
|
However implementation and API design is completely up to the developer, some
|
||||||
enumerable sensors for example may provide much clever instantiation. Displays
|
enumerable sensors for example may provide much clever instantiation. Displays
|
||||||
|
1
doxy/doxygen2jsdoc
Submodule
1
doxy/doxygen2jsdoc
Submodule
Submodule doxy/doxygen2jsdoc added at 67cad69272
1
doxy/doxyport
Submodule
1
doxy/doxyport
Submodule
Submodule doxy/doxyport added at db3e1a6eb8
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Heidi Pan <heidi.pan@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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// dependencies
|
|
||||||
var xml2js = require('./xml2js')
|
|
||||||
, fs = require('fs')
|
|
||||||
, Promise = require('bluebird')
|
|
||||||
, opts = require('commander')
|
|
||||||
, _ = require('lodash')
|
|
||||||
, mkdirp = require('mkdirp');
|
|
||||||
|
|
||||||
|
|
||||||
// parse command line arguments
|
|
||||||
_.extend(opts, { addOptions: function(module) { return module.addOptions(opts); } });
|
|
||||||
opts
|
|
||||||
.option('-m, --module [module]', 'module name for which to build documentation', 'mraa')
|
|
||||||
.option('-f, --formats [formats]', 'format for js comments', 'yuidoc,ternjs')
|
|
||||||
.option('-o, --outdir [directory]', 'top directory to build documentation', __dirname + '/jsdoc')
|
|
||||||
.addOptions(xml2js)
|
|
||||||
.parse(process.argv);
|
|
||||||
|
|
||||||
|
|
||||||
// use promise-style programming rather than spaghetti callbacks
|
|
||||||
Promise.promisifyAll(fs);
|
|
||||||
Promise.promisifyAll(mkdirp);
|
|
||||||
|
|
||||||
|
|
||||||
// main
|
|
||||||
xml2js.parse().then(function(specjs) {
|
|
||||||
var formats = opts.formats.split(',');
|
|
||||||
Promise.all(_.map(formats, function(format) {
|
|
||||||
var generateDocs = require(__dirname + '/generators/' + format + '/generator');
|
|
||||||
var dir = opts.outdir + '/' + format + '/' + specjs.MODULE;
|
|
||||||
return mkdirp.mkdirpAsync(dir).then(function() {
|
|
||||||
return fs.writeFileAsync(dir + '/doc.js', generateDocs(specjs));
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"templates": {
|
|
||||||
"default": {
|
|
||||||
"outputSourceFiles": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Heidi Pan <heidi.pan@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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// dependencies
|
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
|
|
||||||
// generate JSDoc-style documentation
|
|
||||||
function generateDocs(specjs) {
|
|
||||||
var docs = GENERATE_MODULE(specjs.MODULE);
|
|
||||||
docs = _.reduce(specjs.METHODS, function(memo, methodSpec, methodName) {
|
|
||||||
return memo += GENERATE_METHOD(methodName, methodSpec);
|
|
||||||
}, docs);
|
|
||||||
docs = _.reduce(specjs.ENUMS, function(memo, enumSpec, enumName) {
|
|
||||||
return memo += GENERATE_ENUM(enumName, enumSpec);
|
|
||||||
}, docs);
|
|
||||||
docs = _.reduce(specjs.CLASSES, function(memo, classSpec, parentClass) {
|
|
||||||
return _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
|
|
||||||
return memo += GENERATE_METHOD(methodName, methodSpec, parentClass);
|
|
||||||
}, memo);
|
|
||||||
}, docs);
|
|
||||||
return docs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// comment wrapper around entire spec
|
|
||||||
function GENERATE_DOC(text) {
|
|
||||||
return '/**\n' + text + ' */\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate module spec
|
|
||||||
function GENERATE_MODULE(module) {
|
|
||||||
return GENERATE_DOC('@module ' + module + '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate method spec with parent module/class
|
|
||||||
function GENERATE_METHOD(name, spec, parent) {
|
|
||||||
name = name.replace(/!+$/, '');
|
|
||||||
return GENERATE_DOC(spec.description + '\n'
|
|
||||||
+ '@method ' + name + '\n'
|
|
||||||
+ '@instance\n'
|
|
||||||
+ (parent ? ('@memberof ' + parent + '\n') : '')
|
|
||||||
+ _.reduce(spec.params, function(memo, paramSpec, paramName) {
|
|
||||||
return '@param {' + paramSpec.type + '} ' + paramName + ' ' + paramSpec.description + '\n';
|
|
||||||
}, '')
|
|
||||||
+ ( !_.isEmpty(spec.return) ? ('@return {' + spec.return.type + '} ' + spec.return.description + '\n') : ''));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate enum spec
|
|
||||||
function GENERATE_ENUM(name, spec) {
|
|
||||||
return GENERATE_DOC(spec.description + '\n\n'
|
|
||||||
+ '@var ' + name + '\n'
|
|
||||||
+ '@type Enum(' + spec.type + ')\n'
|
|
||||||
+ '@instance\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
// generate link spec
|
|
||||||
function GENERATE_LINK(text) {
|
|
||||||
return '{@link ' + text + '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = generateDocs;
|
|
@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Heidi Pan <heidi.pan@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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// dependencies
|
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
|
|
||||||
// generate json for ternjs input
|
|
||||||
function generateDocs(specjs) {
|
|
||||||
GENERATE_TYPE = (function(enums) {
|
|
||||||
return function(type) {
|
|
||||||
return (_.contains(enums, type) ? ('Enum ' + type) : type);
|
|
||||||
}
|
|
||||||
})(_.keys(specjs.ENUMS_BY_GROUP));
|
|
||||||
var docs = { '!name': specjs.MODULE + 'library' };
|
|
||||||
_.extend(docs, GENERATE_MODULE(specjs.MODULE));
|
|
||||||
_.each(specjs.ENUMS, function(enumSpec, enumName) {
|
|
||||||
_.extend(docs[specjs.MODULE], GENERATE_ENUM(enumName, enumSpec));
|
|
||||||
});
|
|
||||||
_.each(specjs.METHODS, function(methodSpec, methodName) {
|
|
||||||
_.extend(docs[specjs.MODULE], GENERATE_METHOD(methodName, methodSpec));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (_.isEmpty(specjs.CLASSGROUPS)) {
|
|
||||||
_.extend(docs[specjs.MODULE], GENERATE_CLASSES(specjs.CLASSES));
|
|
||||||
} else {
|
|
||||||
var grouped = _.flatten(_.pluck(_.values(specjs.CLASSGROUPS), 'classes'));
|
|
||||||
var ungrouped = _.difference(_.keys(specjs.CLASSES), grouped);
|
|
||||||
_.extend(docs[specjs.MODULE], GENERATE_CLASSES(_.pick(specjs.CLASSES, ungrouped)));
|
|
||||||
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
|
|
||||||
_.extend(docs, GENERATE_MODULE(groupName));
|
|
||||||
_.extend(docs[groupName], GENERATE_CLASSES(_.pick(specjs.CLASSES, groupSpec.classes), groupName));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return JSON.stringify(docs, null, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate module spec
|
|
||||||
function GENERATE_MODULE(module) {
|
|
||||||
var docs = {};
|
|
||||||
docs[module] = {};
|
|
||||||
return docs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate the spec for the given list of classes
|
|
||||||
function GENERATE_CLASSES(classes) {
|
|
||||||
var docs = {};
|
|
||||||
_.each(classes, function(classSpec, parentClass) {
|
|
||||||
var constructor = classSpec.methods[parentClass];
|
|
||||||
_.extend(docs, GENERATE_METHOD(parentClass, constructor ? constructor : { params: {}, return: {}, description: '' } ));
|
|
||||||
if (_.has(docs, parentClass)) {
|
|
||||||
_.each(classSpec.enums, function(enumSpec, enumName) {
|
|
||||||
_.extend(docs[parentClass], GENERATE_ENUM(enumName, enumSpec));
|
|
||||||
});
|
|
||||||
docs[parentClass].prototype = {};
|
|
||||||
_.each(_.omit(classSpec.methods, parentClass), function(methodSpec, methodName) {
|
|
||||||
_.extend(docs[parentClass].prototype, GENERATE_METHOD(methodName, methodSpec));
|
|
||||||
});
|
|
||||||
_.each(classSpec.variables, function(variableSpec, variableName) {
|
|
||||||
_.extend(docs[parentClass].prototype, GENERATE_VARIABLE(variableName, variableSpec));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return docs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate method spec
|
|
||||||
function GENERATE_METHOD(name, spec) {
|
|
||||||
var doc = {};
|
|
||||||
doc[name] = {
|
|
||||||
'!type': 'fn(' + GENERATE_PARAMS(spec.params) + ')' + GENERATE_RETURN(spec.return),
|
|
||||||
'!doc': spec.description
|
|
||||||
}
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate parameter signatures for method
|
|
||||||
function GENERATE_PARAMS(spec) {
|
|
||||||
return _.map(spec, function(paramSpec, paramName) {
|
|
||||||
return paramName + ': ' + paramSpec.type;
|
|
||||||
}).join(', ');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate return signature for method
|
|
||||||
function GENERATE_RETURN(spec) {
|
|
||||||
return (_.isEmpty(spec) ? '' : (' -> ' + spec.type));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate enum spec
|
|
||||||
function GENERATE_ENUM(name, spec) {
|
|
||||||
var doc = {};
|
|
||||||
doc[name] = 'Enum ' + spec.type ;
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate variable spec
|
|
||||||
function GENERATE_VARIABLE(name, spec) {
|
|
||||||
var doc = {};
|
|
||||||
doc[name]= spec.type ;
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = generateDocs;
|
|
144
doxy/node/generators/yuidoc/generator.js
vendored
144
doxy/node/generators/yuidoc/generator.js
vendored
@ -1,144 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Heidi Pan <heidi.pan@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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// dependencies
|
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
|
|
||||||
// generate YuiDocs-style documentation
|
|
||||||
function generateDocs(specjs) {
|
|
||||||
var docs = GENERATE_MODULE(specjs.MODULE, '');
|
|
||||||
GENERATE_TYPE = (function(enums) {
|
|
||||||
return function(type) {
|
|
||||||
return (_.contains(enums, type) ? ('Enum ' + type) : type);
|
|
||||||
}
|
|
||||||
})(_.keys(specjs.ENUMS_BY_GROUP));
|
|
||||||
docs = _.reduce(specjs.METHODS, function(memo, methodSpec, methodName) {
|
|
||||||
return memo += GENERATE_METHOD(methodName, methodSpec);
|
|
||||||
}, docs);
|
|
||||||
docs = _.reduce(specjs.ENUMS, function(memo, enumSpec, enumName) {
|
|
||||||
return memo += GENERATE_ENUM(enumName, enumSpec);
|
|
||||||
}, docs);
|
|
||||||
if (_.isEmpty(specjs.CLASSGROUPS)) {
|
|
||||||
docs += GENERATE_CLASSES(specjs.CLASSES);
|
|
||||||
} else {
|
|
||||||
docs += GENERATE_MODULE('common', '');
|
|
||||||
var grouped = _.flatten(_.pluck(_.values(specjs.CLASSGROUPS), 'classes'));
|
|
||||||
var ungrouped = _.difference(_.keys(specjs.CLASSES), grouped);
|
|
||||||
docs += GENERATE_CLASSES(_.pick(specjs.CLASSES, ungrouped), 'common');
|
|
||||||
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
|
|
||||||
docs += GENERATE_CLASSES(_.pick(specjs.CLASSES, groupSpec.classes), groupName);
|
|
||||||
});
|
|
||||||
// TODO: figure out why yuidoc won't associate the class with the right module if module definitions are interspersed
|
|
||||||
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
|
|
||||||
docs += GENERATE_MODULE(groupName, groupSpec.description);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return docs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// comment wrapper around entire spec
|
|
||||||
function GENERATE_DOC(text) {
|
|
||||||
return '/**\n' + text + ' */\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate module spec
|
|
||||||
function GENERATE_MODULE(name, description) {
|
|
||||||
return GENERATE_DOC(description + '\n'
|
|
||||||
+ '@module ' + name + '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate spec for the given list of classes
|
|
||||||
function GENERATE_CLASSES(classes, parent) {
|
|
||||||
return _.reduce(classes, function(memo, classSpec, className) {
|
|
||||||
return memo
|
|
||||||
+ GENERATE_CLASS(className, classSpec.description, parent, classSpec.parent)
|
|
||||||
+ _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
|
|
||||||
return memo += GENERATE_METHOD(methodName, methodSpec, className);
|
|
||||||
}, '')
|
|
||||||
+ _.reduce(classSpec.variables, function(memo, variableSpec, variableName) {
|
|
||||||
return memo += GENERATE_VAR(variableName, variableSpec, className);
|
|
||||||
}, '')
|
|
||||||
+ _.reduce(classSpec.enums, function(memo, enumSpec, enumName) {
|
|
||||||
return memo += GENERATE_ENUM(enumName, enumSpec, className);
|
|
||||||
}, '');
|
|
||||||
}, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate class spec
|
|
||||||
function GENERATE_CLASS(name, description, namespace, parent) {
|
|
||||||
return GENERATE_DOC(description + '\n'
|
|
||||||
+ '@class ' + name + '\n'
|
|
||||||
+ (namespace ? ('@module ' + namespace + '\n') : '')
|
|
||||||
/*
|
|
||||||
TODO: leave out until figure out what swig does with inheritance
|
|
||||||
+ (parent ? ('@extends ' + parent + '\n') : '')
|
|
||||||
*/
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate method spec with parent module/class
|
|
||||||
function GENERATE_METHOD(name, spec, parent) {
|
|
||||||
name = name.replace(/!+$/, '');
|
|
||||||
return GENERATE_DOC(spec.description + '\n'
|
|
||||||
+ '@method ' + name + '\n'
|
|
||||||
+ (parent ? ('@for ' + parent + '\n') : '@for common\n')
|
|
||||||
+ _.reduce(spec.params, function(memo, paramSpec, paramName) {
|
|
||||||
return memo + '@param {' + GENERATE_TYPE(paramSpec.type) + '} ' + paramName + ' ' + paramSpec.description + '\n';
|
|
||||||
}, '')
|
|
||||||
+ ( !_.isEmpty(spec.return) ? ('@return {' + GENERATE_TYPE(spec.return.type) + '} ' + spec.return.description + '\n') : ''));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate enum spec
|
|
||||||
function GENERATE_ENUM(name, spec, parent) {
|
|
||||||
return GENERATE_DOC(spec.description + '\n'
|
|
||||||
+ '@property ' + name + '\n'
|
|
||||||
+ '@type Enum ' + spec.type + '\n'
|
|
||||||
+ '@for ' + (parent ? parent : 'common') + '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate variable specs
|
|
||||||
function GENERATE_VAR(name, spec, parent) {
|
|
||||||
return GENERATE_DOC(spec.description + '\n'
|
|
||||||
+ '@property ' + name + '\n'
|
|
||||||
+ '@type ' + spec.type + '\n'
|
|
||||||
+ '@for ' + parent + '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
// generate link spec
|
|
||||||
function GENERATE_LINK(text) {
|
|
||||||
return '{{#crossLink "' + text + '"}}{{/crossLink}}';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = generateDocs;
|
|
@ -1,45 +0,0 @@
|
|||||||
document
|
|
||||||
= _ ignore* _ "<doxygen " _ attr:attr* _ ">" body:elements _ "</doxygen>" _ { return body; }
|
|
||||||
|
|
||||||
|
|
||||||
elements
|
|
||||||
= element*
|
|
||||||
|
|
||||||
element
|
|
||||||
= _ "<" startTag:id _ attr:attr* _ ">" _ children:elements _ "</" endTag:id ">" _ {
|
|
||||||
if (startTag != endTag) {
|
|
||||||
throw new Error("Expected </" + startTag + "> but </" + endTag + "> found.");
|
|
||||||
}
|
|
||||||
return {name: startTag, attr: attr, children: children }
|
|
||||||
}
|
|
||||||
/ "<" tag:id _ attr:attr* _ "/>" _ {
|
|
||||||
return {name: tag, attr: attr }
|
|
||||||
}
|
|
||||||
/ _ text:text _ { return text }
|
|
||||||
|
|
||||||
ignore
|
|
||||||
= "<?xml" _ attr* _ "?>" { return }
|
|
||||||
|
|
||||||
attr
|
|
||||||
= name:id _ "=" _ value:string { return { name:name, value:value } }
|
|
||||||
|
|
||||||
string
|
|
||||||
= '"' '"' _ { return ""; }
|
|
||||||
/ "'" "'" _ { return ""; }
|
|
||||||
/ '"' text:quoted '"' _ { return text; }
|
|
||||||
/ "'" text:quoted "'" _ { return text; }
|
|
||||||
|
|
||||||
quoted
|
|
||||||
= chars:[^<>'" \t\n\r]+ { return chars.join(""); }
|
|
||||||
|
|
||||||
text
|
|
||||||
= chars:[^<> \t\n\r]+ { return chars.join(""); }
|
|
||||||
|
|
||||||
id
|
|
||||||
= chars:[^<>/'"=? \t\n\r]+ { return chars.join(""); }
|
|
||||||
|
|
||||||
_ "whitespace"
|
|
||||||
= whitespace*
|
|
||||||
|
|
||||||
whitespace
|
|
||||||
= [ \t\n\r]
|
|
@ -1,125 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Dina M Suehiro <dina.m.suehiro@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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// dependencies
|
|
||||||
var opts = require('commander'), // for command line args
|
|
||||||
fs = require('fs'), // for file system access
|
|
||||||
path = require('path'); // for file path parsing
|
|
||||||
|
|
||||||
// parse command line arguments
|
|
||||||
opts
|
|
||||||
.option('-i, --inputdir [directory]', 'product documents directory', __dirname + '/docs/yuidoc/upm')
|
|
||||||
.parse(process.argv);
|
|
||||||
|
|
||||||
// Set to true for console output
|
|
||||||
var debug = true;
|
|
||||||
|
|
||||||
// Global arrays tracking the files that have been renamed
|
|
||||||
var originalFiles = [];
|
|
||||||
var renamedFiles = [];
|
|
||||||
|
|
||||||
// Filter to get html files from different directories
|
|
||||||
var rootFiles = getHtmlFilenames(opts.inputdir);
|
|
||||||
var classesFiles = getHtmlFilenames(opts.inputdir + "/classes");
|
|
||||||
var modulesFiles = getHtmlFilenames(opts.inputdir + "/modules");
|
|
||||||
|
|
||||||
// Rename files in the classes directory to have lower-cased file names.
|
|
||||||
renameFiles(classesFiles);
|
|
||||||
|
|
||||||
classesFiles = getHtmlFilenames(opts.inputdir + "/classes");
|
|
||||||
|
|
||||||
// Go through the html files and update links to reflect the file names that we changed.
|
|
||||||
renameLinks(rootFiles);
|
|
||||||
renameLinks(classesFiles);
|
|
||||||
renameLinks(modulesFiles);
|
|
||||||
|
|
||||||
// Helper function that returns paths to the html files in the specified directory
|
|
||||||
function getHtmlFilenames (directory)
|
|
||||||
{
|
|
||||||
return fs.readdirSync(directory).map(function (file) {
|
|
||||||
return path.join(directory, file);
|
|
||||||
}).filter(function (file) {
|
|
||||||
return fs.statSync(file).isFile();
|
|
||||||
}).filter(function (file) {
|
|
||||||
return path.extname(file).toLowerCase() == ".html";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Goes through the files and renames them to be lower-cased and tracks them the
|
|
||||||
// renamed files in the originalFiles[] and renamedFiles[] arrays.
|
|
||||||
function renameFiles(files)
|
|
||||||
{
|
|
||||||
files.forEach(function (file)
|
|
||||||
{
|
|
||||||
var originalName = path.basename(file);
|
|
||||||
var newFileName = originalName.toLowerCase();
|
|
||||||
var directory = path.dirname(file);
|
|
||||||
if (originalName != newFileName)
|
|
||||||
{
|
|
||||||
fs.renameSync(file, directory + "/" + newFileName); //, function(err)
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
console.log('Renamed: %s --> %s', originalName, newFileName);
|
|
||||||
|
|
||||||
originalFiles.push(originalName);
|
|
||||||
renamedFiles.push(newFileName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function goes through the specified files and does a file/replace of the
|
|
||||||
// originalFiles to the renamedFiles so that the .html links match what has been renamed.
|
|
||||||
function renameLinks (files)
|
|
||||||
{
|
|
||||||
if (originalFiles.length <= 0)
|
|
||||||
{
|
|
||||||
if (debug)
|
|
||||||
console.log("No links to rename.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
files.forEach(function (file)
|
|
||||||
{
|
|
||||||
// Read the file
|
|
||||||
data = fs.readFileSync(file, 'ascii');
|
|
||||||
|
|
||||||
// Find/replace the file names that were renamed
|
|
||||||
for (var i = 0; i < originalFiles.length; i++)
|
|
||||||
{
|
|
||||||
var findString = '/' + originalFiles[i] + '\"';
|
|
||||||
var replaceString = '/' + renamedFiles[i] + '\"';
|
|
||||||
|
|
||||||
data = data.replace(findString, replaceString);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write back
|
|
||||||
fs.writeFile(file, data, 'ascii', function (err) {
|
|
||||||
if (err)
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
console.log('Renamed links in: %s', file);
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,935 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Heidi Pan <heidi.pan@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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// dependencies
|
|
||||||
var peg = require('pegjs')
|
|
||||||
, fs = require('fs')
|
|
||||||
, path = require('path')
|
|
||||||
, Promise = require('bluebird')
|
|
||||||
, _ = require('lodash')
|
|
||||||
, util = require('util');
|
|
||||||
|
|
||||||
|
|
||||||
// use promise-style programming rather than spaghetti callbacks
|
|
||||||
Promise.promisifyAll(fs);
|
|
||||||
|
|
||||||
|
|
||||||
var xml2js = {
|
|
||||||
|
|
||||||
// js-format specs
|
|
||||||
// MODULE: <module name>
|
|
||||||
// ENUMS: {
|
|
||||||
// <enum name>: {
|
|
||||||
// type: <enum type>,
|
|
||||||
// description: <enum description>
|
|
||||||
// }, ...
|
|
||||||
// }
|
|
||||||
// ENUMS_BY_GROUP: {
|
|
||||||
// <enum type>: {
|
|
||||||
// description: <enum group description>
|
|
||||||
// members: [ <enum name>, ... ]
|
|
||||||
// }, ...
|
|
||||||
// }
|
|
||||||
// METHODS: {
|
|
||||||
// <method name>: {
|
|
||||||
// description: <method description>,
|
|
||||||
// params: {
|
|
||||||
// <param name>: {
|
|
||||||
// type: <param type>,
|
|
||||||
// description: <param description >
|
|
||||||
// }, ...
|
|
||||||
// },
|
|
||||||
// return: {
|
|
||||||
// type: <return type>,
|
|
||||||
// description: <return description>
|
|
||||||
// }
|
|
||||||
// }, ...
|
|
||||||
// }
|
|
||||||
// CLASSES: {
|
|
||||||
// <class name>: {
|
|
||||||
// description: <class description>,
|
|
||||||
// parent: <parent class name>,
|
|
||||||
// group: <group name>,
|
|
||||||
// methods: { ... },
|
|
||||||
// variables: {
|
|
||||||
// <variable name>: {
|
|
||||||
// type: <variable type>,
|
|
||||||
// description: <variable description>
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// enums: { ... },
|
|
||||||
// enums_by_group: { ... }
|
|
||||||
// }, ...
|
|
||||||
// }
|
|
||||||
// CLASSGROUPS: {
|
|
||||||
// <group name>: {
|
|
||||||
// description: <group description>,
|
|
||||||
// classes: [ <class name>, ... ],
|
|
||||||
// enums: { ... },
|
|
||||||
// enums_by_group: { ... }
|
|
||||||
// }, ...
|
|
||||||
// }
|
|
||||||
MODULE: '',
|
|
||||||
ENUMS: {},
|
|
||||||
ENUMS_BY_GROUP: {},
|
|
||||||
METHODS: {},
|
|
||||||
CLASSES: {},
|
|
||||||
CLASSGROUPS: {},
|
|
||||||
|
|
||||||
|
|
||||||
// baseline c -> js type mapping
|
|
||||||
TYPEMAPS: {
|
|
||||||
'^(const)?\\s*(unsigned|signed)?\\s*(int|short|long|float|double|size_t|u?int\\d{1,2}_t)?$': 'Number',
|
|
||||||
'^bool$': 'Boolean',
|
|
||||||
'^(const)?\\s*(unsigned|signed)?\\s*(char|char\\s*\\*|std::string)$': 'String', // TODO: verify that swig does this mapping
|
|
||||||
'^void\\s*\\(\\s*\\*\\s*\\)\\s*\\(\\s*void\\s*\\*\\)\\s*$': 'Function'
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
// custom c -> js type mapping for pointers
|
|
||||||
// ARRAY_TYPEMAPS: {
|
|
||||||
// <pointer data type>: {
|
|
||||||
// arrayType: <swig generated array type that will replace pointers of data type>,
|
|
||||||
// classes: [ <class that contains arrayType>, ... ]
|
|
||||||
// }, ...
|
|
||||||
// }
|
|
||||||
// POINTER_TYPEMAPS: {
|
|
||||||
// <class that contains pointerType>: {
|
|
||||||
// <c pointer data type>: <js swig generated pointer type that will replace pointers of data type>, ...
|
|
||||||
// }, ...
|
|
||||||
// }
|
|
||||||
ARRAY_TYPEMAPS: {},
|
|
||||||
POINTER_TYPEMAPS: {},
|
|
||||||
|
|
||||||
|
|
||||||
// add command line options for this module
|
|
||||||
addOptions: function(opts) {
|
|
||||||
xml2js.opts = opts;
|
|
||||||
return opts
|
|
||||||
.option('-i, --inputdir [directory]', 'directory for xml files', __dirname + '/xml/mraa')
|
|
||||||
.option('-c, --custom [file]', 'json for customizations')
|
|
||||||
.option('-t, --typemaps [directory]', 'directory for custom pointer type maps')
|
|
||||||
.option('-g, --imagedir [directory]', 'directory to link to where the images will be kept', '')
|
|
||||||
.option('-s, --strict', 'leave out methods/variables if unknown type')
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
// parse doxygen xml -> js-format specs
|
|
||||||
// TODO: figure out whether we need to document any protected methods/variables
|
|
||||||
parse: function() {
|
|
||||||
var XML_GRAMMAR_SPEC = 'grammars/xml.peg';
|
|
||||||
var NAMESPACE_SPEC = xml2js.opts.inputdir + '/namespace' + xml2js.opts.module + '.xml';
|
|
||||||
var CLASS_SPEC = function(c) { return xml2js.opts.inputdir + '/' + c + '.xml'; }
|
|
||||||
var TYPES_SPEC = xml2js.opts.inputdir + '/types_8h.xml';
|
|
||||||
xml2js.MODULE = xml2js.opts.module;
|
|
||||||
return Promise.join(createXmlParser(XML_GRAMMAR_SPEC),
|
|
||||||
xml2js.opts.typemaps ? initCustomPointerTypemaps(xml2js.opts.typemaps) : Promise.resolve(),
|
|
||||||
fs.readFileAsync(NAMESPACE_SPEC, 'utf8'),
|
|
||||||
fs.existsSync(TYPES_SPEC) ? fs.readFileAsync(TYPES_SPEC, 'utf8') : Promise.resolve(null),
|
|
||||||
function(xmlparser, ignore, xml, xml_types) {
|
|
||||||
if (xml_types != null) {
|
|
||||||
_.extend(xml2js.ENUMS, getEnums(xmlparser.parse(xml_types)[0], false));
|
|
||||||
_.extend(xml2js.ENUMS_BY_GROUP, getEnums(xmlparser.parse(xml_types)[0], true));
|
|
||||||
}
|
|
||||||
var spec_c = xmlparser.parse(xml)[0];
|
|
||||||
_.extend(xml2js.ENUMS, getEnums(spec_c, false));
|
|
||||||
_.extend(xml2js.ENUMS_BY_GROUP, getEnums(spec_c, true));
|
|
||||||
_.extend(xml2js.METHODS, getMethods(spec_c));
|
|
||||||
_.each(getSubclassNames(spec_c), function(className) { xml2js.CLASSES[className] = {} });
|
|
||||||
var parseClasses = _.map(getSubclasses(spec_c), function(c) {
|
|
||||||
return fs.readFileAsync(CLASS_SPEC(c), 'utf8').then(function(xml) {
|
|
||||||
try {
|
|
||||||
var spec_c = xmlparser.parse(xml)[0];
|
|
||||||
var className = getName(spec_c);
|
|
||||||
_.extend(xml2js.CLASSES[className], {
|
|
||||||
description: getDescription(spec_c),
|
|
||||||
parent: getParent(spec_c, className),
|
|
||||||
enums: getEnums(spec_c, false, className),
|
|
||||||
enums_by_group: getEnums(spec_c, true, className),
|
|
||||||
variables: getVariables(spec_c, className),
|
|
||||||
methods: getMethods(spec_c, className)
|
|
||||||
});
|
|
||||||
} catch(e) {
|
|
||||||
console.log(e.toString() + ': class ' + className + ' was not parsed correctly.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
var parseGroups = fs.readdirAsync(xml2js.opts.inputdir).then(function(files) {
|
|
||||||
var groupxmlfiles = _.filter(files, function(fn) {
|
|
||||||
return ((path.extname(fn) == '.xml') && (path.basename(fn).search(/^group/) != -1));
|
|
||||||
});
|
|
||||||
return Promise.all(_.map(groupxmlfiles, function(fn) {
|
|
||||||
return fs.readFileAsync(xml2js.opts.inputdir + '/' + fn, 'utf8').then(function(xml) {
|
|
||||||
var spec_c = xmlparser.parse(xml)[0];
|
|
||||||
if (_.isEmpty(getSubmodules(spec_c))) {
|
|
||||||
var group = getName(spec_c);
|
|
||||||
var classes = getSubclassNames(spec_c);
|
|
||||||
xml2js.CLASSGROUPS[group] = {
|
|
||||||
description: getDescription(spec_c),
|
|
||||||
classes: classes
|
|
||||||
};
|
|
||||||
_.each(classes, function(c) {
|
|
||||||
if (_.has(xml2js.CLASSES, c)) {
|
|
||||||
xml2js.CLASSES[c].group = group;
|
|
||||||
} else {
|
|
||||||
console.log('Warning: Group ' + group + ' has unknown class ' + c);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
return Promise.all(parseClasses.concat(parseGroups));
|
|
||||||
}).then(function() {
|
|
||||||
if (!_.isEmpty(xml2js.CLASSGROUPS)) {
|
|
||||||
// try to categorize ungrouped classes, if any
|
|
||||||
var grouped = _.flatten(_.pluck(_.values(xml2js.CLASSGROUPS), 'classes'));
|
|
||||||
var ungrouped = _.difference(_.keys(xml2js.CLASSES), grouped);
|
|
||||||
_.each(ungrouped, function(c) {
|
|
||||||
_.each(findUsage(c), function(group) {
|
|
||||||
xml2js.CLASSGROUPS[group].classes.push(c);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
grouped = _.flatten(_.pluck(_.values(xml2js.CLASSGROUPS), 'classes'));
|
|
||||||
ungrouped = _.difference(_.keys(xml2js.CLASSES), grouped);
|
|
||||||
// try to categorize ungrouped enums, if any
|
|
||||||
_.each(xml2js.ENUMS_BY_GROUP, function(enumGroupSpec, enumGroupName) {
|
|
||||||
_.each(findUsage(enumGroupName, true), function(c) {
|
|
||||||
xml2js.CLASSES[c].enums_by_group[enumGroupName] = enumGroupSpec;
|
|
||||||
_.each(enumGroupSpec.members, function(enumName) {
|
|
||||||
xml2js.CLASSES[c].enums[enumName] = xml2js.ENUMS[enumName];
|
|
||||||
delete xml2js.ENUMS[enumName];
|
|
||||||
});
|
|
||||||
delete xml2js.ENUMS_BY_GROUP[enumGroupName];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).then(function() {
|
|
||||||
if (xml2js.opts.custom && fs.existsSync(xml2js.opts.custom)) {
|
|
||||||
return fs.readFileAsync(xml2js.opts.custom, 'utf8').then(function(custom) {
|
|
||||||
try {
|
|
||||||
customizeMethods(JSON.parse(custom));
|
|
||||||
} catch(e) {
|
|
||||||
console.log('invalid custom.json, ignored. ' + e.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log(xml2js.opts.custom ? ('Error: No such customization file exists: ' + xml2js.opts.custom) : 'No customizations given.');
|
|
||||||
}
|
|
||||||
}).then(function() {
|
|
||||||
generateCustomPointerClasses();
|
|
||||||
validateMethods();
|
|
||||||
validateVars();
|
|
||||||
return _.pick(xml2js, 'MODULE', 'ENUMS', 'ENUMS_BY_GROUP', 'METHODS', 'CLASSES', 'CLASSGROUPS');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// create an xml parser
|
|
||||||
function createXmlParser(XML_GRAMMAR_SPEC) {
|
|
||||||
return fs.readFileAsync(XML_GRAMMAR_SPEC, 'utf8').then(function(xmlgrammar) {
|
|
||||||
return peg.buildParser(xmlgrammar);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// configure c->js typemaps from custom swig directives
|
|
||||||
// TODO: many built in assumptions based on current upm file structures & .i customizations
|
|
||||||
function initCustomPointerTypemaps(typemapsdir) {
|
|
||||||
return fs.readdirAsync(typemapsdir).then(function(dirs) {
|
|
||||||
return Promise.all(_.map(dirs, function(dir) {
|
|
||||||
// get all js*.i directives from class-specific subdirectories, to be parsed below for %typemaps directives
|
|
||||||
return fs.readdirAsync(typemapsdir + '/' + dir).then(function(files) {
|
|
||||||
var directive = _.find(files, function(fn) {
|
|
||||||
return ((path.extname(fn) == '.i') && (path.basename(fn).search(/^js/) != -1));
|
|
||||||
});
|
|
||||||
var data = {};
|
|
||||||
if (directive) {
|
|
||||||
data[dir] = typemapsdir + '/' + dir + '/' + directive;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}).catch(function(e) {
|
|
||||||
// get all .i directives from top level directory, and parse for %array_class directives
|
|
||||||
if (e.code == 'ENOTDIR') {
|
|
||||||
var fn = dir;
|
|
||||||
if (path.extname(fn) == '.i') {
|
|
||||||
return fs.readFileAsync(typemapsdir + '/' + fn, 'utf8').then(function(directives) {
|
|
||||||
var arraytypes = _.filter(directives.split(/\n/), function(line) {
|
|
||||||
return (line.search(/^%array_class/) != -1);
|
|
||||||
});
|
|
||||||
_.each(arraytypes, function(arraytype) {
|
|
||||||
var parsed = arraytype.match(/%array_class\(([A-Za-z0-9_]+)[\s]*,[\s]*([A-Za-z0-9_]+)\)/);
|
|
||||||
if (parsed) {
|
|
||||||
var from = parsed[1];
|
|
||||||
var to = parsed[2];
|
|
||||||
xml2js.ARRAY_TYPEMAPS[from] = { arrayType: to, classes: [] };
|
|
||||||
} else {
|
|
||||||
console.log('Incorrectly parsed array_class from ' + fn + ': ' + arraytype);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
}).then(function(__directivesFiles) {
|
|
||||||
// parse for %typemaps & %pointer_functions directives
|
|
||||||
var _directivesFiles = _.filter(__directivesFiles, function(data) { return !_.isEmpty(data); });
|
|
||||||
var directivesFiles = _.object(_.map(_directivesFiles, _.keys), _.flatten(_.map(_directivesFiles, _.values)));
|
|
||||||
return Promise.all(_.map(directivesFiles, function(directivesFn, className) {
|
|
||||||
return fs.readFileAsync(directivesFn, 'utf8').then(function(directives) {
|
|
||||||
var typemaps = _.filter(directives.split(/\n/), function(line) {
|
|
||||||
return (line.search(/^%typemap/) != -1);
|
|
||||||
});
|
|
||||||
_.each(typemaps, function(typemap) {
|
|
||||||
var parsed = typemap.match(/%typemap\((in|out)\)[\s]+([A-Za-z0-9_]+[\s]*[\*])/);
|
|
||||||
if (parsed) {
|
|
||||||
var dir = parsed[1]; // TODO: ignored for now
|
|
||||||
var type = normalizePointer(parsed[2]);
|
|
||||||
var datatype = getPointerDataType(type);
|
|
||||||
if (_.has(xml2js.ARRAY_TYPEMAPS, datatype)) {
|
|
||||||
xml2js.ARRAY_TYPEMAPS[datatype].classes.push(className);
|
|
||||||
} else {
|
|
||||||
console.log('Ignored typemap from ' + directivesFn + ': ' + typemap.replace('{', '') + ' (no %array_class directive found for ' + datatype + ')');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('Ignored typemap from ' + directivesFn + ': ' + typemap.replace('{', '') + ' (only considering in/out typemaps of pointer types)');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var ptrfns = _.filter(directives.split(/\n/), function(line) {
|
|
||||||
return (line.search(/^%pointer_functions/) != -1);
|
|
||||||
});
|
|
||||||
_.each(ptrfns, function(ptrfn) {
|
|
||||||
var parsed = ptrfn.match(/%pointer_functions\(([A-Za-z0-9_]+)[\s]*,[\s]*([A-Za-z0-9_]+)\)/);
|
|
||||||
if (parsed) {
|
|
||||||
var from = parsed[1];
|
|
||||||
var to = parsed[2];
|
|
||||||
if (!_.has(xml2js.POINTER_TYPEMAPS, className)) {
|
|
||||||
xml2js.POINTER_TYPEMAPS[className] = {};
|
|
||||||
}
|
|
||||||
xml2js.POINTER_TYPEMAPS[className][from] = to;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generate class specs for custom pointer types
|
|
||||||
function generateCustomPointerClasses() {
|
|
||||||
var arrayTypes = _.pluck(_.values(xml2js.ARRAY_TYPEMAPS), 'arrayType');
|
|
||||||
var pointerTypes = _.uniq(_.flatten(_.map(_.values(xml2js.POINTER_TYPEMAPS), _.values)));
|
|
||||||
_.each(arrayTypes, function(arrayType) {
|
|
||||||
var dataType = _.findKey(xml2js.ARRAY_TYPEMAPS, function(to) { return to.arrayType == arrayType; });
|
|
||||||
xml2js.CLASSES[arrayType] = {
|
|
||||||
description: 'Array of type ' + dataType + '.',
|
|
||||||
enums: {},
|
|
||||||
enums_by_group: {},
|
|
||||||
variables: {},
|
|
||||||
methods: {}
|
|
||||||
};
|
|
||||||
xml2js.CLASSES[arrayType].methods[arrayType] = {
|
|
||||||
description: 'Instantiates the array.',
|
|
||||||
params: {
|
|
||||||
nelements: {
|
|
||||||
type: 'Number',
|
|
||||||
description: 'number of elements in the array'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
return: {}
|
|
||||||
};
|
|
||||||
xml2js.CLASSES[arrayType].methods.getitem = {
|
|
||||||
description: 'Access a particular element in the array.',
|
|
||||||
params: {
|
|
||||||
index: {
|
|
||||||
type: 'Number',
|
|
||||||
description: 'index of array to read from'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
return: {
|
|
||||||
type: getType(dataType),
|
|
||||||
description: 'the value of the element found at the given index of the array'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xml2js.CLASSES[arrayType].methods.setitem = {
|
|
||||||
description: 'Modify a particular element in the array.',
|
|
||||||
params: {
|
|
||||||
index: {
|
|
||||||
type: 'Number',
|
|
||||||
description: 'index of array to write to'
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
type: getType(dataType),
|
|
||||||
description: 'the value to set the element found at the given index of the array'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
return: {}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
var pointerDataTypeMap = _.reduce(_.map(_.values(xml2js.POINTER_TYPEMAPS), _.invert), function(memo, typemap) {
|
|
||||||
return _.extend(memo, typemap);
|
|
||||||
}, {});
|
|
||||||
_.each(pointerTypes, function(pointerType) {
|
|
||||||
var dataType = pointerDataTypeMap[pointerType];
|
|
||||||
xml2js.CLASSES[pointerType] = {
|
|
||||||
description: 'Proxy object to data of type ' + dataType + '.',
|
|
||||||
enums: {},
|
|
||||||
enums_by_group: {},
|
|
||||||
variables: {},
|
|
||||||
methods: {}
|
|
||||||
};
|
|
||||||
xml2js.CLASSES[pointerType].methods[pointerType] = {
|
|
||||||
description: 'Instantiates the proxy object.',
|
|
||||||
params: {},
|
|
||||||
return: {}
|
|
||||||
};
|
|
||||||
xml2js.CLASSES[pointerType].methods.value = {
|
|
||||||
description: 'Get the value of the object.',
|
|
||||||
params: {},
|
|
||||||
return: {
|
|
||||||
type: getType(dataType),
|
|
||||||
description: 'the value of the object'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xml2js.CLASSES[pointerType].methods.assign = {
|
|
||||||
description: 'Set the value of the object.',
|
|
||||||
params: {
|
|
||||||
value: {
|
|
||||||
type: getType(dataType),
|
|
||||||
description: 'the value to set the object to'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
return: {}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// search for usage of a type
|
|
||||||
function findUsage(type, classOnly) {
|
|
||||||
var filterClasses = function(fn) { return _.without(_.map(xml2js.CLASSES, fn), undefined); };
|
|
||||||
var usesType = function(classSpec, className) {
|
|
||||||
var methodsOfType = (_.find(classSpec.methods, function(methodSpec, methodName) {
|
|
||||||
return ((!_.isEmpty(methodSpec.return) && methodSpec.return.type == type) ||
|
|
||||||
(_.contains(_.pluck(methodSpec.params, 'type'), type)));
|
|
||||||
}) != undefined);
|
|
||||||
var variablesOfType = _.contains(_.pluck(classSpec.variable, 'type'), type);
|
|
||||||
return ((methodsOfType || variablesOfType) ? className : undefined);
|
|
||||||
};
|
|
||||||
var extendsType = function(classSpec, className) {
|
|
||||||
return ((classSpec.parent == type) ? className : undefined);
|
|
||||||
};
|
|
||||||
var classes = _.union(filterClasses(usesType), filterClasses(extendsType));
|
|
||||||
if (classOnly) {
|
|
||||||
return classes;
|
|
||||||
} else {
|
|
||||||
return _.without(_.uniq(_.pluck(_.pick(xml2js.CLASSES, classes), 'group')), undefined);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// override autogenerated methods with custom configuration
|
|
||||||
function customizeMethods(custom) {
|
|
||||||
_.each(custom, function(classMethods, className) {
|
|
||||||
_.extend(xml2js.CLASSES[className].methods, _.pick(classMethods, function(methodSpec, methodName) {
|
|
||||||
return isValidMethodSpec(methodSpec, className + '.' + methodName);
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// make sure methods have valid types, otherwise warn (& don't include if strict)
|
|
||||||
function validateMethods() {
|
|
||||||
xml2js.METHODS = _.pick(xml2js.METHODS, function(methodSpec, methodName) {
|
|
||||||
return hasValidTypes(methodSpec, methodName);
|
|
||||||
});
|
|
||||||
_.each(xml2js.CLASSES, function(classSpec, className) {
|
|
||||||
var valid = _.pick(classSpec.methods, function(methodSpec, methodName) {
|
|
||||||
return hasValidTypes(methodSpec, className + '.' + methodName, className);
|
|
||||||
});
|
|
||||||
if (xml2js.opts.strict) {
|
|
||||||
xml2js.CLASSES[className].methods = valid;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// make sure variables have valid types, otherwise warn (& don't include if strict)
|
|
||||||
function validateVars() {
|
|
||||||
_.each(xml2js.CLASSES, function(classSpec, className) {
|
|
||||||
var valid = _.pick(classSpec.variables, function(varSpec, varName) {
|
|
||||||
return ofValidType(varSpec, className + '.' + varName, className);
|
|
||||||
});
|
|
||||||
if (xml2js.opts.strict) {
|
|
||||||
xml2js.CLASSES[className].variables = valid;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// verify that the json spec is well formatted
|
|
||||||
function isValidMethodSpec(methodSpec, methodName) {
|
|
||||||
var valid = true;
|
|
||||||
var printIgnoredMethodOnce = _.once(function() { console.log(methodName + ' from ' + path.basename(xml2js.opts.custom) + ' is omitted from JS documentation.'); });
|
|
||||||
function checkRule(rule, errMsg) {
|
|
||||||
if (!rule) {
|
|
||||||
printIgnoredMethodOnce();
|
|
||||||
console.log(' ' + errMsg);
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checkRule(_.has(methodSpec, 'description'), 'no description given');
|
|
||||||
checkRule(_.has(methodSpec, 'params'), 'no params given (specify "params": {} for no params)');
|
|
||||||
_.each(methodSpec.params, function(paramSpec, paramName) {
|
|
||||||
checkRule(_.has(paramSpec, 'type'), 'no type given for param ' + paramName);
|
|
||||||
checkRule(_.has(paramSpec, 'description'), 'no description given for param ' + paramName);
|
|
||||||
});
|
|
||||||
checkRule(_.has(methodSpec, 'return'), 'no return given (specify "return": {} for no return value)');
|
|
||||||
checkRule(_.has(methodSpec.return, 'type'), 'no type given for return value');
|
|
||||||
checkRule(_.has(methodSpec.return, 'description'), 'no description given for return value');
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get enum specifications
|
|
||||||
function getEnums(spec_c, bygroup, parent) {
|
|
||||||
var spec_js = {};
|
|
||||||
var enumGroups = _.find(getChildren(spec_c, 'sectiondef'), function(section) {
|
|
||||||
var kind = getAttr(section, 'kind');
|
|
||||||
return ((kind == 'enum') || (kind == 'public-type'));
|
|
||||||
});
|
|
||||||
if (enumGroups) {
|
|
||||||
_.each(enumGroups.children, function(enumGroup) {
|
|
||||||
var enumGroupName = getText(getChild(enumGroup, 'name'), 'name');
|
|
||||||
var enumGroupDescription = getText(getChild(enumGroup, 'detaileddescription'), 'description');
|
|
||||||
var enumGroupVals = getChildren(enumGroup, 'enumvalue');
|
|
||||||
if (bygroup) {
|
|
||||||
spec_js[enumGroupName] = {
|
|
||||||
description: enumGroupDescription,
|
|
||||||
members: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
_.each(enumGroupVals, function(e) {
|
|
||||||
// TODO: get prefix as option
|
|
||||||
var enumName = getText(getChild(e, 'name'), 'name').replace(/^MRAA_/, '');
|
|
||||||
var enumDescription = getText(getChild(e, 'detaileddescription'), 'description');
|
|
||||||
if (!bygroup) {
|
|
||||||
spec_js[enumName] = {
|
|
||||||
type: enumGroupName,
|
|
||||||
description: enumDescription
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
spec_js[enumGroupName].members.push(enumName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return spec_js;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the name for the module/group/class
|
|
||||||
function getName(spec_c) {
|
|
||||||
return getText(getChild(spec_c, 'compoundname'), 'name').replace(xml2js.opts.module + '::', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the description for the module/group/class
|
|
||||||
function getDescription(spec_c) {
|
|
||||||
return getText(getChild(spec_c, 'detaileddescription'), 'description');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the classes (xml file names) for the given module
|
|
||||||
function getSubclasses(spec_c) {
|
|
||||||
return _.map(getChildren(spec_c, 'innerclass'), function(innerclass) {
|
|
||||||
return getAttr(innerclass, 'refid');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the classes (class names) for the given module
|
|
||||||
function getSubclassNames(spec_c) {
|
|
||||||
return _.map(getChildren(spec_c, 'innerclass'), function(innerclass) {
|
|
||||||
return getText(innerclass).replace(xml2js.opts.module + '::', '');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the submodules (xml file names) for the given module
|
|
||||||
function getSubmodules(spec_c) {
|
|
||||||
return _.map(getChildren(spec_c, 'innergroup'), function(innergroup) {
|
|
||||||
return getAttr(innergroup, 'refid');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get parent class, if any
|
|
||||||
function getParent(spec_c, className) {
|
|
||||||
var parent = getChild(spec_c, 'basecompoundref');
|
|
||||||
if (parent) {
|
|
||||||
parent = getText(parent);
|
|
||||||
if (!_.has(xml2js.CLASSES, parent)) {
|
|
||||||
console.log('WARNING: Class ' + className + ' has unknown parent class ' + parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function hasParams(paramsSpec) {
|
|
||||||
return !(_.isEmpty(paramsSpec) ||
|
|
||||||
((_.size(paramsSpec) == 1) && getText(getChild(paramsSpec[0], 'type')) == 'void'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get method specifications for top-level module or a given class
|
|
||||||
// TODO: overloaded functions
|
|
||||||
// TODO: functions w/ invalid parameter(s)/return
|
|
||||||
function getMethods(spec_c, parent) {
|
|
||||||
var spec_js = {};
|
|
||||||
var methods = _.find(getChildren(spec_c, 'sectiondef'), function(section) {
|
|
||||||
var kind = getAttr(section, 'kind');
|
|
||||||
return ((kind == 'public-func') || (kind == 'func'));
|
|
||||||
});
|
|
||||||
if (methods) {
|
|
||||||
_.each(methods.children, function(method) {
|
|
||||||
var methodName = getText(getChild(method, 'name'), 'name');
|
|
||||||
if (methodName[0] != '~') { // filter out destructors
|
|
||||||
try {
|
|
||||||
var description = getChild(method, 'detaileddescription');
|
|
||||||
var methodDescription = getText(description, 'description');
|
|
||||||
var paramsSpec = getChildren(method, 'param');
|
|
||||||
var params = {};
|
|
||||||
if (hasParams(paramsSpec)) {
|
|
||||||
params = getParams(paramsSpec, getParamsDetails(description), methodName, parent);
|
|
||||||
}
|
|
||||||
var returnSpec = getChild(method, 'type');
|
|
||||||
var retval = {};
|
|
||||||
if (!_.isEmpty(returnSpec)) {
|
|
||||||
retval = getReturn(returnSpec, getReturnDetails(description), methodName, parent);
|
|
||||||
}
|
|
||||||
methodName = getUniqueMethodName(methodName, spec_js, parent);
|
|
||||||
spec_js[methodName] = {
|
|
||||||
description: methodDescription,
|
|
||||||
params: params,
|
|
||||||
return: retval
|
|
||||||
};
|
|
||||||
} catch(e) {
|
|
||||||
console.log((parent ? (parent + '.') : '') + methodName + ' is omitted from JS documentation.');
|
|
||||||
console.log(' ' + e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return spec_js;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get a unique string to represent the name of an overloaded method
|
|
||||||
function getUniqueMethodName(methodName, module, parent) {
|
|
||||||
if (methodName in module) {
|
|
||||||
do {
|
|
||||||
methodName += '!';
|
|
||||||
} while (methodName in module);
|
|
||||||
}
|
|
||||||
return methodName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get variable specifications for a class
|
|
||||||
function getVariables(spec_c, parent) {
|
|
||||||
var spec_js = {};
|
|
||||||
var vars = _.find(getChildren(spec_c, 'sectiondef'), function(section) {
|
|
||||||
var kind = getAttr(section, 'kind');
|
|
||||||
return (kind == 'public-attrib');
|
|
||||||
});
|
|
||||||
if (vars) {
|
|
||||||
_.each(_.filter(vars.children, function(variable) {
|
|
||||||
return (getAttr(variable, 'kind') == 'variable');
|
|
||||||
}), function(variable) {
|
|
||||||
var varName = getText(getChild(variable, 'name'), 'name');
|
|
||||||
var varType = getType(getText(getChild(variable, 'type')), parent);
|
|
||||||
var varDescription = getText(getChild(variable, 'detaileddescription'));
|
|
||||||
spec_js[varName] = {
|
|
||||||
type: varType,
|
|
||||||
description: varDescription
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return spec_js;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get return value specs of a method
|
|
||||||
function getReturn(spec_c, details, method, parent) {
|
|
||||||
var retType = getType(getText(spec_c, 'type'), parent);
|
|
||||||
var retDescription = (details ? getText(details, 'description') : '');
|
|
||||||
return ((retType == 'void') ? {} : {
|
|
||||||
type: retType,
|
|
||||||
description: retDescription
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get paramater specs of a method
|
|
||||||
function getParams(spec_c, details, method, parent) {
|
|
||||||
var spec_js = {};
|
|
||||||
_.each(spec_c, function(param) {
|
|
||||||
try {
|
|
||||||
var paramType = getType(getText(getChild(param, 'type'), 'type'), parent);
|
|
||||||
var paramName = getText(getChild(param, 'declname'), 'name');
|
|
||||||
spec_js[paramName] = { type: paramType };
|
|
||||||
} catch(e) {
|
|
||||||
if (paramType == '...') {
|
|
||||||
spec_js['arguments'] = { type: paramType };
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
_.each(details, function(param) {
|
|
||||||
var getParamName = function(p) { return getText(getChild(getChild(p, 'parameternamelist'), 'parametername'), 'name'); }
|
|
||||||
var paramName = getParamName(param);
|
|
||||||
var paramDescription = getText(getChild(param, 'parameterdescription'), 'description');
|
|
||||||
if (_.has(spec_js, paramName)) {
|
|
||||||
spec_js[paramName].description = paramDescription;
|
|
||||||
} else {
|
|
||||||
var msg = ' has documentation for an unknown parameter: ' + paramName + '. ';
|
|
||||||
var suggestions = _.difference(_.keys(spec_js), _.map(details, getParamName));
|
|
||||||
var msgAddendum = (!_.isEmpty(suggestions) ? ('Did you mean ' + suggestions.join(', or ') + '?') : '');
|
|
||||||
console.log('Warning: ' + (parent ? (parent + '.') : '') + method + msg + msgAddendum);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return spec_js;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the equivalent javascript type from the given c type
|
|
||||||
function getType(type_c, parent) {
|
|
||||||
var type_js = type_c;
|
|
||||||
_.find(xml2js.TYPEMAPS, function(to, from) {
|
|
||||||
var pattern = new RegExp(from, 'i');
|
|
||||||
if (type_c.search(pattern) == 0) {
|
|
||||||
type_js = to;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (isPointer(type_js)) {
|
|
||||||
var dataType = getPointerDataType(type_js);
|
|
||||||
var className = parent.toLowerCase();
|
|
||||||
if (_.has(xml2js.ARRAY_TYPEMAPS, dataType) && _.contains(xml2js.ARRAY_TYPEMAPS[dataType].classes, className)) {
|
|
||||||
type_js = xml2js.ARRAY_TYPEMAPS[dataType].arrayType;
|
|
||||||
} else if (_.has(xml2js.POINTER_TYPEMAPS, className) && _.has(xml2js.POINTER_TYPEMAPS[className], dataType)) {
|
|
||||||
type_js = xml2js.POINTER_TYPEMAPS[className][dataType];
|
|
||||||
} else if (_.has(xml2js.CLASSES, dataType)) { // TODO: verify that swig does this mapping
|
|
||||||
type_js = dataType;
|
|
||||||
} else {
|
|
||||||
type_js = dataType + ' *'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return type_js;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// verify that all types associated with the method are valid
|
|
||||||
function hasValidTypes(methodSpec, methodName, parent) {
|
|
||||||
var valid = true;
|
|
||||||
var msg = (xml2js.opts.strict ? ' is omitted from JS documentation.' : ' has invalid type(s).');
|
|
||||||
var printIgnoredMethodOnce = _.once(function() { console.log(methodName + msg); });
|
|
||||||
_.each(methodSpec.params, function(paramSpec, paramName) {
|
|
||||||
if (!isValidType(paramSpec.type, parent)) {
|
|
||||||
valid = false;
|
|
||||||
printIgnoredMethodOnce();
|
|
||||||
console.log(' Error: parameter ' + paramName + ' has invalid type ' + typeToString(paramSpec.type));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!_.isEmpty(methodSpec.return) && !isValidType(methodSpec.return.type, parent)) {
|
|
||||||
valid = false;
|
|
||||||
printIgnoredMethodOnce();
|
|
||||||
console.log(' Error: returns invalid type ' + typeToString(methodSpec.return.type));
|
|
||||||
}
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// verify that type of variable is valid
|
|
||||||
function ofValidType(varSpec, varName, parent) {
|
|
||||||
if (isValidType(varSpec.type, parent)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
var msgAddendum = (xml2js.opts.strict ? ' Omitted from JS documentation.' : '');
|
|
||||||
console.log('Error: ' + varName + ' is of invalid type ' + typeToString(varSpec.type) + '.' + msgAddendum);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// verify whether the given type is valid JS
|
|
||||||
function isValidType(type, parent) {
|
|
||||||
return (_.contains(_.values(xml2js.TYPEMAPS), type) ||
|
|
||||||
_.has(xml2js.CLASSES, type) ||
|
|
||||||
_.has(xml2js.ENUMS_BY_GROUP, type) ||
|
|
||||||
_.contains(['Buffer', 'Function', 'mraa_result_t'], type) ||
|
|
||||||
_.has((parent ? xml2js.CLASSES[parent].enums_by_group : []), type) ||
|
|
||||||
isValidPointerType(type, parent));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function isValidPointerType(type, parent) {
|
|
||||||
var className = parent.toLowerCase();
|
|
||||||
var arrayTypemap = _.find(xml2js.ARRAY_TYPEMAPS, function(to) { return to.arrayType == type; });
|
|
||||||
var valid = ((arrayTypemap && _.contains(arrayTypemap.classes, className)) ||
|
|
||||||
(_.has(xml2js.POINTER_TYPEMAPS, className) && (_.contains(_.values(xml2js.POINTER_TYPEMAPS[className]), type))));
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// determines whether a type looks like a c pointer
|
|
||||||
function isPointer(type) {
|
|
||||||
return (type.search(/\w+\s*(\*|&)$/) != -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// remove extraneous whitespace from pointer types as canonical representation
|
|
||||||
function normalizePointer(ptr) {
|
|
||||||
return ptr.replace(/\s*$/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the data type of a pointer (e.g. int is the data type of int*)
|
|
||||||
function getPointerDataType(ptr) {
|
|
||||||
return ptr.replace(/\s*(\*|&)$/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// print more human friendly type for error messages
|
|
||||||
function typeToString(type) {
|
|
||||||
return type.replace('*', '*');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the detailed description of a method's parameters
|
|
||||||
function getParamsDetails(spec_c) {
|
|
||||||
var paras = getChildren(spec_c, 'para');
|
|
||||||
var details = _.find(_.map(paras, function(para) {
|
|
||||||
return getChild(para, 'parameterlist');
|
|
||||||
}), function(obj) { return (obj != undefined); });
|
|
||||||
return (details ? details.children : undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the detailed description of a method's return value
|
|
||||||
function getReturnDetails(spec_c) {
|
|
||||||
var paras = getChildren(spec_c, 'para');
|
|
||||||
return _.find(_.map(paras, function(para) {
|
|
||||||
return getChild(para, 'simplesect');
|
|
||||||
}), function(obj) { return ((obj != undefined) && (getAttr(obj, 'kind') == 'return')); });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get (and flatten) the text of the given object
|
|
||||||
function getText(obj, why) {
|
|
||||||
// TODO: links ignored for now, patched for types for
|
|
||||||
var GENERATE_LINK = function(x) { return x + ' '; }
|
|
||||||
return _.reduce(obj.children, function(text, elem) {
|
|
||||||
if (_.isString(elem)) {
|
|
||||||
return text += elem.trim() + ' ';
|
|
||||||
} else if (_.isPlainObject(elem)) {
|
|
||||||
switch(elem.name) {
|
|
||||||
case 'para':
|
|
||||||
return text += getText(elem, why) + ' \n';
|
|
||||||
case 'ref':
|
|
||||||
return text += GENERATE_LINK(getText(elem, why));
|
|
||||||
case 'parameterlist':
|
|
||||||
case 'simplesect':
|
|
||||||
return text; // to be handled elsewhere
|
|
||||||
case 'programlisting':
|
|
||||||
case 'htmlonly':
|
|
||||||
return text; // ignored
|
|
||||||
// TODO: html doesn't seem to work for yuidoc, using markdown for now
|
|
||||||
case 'itemizedlist':
|
|
||||||
return text += '\n' + getText(elem, why) + ' \n \n';
|
|
||||||
case 'listitem':
|
|
||||||
return text += '+ ' + getText(elem, why) + '\n';
|
|
||||||
case 'bold':
|
|
||||||
return text += '__' + getText(elem, why).trim() + '__ ';
|
|
||||||
case 'ulink':
|
|
||||||
return text += '[' + getText(elem, why).trim() + '](' + getAttr(elem, 'url').trim() + ') ';
|
|
||||||
case 'image':
|
|
||||||
// TODO: copy images over; hard coded for now
|
|
||||||
var fn = getAttr(elem, 'name');
|
|
||||||
return text += ' \n \n ';
|
|
||||||
case 'linebreak':
|
|
||||||
return text += ' \n';
|
|
||||||
case 'ndash':
|
|
||||||
return text += '– ';
|
|
||||||
default:
|
|
||||||
// TODO: incomplete list of doxygen xsd implemented
|
|
||||||
console.warn('NYI Unknown Object Type: ' + elem.name);
|
|
||||||
return text;
|
|
||||||
//throw new Error('NYI Unknown Object Type: ' + elem.name);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error('NYI Unknown Type: ' + (typeof elem));
|
|
||||||
}
|
|
||||||
}, '').trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the value of attribute with the given name of the given object
|
|
||||||
function getAttr(obj, name) {
|
|
||||||
return _.find(obj.attr, function(item) {
|
|
||||||
return item.name == name;
|
|
||||||
}).value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get the child object with the given name of the given object
|
|
||||||
function getChild(obj, name) {
|
|
||||||
return _.find(obj.children, function(child) {
|
|
||||||
return child.name == name;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get all children objects with the given name of the given object
|
|
||||||
function getChildren(obj, name) {
|
|
||||||
return _.filter(obj.children, function(child) {
|
|
||||||
return child.name == name;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// debug helper: print untruncated object
|
|
||||||
function printObj(obj) {
|
|
||||||
console.log(util.inspect(obj, false, null));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = xml2js;
|
|
@ -33,7 +33,7 @@ lcm1602-i2c.cxx Lcm1602_i2cSample.java lcm1602-i2c.js lcm1602-i2c.py
|
|||||||
ldt0028.cxx LDT0028Sample.java ldt0028.js ldt0028.py
|
ldt0028.cxx LDT0028Sample.java ldt0028.js ldt0028.py
|
||||||
light.cxx LightSample.java light.js light.py
|
light.cxx LightSample.java light.js light.py
|
||||||
lol.cxx LoLSample.java lol.js lol.py
|
lol.cxx LoLSample.java lol.js lol.py
|
||||||
lsm303.cxx LSM303Sample.java lsm303.js lsm303.py
|
lsm303dlh.cxx LSM303DLHSample.java lsm303dlh.js lsm303dlh.py
|
||||||
m24lr64e.cxx M24LR64ESample.java m24lr64e.js m24lr64e.py
|
m24lr64e.cxx M24LR64ESample.java m24lr64e.js m24lr64e.py
|
||||||
max44000.cxx MAX44000Sample.java max44000.js max44000.py
|
max44000.cxx MAX44000Sample.java max44000.js max44000.py
|
||||||
mic.cxx MicrophoneSample.java mic.js mic.py
|
mic.cxx MicrophoneSample.java mic.js mic.py
|
||||||
|
@ -50,6 +50,11 @@ function (add_example example_src)
|
|||||||
# Parse function parameters
|
# Parse function parameters
|
||||||
cmake_parse_arguments(add_example "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
cmake_parse_arguments(add_example "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
# Attempt to remove this example source file from a list of example
|
||||||
|
# sources. This allows for handling special case examples.
|
||||||
|
list (REMOVE_ITEM example_src_list ${example_src})
|
||||||
|
set (example_src_list ${example_src_list} PARENT_SCOPE)
|
||||||
|
|
||||||
# Get the base filename from the full filename
|
# Get the base filename from the full filename
|
||||||
# For file /some/path/to/sensorfoo-bar.c, example_name = sensorfoo-bar
|
# For file /some/path/to/sensorfoo-bar.c, example_name = sensorfoo-bar
|
||||||
get_filename_component(example_name ${example_src} NAME_WE)
|
get_filename_component(example_name ${example_src} NAME_WE)
|
||||||
@ -84,7 +89,7 @@ function (add_example example_src)
|
|||||||
# If a dependency target does NOT exist, print a warning and skip
|
# If a dependency target does NOT exist, print a warning and skip
|
||||||
foreach(_dep_target ${lib_target_names})
|
foreach(_dep_target ${lib_target_names})
|
||||||
if (NOT TARGET ${_dep_target})
|
if (NOT TARGET ${_dep_target})
|
||||||
message(STATUS "Missing CMake target (${_dep_target}), skipping example ${example_src}")
|
message(STATUS "Example ${example_src} is missing a required CMake target (${_dep_target}), skipping...")
|
||||||
return()
|
return()
|
||||||
endif ()
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
@ -96,10 +101,6 @@ function (add_example example_src)
|
|||||||
foreach(_dep_target ${lib_target_names})
|
foreach(_dep_target ${lib_target_names})
|
||||||
target_link_libraries(${this_target_name} ${_dep_target} ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(${this_target_name} ${_dep_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
|
||||||
# Special case...
|
|
||||||
list (REMOVE_ITEM example_src_list ${example_src})
|
|
||||||
set (example_src_list ${example_src_list} PARENT_SCOPE)
|
|
||||||
endfunction (add_example example_src)
|
endfunction (add_example example_src)
|
||||||
|
|
||||||
# Add subdirectories if BUILDEXAMPLES=on
|
# Add subdirectories if BUILDEXAMPLES=on
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include "buzzer.hpp"
|
#include "buzzer.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -29,15 +29,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
upm::HCSR04 *sonar = NULL;
|
int shouldRun = true;
|
||||||
|
|
||||||
void
|
void
|
||||||
sig_handler(int signo)
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
printf("got signal\n");
|
|
||||||
if (signo == SIGINT) {
|
if (signo == SIGINT) {
|
||||||
printf("exiting application\n");
|
shouldRun = false;
|
||||||
sonar->m_doWork = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,20 +43,20 @@ sig_handler(int signo)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
sonar = new upm::HCSR04(5, 6);
|
upm::HCSR04 *sonar = new upm::HCSR04(2, 4);
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
for(;;){
|
while(shouldRun){
|
||||||
std::cout << "get distance" << std::endl;
|
std::cout << "get distance" << std::endl;
|
||||||
double distance = sonar->getDistance(CM);
|
double distance = sonar->getDistance(HCSR04_CM);
|
||||||
std::cout << "distance " << distance << std::endl;
|
std::cout << "distance " << distance << std::endl;
|
||||||
sleep(5);
|
sleep(2);
|
||||||
}
|
}
|
||||||
|
std::cout << "Exiting... " << std::endl;
|
||||||
|
|
||||||
delete sonar;
|
delete sonar;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -46,19 +46,25 @@ int main(int argc, char **argv)
|
|||||||
// Instantiate a IMS instance using i2c bus 0 and default address
|
// Instantiate a IMS instance using i2c bus 0 and default address
|
||||||
upm::IMS sensor(0);
|
upm::IMS sensor(0);
|
||||||
|
|
||||||
|
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
|
||||||
while (shouldRun)
|
while (shouldRun)
|
||||||
{
|
{
|
||||||
std::cout << "Version: "
|
std::cout << std::hex << "Version: 0x"
|
||||||
<< sensor.get_version()
|
<< sensor.get_version()
|
||||||
<< " light: "
|
<< " light: 0x"
|
||||||
<< sensor.get_light()
|
<< sensor.get_light()
|
||||||
<< " moisture: "
|
<< " moisture: 0x"
|
||||||
<< sensor.get_moisture()
|
<< sensor.get_moisture()
|
||||||
<< " temp: "
|
<< " temp: "
|
||||||
<< sensor.get_temperature()
|
<< sensor.get_temperature()
|
||||||
<< " C"
|
<< " C"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
// Change the address and continue
|
||||||
|
if (i2c_addr_cur >= 128) i2c_addr_cur = 1;
|
||||||
|
std::cout << "Changing device address to 0x" << i2c_addr_cur
|
||||||
|
<< std::endl;
|
||||||
|
sensor.reset_i2c_address(i2c_addr_cur++);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -23,7 +23,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "jhd1313m1.hpp"
|
#include "jhd1313m1.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
@ -64,7 +67,7 @@ main(int argc, char **argv)
|
|||||||
// Echo via printf
|
// Echo via printf
|
||||||
printf("Hello World %d rgb: 0x%02x%02x%02x\n", ndx++, r, g, b);
|
printf("Hello World %d rgb: 0x%02x%02x%02x\n", ndx++, r, g, b);
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -41,7 +41,7 @@ sig_handler(int signo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
data_callback(char* data)
|
data_callback(char* data, void* args)
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
accelerometer->extract3Axis(data, &x, &y, &z);
|
accelerometer->extract3Axis(data, &x, &y, &z);
|
||||||
|
@ -41,7 +41,7 @@ sig_handler(int signo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
data_callback(char* data)
|
data_callback(char* data, void* args)
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
if (gyroscope->extract3Axis(data, &x, &y, &z)) {
|
if (gyroscope->extract3Axis(data, &x, &y, &z)) {
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lcm1602.hpp"
|
#include "lcm1602.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
@ -32,16 +33,16 @@ main(int argc, char **argv)
|
|||||||
lcd->setCursor(0,0);
|
lcd->setCursor(0,0);
|
||||||
lcd->write("Hello World");
|
lcd->write("Hello World");
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
sleep(3);
|
upm_delay(3);
|
||||||
lcd->setCursor(1,2);
|
lcd->setCursor(1,2);
|
||||||
lcd->write("Hello World");
|
lcd->write("Hello World");
|
||||||
sleep(3);
|
upm_delay(3);
|
||||||
lcd->setCursor(2,4);
|
lcd->setCursor(2,4);
|
||||||
lcd->write("Hello World");
|
lcd->write("Hello World");
|
||||||
sleep(3);
|
upm_delay(3);
|
||||||
lcd->setCursor(3,6);
|
lcd->setCursor(3,6);
|
||||||
lcd->write("Hello World");
|
lcd->write("Hello World");
|
||||||
sleep(3);
|
upm_delay(3);
|
||||||
delete lcd;
|
delete lcd;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <lcm1602.hpp>
|
#include "lcm1602.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
@ -47,7 +48,7 @@ main(int argc, char **argv)
|
|||||||
lcd->write("Hello World");
|
lcd->write("Hello World");
|
||||||
|
|
||||||
printf("Sleeping for 5 seconds\n");
|
printf("Sleeping for 5 seconds\n");
|
||||||
sleep(5);
|
upm_delay(5);
|
||||||
delete lcd;
|
delete lcd;
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
return 0;
|
return 0;
|
||||||
|
64
examples/c++/lidarlitev3.cxx
Normal file
64
examples/c++/lidarlitev3.cxx
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Author: Saloni Jain <saloni.jain@tcs.com>
|
||||||
|
* Author: Niti Rohilla <niti.rohilla@tcs.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "lidarlitev3.hpp"
|
||||||
|
|
||||||
|
volatile int doWork = 0;
|
||||||
|
|
||||||
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT) {
|
||||||
|
printf("\nCtrl-C received.\n");
|
||||||
|
doWork = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Register signal handler
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
upm::LIDARLITEV3 *sensor = new upm::LIDARLITEV3(0, ADDR);
|
||||||
|
|
||||||
|
while (!doWork) {
|
||||||
|
std::cout << "Distance = " << sensor->getDistance () << std::endl;
|
||||||
|
usleep (50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
std::cout << "exiting application" << std::endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
81
examples/c++/lis2ds12.cxx
Normal file
81
examples/c++/lis2ds12.cxx
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* 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 "lis2ds12.hpp"
|
||||||
|
|
||||||
|
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 an LIS2DS12 using default I2C parameters
|
||||||
|
upm::LIS2DS12 sensor;
|
||||||
|
|
||||||
|
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||||
|
// for CS: LIS2DS12(0, -1, 10);
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
|
cout << "Accelerometer x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " g"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||||
|
<< " C / " << sensor.getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
usleep(250000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
87
examples/c++/lsm303agr.cxx
Normal file
87
examples/c++/lsm303agr.cxx
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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 "lsm303agr.hpp"
|
||||||
|
|
||||||
|
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 an LSM303AGR using default I2C parameters
|
||||||
|
upm::LSM303AGR sensor;
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
|
cout << "Accelerometer x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " g"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
sensor.getMagnetometer(&x, &y, &z);
|
||||||
|
cout << "Magnetometer x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " uT"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Temperature: "
|
||||||
|
<< sensor.getTemperature()
|
||||||
|
<< " C"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
usleep(250000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
87
examples/c++/lsm303d.cxx
Normal file
87
examples/c++/lsm303d.cxx
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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 "lsm303d.hpp"
|
||||||
|
|
||||||
|
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 an LSM303D using default I2C parameters
|
||||||
|
upm::LSM303D sensor;
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
|
cout << "Accelerometer x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " g"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
sensor.getMagnetometer(&x, &y, &z);
|
||||||
|
cout << "Magnetometer x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " uT"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Temperature: "
|
||||||
|
<< sensor.getTemperature()
|
||||||
|
<< " C"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
usleep(250000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -25,19 +25,19 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
#include "lsm303.hpp"
|
#include "lsm303dlh.hpp"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// Instantiate LSM303 compass on I2C
|
// Instantiate LSM303DLH compass on I2C
|
||||||
upm::LSM303 *sensor = new upm::LSM303(0);
|
upm::LSM303DLH *sensor = new upm::LSM303DLH(0);
|
||||||
|
|
||||||
// Get the coordinate data
|
// Get the coordinate data
|
||||||
sensor->getCoordinates();
|
sensor->getCoordinates();
|
||||||
int16_t* coor = sensor->getRawCoorData(); // in XYZ order.
|
int16_t* coor = sensor->getRawCoorData(); // in XYZ order.
|
||||||
// The sensor returns XZY, but the driver compensates and makes it XYZ
|
// The sensor returns XZY, but the driver compensates and makes it XYZ
|
||||||
|
|
||||||
// Print out the X, Y, and Z coordinate data using two different methods
|
// Print out the X, Y, and Z coordinate data using two different methods
|
||||||
std::cout << "coor: rX " << (int)coor[0]
|
std::cout << "coor: rX " << (int)coor[0]
|
||||||
<< " - rY " << (int)coor[1]
|
<< " - rY " << (int)coor[1]
|
88
examples/c++/lsm6ds3h.cxx
Normal file
88
examples/c++/lsm6ds3h.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 "lsm6ds3h.hpp"
|
||||||
|
|
||||||
|
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 an LSM6DS3H using default I2C parameters
|
||||||
|
upm::LSM6DS3H sensor;
|
||||||
|
|
||||||
|
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||||
|
// for CS: LSM6DS3H(0, -1, 10);
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
|
cout << "Accelerometer x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " g"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
sensor.getGyroscope(&x, &y, &z);
|
||||||
|
cout << "Gyroscope x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " dps"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||||
|
<< " C / " << sensor.getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
usleep(250000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
88
examples/c++/lsm6dsl.cxx
Normal file
88
examples/c++/lsm6dsl.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 "lsm6dsl.hpp"
|
||||||
|
|
||||||
|
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 an LSM6DSL using default I2C parameters
|
||||||
|
upm::LSM6DSL sensor;
|
||||||
|
|
||||||
|
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||||
|
// for CS: LSM6DSL(0, -1, 10);
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
|
cout << "Accelerometer x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " g"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
sensor.getGyroscope(&x, &y, &z);
|
||||||
|
cout << "Gyroscope x: " << x
|
||||||
|
<< " y: " << y
|
||||||
|
<< " z: " << z
|
||||||
|
<< " dps"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||||
|
<< " C / " << sensor.getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
usleep(250000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -27,6 +27,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "max30100.hpp"
|
#include "max30100.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ int main()
|
|||||||
{
|
{
|
||||||
float t;
|
float t;
|
||||||
case 1:
|
case 1:
|
||||||
std::cout << "Temp: " << temp->getTemp() << "° " << (temp->isCelsius()? "Celsius" : "Fahrenheit")<< std::endl;
|
std::cout << "Temp: " << temp->getTemp() << "* " << (temp->isCelsius()? "Celsius" : "Fahrenheit")<< std::endl;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
cout << "shutdown sensor (sleep mode)" << endl;
|
cout << "shutdown sensor (sleep mode)" << endl;
|
||||||
|
@ -40,7 +40,7 @@ sig_handler(int signo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
data_callback(char* data)
|
data_callback(char* data, void* args)
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
double azimuth;
|
double azimuth;
|
||||||
|
121
examples/c++/rn2903-p2p-rx.cxx
Normal file
121
examples/c++/rn2903-p2p-rx.cxx
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 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 <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "rn2903.hpp"
|
||||||
|
#include "upm_utilities.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 (argc > 1)
|
||||||
|
defaultDev = argv[1];
|
||||||
|
|
||||||
|
cout << "Using device: " << defaultDev << endl;
|
||||||
|
|
||||||
|
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||||
|
upm::RN2903 sensor (defaultDev, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
// To use an internal UART understood by MRAA, use the following
|
||||||
|
// to inititialize rather than the above, which by default uses a
|
||||||
|
// tty path.
|
||||||
|
//
|
||||||
|
// upm::RN2903 sensor = upm::RN2903(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
// enable debugging
|
||||||
|
// sensor.setDebug(true);
|
||||||
|
|
||||||
|
// get version
|
||||||
|
if (sensor.command("sys get ver"))
|
||||||
|
{
|
||||||
|
cout << "Failed to retrieve device version string" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
cout << "Firmware version: " << sensor.getResponse() << endl;
|
||||||
|
|
||||||
|
cout << "Hardware EUI: " << sensor.getHardwareEUI() << endl;
|
||||||
|
|
||||||
|
// For this example, we will just try to receive a packet
|
||||||
|
// transmitted by the p2p-tx rn2903 example. We reset the
|
||||||
|
// device to defaults, and we do not make any adjustments to the
|
||||||
|
// radio configuration. You will probably want to do so for a
|
||||||
|
// real life application.
|
||||||
|
|
||||||
|
// The first thing to do is to suspend the LoRaWAN stack on the device.
|
||||||
|
sensor.macPause();
|
||||||
|
|
||||||
|
// We will use continuous mode (window_size 0), though the default
|
||||||
|
// radio watch dog timer will expire every 15 seconds. We will
|
||||||
|
// just loop here.
|
||||||
|
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
cout << "Waiting for packet..." << endl;
|
||||||
|
RN2903_RESPONSE_T rv;
|
||||||
|
rv = sensor.radioRx(0);
|
||||||
|
if (rv)
|
||||||
|
{
|
||||||
|
cout << "radioRx() failed with code " << int(rv) << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string resp = sensor.getResponse();
|
||||||
|
string payload = sensor.getRadioRxPayload();
|
||||||
|
if (!payload.size())
|
||||||
|
cout << "Got response: '" << resp << "'" << endl;
|
||||||
|
else
|
||||||
|
cout <<"Got payload: '"
|
||||||
|
<< sensor.fromHex(payload)
|
||||||
|
<< "'"
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
125
examples/c++/rn2903-p2p-tx.cxx
Normal file
125
examples/c++/rn2903-p2p-tx.cxx
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 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 <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "rn2903.hpp"
|
||||||
|
#include "upm_utilities.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 (argc > 1)
|
||||||
|
defaultDev = argv[1];
|
||||||
|
|
||||||
|
cout << "Using device: " << defaultDev << endl;
|
||||||
|
|
||||||
|
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||||
|
upm::RN2903 sensor(defaultDev, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
// To use an internal UART understood by MRAA, use the following
|
||||||
|
// to inititialize rather than the above, which by default uses a
|
||||||
|
// tty path.
|
||||||
|
//
|
||||||
|
// upm::RN2903 sensor = upm::RN2903(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
// enable debugging
|
||||||
|
// sensor.setDebug(true);
|
||||||
|
|
||||||
|
// get version
|
||||||
|
if (sensor.command("sys get ver"))
|
||||||
|
{
|
||||||
|
cout << "Failed to retrieve device version string" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
cout << "Firmware version: " << sensor.getResponse() << endl;
|
||||||
|
|
||||||
|
cout << "Hardware EUI: " << sensor.getHardwareEUI() << endl;
|
||||||
|
|
||||||
|
// For this example, we will just try transmitting a packet over
|
||||||
|
// LoRa. We reset the device to defaults, and we do not make any
|
||||||
|
// adjustments to the radio configuration. You will probably want
|
||||||
|
// to do so for a real life application.
|
||||||
|
|
||||||
|
// The first thing to do is to suspend the LoRaWAN stack on the device.
|
||||||
|
sensor.macPause();
|
||||||
|
|
||||||
|
// the default radio watchdog timer is set for 15 seconds, so we
|
||||||
|
// will send a packet every 10 seconds. In reality, local
|
||||||
|
// restrictions limit the amount of time on the air, so in a real
|
||||||
|
// implementation, you would not want to send packets that
|
||||||
|
// frequently.
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
ostringstream output;
|
||||||
|
output << "Ping " << count++;
|
||||||
|
|
||||||
|
// All payloads must be hex encoded
|
||||||
|
string payload = sensor.toHex(output.str());
|
||||||
|
|
||||||
|
cout << "Transmitting a packet, data: '"
|
||||||
|
<< output.str()
|
||||||
|
<< "' -> hex: '"
|
||||||
|
<< payload
|
||||||
|
<< "'"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
RN2903_RESPONSE_T rv;
|
||||||
|
rv = sensor.radioTx(payload);
|
||||||
|
|
||||||
|
if (rv == RN2903_RESPONSE_OK)
|
||||||
|
cout << "Transmit successful." << endl;
|
||||||
|
else
|
||||||
|
cout << "Transmit failed with code " << int(rv) << endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
upm_delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
136
examples/c++/rn2903.cxx
Normal file
136
examples/c++/rn2903.cxx
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 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 <string>
|
||||||
|
|
||||||
|
#include "rn2903.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
string defaultDev = "/dev/ttyUSB0";
|
||||||
|
if (argc > 1)
|
||||||
|
defaultDev = argv[1];
|
||||||
|
|
||||||
|
cout << "Using device: " << defaultDev << endl;
|
||||||
|
|
||||||
|
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||||
|
upm::RN2903 sensor(defaultDev, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
// To use an internal UART understood by MRAA, use the following
|
||||||
|
// to inititialize rather than the above, which by default uses a
|
||||||
|
// tty path.
|
||||||
|
//
|
||||||
|
// upm::RN2903 sensor = upm::RN2903(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
// enable debugging
|
||||||
|
// sensor.setDebug(true);
|
||||||
|
|
||||||
|
// get version
|
||||||
|
if (sensor.command("sys get ver"))
|
||||||
|
{
|
||||||
|
cout << "Failed to retrieve device version string" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
cout << "Firmware version: " << sensor.getResponse() << endl;
|
||||||
|
|
||||||
|
cout << "Hardware EUI: " << sensor.getHardwareEUI() << endl;
|
||||||
|
|
||||||
|
// we can support two types of join, OTAA and ABP. Each requires
|
||||||
|
// that certain parameters be set first. We will only attempt ABP
|
||||||
|
// joining with this example since it's the only one that can
|
||||||
|
// succeed without actual configuration. In both cases, if you
|
||||||
|
// are actually attempting to join a real LoRaWAN network, you
|
||||||
|
// must change the parameters below to match the network you are
|
||||||
|
// attempting to join.
|
||||||
|
|
||||||
|
// For OTAA, you need to supply valid Device EUI, Application EUI,
|
||||||
|
// and Application key:
|
||||||
|
//
|
||||||
|
// sensor.setDeviceEUI("0011223344556677");
|
||||||
|
// sensor.setApplicationEUI("0011223344556677");
|
||||||
|
// sensor.setApplicationKey("01234567012345670123456701234567");
|
||||||
|
//
|
||||||
|
// RN2903_JOIN_STATUS_T rv = sensor.join(RN2903_JOIN_TYPE_OTAA);
|
||||||
|
// A successful join will return RN2903_JOIN_STATUS_ACCEPTED (0).
|
||||||
|
// cout << "JOIN: got rv " << int(rv) << endl;
|
||||||
|
|
||||||
|
// Try an ABP join. Note, these parameters are made up. For a
|
||||||
|
// real network, you will want to use the correct values
|
||||||
|
// obviously. For an ABP join, you need to supply the Device
|
||||||
|
// Address, Network Session Key, and the Application Session Key.
|
||||||
|
|
||||||
|
sensor.setDeviceAddr("00112233");
|
||||||
|
sensor.setNetworkSessionKey("00112233001122330011223300112233");
|
||||||
|
sensor.setApplicationSessionKey("00112233001122330011223300112233");
|
||||||
|
|
||||||
|
RN2903_JOIN_STATUS_T rv = sensor.join(RN2903_JOIN_TYPE_ABP);
|
||||||
|
if (rv == RN2903_JOIN_STATUS_ACCEPTED)
|
||||||
|
{
|
||||||
|
cout << "Join successful." << endl;
|
||||||
|
|
||||||
|
// All transmit payloads must be hex encoded strings, so
|
||||||
|
// pretend we have a temperature sensor that gave us a value
|
||||||
|
// of 25.6 C, and we want to transmit it.
|
||||||
|
string faketemp = "25.6";
|
||||||
|
cout << "Transmitting a packet..." << endl;
|
||||||
|
|
||||||
|
RN2903_MAC_TX_STATUS_T trv;
|
||||||
|
trv = sensor.macTx(RN2903_MAC_MSG_TYPE_UNCONFIRMED,
|
||||||
|
1, // port number
|
||||||
|
sensor.toHex(faketemp));
|
||||||
|
|
||||||
|
if (trv == RN2903_MAC_TX_STATUS_TX_OK)
|
||||||
|
cout << "Transmit successful." << endl;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// check to see if we got a downlink packet
|
||||||
|
if (trv == RN2903_MAC_TX_STATUS_RX_RECEIVED)
|
||||||
|
{
|
||||||
|
cout << "Transmit successful, downlink packet received: "
|
||||||
|
<< sensor.getResponse();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "Transmit failed with code " << int(trv) << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "Join failed with code " << int(rv) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
103
examples/c++/tca9548a.cxx
Normal file
103
examples/c++/tca9548a.cxx
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Author: Gerard Vidal <gerard.vidal@ens-lyon.fr>
|
||||||
|
* 2017 IFE ENS de Lyon
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 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 <sstream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "tca9548a.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This examble is built to multiplex channel 2 and Channel 4
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
showAllPorts(upm::TCA9548A *multiplex) {
|
||||||
|
int i;
|
||||||
|
char ports [80];
|
||||||
|
std::string convert;
|
||||||
|
for (i = 0; i<8; i++) {
|
||||||
|
if (multiplex->getPort(i))
|
||||||
|
strcat (ports, "1." );
|
||||||
|
else
|
||||||
|
strcat (ports,"0.");
|
||||||
|
}
|
||||||
|
cout << "Ports: " << ports;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Instantiate a TCA9548A instance of i2c multiplexer
|
||||||
|
upm::TCA9548A *multiplex = new upm::TCA9548A(0);
|
||||||
|
|
||||||
|
//Clean
|
||||||
|
multiplex->disableAllPorts();
|
||||||
|
cout << "All ports disabled.";
|
||||||
|
|
||||||
|
// Open i2c bus on multiplexer channel 4
|
||||||
|
multiplex->setPort(4,multiplex->ENABLED,multiplex->EXCLUSIVE);
|
||||||
|
cout << "Port 4 enabled with exclusive access.";
|
||||||
|
showAllPorts(multiplex);
|
||||||
|
|
||||||
|
// Close com with channel 4
|
||||||
|
multiplex->disableAllPorts();
|
||||||
|
|
||||||
|
// Open i2c bus on multiplexer channel 2
|
||||||
|
multiplex->setPort(2,multiplex->ENABLED,multiplex->EXCLUSIVE);
|
||||||
|
cout << "Port 2 enabled with exclusive access.";
|
||||||
|
showAllPorts(multiplex);
|
||||||
|
|
||||||
|
//close com with channel 2
|
||||||
|
multiplex->disableAllPorts();
|
||||||
|
|
||||||
|
// Open 2 i2c bus on multiplexer channel 4 and channel2
|
||||||
|
multiplex->setPort(4,multiplex->ENABLED,multiplex->EXCLUSIVE);
|
||||||
|
multiplex->setPort(2,multiplex->ENABLED,multiplex->INCLUSIVE);
|
||||||
|
cout << "Port 4 enabled with exclusive access.";
|
||||||
|
cout << "Port 2 enabled with exclusive access.";
|
||||||
|
showAllPorts(multiplex);
|
||||||
|
|
||||||
|
//close com with all channels
|
||||||
|
multiplex->disableAllPorts();
|
||||||
|
|
||||||
|
// Open i2c bus on all multiplexer channels
|
||||||
|
multiplex->enableAllPorts();
|
||||||
|
cout << "All ports enabled.";
|
||||||
|
showAllPorts(multiplex);
|
||||||
|
|
||||||
|
//close com with all channels
|
||||||
|
multiplex->disableAllPorts();
|
||||||
|
|
||||||
|
delete multiplex;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -44,8 +44,13 @@ int main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
std::cout << "Initializing test-application..." << std::endl;
|
std::cout << "Initializing test-application..." << std::endl;
|
||||||
|
|
||||||
|
// please make sure that you have the right i2c address for your device
|
||||||
|
// the correct range of addresses is 0x40 - 0x47
|
||||||
// Instantiate an TMP006 instance on bus 1
|
// Instantiate an TMP006 instance on bus 1
|
||||||
upm::TMP006 *mySensor = new upm::TMP006(1);
|
upm::TMP006 *mySensor = new upm::TMP006(1, TMP006_CONFIG_CR_DEF, TMP006_I2C_ADDRESS);
|
||||||
|
|
||||||
|
// you can also get basic tmp007 functionality by initializing it as follows
|
||||||
|
//upm::TMP006 *mySensor = new upm::TMP006(1, TMP006_CONFIG_CR_DEF, TMP007_I2C_ADDRESS);
|
||||||
|
|
||||||
// activate periodic measurements
|
// activate periodic measurements
|
||||||
mySensor->setActive();
|
mySensor->setActive();
|
||||||
@ -53,8 +58,8 @@ int main(int argc, char **argv)
|
|||||||
// update and print available values every second
|
// update and print available values every second
|
||||||
while (run)
|
while (run)
|
||||||
{
|
{
|
||||||
// Print out temperature value in °C
|
// Print out temperature value in *C
|
||||||
std::cout << "Temperature: " << mySensor->getTemperature(true) << " °C"
|
std::cout << "Temperature: " << mySensor->getTemperature(true) << " *C"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
58
examples/c++/veml6070.cxx
Normal file
58
examples/c++/veml6070.cxx
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2017 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 "veml6070.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate an VEML6070 sensor on i2c bus 0
|
||||||
|
upm::VEML6070* veml = new upm::VEML6070(0);
|
||||||
|
while (shouldRun) {
|
||||||
|
cout << "Retrieved UV value: " << veml->getUVIntensity() << endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete veml;
|
||||||
|
return 0;
|
||||||
|
}
|
@ -7,5 +7,5 @@ file (GLOB example_src_list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.c")
|
|||||||
|
|
||||||
# - Create an executable for all other src files in this directory -------------
|
# - Create an executable for all other src files in this directory -------------
|
||||||
foreach (_example_src ${example_src_list})
|
foreach (_example_src ${example_src_list})
|
||||||
add_example(${_example_src} SUFFIX "-c")
|
add_example(${_example_src} TARGETS utilities-c SUFFIX "-c")
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
48
examples/c/hcsr04.c
Normal file
48
examples/c/hcsr04.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2017 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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "hcsr04.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
hcsr04_context dev = hcsr04_init(2,4);
|
||||||
|
if(dev == NULL) {
|
||||||
|
printf("Unable to intialize the sensor\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double distance;
|
||||||
|
while(1) {
|
||||||
|
distance = hcsr04_get_distance(dev, HCSR04_CM);
|
||||||
|
printf("Distance detected: %f\n", distance);
|
||||||
|
upm_delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -50,6 +50,8 @@ int main()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
|
||||||
|
|
||||||
// Every second, sample the sensor outputs
|
// Every second, sample the sensor outputs
|
||||||
while (shouldRun)
|
while (shouldRun)
|
||||||
{
|
{
|
||||||
@ -62,8 +64,19 @@ int main()
|
|||||||
printf("Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C\n",
|
printf("Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C\n",
|
||||||
version, light, moisture, temp/10.0);
|
version, light, moisture, temp/10.0);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
printf("Failed to read IMS sensor data...\n");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change the address and continue
|
||||||
|
if (i2c_addr_cur >= 128) i2c_addr_cur = 1;
|
||||||
|
printf("Changing device address to 0x%02x\n", i2c_addr_cur);
|
||||||
|
if (ims_reset_i2c_address(sensor, i2c_addr_cur++) != UPM_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("Failed to change IMS I2C address...\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
upm_delay(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lcm1602.h"
|
#include "lcm1602.h"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lcm1602.h"
|
#include "lcm1602.h"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
100
examples/c/lis2ds12.c
Normal file
100
examples/c/lis2ds12.c
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "lis2ds12.h"
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
#if defined(CONFIG_BOARD_ARDUINO_101_SSS)
|
||||||
|
// ARDUINO_101_SSS (ARC core) must use I2C
|
||||||
|
// Instantiate a LIS2DS12 instance using default i2c bus and address
|
||||||
|
lis2ds12_context sensor = lis2ds12_init(LIS2DS12_DEFAULT_I2C_BUS,
|
||||||
|
LIS2DS12_DEFAULT_I2C_ADDR, -1);
|
||||||
|
#elif defined(CONFIG_BOARD_ARDUINO_101)
|
||||||
|
// ARDUINO_101 (Quark core) must use SPI
|
||||||
|
// Instantiate a LIS2DS12 instance using default SPI bus and pin 10 as CS
|
||||||
|
lis2ds12_context sensor = lis2ds12_init(LIS2DS12_DEFAULT_SPI_BUS,
|
||||||
|
-1, 10);
|
||||||
|
#else
|
||||||
|
// everything else use I2C by default
|
||||||
|
// Instantiate a LIS2DS12 instance using default i2c bus and address
|
||||||
|
lis2ds12_context sensor = lis2ds12_init(LIS2DS12_DEFAULT_I2C_BUS,
|
||||||
|
LIS2DS12_DEFAULT_I2C_ADDR, -1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sensor)
|
||||||
|
{
|
||||||
|
printf("lis2ds12_init() failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
if (lis2ds12_update(sensor))
|
||||||
|
{
|
||||||
|
printf("lis2ds12_update() failed\n");
|
||||||
|
lis2ds12_close(sensor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lis2ds12_get_accelerometer(sensor, &x, &y, &z);
|
||||||
|
printf("Acceleration x: %f y: %f z: %f g\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
printf("Compensation Temperature: %f C\n\n",
|
||||||
|
lis2ds12_get_temperature(sensor));
|
||||||
|
|
||||||
|
upm_delay_ms(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Exiting...\n");
|
||||||
|
|
||||||
|
lis2ds12_close(sensor);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
90
examples/c/lsm303agr.c
Normal file
90
examples/c/lsm303agr.c
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "lsm303agr.h"
|
||||||
|
|
||||||
|
bool 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 LSM303AGR instance using default i2c bus and addresses
|
||||||
|
lsm303agr_context sensor = lsm303agr_init(LSM303AGR_DEFAULT_I2C_BUS,
|
||||||
|
LSM303AGR_DEFAULT_ACC_ADDR,
|
||||||
|
LSM303AGR_DEFAULT_MAG_ADDR);
|
||||||
|
|
||||||
|
if (!sensor)
|
||||||
|
{
|
||||||
|
printf("lsm303agr_init() failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
if (lsm303agr_update(sensor))
|
||||||
|
{
|
||||||
|
printf("lsm303agr_update() failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lsm303agr_get_accelerometer(sensor, &x, &y, &z);
|
||||||
|
printf("Accelerometer x: %f y: %f z: %f g\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
lsm303agr_get_magnetometer(sensor, &x, &y, &z);
|
||||||
|
printf("Magnetometer x: %f y: %f z: %f uT\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
printf("Temperature: %f C\n\n", lsm303agr_get_temperature(sensor));
|
||||||
|
|
||||||
|
upm_delay_ms(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Exiting...\n");
|
||||||
|
|
||||||
|
lsm303agr_close(sensor);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
89
examples/c/lsm303d.c
Normal file
89
examples/c/lsm303d.c
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "lsm303d.h"
|
||||||
|
|
||||||
|
bool 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 LSM303D instance using default i2c bus and addresses
|
||||||
|
lsm303d_context sensor = lsm303d_init(LSM303D_DEFAULT_I2C_BUS,
|
||||||
|
LSM303D_DEFAULT_I2C_ADDR);
|
||||||
|
|
||||||
|
if (!sensor)
|
||||||
|
{
|
||||||
|
printf("lsm303d_init() failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
if (lsm303d_update(sensor))
|
||||||
|
{
|
||||||
|
printf("lsm303d_update() failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lsm303d_get_accelerometer(sensor, &x, &y, &z);
|
||||||
|
printf("Accelerometer x: %f y: %f z: %f g\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
lsm303d_get_magnetometer(sensor, &x, &y, &z);
|
||||||
|
printf("Magnetometer x: %f y: %f z: %f uT\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
printf("Temperature: %f C\n\n", lsm303d_get_temperature(sensor));
|
||||||
|
|
||||||
|
upm_delay_ms(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Exiting...\n");
|
||||||
|
|
||||||
|
lsm303d_close(sensor);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
104
examples/c/lsm6ds3h.c
Normal file
104
examples/c/lsm6ds3h.c
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "lsm6ds3h.h"
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
#if defined(CONFIG_BOARD_ARDUINO_101_SSS)
|
||||||
|
// ARDUINO_101_SSS (ARC core) must use I2C
|
||||||
|
// Instantiate a LSM6DS3H instance using default i2c bus and address
|
||||||
|
lsm6ds3h_context sensor = lsm6ds3h_init(LSM6DS3H_DEFAULT_I2C_BUS,
|
||||||
|
LSM6DS3H_DEFAULT_I2C_ADDR, -1);
|
||||||
|
#elif defined(CONFIG_BOARD_ARDUINO_101)
|
||||||
|
// ARDUINO_101 (Quark core) must use SPI
|
||||||
|
// Instantiate a LSM6DS3H instance using default SPI bus and pin 10 as CS
|
||||||
|
lsm6ds3h_context sensor = lsm6ds3h_init(LSM6DS3H_DEFAULT_SPI_BUS,
|
||||||
|
-1, 10);
|
||||||
|
#else
|
||||||
|
// everything else use I2C by default
|
||||||
|
// Instantiate a LSM6DS3H instance using default i2c bus and address
|
||||||
|
lsm6ds3h_context sensor = lsm6ds3h_init(LSM6DS3H_DEFAULT_I2C_BUS,
|
||||||
|
LSM6DS3H_DEFAULT_I2C_ADDR, -1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sensor)
|
||||||
|
{
|
||||||
|
printf("lsm6ds3h_init() failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
if (lsm6ds3h_update(sensor))
|
||||||
|
{
|
||||||
|
printf("lsm6ds3h_update() failed\n");
|
||||||
|
lsm6ds3h_close(sensor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lsm6ds3h_get_accelerometer(sensor, &x, &y, &z);
|
||||||
|
printf("Acceleration x: %f y: %f z: %f g\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
lsm6ds3h_get_gyroscope(sensor, &x, &y, &z);
|
||||||
|
printf("Gyroscope x: %f y: %f z: %f dps\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
printf("Compensation Temperature: %f C\n\n",
|
||||||
|
lsm6ds3h_get_temperature(sensor));
|
||||||
|
|
||||||
|
upm_delay_ms(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Exiting...\n");
|
||||||
|
|
||||||
|
lsm6ds3h_close(sensor);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
104
examples/c/lsm6dsl.c
Normal file
104
examples/c/lsm6dsl.c
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "lsm6dsl.h"
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
#if defined(CONFIG_BOARD_ARDUINO_101_SSS)
|
||||||
|
// ARDUINO_101_SSS (ARC core) must use I2C
|
||||||
|
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||||
|
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_I2C_BUS,
|
||||||
|
LSM6DSL_DEFAULT_I2C_ADDR, -1);
|
||||||
|
#elif defined(CONFIG_BOARD_ARDUINO_101)
|
||||||
|
// ARDUINO_101 (Quark core) must use SPI
|
||||||
|
// Instantiate a LSM6DSL instance using default SPI bus and pin 10 as CS
|
||||||
|
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_SPI_BUS,
|
||||||
|
-1, 10);
|
||||||
|
#else
|
||||||
|
// everything else use I2C by default
|
||||||
|
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||||
|
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_I2C_BUS,
|
||||||
|
LSM6DSL_DEFAULT_I2C_ADDR, -1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sensor)
|
||||||
|
{
|
||||||
|
printf("lsm6dsl_init() failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now output data every 250 milliseconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
|
||||||
|
if (lsm6dsl_update(sensor))
|
||||||
|
{
|
||||||
|
printf("lsm6dsl_update() failed\n");
|
||||||
|
lsm6dsl_close(sensor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lsm6dsl_get_accelerometer(sensor, &x, &y, &z);
|
||||||
|
printf("Acceleration x: %f y: %f z: %f g\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
lsm6dsl_get_gyroscope(sensor, &x, &y, &z);
|
||||||
|
printf("Gyroscope x: %f y: %f z: %f dps\n",
|
||||||
|
x, y, z);
|
||||||
|
|
||||||
|
printf("Compensation Temperature: %f C\n\n",
|
||||||
|
lsm6dsl_get_temperature(sensor));
|
||||||
|
|
||||||
|
upm_delay_ms(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Exiting...\n");
|
||||||
|
|
||||||
|
lsm6dsl_close(sensor);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
137
examples/c/rn2903-p2p-rx.c
Normal file
137
examples/c/rn2903-p2p-rx.c
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 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 <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "rn2903.h"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "upm_platform.h"
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(UPM_PLATFORM_ZEPHYR) && !defined(CONFIG_STDOUT_CONSOLE)
|
||||||
|
# define printf printk
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
char *defaultDev = "/dev/ttyUSB0";
|
||||||
|
if (argc > 1)
|
||||||
|
defaultDev = argv[1];
|
||||||
|
|
||||||
|
printf("Using device: %s\n", defaultDev);
|
||||||
|
|
||||||
|
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||||
|
#if defined(UPM_PLATFORM_ZEPHYR)
|
||||||
|
rn2903_context sensor = rn2903_init(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
#else
|
||||||
|
rn2903_context sensor = rn2903_init_tty(defaultDev,
|
||||||
|
RN2903_DEFAULT_BAUDRATE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// To use an internal UART understood by MRAA, use the following
|
||||||
|
// to inititialize rather than the above, which by default uses a
|
||||||
|
// tty path.
|
||||||
|
//
|
||||||
|
// rn2903_context sensor = rn2903_init(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
if (!sensor)
|
||||||
|
{
|
||||||
|
printf("rn2903_init_tty() failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable debugging
|
||||||
|
// rn2903_set_debug(sensor, true);
|
||||||
|
|
||||||
|
// get version
|
||||||
|
if (rn2903_command(sensor, "sys get ver"))
|
||||||
|
{
|
||||||
|
printf("Failed to retrieve device version string\n");
|
||||||
|
rn2903_close(sensor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("Firmware version: %s\n", rn2903_get_response(sensor));
|
||||||
|
|
||||||
|
printf("Hardware EUI: %s\n", rn2903_get_hardware_eui(sensor));
|
||||||
|
|
||||||
|
// For this example, we will just try to receive a packet
|
||||||
|
// transmitted by the p2p-tx rn2903 example. We reset the
|
||||||
|
// device to defaults, and we do not make any adjustments to the
|
||||||
|
// radio configuration. You will probably want to do so for a
|
||||||
|
// real life application.
|
||||||
|
|
||||||
|
// The first thing to do is to suspend the LoRaWAN stack on the device.
|
||||||
|
if (rn2903_mac_pause(sensor))
|
||||||
|
{
|
||||||
|
printf("Failed to pause the LoRaWAN stack\n");
|
||||||
|
rn2903_close(sensor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We will use continuous mode (window_size 0), though the default
|
||||||
|
// radio watch dog timer will expire every 15 seconds. We will
|
||||||
|
// just loop here.
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
printf("Waiting for packet...\n");
|
||||||
|
RN2903_RESPONSE_T rv;
|
||||||
|
rv = rn2903_radio_rx(sensor, 0);
|
||||||
|
if (rv)
|
||||||
|
{
|
||||||
|
printf("rn2903_radio_rx() failed with code (%d)\n", rv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const char *resp = rn2903_get_response(sensor);
|
||||||
|
const char *payload = rn2903_get_radio_rx_payload(sensor);
|
||||||
|
if (!payload)
|
||||||
|
printf("Got response: '%s'\n", resp);
|
||||||
|
else
|
||||||
|
printf("Got payload: '%s'\n",
|
||||||
|
rn2903_from_hex(sensor, payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Exiting\n");
|
||||||
|
|
||||||
|
rn2903_close(sensor);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
139
examples/c/rn2903-p2p-tx.c
Normal file
139
examples/c/rn2903-p2p-tx.c
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 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 <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "rn2903.h"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "upm_platform.h"
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(UPM_PLATFORM_ZEPHYR) && !defined(CONFIG_STDOUT_CONSOLE)
|
||||||
|
# define printf printk
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
char *defaultDev = "/dev/ttyUSB0";
|
||||||
|
if (argc > 1)
|
||||||
|
defaultDev = argv[1];
|
||||||
|
|
||||||
|
printf("Using device: %s\n", defaultDev);
|
||||||
|
|
||||||
|
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||||
|
#if defined(UPM_PLATFORM_ZEPHYR)
|
||||||
|
rn2903_context sensor = rn2903_init(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
#else
|
||||||
|
rn2903_context sensor = rn2903_init_tty(defaultDev,
|
||||||
|
RN2903_DEFAULT_BAUDRATE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// To use an internal UART understood by MRAA, use the following
|
||||||
|
// to inititialize rather than the above, which by default uses a
|
||||||
|
// tty path.
|
||||||
|
//
|
||||||
|
// rn2903_context sensor = rn2903_init(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
if (!sensor)
|
||||||
|
{
|
||||||
|
printf("rn2903_init_tty() failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable debugging
|
||||||
|
// rn2903_set_debug(sensor, true);
|
||||||
|
|
||||||
|
// get version
|
||||||
|
if (rn2903_command(sensor, "sys get ver"))
|
||||||
|
{
|
||||||
|
printf("Failed to retrieve device version string\n");
|
||||||
|
rn2903_close(sensor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("Firmware version: %s\n", rn2903_get_response(sensor));
|
||||||
|
|
||||||
|
printf("Hardware EUI: %s\n", rn2903_get_hardware_eui(sensor));
|
||||||
|
|
||||||
|
// For this example, we will just try transmitting a packet over
|
||||||
|
// LoRa. We reset the device to defaults, and we do not make any
|
||||||
|
// adjustments to the radio configuration. You will probably want
|
||||||
|
// to do so for a real life application.
|
||||||
|
|
||||||
|
// The first thing to do is to suspend the LoRaWAN stack on the device.
|
||||||
|
if (rn2903_mac_pause(sensor))
|
||||||
|
{
|
||||||
|
printf("Failed to pause the LoRaWAN stack\n");
|
||||||
|
rn2903_close(sensor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the default radio watchdog timer is set for 15 seconds, so we
|
||||||
|
// will send a packet every 10 seconds. In reality, local
|
||||||
|
// restrictions limit the amount of time on the air, so in a real
|
||||||
|
// implementation, you would not want to send packets that
|
||||||
|
// frequently.
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
char pingbuf[32] = {};
|
||||||
|
snprintf(pingbuf, 32, "Ping %d", count++);
|
||||||
|
// All payloads must be hex encoded
|
||||||
|
const char *payload = rn2903_to_hex(sensor, pingbuf, strlen(pingbuf));
|
||||||
|
|
||||||
|
printf("Transmitting a packet, data: '%s' -> hex: '%s'\n",
|
||||||
|
pingbuf, payload);
|
||||||
|
|
||||||
|
RN2903_RESPONSE_T rv;
|
||||||
|
rv = rn2903_radio_tx(sensor, payload);
|
||||||
|
|
||||||
|
if (rv == RN2903_RESPONSE_OK)
|
||||||
|
printf("Transmit successful.\n");
|
||||||
|
else
|
||||||
|
printf("Transmit failed with code %d.\n", rv);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
upm_delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Exiting\n");
|
||||||
|
|
||||||
|
rn2903_close(sensor);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
153
examples/c/rn2903.c
Normal file
153
examples/c/rn2903.c
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 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 <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "rn2903.h"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
#include "upm_platform.h"
|
||||||
|
|
||||||
|
#if defined(UPM_PLATFORM_ZEPHYR) && !defined(CONFIG_STDOUT_CONSOLE)
|
||||||
|
# define printf printk
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
char *defaultDev = "/dev/ttyUSB0";
|
||||||
|
if (argc > 1)
|
||||||
|
defaultDev = argv[1];
|
||||||
|
|
||||||
|
printf("Using device: %s\n", defaultDev);
|
||||||
|
|
||||||
|
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||||
|
#if defined(UPM_PLATFORM_ZEPHYR)
|
||||||
|
rn2903_context sensor = rn2903_init(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
#else
|
||||||
|
rn2903_context sensor = rn2903_init_tty(defaultDev,
|
||||||
|
RN2903_DEFAULT_BAUDRATE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// To use an internal UART understood by MRAA, use the following
|
||||||
|
// to inititialize rather than the above, which by default uses a
|
||||||
|
// tty path.
|
||||||
|
//
|
||||||
|
// rn2903_context sensor = rn2903_init(0, RN2903_DEFAULT_BAUDRATE);
|
||||||
|
|
||||||
|
if (!sensor)
|
||||||
|
{
|
||||||
|
printf("rn2903_init_tty() failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable debugging
|
||||||
|
// rn2903_set_debug(sensor, true);
|
||||||
|
|
||||||
|
// get version
|
||||||
|
if (rn2903_command(sensor, "sys get ver"))
|
||||||
|
{
|
||||||
|
printf("Failed to retrieve device version string\n");
|
||||||
|
rn2903_close(sensor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("Firmware version: %s\n", rn2903_get_response(sensor));
|
||||||
|
|
||||||
|
printf("Hardware EUI: %s\n", rn2903_get_hardware_eui(sensor));
|
||||||
|
|
||||||
|
// we can support two types of join, OTAA and ABP. Each requires
|
||||||
|
// that certain parameters be set first. We will only attempt ABP
|
||||||
|
// joining with this example since it's the only one that can
|
||||||
|
// succeed without actual configuration. In both cases, if you
|
||||||
|
// are actually attempting to join a real LoRaWAN network, you
|
||||||
|
// must change the parameters below to match the network you are
|
||||||
|
// attempting to join.
|
||||||
|
|
||||||
|
// For OTAA, you need to supply valid Device EUI, Application EUI,
|
||||||
|
// and Application key:
|
||||||
|
//
|
||||||
|
// rn2903_set_device_eui(sensor, "0011223344556677");
|
||||||
|
// rn2903_set_application_eui(sensor, "0011223344556677");
|
||||||
|
// rn2903_set_application_key(sensor, "01234567012345670123456701234567");
|
||||||
|
//
|
||||||
|
// RN2903_JOIN_STATUS_T rv = rn2903_join(sensor, RN2903_JOIN_TYPE_OTAA);
|
||||||
|
// A successful join will return RN2903_JOIN_STATUS_ACCEPTED (0).
|
||||||
|
// printf("JOIN: got rv %d\n", rv);
|
||||||
|
|
||||||
|
// Try an ABP join. Note, these parameters are made up. For a
|
||||||
|
// real network, you will want to use the correct values
|
||||||
|
// obviously. For an ABP join, you need to supply the Device
|
||||||
|
// Address, Network Session Key, and the Application Session Key.
|
||||||
|
|
||||||
|
rn2903_set_device_addr(sensor, "00112233");
|
||||||
|
rn2903_set_network_session_key(sensor, "00112233001122330011223300112233");
|
||||||
|
rn2903_set_application_session_key(sensor,
|
||||||
|
"00112233001122330011223300112233");
|
||||||
|
RN2903_JOIN_STATUS_T rv = rn2903_join(sensor, RN2903_JOIN_TYPE_ABP);
|
||||||
|
if (rv == RN2903_JOIN_STATUS_ACCEPTED)
|
||||||
|
{
|
||||||
|
printf("Join successful.\n");
|
||||||
|
|
||||||
|
// All transmit payloads must be hex encoded strings, so
|
||||||
|
// pretend we have a temperature sensor that gave us a value
|
||||||
|
// of 25.6 C, and we want to transmit it.
|
||||||
|
const char *faketemp = "25.6";
|
||||||
|
printf("Transmitting a packet....\n");
|
||||||
|
|
||||||
|
RN2903_MAC_TX_STATUS_T trv;
|
||||||
|
trv = rn2903_mac_tx(sensor, RN2903_MAC_MSG_TYPE_UNCONFIRMED,
|
||||||
|
1, // port number
|
||||||
|
rn2903_to_hex(sensor, faketemp, strlen(faketemp)));
|
||||||
|
|
||||||
|
if (trv == RN2903_MAC_TX_STATUS_TX_OK)
|
||||||
|
printf("Transmit successful.\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// check to see if we got a downlink packet
|
||||||
|
if (trv == RN2903_MAC_TX_STATUS_RX_RECEIVED)
|
||||||
|
{
|
||||||
|
printf("Transmit successful, downlink packet received: %s\n",
|
||||||
|
rn2903_get_response(sensor));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Transmit failed with code %d.\n", trv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Join failed with code %d.\n", rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Exiting\n");
|
||||||
|
|
||||||
|
rn2903_close(sensor);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
49
examples/c/veml6070.c
Normal file
49
examples/c/veml6070.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2017 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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "veml6070.h"
|
||||||
|
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
veml6070_context dev = veml6070_init(0);
|
||||||
|
if(dev == NULL) {
|
||||||
|
printf("Unable to initialize sensor\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
upm_delay(1);
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
printf("Retrieved UV Value: %d\n", veml6070_get_uv_intensity(dev));
|
||||||
|
upm_delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -31,7 +31,7 @@ public class ADC121C021Sample {
|
|||||||
upm_adc121c021.ADC121C021 adc = new upm_adc121c021.ADC121C021(0);
|
upm_adc121c021.ADC121C021 adc = new upm_adc121c021.ADC121C021(0);
|
||||||
|
|
||||||
// An analog sensor, such as a Grove light sensor,
|
// An analog sensor, such as a Grove light sensor,
|
||||||
// must be attached to the adc·
|
// must be attached to the adc
|
||||||
// Prints the value and corresponding voltage every 50 milliseconds
|
// Prints the value and corresponding voltage every 50 milliseconds
|
||||||
while (true) {
|
while (true) {
|
||||||
int val = adc.value();
|
int val = adc.value();
|
||||||
@ -43,4 +43,4 @@ public class ADC121C021Sample {
|
|||||||
// ! [Interesting]
|
// ! [Interesting]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
46
examples/java/BMA220Sample.java
Normal file
46
examples/java/BMA220Sample.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 BMA220Sample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate an BMA220 using default parameters (bus 0, addr 0x0a)
|
||||||
|
upm_bma220.BMA220 sensor = new upm_bma220.BMA220();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
float acc[];
|
||||||
|
|
||||||
|
sensor.update();
|
||||||
|
acc = sensor.getAccelerometer();
|
||||||
|
System.out.print("Accelerometer: ");
|
||||||
|
System.out.println("AX: " + acc[0] + "AY: " + acc[1] + "AZ: " + acc[2]);
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import upm_bma250e.BMA250E;
|
import upm_bma250e.BMA250E;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
public class BMA250E_Example
|
public class BMA250E_Example
|
||||||
{
|
{
|
||||||
@ -42,7 +44,7 @@ public class BMA250E_Example
|
|||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
upm_bma250e.floatVector dataA = sensor.getAccelerometer();
|
AbstractList<Float> dataA = sensor.getAccelerometer();
|
||||||
|
|
||||||
System.out.println("Accelerometer x: " + dataA.get(0)
|
System.out.println("Accelerometer x: " + dataA.get(0)
|
||||||
+ " y: " + dataA.get(1)
|
+ " y: " + dataA.get(1)
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import upm_bmx055.BMC150;
|
import upm_bmx055.BMC150;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
public class BMC150_Example
|
public class BMC150_Example
|
||||||
{
|
{
|
||||||
@ -40,7 +42,7 @@ public class BMC150_Example
|
|||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
upm_bmx055.floatVector data = sensor.getAccelerometer();
|
AbstractList<Float> data = sensor.getAccelerometer();
|
||||||
|
|
||||||
System.out.println("Accelerometer x: " + data.get(0)
|
System.out.println("Accelerometer x: " + data.get(0)
|
||||||
+ " y: " + data.get(1)
|
+ " y: " + data.get(1)
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import upm_bmp280.*;
|
import upm_bmp280.*;
|
||||||
|
import upm_interfaces.*;
|
||||||
|
|
||||||
public class BME280_InterfaceExample
|
public class BME280_InterfaceExample
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import upm_bmg160.BMG160;
|
import upm_bmg160.BMG160;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
public class BMG160_Example
|
public class BMG160_Example
|
||||||
{
|
{
|
||||||
@ -42,7 +44,7 @@ public class BMG160_Example
|
|||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
upm_bmg160.floatVector data = sensor.getGyroscope();
|
AbstractList<Float> data = sensor.getGyroscope();
|
||||||
|
|
||||||
System.out.println("Gyroscope x: " + data.get(0)
|
System.out.println("Gyroscope x: " + data.get(0)
|
||||||
+ " y: " + data.get(1)
|
+ " y: " + data.get(1)
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import upm_bmx055.BMI055;
|
import upm_bmx055.BMI055;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
public class BMI055_Example
|
public class BMI055_Example
|
||||||
{
|
{
|
||||||
@ -40,7 +42,7 @@ public class BMI055_Example
|
|||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
upm_bmx055.floatVector data = sensor.getAccelerometer();
|
AbstractList<Float> data = sensor.getAccelerometer();
|
||||||
|
|
||||||
System.out.println("Accelerometer x: " + data.get(0)
|
System.out.println("Accelerometer x: " + data.get(0)
|
||||||
+ " y: " + data.get(1)
|
+ " y: " + data.get(1)
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import upm_bmm150.BMM150;
|
import upm_bmm150.BMM150;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
public class BMM150_Example
|
public class BMM150_Example
|
||||||
{
|
{
|
||||||
@ -44,7 +46,7 @@ public class BMM150_Example
|
|||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
upm_bmm150.floatVector data = sensor.getMagnetometer();
|
AbstractList<Float> data = sensor.getMagnetometer();
|
||||||
|
|
||||||
System.out.println("Magnetometer x: " + data.get(0)
|
System.out.println("Magnetometer x: " + data.get(0)
|
||||||
+ " y: " + data.get(1)
|
+ " y: " + data.get(1)
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import upm_bmx055.BMX055;
|
import upm_bmx055.BMX055;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
public class BMX055_Example
|
public class BMX055_Example
|
||||||
{
|
{
|
||||||
@ -40,7 +42,7 @@ public class BMX055_Example
|
|||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
upm_bmx055.floatVector data = sensor.getAccelerometer();
|
AbstractList<Float> data = sensor.getAccelerometer();
|
||||||
|
|
||||||
System.out.println("Accelerometer x: " + data.get(0)
|
System.out.println("Accelerometer x: " + data.get(0)
|
||||||
+ " y: " + data.get(1)
|
+ " y: " + data.get(1)
|
||||||
|
@ -17,13 +17,26 @@ macro(add_example_with_path example_name jar_path jar_name)
|
|||||||
add_dependencies(${example_name} javaupm_${jar_name})
|
add_dependencies(${example_name} javaupm_${jar_name})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
macro(add_example_multiple_jars example_name example_jar_name jar_name_list)
|
||||||
|
set(example_src "${example_name}.java")
|
||||||
|
|
||||||
|
set(list_of_jars "")
|
||||||
|
foreach(jar_name ${jar_name_list})
|
||||||
|
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_name}/upm_${jar_name}.jar")
|
||||||
|
list(APPEND list_of_jars ${example_jar})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${list_of_jars})
|
||||||
|
add_dependencies(${example_name} javaupm_${example_jar_name})
|
||||||
|
endmacro()
|
||||||
|
|
||||||
add_example(A110X_intrSample a110x)
|
add_example(A110X_intrSample a110x)
|
||||||
add_example(A110XSample a110x)
|
add_example(A110XSample a110x)
|
||||||
add_example(ADC121C021Sample adc121c021)
|
add_example(ADC121C021Sample adc121c021)
|
||||||
add_example(Adxl345Sample adxl345)
|
add_example(Adxl345Sample adxl345)
|
||||||
add_example(Apds9002 apds9002)
|
add_example(Apds9002 apds9002)
|
||||||
add_example(BISS0001Sample biss0001)
|
add_example(BISS0001Sample biss0001)
|
||||||
add_example(BMPX8XSample bmpx8x)
|
add_example_multiple_jars(BMPX8XSample bmpx8x "bmpx8x;interfaces")
|
||||||
add_example(BuzzerSample buzzer)
|
add_example(BuzzerSample buzzer)
|
||||||
add_example(CJQ4435Sample cjq4435)
|
add_example(CJQ4435Sample cjq4435)
|
||||||
add_example(DS1307Sample ds1307)
|
add_example(DS1307Sample ds1307)
|
||||||
@ -86,7 +99,7 @@ add_example(Itg3200Sample itg3200)
|
|||||||
add_example(Joystick12Sample joystick12)
|
add_example(Joystick12Sample joystick12)
|
||||||
add_example(LDT0028Sample ldt0028)
|
add_example(LDT0028Sample ldt0028)
|
||||||
add_example(LoLSample lol)
|
add_example(LoLSample lol)
|
||||||
add_example(LSM303Sample lsm303)
|
add_example(LSM303DLHSample lsm303dlh)
|
||||||
add_example(M24LR64ESample m24lr64e)
|
add_example(M24LR64ESample m24lr64e)
|
||||||
add_example(MAX44000Sample max44000)
|
add_example(MAX44000Sample max44000)
|
||||||
add_example(MHZ16Sample mhz16)
|
add_example(MHZ16Sample mhz16)
|
||||||
@ -111,7 +124,9 @@ add_example(RotaryEncoderSample rotaryencoder)
|
|||||||
add_example(RPR220_intrSample rpr220)
|
add_example(RPR220_intrSample rpr220)
|
||||||
add_example(RPR220Sample rpr220)
|
add_example(RPR220Sample rpr220)
|
||||||
add_example(ST7735Sample st7735)
|
add_example(ST7735Sample st7735)
|
||||||
add_example(StepMotorSample stepmotor)
|
if (NOT ANDROID)
|
||||||
|
add_example(StepMotorSample stepmotor)
|
||||||
|
endif ()
|
||||||
add_example(TM1637Sample tm1637)
|
add_example(TM1637Sample tm1637)
|
||||||
add_example(TP401Sample gas)
|
add_example(TP401Sample gas)
|
||||||
add_example(TSL2561Sample tsl2561)
|
add_example(TSL2561Sample tsl2561)
|
||||||
@ -145,8 +160,10 @@ if (BACNET_FOUND)
|
|||||||
add_example(T8100_Example t8100)
|
add_example(T8100_Example t8100)
|
||||||
add_example(TB7300_Example tb7300)
|
add_example(TB7300_Example tb7300)
|
||||||
endif()
|
endif()
|
||||||
add_example(VCAP_Example vcap)
|
if (JPEG_FOUND)
|
||||||
add_example(BMP280_Example bmp280)
|
add_example(VCAP_Example vcap)
|
||||||
|
endif()
|
||||||
|
add_example_multiple_jars(BMP280_Example bmp280 "bmp280;interfaces")
|
||||||
add_example(BNO055_Example bno055)
|
add_example(BNO055_Example bno055)
|
||||||
add_example(BMX055_Example bmx055)
|
add_example(BMX055_Example bmx055)
|
||||||
add_example(NMEAGPS_Example nmea_gps)
|
add_example(NMEAGPS_Example nmea_gps)
|
||||||
@ -161,7 +178,7 @@ add_example(ECEZO_Example ecezo)
|
|||||||
add_example(IMS_Example ims)
|
add_example(IMS_Example ims)
|
||||||
add_example(MB704X_Example mb704x)
|
add_example(MB704X_Example mb704x)
|
||||||
add_example(MCP2515_Example mcp2515)
|
add_example(MCP2515_Example mcp2515)
|
||||||
add_example(Ads1015Sample ads1x15)
|
add_example_multiple_jars(Ads1015Sample ads1x15 "ads1x15;interfaces")
|
||||||
add_example(MAX30100_Example max30100)
|
add_example(MAX30100_Example max30100)
|
||||||
add_example(Ads1115Sample ads1x15)
|
add_example(Ads1115Sample ads1x15)
|
||||||
add_example(SensorTemplateSample sensortemplate)
|
add_example(SensorTemplateSample sensortemplate)
|
||||||
@ -169,6 +186,13 @@ add_example(P9813Sample p9813)
|
|||||||
add_example(BMG160_Example bmg160)
|
add_example(BMG160_Example bmg160)
|
||||||
add_example(BMA250E_Example bma250e)
|
add_example(BMA250E_Example bma250e)
|
||||||
add_example(BMM150_Example bmm150)
|
add_example(BMM150_Example bmm150)
|
||||||
|
add_example(LSM303AGR_Example lsm303agr)
|
||||||
|
add_example(LSM303D_Example lsm303d)
|
||||||
|
add_example(VEML6070Sample veml6070)
|
||||||
|
add_example(RN2903_Example rn2903)
|
||||||
|
add_example(LIS2DS12_Example lis2ds12)
|
||||||
|
add_example(LSM6DS3H_Example lsm6ds3h)
|
||||||
|
add_example(LSM6DSL_Example lsm6dsl)
|
||||||
|
|
||||||
add_example_with_path(Jhd1313m1_lcdSample jhd1313m1 jhd1313m1)
|
add_example_with_path(Jhd1313m1_lcdSample jhd1313m1 jhd1313m1)
|
||||||
add_example_with_path(Jhd1313m1Sample jhd1313m1 jhd1313m1)
|
add_example_with_path(Jhd1313m1Sample jhd1313m1 jhd1313m1)
|
||||||
@ -176,10 +200,10 @@ add_example_with_path(Lcm1602_i2cSample lcm1602 lcm1602)
|
|||||||
add_example_with_path(Lcm1602_parallelSample lcm1602 lcm1602)
|
add_example_with_path(Lcm1602_parallelSample lcm1602 lcm1602)
|
||||||
add_example_with_path(SSD1308_oledSample lcd i2clcd)
|
add_example_with_path(SSD1308_oledSample lcd i2clcd)
|
||||||
add_example_with_path(SSD1327_oledSample lcd i2clcd)
|
add_example_with_path(SSD1327_oledSample lcd i2clcd)
|
||||||
add_example_with_path(BME280_Example bmp280 bmp280)
|
add_example_multiple_jars(BME280_Example bmp280 "bmp280;interfaces")
|
||||||
|
|
||||||
if(SWIG_VERSION VERSION_GREATER 3.0.8)
|
if(SWIG_VERSION VERSION_GREATER 3.0.8)
|
||||||
add_example_with_path(BME280_InterfaceExample bmp280 bmp280)
|
add_example_multiple_jars(BME280_InterfaceExample bmp280 "bmp280;interfaces")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_example_with_path(BMC150_Example bmx055 bmx055)
|
add_example_with_path(BMC150_Example bmx055 bmx055)
|
||||||
@ -195,3 +219,5 @@ add_example_with_path(NMEAGPS_I2C_Example nmea_gps nmea_gps)
|
|||||||
add_example_with_path(MCP2515_TXRX_Example mcp2515 mcp2515)
|
add_example_with_path(MCP2515_TXRX_Example mcp2515 mcp2515)
|
||||||
add_example_with_path(LE910_Example uartat uartat)
|
add_example_with_path(LE910_Example uartat uartat)
|
||||||
add_example_with_path(SpeakerPWMSample speaker speaker)
|
add_example_with_path(SpeakerPWMSample speaker speaker)
|
||||||
|
add_example_with_path(RN2903_P2P_RX_Example rn2903 rn2903)
|
||||||
|
add_example_with_path(RN2903_P2P_TX_Example rn2903 rn2903)
|
||||||
|
49
examples/java/DFRPHSample.java
Normal file
49
examples/java/DFRPHSample.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 DFRPHSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a DFRPH sensor on analog pin A0, with an analog
|
||||||
|
// reference voltage of 5.0 V
|
||||||
|
upm_dfrph.DFRPH sensor = new upm_dfrph.DFRPH(0, 5.0f);
|
||||||
|
|
||||||
|
// After calibration, set the offset (based on calibration with a pH
|
||||||
|
// 7.0 buffer solution). See the UPM sensor documentation for
|
||||||
|
// calibrations instructions.
|
||||||
|
sensor.setOffset(0.065f);
|
||||||
|
|
||||||
|
// Every second, sample the pH and output it's corresponding
|
||||||
|
// analog voltage.
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Detected volts: = " + sensor.volts());
|
||||||
|
System.out.println("pH value: " + sensor.pH());
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
41
examples/java/GroveUltraSonicSample.java
Normal file
41
examples/java/GroveUltraSonicSample.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 GroveUltraSonicSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
upm_groveultrasonic.GroveUltraSonic sonar = new upm_groveultrasonic.GroveUltraSonic(2);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
int width = sonar.getDistance();
|
||||||
|
System.out.println("Echo width = " + width);
|
||||||
|
System.out.println("Distance inches = " + width / 148.0);
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
@ -23,17 +23,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//NOT TESTED!!!
|
//NOT TESTED!!!
|
||||||
|
import upm_hcsr04.*;
|
||||||
|
|
||||||
public class HCSR04Sample {
|
public class HCSR04Sample {
|
||||||
|
|
||||||
// ! [Interesting]
|
// ! [Interesting]
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
upm_hcsr04.HCSR04 sonar = new upm_hcsr04.HCSR04((short) 5, (short) 6);
|
HCSR04 sonar = new HCSR04((short) 2, (short) 4);
|
||||||
|
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
System.out.println("Get distance");
|
System.out.println("Get distance");
|
||||||
double distance = sonar.getDistance(upm_hcsr04.javaupm_hcsr04Constants.CM);
|
double distance = sonar.getDistance(HCSR04_U.swigToEnum(0));
|
||||||
System.out.println("Distance: " + distance);
|
System.out.println("Distance: " + distance);
|
||||||
|
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
|
@ -59,7 +59,7 @@ public class HMTRPSample {
|
|||||||
// device, and periodically transmit "Hello World".
|
// device, and periodically transmit "Hello World".
|
||||||
|
|
||||||
// If any argument was specified on the command line, do a simple
|
// If any argument was specified on the command line, do a simple
|
||||||
// configuration query and output the results. The radio must be in·
|
// configuration query and output the results. The radio must be in
|
||||||
// CONFIG mode for this to work.
|
// CONFIG mode for this to work.
|
||||||
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
|
@ -22,29 +22,24 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//NOT TESTED!!!
|
|
||||||
public class HTU21DSample {
|
public class HTU21DSample {
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
// ! [Interesting]
|
// ! [Interesting]
|
||||||
float humidity = 0;
|
|
||||||
float temperature = 0;
|
|
||||||
float compRH = 0;
|
|
||||||
|
|
||||||
upm_htu21d.HTU21D sensor = new upm_htu21d.HTU21D(0);
|
upm_htu21d.HTU21D sensor = new upm_htu21d.HTU21D(0);
|
||||||
sensor.testSensor();
|
sensor.testSensor();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
compRH = sensor.getCompRH();
|
sensor.sampleData();
|
||||||
humidity = sensor.getHumidity();
|
|
||||||
temperature = sensor.getTemperature();
|
|
||||||
|
|
||||||
System.out.println("Humidity: " + humidity + ", Temperature: " + temperature
|
System.out.println("Humidity: " + sensor.getHumidity() + "%");
|
||||||
+ ", compensated RH: " + compRH);
|
System.out.println("Compensated RH: " + sensor.getCompRH() + "%");
|
||||||
|
System.out.println("Temperature: " + sensor.getTemperature() + "C");
|
||||||
|
System.out.println("Dew Point: " + sensor.getDewPoint() + "C");
|
||||||
|
|
||||||
Thread.sleep(5000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
// ! [Interesting]
|
// ! [Interesting]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
47
examples/java/I2CLCD_EBOLEDSample.java
Normal file
47
examples/java/I2CLCD_EBOLEDSample.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 I2CLCD_EBOLEDSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate an Edison Block OLED using default values
|
||||||
|
upm_i2clcd.EBOLED lcd = new upm_i2clcd.EBOLED();
|
||||||
|
|
||||||
|
lcd.clear();
|
||||||
|
lcd.setCursor(10, 15);
|
||||||
|
lcd.write("Hello");
|
||||||
|
lcd.setCursor(30, 15);
|
||||||
|
lcd.write("World!");
|
||||||
|
lcd.refresh();
|
||||||
|
|
||||||
|
System.out.println("Sleeping for 5 secconds...");
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
lcd.delete();
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
146
examples/java/I2CLCD_SSD1306Sample.java
Normal file
146
examples/java/I2CLCD_SSD1306Sample.java
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 I2CLCD_SSD1306Sample {
|
||||||
|
|
||||||
|
static private final int[] intel_logo = new int[]{
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -128, -128, -128, -128, 192, 192, 192, 224,
|
||||||
|
224, 224, 224, 240, 240, 248, 248, 120, 120, 120, 120, 60, 60, 60, 60, 60,
|
||||||
|
62, 30, 30, 30, 30, 30, 30, 30, 31, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||||
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 31, 31, 31, 31, 31,
|
||||||
|
30, 62, 62, 62, 62, 126, 126, 124, 124, 252, 252, 248, 248, 240, 240, 240,
|
||||||
|
224, 224, 224, 192, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128,
|
||||||
|
128, 0, 56, 56, 28, 30, 14, 15, 15, 7, 7, 7, 7, 3, 3, 1, 1, 1, 1, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 192, 193, 195, 195,
|
||||||
|
195, 7, 15, 15, 63, 127, 255, 255, 255, 254, 252, 252, 240, 192, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 128, 192, 192, 240, 248, 124, 124, 60, 0, 0, 0, 0, 159, 159,
|
||||||
|
159, 159, 159, 159, 159, 159, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128,
|
||||||
|
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0,
|
||||||
|
0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 128, 128, 128, 128,
|
||||||
|
128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 192, 192, 192, 192, 192, 192, 128,
|
||||||
|
128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
0, 0, 0, 0, 3, 7, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 0, 0, 224, 248, 252, 252, 255, 127, 15, 15, 3, 1, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 15, 15, 15, 15, 15, 15, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 252, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 15, 15,
|
||||||
|
15, 15, 15, 224, 224, 252, 254, 255, 255, 255, 255, 159, 159, 143, 143,
|
||||||
|
135, 135, 143, 159, 255, 255, 255, 255, 255, 255, 252, 248, 0, 0, 0, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,
|
||||||
|
224, 248, 248, 255, 255, 255, 255, 255, 127, 15, 255, 255, 255, 255, 255,
|
||||||
|
255, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0,
|
||||||
|
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 192, 192, 192, 192, 192, 31, 31, 255, 255, 255,
|
||||||
|
255, 255, 255, 231, 231, 199, 199, 199, 199, 199, 199, 199, 199, 231, 231,
|
||||||
|
231, 231, 199, 135, 0, 0, 0, 63, 255, 255, 255, 255, 255, 255, 255, 0, 0,
|
||||||
|
0, 0, 224, 240, 248, 248, 252, 254, 255, 255, 255, 127, 63, 63, 31, 15, 7,
|
||||||
|
7, 1, 0, 0, 63, 63, 255, 255, 255, 255, 255, 240, 192, 192, 128, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||||
|
0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 3, 3, 7, 7, 7,
|
||||||
|
7, 7, 7, 7, 7, 7, 0, 0, 0, 1, 3, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7,
|
||||||
|
7, 7, 3, 3, 3, 1, 0, 0, 0, 0, 1, 3, 3, 7, 135, 135, 135, 192, 192, 0, 0, 7,
|
||||||
|
7, 3, 3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 15,
|
||||||
|
31, 127, 127, 127, 255, 255, 252, 252, 252, 248, 240, 240, 240, 224, 224,
|
||||||
|
224, 192, 192, 192, 192, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 192, 192, 192, 192, 192,
|
||||||
|
224, 224, 224, 224, 240, 240, 240, 240, 248, 248, 248, 248, 252, 252, 252,
|
||||||
|
254, 254, 255, 255, 255, 255, 255, 255, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||||
|
3, 3, 3, 7, 7, 7, 15, 15, 31, 31, 31, 63, 63, 63, 63, 63, 127, 127, 127,
|
||||||
|
127, 127, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||||
|
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||||
|
63, 63, 63, 63, 63, 31, 31, 31, 31, 31, 15, 15, 15, 15, 7, 7, 7, 7, 3, 3,
|
||||||
|
3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
upm_i2clcd.SSD1306 lcd = new upm_i2clcd.SSD1306(0x0, 0x3D);
|
||||||
|
|
||||||
|
byte[] image = new byte[intel_logo.length];
|
||||||
|
for (int i = 0; i < intel_logo.length; i++)
|
||||||
|
image[i] = (byte) intel_logo[i];
|
||||||
|
|
||||||
|
lcd.clear();
|
||||||
|
lcd.stopscroll();
|
||||||
|
lcd.draw(image);
|
||||||
|
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
lcd.clear();
|
||||||
|
lcd.setCursor(2, 0);
|
||||||
|
lcd.write("Hello");
|
||||||
|
lcd.setCursor(3,0);
|
||||||
|
lcd.write("World");
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
|
||||||
|
lcd.invert(true);
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
|
||||||
|
lcd.dim(true);
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
|
||||||
|
lcd.dim(false);
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
|
||||||
|
lcd.invert(false);
|
||||||
|
lcd.startscrollright((short) 0x00, (short) 0x0F);
|
||||||
|
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
lcd.stopscroll();
|
||||||
|
lcd.startscrollleft((short) 0x00, (short) 0x0F);
|
||||||
|
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
lcd.stopscroll();
|
||||||
|
lcd.startscrolldiagleft((short) 0x00, (short) 0x0F);
|
||||||
|
|
||||||
|
Thread.sleep(5000);;
|
||||||
|
|
||||||
|
lcd.stopscroll();
|
||||||
|
lcd.startscrolldiagright((short) 0x00,(short) 0x0F);
|
||||||
|
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
lcd.stopscroll();
|
||||||
|
|
||||||
|
lcd.delete();
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
64
examples/java/LIS2DS12_Example.java
Normal file
64
examples/java/LIS2DS12_Example.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016-2017 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_lis2ds12.*;
|
||||||
|
|
||||||
|
public class LIS2DS12_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a LIS2DS12 instance using default i2c bus and address
|
||||||
|
LIS2DS12 sensor = new LIS2DS12();
|
||||||
|
|
||||||
|
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||||
|
// valid pin for CS:
|
||||||
|
// LIS2DS12(0, -1, 10);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
floatVector dataA = sensor.getAccelerometer();
|
||||||
|
|
||||||
|
System.out.println("Accelerometer x: " + dataA.get(0)
|
||||||
|
+ " y: " + dataA.get(1)
|
||||||
|
+ " z: " + dataA.get(2)
|
||||||
|
+ " g");
|
||||||
|
|
||||||
|
System.out.println("Compensation Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
43
examples/java/LM35Sample.java
Normal file
43
examples/java/LM35Sample.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 LM35Sample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a LM35 on analog pin A0, with a default analog
|
||||||
|
// reference voltage of 5.0
|
||||||
|
upm_lm35.LM35 sensor = new upm_lm35.LM35(0);
|
||||||
|
|
||||||
|
// Every half second, sample the sensor and output the temperature
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Temperature: " + sensor.getTemperature() + " C");
|
||||||
|
Thread.sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
67
examples/java/LSM303AGR_Example.java
Normal file
67
examples/java/LSM303AGR_Example.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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_lsm303agr.LSM303AGR;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
|
public class LSM303AGR_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a LSM303AGR instance using default i2c bus and address
|
||||||
|
LSM303AGR sensor = new LSM303AGR();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
AbstractList<Float> data = sensor.getAccelerometer();
|
||||||
|
|
||||||
|
System.out.println("Accelerometer x: " + data.get(0)
|
||||||
|
+ " y: " + data.get(1)
|
||||||
|
+ " z: " + data.get(2)
|
||||||
|
+ " g");
|
||||||
|
|
||||||
|
data = sensor.getMagnetometer();
|
||||||
|
System.out.println("Magnetometer x: " + data.get(0)
|
||||||
|
+ " y: " + data.get(1)
|
||||||
|
+ " z: " + data.get(2)
|
||||||
|
+ " uT");
|
||||||
|
|
||||||
|
System.out.println("Temperature: "
|
||||||
|
+ sensor.getTemperature());
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
@ -23,16 +23,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//NOT TESTED!!!
|
//NOT TESTED!!!
|
||||||
public class LSM303Sample {
|
public class LSM303DLHSample {
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
// ! [Interesting]
|
// ! [Interesting]
|
||||||
// Instantiate LSM303 compass on I2C
|
// Instantiate LSM303DLH compass on I2C
|
||||||
upm_lsm303.LSM303 sensor = new upm_lsm303.LSM303(0);
|
upm_lsm303dlh.LSM303DLH sensor = new upm_lsm303dlh.LSM303DLH(0);
|
||||||
|
|
||||||
// Get the coordinate data
|
// Get the coordinate data
|
||||||
sensor.getCoordinates();
|
sensor.getCoordinates();
|
||||||
short[] coor = sensor.getRawCoorData(); // in XYZ order.·
|
short[] coor = sensor.getRawCoorData(); // in XYZ order.
|
||||||
// The sensor returns XZY, but the driver compensates and makes it XYZ
|
// The sensor returns XZY, but the driver compensates and makes it XYZ
|
||||||
|
|
||||||
// Print out the X, Y, and Z coordinate data using two different methods
|
// Print out the X, Y, and Z coordinate data using two different methods
|
||||||
@ -56,4 +56,4 @@ public class LSM303Sample {
|
|||||||
// ! [Interesting]
|
// ! [Interesting]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
67
examples/java/LSM303D_Example.java
Normal file
67
examples/java/LSM303D_Example.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* 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_lsm303d.LSM303D;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
|
public class LSM303D_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a LSM303D instance using default i2c bus and address
|
||||||
|
LSM303D sensor = new LSM303D();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
AbstractList<Float> data = sensor.getAccelerometer();
|
||||||
|
|
||||||
|
System.out.println("Accelerometer x: " + data.get(0)
|
||||||
|
+ " y: " + data.get(1)
|
||||||
|
+ " z: " + data.get(2)
|
||||||
|
+ " g");
|
||||||
|
|
||||||
|
data = sensor.getMagnetometer();
|
||||||
|
System.out.println("Magnetometer x: " + data.get(0)
|
||||||
|
+ " y: " + data.get(1)
|
||||||
|
+ " z: " + data.get(2)
|
||||||
|
+ " uT");
|
||||||
|
|
||||||
|
System.out.println("Temperature: "
|
||||||
|
+ sensor.getTemperature());
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
71
examples/java/LSM6DS3H_Example.java
Normal file
71
examples/java/LSM6DS3H_Example.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016-2017 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_lsm6ds3h.*;
|
||||||
|
|
||||||
|
public class LSM6DS3H_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a LSM6DS3H instance using default i2c bus and address
|
||||||
|
LSM6DS3H sensor = new LSM6DS3H();
|
||||||
|
|
||||||
|
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||||
|
// valid pin for CS:
|
||||||
|
// LSM6DS3H(0, -1, 10);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
floatVector data = sensor.getAccelerometer();
|
||||||
|
|
||||||
|
System.out.println("Accelerometer x: " + data.get(0)
|
||||||
|
+ " y: " + data.get(1)
|
||||||
|
+ " z: " + data.get(2)
|
||||||
|
+ " g");
|
||||||
|
|
||||||
|
data = sensor.getGyroscope();
|
||||||
|
|
||||||
|
System.out.println("Gyroscope x: " + data.get(0)
|
||||||
|
+ " y: " + data.get(1)
|
||||||
|
+ " z: " + data.get(2)
|
||||||
|
+ " dps");
|
||||||
|
|
||||||
|
System.out.println("Compensation Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
71
examples/java/LSM6DSL_Example.java
Normal file
71
examples/java/LSM6DSL_Example.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016-2017 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_lsm6dsl.*;
|
||||||
|
|
||||||
|
public class LSM6DSL_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||||
|
LSM6DSL sensor = new LSM6DSL();
|
||||||
|
|
||||||
|
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||||
|
// valid pin for CS:
|
||||||
|
// LSM6DSL(0, -1, 10);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
floatVector data = sensor.getAccelerometer();
|
||||||
|
|
||||||
|
System.out.println("Accelerometer x: " + data.get(0)
|
||||||
|
+ " y: " + data.get(1)
|
||||||
|
+ " z: " + data.get(2)
|
||||||
|
+ " g");
|
||||||
|
|
||||||
|
data = sensor.getGyroscope();
|
||||||
|
|
||||||
|
System.out.println("Gyroscope x: " + data.get(0)
|
||||||
|
+ " y: " + data.get(1)
|
||||||
|
+ " z: " + data.get(2)
|
||||||
|
+ " dps");
|
||||||
|
|
||||||
|
System.out.println("Compensation Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
59
examples/java/LSM9DS0Sample.java
Normal file
59
examples/java/LSM9DS0Sample.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 LSM9DS0Sample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting
|
||||||
|
|
||||||
|
// Instantiate an LSM9DS0 using default parameters (bus 1, gyro addr 6b,
|
||||||
|
// xm addr 1d)
|
||||||
|
|
||||||
|
upm_lsm9ds0.LSM9DS0 sensor = new upm_lsm9ds0.LSM9DS0();
|
||||||
|
|
||||||
|
sensor.init();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
float[] accel = sensor.getAccelerometer();
|
||||||
|
System.out.println("Accelerometer: ");
|
||||||
|
System.out.println("AX: " + accel[0] + "; AY: " + accel[1] + "; AZ: " + accel[2]);
|
||||||
|
|
||||||
|
float[] gyro = sensor.getGyroscope();
|
||||||
|
System.out.println("Gyroscope: ");
|
||||||
|
System.out.println("GX: " + gyro[0] + "; GY: " + gyro[1] + "; GZ: " + gyro[2]);
|
||||||
|
|
||||||
|
float[] magnet = sensor.getMagnetometer();
|
||||||
|
System.out.println("Magnetometer: ");
|
||||||
|
System.out.println("MX: " + magnet[0] + "; MY: " + magnet[1] + "; MZ: " + magnet[2]);
|
||||||
|
|
||||||
|
System.out.println("Temperature: " + sensor.getTemperature());
|
||||||
|
|
||||||
|
Thread.sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
42
examples/java/LoudnessSample.java
Normal file
42
examples/java/LoudnessSample.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 LoudnessSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Instantiate a Loudness sensor on analog pin A0, with an analog
|
||||||
|
// reference voltage of 5.0V
|
||||||
|
upm_loudness.Loudness loud = new upm_loudness.Loudness(0, (float) 5.0);
|
||||||
|
|
||||||
|
// Every tenth of a second, sample the loudness and output it's
|
||||||
|
// corresponding analog voltage.
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Detected loudness (volts): " + loud.loudness());
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
216
examples/java/MCP9808Sample.java
Normal file
216
examples/java/MCP9808Sample.java
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 java.io.*;
|
||||||
|
import upm_mcp9808.MCP9808;
|
||||||
|
|
||||||
|
public class MCP9808Sample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException, IOException {
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
int command;
|
||||||
|
upm_mcp9808.MCP9808 temp = new upm_mcp9808.MCP9808(6);
|
||||||
|
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
|
||||||
|
do {
|
||||||
|
System.out.println("1 - read temp");
|
||||||
|
System.out.println("2 - sleep mode");
|
||||||
|
System.out.println("3 - wake up");
|
||||||
|
System.out.println("4 - set mode to " + (temp.isCelsius() == true ? "Fahrenheit" : "Celsius"));
|
||||||
|
System.out.println("5 - show status bits");
|
||||||
|
System.out.println("6 - Set Tcrit");
|
||||||
|
System.out.println("7 - Set Tupper");
|
||||||
|
System.out.println("8 - Set Tlower");
|
||||||
|
System.out.println("9 - Display monitor temps");
|
||||||
|
System.out.println("10 - Enable alert default");
|
||||||
|
System.out.println("11 - Enable alert interrupt");
|
||||||
|
System.out.println("12 - Clear interrupt");
|
||||||
|
System.out.println("13 - Clear alert mode");
|
||||||
|
System.out.println("14 - Get Hysteresis");
|
||||||
|
System.out.println("15 - Set Hysteresis");
|
||||||
|
System.out.println("16 - Get Resolution");
|
||||||
|
System.out.println("17 - Set Resolution");
|
||||||
|
System.out.println("18 - Get Manufacturer ID");
|
||||||
|
System.out.println("19 - Get Device ID");
|
||||||
|
System.out.println("-1 - exit");
|
||||||
|
System.out.print("Enter a command:");
|
||||||
|
|
||||||
|
try {
|
||||||
|
command = Integer.parseInt(read.readLine());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Not valid command");
|
||||||
|
command = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
float t;
|
||||||
|
switch (command) {
|
||||||
|
case 1:
|
||||||
|
System.out.println("Temp: " + temp.getTemp() + " degrees " + (temp.isCelsius() ? "Celsius" : "Fahrenheit"));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
System.out.println("shutdown sensor (sleep mode)");
|
||||||
|
temp.shutDown();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
System.out.println("wake up sensor");
|
||||||
|
temp.shutDown(false);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
System.out.println("set mode to " + (temp.isCelsius() ? "Fahrenheit" : "Celsius"));
|
||||||
|
temp.setMode(!temp.isCelsius());
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
System.out.println("Tcrit = " + temp.isTcrit());
|
||||||
|
System.out.println("Tupper = " + temp.isTupper());
|
||||||
|
System.out.println("Tlower = " + temp.isTlower());
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
System.out.print("Enter a value: ");
|
||||||
|
try {
|
||||||
|
t = Float.valueOf(read.readLine()).floatValue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("\nNot a valid value\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
temp.setMonitorReg(MCP9808.MCP9808_REG.CRIT_TEMP, t);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
System.out.print("Enter a value: ");
|
||||||
|
try {
|
||||||
|
t = Float.valueOf(read.readLine()).floatValue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("\nNot a valid value\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
temp.setMonitorReg(MCP9808.MCP9808_REG.UPPER_TEMP, t);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
System.out.print("Enter a value: ");
|
||||||
|
try {
|
||||||
|
t = Float.valueOf(read.readLine()).floatValue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("\nNot a valid value\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
temp.setMonitorReg(MCP9808.MCP9808_REG.LOWER_TEMP, t);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
System.out.println("Tcrit = " + temp.getMonitorReg(MCP9808.MCP9808_REG.CRIT_TEMP));
|
||||||
|
System.out.println("Tupper = " + temp.getMonitorReg(MCP9808.MCP9808_REG.UPPER_TEMP));
|
||||||
|
System.out.println("Tlower = " + temp.getMonitorReg(MCP9808.MCP9808_REG.LOWER_TEMP));
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
System.out.println("Set alert mode default");
|
||||||
|
temp.setAlertMode(MCP9808.MCP9808_CONFIG.ALERTCTRL.swigValue());
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
System.out.println("Set alert mode interrupt");
|
||||||
|
temp.setAlertMode(
|
||||||
|
MCP9808.MCP9808_CONFIG.ALERTMODE.swigValue() | MCP9808.MCP9808_CONFIG.ALERTCTRL.swigValue());
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
temp.clearInterrupt();
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
System.out.println("Clear alerts");
|
||||||
|
temp.clearAlertMode();
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
System.out.println("Hysteresis: " + temp.getHysteresis());
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
int u;
|
||||||
|
System.out.print("Enter 1 to 4: ");
|
||||||
|
try {
|
||||||
|
u = Integer.parseInt(read.readLine());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("\nNot a valid command\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (u) {
|
||||||
|
case 1:
|
||||||
|
temp.setHysteresis(MCP9808.MCP9808_CONFIG.HYST_0);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
temp.setHysteresis(MCP9808.MCP9808_CONFIG.HYST_1_5);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
temp.setHysteresis(MCP9808.MCP9808_CONFIG.HYST_3_0);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
temp.setHysteresis(MCP9808.MCP9808_CONFIG.HYST_6_0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("\nNot a valid option\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
System.out.println("Resolution: " + temp.getResolution());
|
||||||
|
break;
|
||||||
|
case 17:
|
||||||
|
int v;
|
||||||
|
System.out.print("Enter 1 to 4: ");
|
||||||
|
try {
|
||||||
|
v = Integer.parseInt(read.readLine());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("\nNot a valid command\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (v) {
|
||||||
|
case 1:
|
||||||
|
temp.setResolution(MCP9808.MCP9808_RESOLUTION.RES_LOW);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
temp.setResolution(MCP9808.MCP9808_RESOLUTION.RES_MEDIUM);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
temp.setResolution(MCP9808.MCP9808_RESOLUTION.RES_HIGH);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
temp.setResolution(MCP9808.MCP9808_RESOLUTION.RES_PRECISION);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("\nNot a valid option\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 18:
|
||||||
|
System.out.println("Manufacturer ID: " + temp.getManufacturer());
|
||||||
|
break;
|
||||||
|
case 19:
|
||||||
|
System.out.println("Get device ID: " + temp.getDevicedId());
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("That option is not available. Try again");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (command != -1);
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
examples/java/MG811Sample.java
Normal file
44
examples/java/MG811Sample.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||||
|
* Copyright (c) 2017 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 MG811Sample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate an MG811 on analog pin A0, and digital pin D2 with an
|
||||||
|
// analog reference voltage of 5.0V
|
||||||
|
upm_mg811.MG811 sensor = new upm_mg811.MG811(0, 2, (float) 5.0);
|
||||||
|
|
||||||
|
// Every tenth of a second, sample the sensor and output it's
|
||||||
|
// detected CO2 concentration in parts per million (ppm)
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
System.out.println("CO2 concentration in PPM: " + sensor.ppm());
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
@ -34,13 +34,14 @@ public class MPU9150Sample {
|
|||||||
while (true) {
|
while (true) {
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
float[] accel = sensor.getAccelerometer();
|
// These don't exist
|
||||||
System.out.println("Accelerometer: " + "AX: " + accel[0] + " AY: " + accel[1] + " AZ: "
|
// float[] accel = sensor.getAccelerometer();
|
||||||
+ accel[2]);
|
// System.out.println("Accelerometer: " + "AX: " + accel[0] + " AY: " + accel[1] + " AZ: "
|
||||||
|
// + accel[2]);
|
||||||
float[] gyro = sensor.getGyroscope();
|
//
|
||||||
System.out.println("Gryoscope: " + "GX: " + gyro[0] + " GY: " + gyro[1] + " GZ: "
|
// float[] gyro = sensor.getGyroscope();
|
||||||
+ gyro[2]);
|
// System.out.println("Gryoscope: " + "GX: " + gyro[0] + " GY: " + gyro[1] + " GZ: "
|
||||||
|
// + gyro[2]);
|
||||||
|
|
||||||
float[] magn = sensor.getMagnetometer();
|
float[] magn = sensor.getMagnetometer();
|
||||||
System.out.println("Magnetometer: " + "MX: " + magn[0] + " MY: " + magn[1] + " MZ: "
|
System.out.println("Magnetometer: " + "MX: " + magn[0] + " MY: " + magn[1] + " MZ: "
|
||||||
@ -50,4 +51,4 @@ public class MPU9150Sample {
|
|||||||
}
|
}
|
||||||
// ! [Interesting]
|
// ! [Interesting]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user