Compare commits
222 Commits
v1.2.0
...
cxx-interf
Author | SHA1 | Date | |
---|---|---|---|
0223cd2b85 | |||
b55501e327 | |||
e99f1d73fd | |||
fc56e56048 | |||
757683b2ca | |||
b09944f4b8 | |||
f45429e1f0 | |||
54c6d294af | |||
83f541a5db | |||
090ce2040e | |||
76dd42a47d | |||
63c3b4bc69 | |||
7254d5f75e | |||
f907ebcf2e | |||
334f7365f0 | |||
41e80d611e | |||
92b0919f56 | |||
c54d6de054 | |||
86e8471cad | |||
2c17998ac9 | |||
a43bcfe8d2 | |||
1be36ec1df | |||
e4dd6457bb | |||
ad36f83857 | |||
2a17fe094e | |||
8f99289a48 | |||
829da899fc | |||
20aa4962f0 | |||
3d674efb51 | |||
cc7fec9ae0 | |||
4a1eb99d6d | |||
a12baf379f | |||
38817b72dc | |||
fe7bd75c91 | |||
460fdc2eb5 | |||
9d51454290 | |||
6f72c52a44 | |||
7d83e8c569 | |||
96bcfc9128 | |||
6be656d5b0 | |||
3cfea676e2 | |||
f64060b9d2 | |||
36ebd15abc | |||
23a57b8c90 | |||
666452e873 | |||
d49ab2ac95 | |||
d06e632f3b | |||
e192a125f3 | |||
63b2b33df7 | |||
2551596309 | |||
6725559669 | |||
680649ba6f | |||
74b5ec00dc | |||
abefdfc756 | |||
f97a62b055 | |||
7422ec937c | |||
a842898bd5 | |||
76949d9358 | |||
b244fe45d1 | |||
b367a63010 | |||
a5680d9b9a | |||
a6111a83b5 | |||
450f071f7d | |||
82c8acf0fe | |||
a65cd2e59b | |||
c154ec6cb8 | |||
d9d48e939f | |||
b1a49f0d3c | |||
ac89a4a130 | |||
f848deb35b | |||
71b2b9b1fc | |||
18b8ca2633 | |||
a96c607fb5 | |||
bc4f124d54 | |||
35e4fc012e | |||
4037ec517c | |||
40084ea651 | |||
91876d48ed | |||
b9010059ad | |||
166332744e | |||
614c4a516b | |||
40e73e648a | |||
153d8cfb12 | |||
cffaf5c6ba | |||
ab841ef591 | |||
5228df9a8b | |||
b75a9daee4 | |||
6cc5c9691d | |||
e8aeaff162 | |||
694034d052 | |||
fc17744104 | |||
3b8f215590 | |||
e22f62f948 | |||
5cefe7f5f3 | |||
bd6e4ec786 | |||
2f9132c429 | |||
e734459ddd | |||
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
@ -0,0 +1,3 @@
|
|||||||
|
Dockerfile
|
||||||
|
docker-compose.yaml
|
||||||
|
build
|
3
.gitignore
vendored
@ -11,3 +11,6 @@ build*/
|
|||||||
# Temp files
|
# Temp files
|
||||||
*.swp
|
*.swp
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
# Node modules
|
||||||
|
**/node_modules
|
||||||
|
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
|
133
.travis.yml
@ -1,48 +1,89 @@
|
|||||||
|
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 wget -q https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` -O /usr/local/bin/docker-compose
|
||||||
- JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
|
||||||
matrix:
|
jobs:
|
||||||
- NODE010=true
|
fast_finish: true
|
||||||
- NODE012=true
|
allow_failures:
|
||||||
- NODE4=true
|
- env: TARGET=ipk
|
||||||
- NODE5=true
|
include:
|
||||||
compiler:
|
- &run-with-clang-minimal
|
||||||
- clang
|
stage: Clang 3.8 - minimal with unit tests
|
||||||
- gcc
|
env: TARGET=minimal
|
||||||
install:
|
before_script: docker-compose pull ${TARGET}
|
||||||
- sudo add-apt-repository --yes ppa:rosmo/swig3.0.7
|
|
||||||
- sudo apt-get update -qq
|
|
||||||
- sudo apt-get install -y --force-yes -qq swig3.0 git
|
|
||||||
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
|
||||||
- sudo update-java-alternatives -s java-8-oracle
|
|
||||||
before_script:
|
|
||||||
# Turn off JAVA SWIG for clang++, use 4.8 for all g++ builds
|
|
||||||
- if [ "$CC" == "gcc" ]; then export BUILDJAVA=ON; export CC=gcc-4.8; export CXX=g++-4.8; else export BUILDJAVA=OFF; fi
|
|
||||||
- if [ "${NODE012}" ]; then nvm install 0.12; fi
|
|
||||||
- if [ "${NODE4}" ]; then nvm install 4.1; fi
|
|
||||||
- if [ "${NODE5}" ]; then nvm install 5; fi
|
|
||||||
# Handle 0.10 NODE_ROOT_DIR differently than other versions
|
|
||||||
- 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
|
|
||||||
script:
|
script:
|
||||||
# Build/install MRAA
|
- export CC=clang-3.8 CXX=clang++-3.8
|
||||||
- echo "CC=$CC BUILDJAVA=$BUILDJAVA NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
|
- BUILDARCH=MOCK docker-compose run ${TARGET}
|
||||||
- git clone https://github.com/intel-iot-devkit/mraa.git $MRAA_ROOT
|
- &run-with-clang
|
||||||
- mkdir -p $MRAA_BUILD && cd $_ && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=ON -DFIRMATA=ON -DENABLEEXAMPLES=OFF $MRAA_ROOT
|
stage: Clang 3.8
|
||||||
- sudo make install
|
env: TARGET=python
|
||||||
- sudo ldconfig
|
before_script: docker-compose pull ${TARGET}
|
||||||
# Build/install UPM
|
script:
|
||||||
- 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
|
- export CC=clang-3.8 CXX=clang++-3.8
|
||||||
addons:
|
- docker-compose run ${TARGET}
|
||||||
apt:
|
- <<: *run-with-clang
|
||||||
sources:
|
env: TARGET=node4
|
||||||
- ubuntu-toolchain-r-test
|
- <<: *run-with-clang
|
||||||
- george-edison55-precise-backports
|
env: TARGET=node5
|
||||||
packages:
|
- <<: *run-with-clang
|
||||||
- cmake
|
env: TARGET=node6
|
||||||
- cmake-data
|
- <<: *run-with-clang
|
||||||
- g++-4.8
|
env: TARGET=java
|
||||||
|
- &run-with-gcc-5
|
||||||
|
stage: Gcc 5
|
||||||
|
env: TARGET=python
|
||||||
|
before_script: docker-compose pull ${TARGET}
|
||||||
|
script:
|
||||||
|
- export CC=gcc-5 CXX=g++-5
|
||||||
|
- docker-compose run ${TARGET}
|
||||||
|
- <<: *run-with-gcc-5
|
||||||
|
env: TARGET=node4
|
||||||
|
- <<: *run-with-gcc-5
|
||||||
|
env: TARGET=node5
|
||||||
|
- <<: *run-with-gcc-5
|
||||||
|
env: TARGET=node6
|
||||||
|
- <<: *run-with-gcc-5
|
||||||
|
env: TARGET=java
|
||||||
|
- &run-with-gcc-6
|
||||||
|
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=cordova
|
||||||
|
- <<: *run-additional-jobs
|
||||||
|
env: TARGET=examples
|
||||||
|
- <<: *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
|
||||||
|
177
CMakeLists.txt
@ -8,6 +8,7 @@ option (BUILDFTI "Build Funtion Table Interface (FTI) in C sensor libraries" OFF
|
|||||||
option (BUILDSWIGPYTHON "Build swig python modules" ON)
|
option (BUILDSWIGPYTHON "Build swig python modules" ON)
|
||||||
option (BUILDSWIGNODE "Build swig node modules" ON)
|
option (BUILDSWIGNODE "Build swig node modules" ON)
|
||||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
||||||
|
option (BUILDCORDOVA "Build cordova bindings" OFF)
|
||||||
option (BUILDEXAMPLES "Build C/C++/JAVA examples" OFF)
|
option (BUILDEXAMPLES "Build C/C++/JAVA examples" OFF)
|
||||||
option (IPK "Generate IPK using CPack" OFF)
|
option (IPK "Generate IPK using CPack" OFF)
|
||||||
option (RPM "Generate RPM using CPack" OFF)
|
option (RPM "Generate RPM using CPack" OFF)
|
||||||
@ -91,11 +92,15 @@ endfunction ()
|
|||||||
# Compiler flags common to both C and CXX
|
# Compiler flags common to both C and CXX
|
||||||
# Enable -Wall
|
# Enable -Wall
|
||||||
# GCC-6 added -Wmisleading-indentation to -Wall, skip these for now
|
# GCC-6 added -Wmisleading-indentation to -Wall, skip these for now
|
||||||
set (C_CXX_WARNING_FLAGS -Wall -Wno-misleading-indentation -Wno-strict-aliasing)
|
set (C_CXX_WARNING_FLAGS -Wall
|
||||||
|
-Wno-misleading-indentation
|
||||||
|
-Wno-strict-aliasing
|
||||||
|
-Wno-deprecated-declarations # Temp fix for MRAA deprecated methods
|
||||||
|
)
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
||||||
@ -104,6 +109,7 @@ endif (WERROR)
|
|||||||
upm_add_compile_flags(C ${C_CXX_WARNING_FLAGS}
|
upm_add_compile_flags(C ${C_CXX_WARNING_FLAGS}
|
||||||
-Winit-self
|
-Winit-self
|
||||||
-Wimplicit
|
-Wimplicit
|
||||||
|
-Wsign-compare
|
||||||
-Wmissing-parameter-type)
|
-Wmissing-parameter-type)
|
||||||
|
|
||||||
# Set CXX compiler warning flags at top-level scope and emit a warning about
|
# Set CXX compiler warning flags at top-level scope and emit a warning about
|
||||||
@ -111,17 +117,29 @@ upm_add_compile_flags(C ${C_CXX_WARNING_FLAGS}
|
|||||||
upm_add_compile_flags(CXX ${C_CXX_WARNING_FLAGS}
|
upm_add_compile_flags(CXX ${C_CXX_WARNING_FLAGS}
|
||||||
-Wnon-virtual-dtor
|
-Wnon-virtual-dtor
|
||||||
-Woverloaded-virtual
|
-Woverloaded-virtual
|
||||||
|
-Wsign-compare
|
||||||
-Wreorder)
|
-Wreorder)
|
||||||
|
|
||||||
|
# Allow exception error handling for Android C++
|
||||||
|
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.9.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,17 +156,31 @@ 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)
|
||||||
|
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)
|
||||||
|
|
||||||
|
# Cordova binding
|
||||||
|
if (BUILDCORDOVA)
|
||||||
|
if (NOT BUILDSWIGJAVA)
|
||||||
|
message(FATAL_ERROR "Cordova bindings require JAVA packages, please enable BUILDSWIGJAVA (-DBUILDSWIGJAVA=on).")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package (Node REQUIRED)
|
||||||
|
find_package (Npm REQUIRED)
|
||||||
|
find_package (UpmCordovaGenerator 0.2.1 REQUIRED)
|
||||||
|
endif (BUILDCORDOVA)
|
||||||
|
|
||||||
# Find swig if any wrapper is enabled
|
# Find swig if any wrapper is enabled
|
||||||
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
|
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
|
||||||
find_package (SWIG 3.0.5 REQUIRED)
|
find_package (SWIG 3.0.5 REQUIRED)
|
||||||
@ -197,7 +229,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.6.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 +257,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")
|
||||||
@ -264,39 +291,39 @@ else()
|
|||||||
set (C_EXTENSIONS OFF)
|
set (C_EXTENSIONS OFF)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# The doc target depends on each sensor target
|
# The doc target depends on the C/C++ source and all libraries
|
||||||
#
|
#
|
||||||
# doc
|
# doc
|
||||||
|
# ├──> src
|
||||||
|
# ├──> include
|
||||||
# ├──> libupm_sensor0
|
# ├──> libupm_sensor0
|
||||||
# ├──> libupm_sensor1
|
# ├──> libupm_sensor1
|
||||||
# ├──> libupm_sensor2
|
# ├──> ...
|
||||||
# └──> libupm_sensor_n
|
# └──> libupm_sensor_n
|
||||||
#
|
#
|
||||||
# The pydoc target builds documentation with sphinx via inspection by loading
|
# The pydoc target builds documentation with sphinx via inspection by loading
|
||||||
# each python module. Those modules must include the CXX documentation via
|
# each python2 module. Those modules must include the CXX documentation via
|
||||||
# a monolithic swig file generated by doxy2swig
|
# a monolithic swig file generated by doxy2swig
|
||||||
#
|
#
|
||||||
# pydoc
|
# pydoc
|
||||||
# └──> _pyupm_sensor0_python2
|
# └──> _pyupm_sensor0_python2
|
||||||
# ├──────> libupm_sensor0
|
# ├──> libupm_sensor0
|
||||||
# └──────> doxy2swig
|
# └──> doxy2swig
|
||||||
#
|
#
|
||||||
# The doxy2swig target is dependent upon the doc target IF BUILDDOC=ON,
|
# The doxy2swig target is dependent upon the doc target IF BUILDDOC=ON,
|
||||||
# otherwise doxy2swig uses an empty file. Doxy2swig also depends on each
|
|
||||||
# sensor target
|
|
||||||
#
|
#
|
||||||
# doxy2swig
|
# doxy2swig
|
||||||
# ├──> BUILDDOC=ON───> doc
|
# └──> BUILDDOC=ON───> doc
|
||||||
# └──> libupm_sensor0
|
|
||||||
#
|
#
|
||||||
# The jsdoc target builds js documentation via yuidoc and only requires
|
# The jsdoc target builds js documentation via yuidoc and only requires
|
||||||
# the doc target
|
# the doc target
|
||||||
#
|
#
|
||||||
# jsdoc ─> doc
|
# jsdoc ─> doc
|
||||||
#
|
#
|
||||||
if (BUILDDOC)
|
function (CreateDocumentationTargets)
|
||||||
# Add a target to generate API documentation with Doxygen
|
# Add a target to generate API documentation with Doxygen
|
||||||
find_package (Doxygen REQUIRED)
|
find_package (Doxygen 1.8 REQUIRED)
|
||||||
|
if (DOXYGEN_FOUND AND DOXYGEN_VERSION VERSION_GREATER "1.8")
|
||||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
||||||
if (BUILDSWIGJAVA)
|
if (BUILDSWIGJAVA)
|
||||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
|
||||||
@ -305,52 +332,90 @@ if (BUILDDOC)
|
|||||||
foreach(PNG_FILE ${PNG_FILES})
|
foreach(PNG_FILE ${PNG_FILES})
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
|
||||||
endforeach()
|
endforeach()
|
||||||
add_custom_target (doc
|
|
||||||
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
# Custom command to run doxygen (note depends on ALL UPM C++ targets)
|
||||||
|
add_custom_command (
|
||||||
|
OUTPUT ${CMAKE_BINARY_DIR}/xml/index.xml
|
||||||
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile ${UPM_TARGETS_CXX}
|
||||||
|
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||||
COMMAND tar -czf html/xml.tar.gz -C xml .
|
COMMAND tar -czf html/xml.tar.gz -C xml .
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
COMMENT "Generating C/C++ API documentation with Doxygen"
|
||||||
)
|
VERBATIM)
|
||||||
|
add_custom_target(doc DEPENDS ${CMAKE_BINARY_DIR}/xml/index.xml)
|
||||||
|
else ()
|
||||||
|
message (SEND_ERROR "ERROR - Failed to find a compatible version of Doxygen. API doc will not be generated")
|
||||||
|
endif (DOXYGEN_FOUND AND DOXYGEN_VERSION VERSION_GREATER "1.8")
|
||||||
|
|
||||||
# Check if Sphinx is installed and add target to generate API 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.
|
||||||
|
# Since python2 is required for documentation, only copy from python2 paths, this
|
||||||
|
# ensures that sphinx doesn't run across python2 and python3 binaries. When running
|
||||||
|
# the sphinx tools, explicitly run from the python2 interpreter (tested with the sphinx
|
||||||
|
# 1.3.6 python2 and python3 modules).
|
||||||
if(BUILDSWIGPYTHON)
|
if(BUILDSWIGPYTHON)
|
||||||
find_package (Sphinx REQUIRED)
|
# Generate python module documentation from doxygen collateral
|
||||||
|
#
|
||||||
|
# doxygen index.xml -> doxy2swig.py -> pyupm_doxy2swig.i
|
||||||
|
add_custom_command (
|
||||||
|
OUTPUT ${CMAKE_BINARY_DIR}/src/pyupm_doxy2swig.i
|
||||||
|
COMMAND ${PYTHON2_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/doxy2swig.py
|
||||||
|
${CMAKE_BINARY_DIR}/xml/index.xml --quiet
|
||||||
|
${CMAKE_BINARY_DIR}/src/pyupm_doxy2swig.i
|
||||||
|
COMMENT "Generating pyupm_doxy2swig.i from Doxygen output for use by SWIG"
|
||||||
|
DEPENDS doc
|
||||||
|
VERBATIM)
|
||||||
|
add_custom_target(pyupm_doxy2swig DEPENDS ${CMAKE_BINARY_DIR}/src/pyupm_doxy2swig.i)
|
||||||
|
foreach (_python2_target ${UPM_TARGETS_PYTHON2})
|
||||||
|
add_dependencies(${_python2_target} pyupm_doxy2swig)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
find_package (Sphinx 1.3 REQUIRED)
|
||||||
|
if (SPHINX_FOUND AND SPHINX_VERSION VERSION_GREATER "1.3")
|
||||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
|
||||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
|
||||||
add_custom_target (pydoc ALL
|
add_custom_command (
|
||||||
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pydoc.stamp
|
||||||
COMMAND rm -r -f ${CMAKE_BINARY_DIR}/pyupm && mkdir -p ${CMAKE_BINARY_DIR}/pyupm
|
COMMAND rm -r -f ${CMAKE_BINARY_DIR}/pyupm && mkdir -p ${CMAKE_BINARY_DIR}/pyupm
|
||||||
COMMAND find ${CMAKE_BINARY_DIR}/src -name "_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
|
COMMAND find ${CMAKE_BINARY_DIR}/src -path "*python${MIN_VER_PYTHON2}/_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
|
||||||
COMMAND find ${CMAKE_BINARY_DIR}/src -name "pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
|
COMMAND find ${CMAKE_BINARY_DIR}/src -path "*python${MIN_VER_PYTHON2}/pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
|
||||||
COMMAND ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/pyupm
|
COMMAND ${PYTHON2_EXECUTABLE} ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/pyupm
|
||||||
# TODO: use a separate cmake FILE module for string replacement instead
|
# TODO: use a separate cmake FILE module for string replacement instead
|
||||||
COMMAND ${SPHINX_EXECUTABLE} -b html pydoc html/python
|
COMMAND ${PYTHON2_EXECUTABLE} ${SPHINX_EXECUTABLE} -b html pydoc html/python
|
||||||
COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
|
COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
|
||||||
COMMAND sed -i.bak s|[[:space:]][mM]odule</a>|</a>|g html/python/index.html html/python/modules.html
|
COMMAND sed -i.bak s|[[:space:]][mM]odule</a>|</a>|g html/python/index.html html/python/modules.html
|
||||||
DEPENDS doc
|
COMMAND cmake -E touch ${CMAKE_CURRENT_BINARY_DIR}/pydoc.stamp
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMENT "Generating API documentation with Sphinx" VERBATIM
|
COMMENT "Generating Python API documentation with Sphinx"
|
||||||
)
|
DEPENDS doc ${UPM_TARGETS_PYTHON2}
|
||||||
|
VERBATIM)
|
||||||
|
add_custom_target(pydoc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pydoc.stamp)
|
||||||
|
else ()
|
||||||
|
message (SEND_ERROR "ERROR - Failed to find a compatible version of Sphinx. Python API doc will not be generated")
|
||||||
|
endif ()
|
||||||
endif(BUILDSWIGPYTHON)
|
endif(BUILDSWIGPYTHON)
|
||||||
|
|
||||||
# Check if Yuidoc is installed and add target for API documentation
|
# Check if Yuidoc is installed and add target for API documentation
|
||||||
if(BUILDSWIGNODE)
|
if(BUILDSWIGNODE)
|
||||||
find_package(Yuidoc REQUIRED)
|
find_package (Yuidoc 0.10 REQUIRED)
|
||||||
file(GLOB_RECURSE JSDOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/doxy/node doxy/node/*)
|
if (YUIDOC_FOUND AND YUIDOC_VERSION VERSION_GREATER "0.10")
|
||||||
foreach(JSDOC_FILE ${JSDOC_FILES})
|
add_custom_command (
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy/node/${JSDOC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${JSDOC_FILE} COPYONLY)
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/jsdoc/jsdoc.stamp
|
||||||
endforeach()
|
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/docgen.js -m upm -i xml -o jsdoc -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
||||||
add_custom_target(jsdoc ALL
|
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} docgen -m upm -i xml -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/tolower.js -i html/node
|
||||||
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers generators/yuidoc/helper.js --themedir generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
|
COMMAND cmake -E touch ${CMAKE_CURRENT_BINARY_DIR}/jsdoc/jsdoc.stamp
|
||||||
COMMAND ${NODEJS_EXECUTABLE} tolower -i html/node
|
|
||||||
DEPENDS doc
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
COMMENT "Generating Javascript API documentation with Yuidoc"
|
||||||
)
|
DEPENDS doc
|
||||||
|
VERBATIM)
|
||||||
|
add_custom_target(jsdoc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/jsdoc/jsdoc.stamp)
|
||||||
|
else ()
|
||||||
|
message (SEND_ERROR "ERROR - Failed to find a compatible version of Yuidoc. Node.js API doc will not be generated")
|
||||||
|
endif ()
|
||||||
endif(BUILDSWIGNODE)
|
endif(BUILDSWIGNODE)
|
||||||
endif (BUILDDOC)
|
endfunction()
|
||||||
|
|
||||||
if (IPK)
|
if (IPK)
|
||||||
# Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
|
# Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
|
||||||
@ -415,9 +480,7 @@ 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)
|
|
||||||
|
|
||||||
# UPM source
|
# UPM source
|
||||||
add_subdirectory (src)
|
add_subdirectory (src)
|
||||||
@ -431,6 +494,12 @@ if (BUILDTESTS)
|
|||||||
add_subdirectory (tests)
|
add_subdirectory (tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Setup documentation AFTER all source targets have been added
|
||||||
|
if (BUILDDOC)
|
||||||
|
CreateDocumentationTargets()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Install C headers
|
# Install C headers
|
||||||
install(DIRECTORY include/ DESTINATION include/upm
|
install(DIRECTORY include/ DESTINATION include/upm
|
||||||
FILES_MATCHING PATTERN "*.h")
|
COMPONENT ${CMAKE_PROJECT_NAME}-dev
|
||||||
|
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
|
||||||
|
27
README.md
@ -1,3 +1,7 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img src="https://github.com/intel-iot-devkit/upm/blob/master/docs/icons/upm_logo.png" height="150px" width="auto" algt="UPM Logo"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
UPM (Useful Packages & Modules) Sensor/Actuator repository for MRAA
|
UPM (Useful Packages & Modules) Sensor/Actuator repository for MRAA
|
||||||
==============
|
==============
|
||||||
|
|
||||||
@ -11,8 +15,9 @@ corresponding header file and instantiating the associated sensor class. In the
|
|||||||
typical use case, a constructor initializes the sensor based on parameters that
|
typical use case, a constructor initializes the sensor based on parameters that
|
||||||
identify the sensor, the I/O protocol used and the pin location of the sensor.
|
identify the sensor, the I/O protocol used and the pin location of the sensor.
|
||||||
|
|
||||||
C++ interfaces have been defined for the following sensor/actuator types, but
|
We endorse additions that implement the generic C and C++ interfaces provided
|
||||||
they are subject to change:
|
with the libraries. Multiple sensor and actuator types have been defined, for
|
||||||
|
instance:
|
||||||
|
|
||||||
* Light controller
|
* Light controller
|
||||||
* Light sensor
|
* Light sensor
|
||||||
@ -22,8 +27,8 @@ they are subject to change:
|
|||||||
* Gas sensor
|
* Gas sensor
|
||||||
* Analog to digital converter
|
* Analog to digital converter
|
||||||
|
|
||||||
The developer community is encouraged to help expand the list of supported
|
The developer community is welcome to submit feedback on existing categories or
|
||||||
sensors and actuators and provide feedback on interface design.
|
suggest new ones.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
@ -67,12 +72,16 @@ Supported [sensor list](http://iotdk.intel.com/docs/master/upm/modules.html) fro
|
|||||||
|
|
||||||
You can also refer to the [Intel® IoT Developer Zone](https://software.intel.com/iot/hardware/sensors).
|
You can also refer to the [Intel® IoT Developer Zone](https://software.intel.com/iot/hardware/sensors).
|
||||||
|
|
||||||
### IDE Integration
|
### IDE Support
|
||||||
|
|
||||||
If you would like to create projects and run the UPM samples using an Intel recommended IDE,
|
The UPM sensor libraries are directly supported by the IDEs listed on the Intel®
|
||||||
please refer to the Intel Developer Zone IDE page.
|
Developer Zone Tools & IDEs page.
|
||||||
|
|
||||||
<a href="https://software.intel.com/iot/software/ide"><img src="docs/icons/allides.png"/></a>
|
<a href="https://software.intel.com/iot/tools"><img src="docs/icons/iss.png"/></a>
|
||||||
|
|
||||||
|
Intel® System Studio integration offers IoT specific features such as a sensor explorer,
|
||||||
|
library sync tools and the ability to easily import existing projects and samples that
|
||||||
|
use the UPM libraries. For further details please refer to the IoT User Guides on IDZ.
|
||||||
|
|
||||||
### Installing UPM
|
### Installing UPM
|
||||||
|
|
||||||
@ -129,7 +138,7 @@ unable to compile code that was working fine before a library update, make sure
|
|||||||
you check the [API changes](docs/apichanges.md) section first.
|
you check the [API changes](docs/apichanges.md) section first.
|
||||||
|
|
||||||
**NOTE** - Several important API changes are currently underway for some of our
|
**NOTE** - Several important API changes are currently underway for some of our
|
||||||
widely used libraries including `libupm-grove` and `libupm-i2clcd`!
|
widely used libraries including `libupm-grove`
|
||||||
|
|
||||||
### Changelog
|
### Changelog
|
||||||
Version changelog [here](docs/changelog.md).
|
Version changelog [here](docs/changelog.md).
|
||||||
|
@ -5,13 +5,11 @@
|
|||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
find_program (NODEJS_EXECUTABLE NAMES node nodejs
|
find_program (NODEJS_EXECUTABLE NAMES node nodejs
|
||||||
HINTS
|
HINTS
|
||||||
$ENV{NODE_DIR}
|
$ENV{NODE_DIR}
|
||||||
PATH_SUFFIXES bin
|
PATH_SUFFIXES bin
|
||||||
DOC "Node.js interpreter"
|
DOC "Node.js interpreter")
|
||||||
)
|
|
||||||
|
|
||||||
include (FindPackageHandleStandardArgs)
|
include (FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
@ -23,13 +21,20 @@ 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
|
||||||
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
NAMES node.h src/node.h
|
||||||
|
PATH_SUFFIXES node node4 node5 node6 node7 node8 nodejs
|
||||||
|
PATHS /usr/include /usr/local/include)
|
||||||
|
|
||||||
if (NODE_ROOT_DIR)
|
if (NODE_ROOT_DIR)
|
||||||
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
add_include_dir(${NODE_ROOT_DIR})
|
||||||
add_include_dir(${NODE_ROOT_DIR}/include/node)
|
add_include_dir(${NODE_ROOT_DIR}/deps/uv/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}/include/deps/v8/include)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/include/node)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/src)
|
||||||
else()
|
else()
|
||||||
unset(NODEJS_INCLUDE_DIRS)
|
unset(NODEJS_INCLUDE_DIRS)
|
||||||
message(ERROR " - node.h not found")
|
message(ERROR " - node.h not found")
|
||||||
@ -49,11 +54,6 @@ if (NOT UV_ROOT_DIR)
|
|||||||
message(ERROR " - uv.h not found")
|
message(ERROR " - uv.h not found")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package_handle_standard_args (Nodejs DEFAULT_MSG
|
|
||||||
NODEJS_EXECUTABLE
|
|
||||||
NODEJS_INCLUDE_DIRS
|
|
||||||
)
|
|
||||||
|
|
||||||
if (NODEJS_EXECUTABLE)
|
if (NODEJS_EXECUTABLE)
|
||||||
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
|
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
|
||||||
OUTPUT_VARIABLE _VERSION
|
OUTPUT_VARIABLE _VERSION
|
||||||
@ -85,13 +85,15 @@ if (NODEJS_EXECUTABLE)
|
|||||||
set (V8_VERSION_MINOR "28")
|
set (V8_VERSION_MINOR "28")
|
||||||
set (V8_VERSION_PATCH "72")
|
set (V8_VERSION_PATCH "72")
|
||||||
set (V8_VERSION_STRING "3.28.72")
|
set (V8_VERSION_STRING "3.28.72")
|
||||||
message ("defaulted to node 0.10.30")
|
message (STATUS "defaulted to node 0.10.30")
|
||||||
endif ()
|
endif ()
|
||||||
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
|
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
|
||||||
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
|
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
|
||||||
message (STATUS "Node version is ${NODE_VERSION_STRING}")
|
|
||||||
message (STATUS "Node using v8 ${V8_VERSION_STRING}")
|
|
||||||
mark_as_advanced (NODEJS_EXECUTABLE)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
mark_as_advanced (NODEJS_EXECUTABLE)
|
mark_as_advanced (NODEJS_EXECUTABLE)
|
||||||
|
|
||||||
|
find_package_handle_standard_args (Nodejs
|
||||||
|
REQUIRED_VARS NODEJS_EXECUTABLE NODEJS_INCLUDE_DIRS
|
||||||
|
VERSION_VAR NODE_VERSION_STRING)
|
||||||
|
message(STATUS "Found v8: ${V8_ROOT_DIR}/v8.h (found version \"${V8_VERSION_STRING}\")")
|
||||||
|
endif ()
|
||||||
|
71
cmake/modules/FindNpm.cmake
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# FindNpm
|
||||||
|
# --------
|
||||||
|
#
|
||||||
|
# Find npm
|
||||||
|
#
|
||||||
|
# This module finds an installed npm. It sets the following variables:
|
||||||
|
#
|
||||||
|
# NPM_FOUND - Set to true if npm is found
|
||||||
|
# NPM_DIR - The directory where npm is installed
|
||||||
|
# NPM_GLOBAL_NODE_MODULE_DIR - The global node_modules directory
|
||||||
|
# NPM_EXECUTABLE - The path to the npm executable
|
||||||
|
# NPM_VERSION - The version number of the npm executable
|
||||||
|
|
||||||
|
find_program(NPM_EXECUTABLE NAMES npm HINTS /usr)
|
||||||
|
|
||||||
|
# If npm was found, fill in the rest
|
||||||
|
if (NPM_EXECUTABLE)
|
||||||
|
# Set the global node_modules location
|
||||||
|
execute_process(COMMAND ${NPM_EXECUTABLE} root -g
|
||||||
|
OUTPUT_VARIABLE NPM_GLOBAL_NODE_MODULE_DIR
|
||||||
|
ERROR_VARIABLE NPM_root_g_error
|
||||||
|
RESULT_VARIABLE NPM_root_g_result_code)
|
||||||
|
# Remove and newlines
|
||||||
|
string (STRIP ${NPM_GLOBAL_NODE_MODULE_DIR} NPM_GLOBAL_NODE_MODULE_DIR)
|
||||||
|
if(NPM_root_g_result_code)
|
||||||
|
if(NPM_FIND_REQUIRED)
|
||||||
|
message(SEND_ERROR "Command \"${NPM_EXECUTABLE} root -g\" failed with output:\n${NPM_root_g_error}")
|
||||||
|
else ()
|
||||||
|
message(STATUS "Command \"${NPM_EXECUTABLE} root -g\" failed with output:\n${NPM_root_g_error}")
|
||||||
|
endif ()
|
||||||
|
endif()
|
||||||
|
unset(NPM_root_g_error)
|
||||||
|
unset(NPM_root_g_result_code)
|
||||||
|
|
||||||
|
# Set the NPM dir
|
||||||
|
if (EXISTS "${NPM_GLOBAL_NODE_MODULE_DIR}/npm")
|
||||||
|
set(NPM_DIR "${NPM_GLOBAL_NODE_MODULE_DIR}/npm")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Set the VERSION
|
||||||
|
execute_process(COMMAND ${NPM_EXECUTABLE} -v
|
||||||
|
OUTPUT_VARIABLE NPM_VERSION
|
||||||
|
ERROR_VARIABLE NPM_version_error
|
||||||
|
RESULT_VARIABLE NPM_version_result_code)
|
||||||
|
|
||||||
|
if(NPM_version_result_code)
|
||||||
|
if(NPM_FIND_REQUIRED)
|
||||||
|
message(SEND_ERROR "Command \"${NPM_EXECUTABLE} -v\" failed with output:\n${NPM_version_error}")
|
||||||
|
else()
|
||||||
|
message(STATUS "Command \"${NPM_EXECUTABLE} -v\" failed with output:\n${NPM_version_error}")
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
unset(NPM_version_error)
|
||||||
|
unset(NPM_version_result_code)
|
||||||
|
|
||||||
|
# Remove and newlines
|
||||||
|
string (STRIP ${NPM_VERSION} NPM_VERSION)
|
||||||
|
|
||||||
|
set (NPM_FOUND TRUE)
|
||||||
|
else()
|
||||||
|
# Fail on REQUIRED
|
||||||
|
if (Npm_FIND_REQUIRED)
|
||||||
|
message(SEND_ERROR "Failed to find npm executable")
|
||||||
|
endif()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
find_package_handle_standard_args(NPM
|
||||||
|
REQUIRED_VARS NPM_EXECUTABLE NPM_DIR
|
||||||
|
VERSION_VAR NPM_VERSION )
|
||||||
|
|
||||||
|
mark_as_advanced(NPM_DIR NPM_GLOBAL_NODE_MODULE_DIR NPM_EXECUTABLE NPM_VERSION)
|
@ -17,13 +17,15 @@ find_package_handle_standard_args (Sphinx DEFAULT_MSG
|
|||||||
SPHINX_API_EXECUTABLE
|
SPHINX_API_EXECUTABLE
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get Sphinx version
|
# Get Sphinx Version
|
||||||
if (SPHINX_EXECUTABLE)
|
if (SPHINX_EXECUTABLE)
|
||||||
execute_process(COMMAND ${SPHINX_EXECUTABLE} --version
|
execute_process(COMMAND ${SPHINX_EXECUTABLE} --version
|
||||||
OUTPUT_VARIABLE SPHINX_VERSION)
|
OUTPUT_VARIABLE SPHINX_VERSION_STRING
|
||||||
if(SPHINX_VERSION)
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
string(REGEX MATCH "([0-9]\\.[0-9]\\.[0-9])" SPHINX_VERSION_STR ${SPHINX_VERSION})
|
ERROR_STRIP_TRAILING_WHITESPACE)
|
||||||
message (STATUS "Sphinx version is ${SPHINX_VERSION_STR}")
|
if (SPHINX_VERSION_STRING)
|
||||||
|
string(REPLACE "Sphinx (sphinx-build) " "" SPHINX_VERSION ${SPHINX_VERSION_STRING})
|
||||||
|
message (STATUS "Sphinx version is ${SPHINX_VERSION}")
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
20
cmake/modules/FindUpmCordovaGenerator.cmake
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
find_program (UPM_CORDOVA_BINDING NAMES upm-cordova-binding
|
||||||
|
DOC "UPM Cordova binding generator")
|
||||||
|
|
||||||
|
include (FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
# Get version
|
||||||
|
if (UPM_CORDOVA_BINDING)
|
||||||
|
execute_process(COMMAND ${NPM_EXECUTABLE} info upm-cordova-binding version
|
||||||
|
OUTPUT_VARIABLE UPM_CORDOVA_BINDING_VERSION
|
||||||
|
ERROR_VARIABLE UPM_CORDOVA_BINDING_VERSION
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
ERROR_STRIP_TRAILING_WHITESPACE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package_handle_standard_args(UpmCordovaGenerator
|
||||||
|
REQUIRED_VARS UPM_CORDOVA_BINDING
|
||||||
|
VERSION_VAR UPM_CORDOVA_BINDING_VERSION
|
||||||
|
FAIL_MESSAGE "Unable to find the npm package for generating UPM Cordova bindings. The generator can be installed via: 'npm install -g upm-cordova-binding'")
|
||||||
|
|
||||||
|
mark_as_advanced (UPM_CORDOVA_BINDING UPM_CORDOVA_BINDING_VERSION)
|
@ -1,4 +0,0 @@
|
|||||||
#include "version.h"
|
|
||||||
|
|
||||||
const char* gVERSION = "@VERSION@";
|
|
||||||
const char* gVERSION_SHORT = "@VERSION_SHORT@";
|
|
137
docker-compose.yaml
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
version: '2.1'
|
||||||
|
|
||||||
|
services:
|
||||||
|
|
||||||
|
base:
|
||||||
|
image: inteliotdevkit/upm-base
|
||||||
|
environment:
|
||||||
|
- http_proxy
|
||||||
|
- https_proxy
|
||||||
|
- no_proxy
|
||||||
|
- BUILDDOC=${BUILDDOC:-OFF}
|
||||||
|
- BUILDCPP=${BUILDCPP:-ON}
|
||||||
|
- BUILDFTI=${BUILDFTI:-ON}
|
||||||
|
- BUILDSWIGPYTHON=${BUILDSWIGPYTHON:-OFF}
|
||||||
|
- BUILDSWIGJAVA=${BUILDSWIGJAVA:-OFF}
|
||||||
|
- BUILDCORDOVA=${BUILDCORDOVA:-OFF}
|
||||||
|
- BUILDSWIGNODE=${BUILDSWIGNODE:-OFF}
|
||||||
|
- BUILDEXAMPLES=${BUILDEXAMPLES:-OFF}
|
||||||
|
- 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}
|
||||||
|
|
||||||
|
all:
|
||||||
|
extends: base
|
||||||
|
image: inteliotdevkit/upm-all
|
||||||
|
|
||||||
|
minimal:
|
||||||
|
extends: base
|
||||||
|
environment:
|
||||||
|
- BUILDFTI=OFF
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make && ctest -R unit --output-on-failure"
|
||||||
|
|
||||||
|
doc:
|
||||||
|
extends: all
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGPYTHON=ON
|
||||||
|
- BUILDSWIGJAVA=ON
|
||||||
|
- BUILDSWIGNODE=ON
|
||||||
|
- BUILDDOC=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && ./scripts/build-doc.sh"
|
||||||
|
|
||||||
|
examples:
|
||||||
|
extends: all
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGPYTHON=ON
|
||||||
|
- BUILDSWIGJAVA=ON
|
||||||
|
- BUILDSWIGNODE=ON
|
||||||
|
- BUILDEXAMPLES=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8"
|
||||||
|
|
||||||
|
ipk:
|
||||||
|
extends: all
|
||||||
|
environment:
|
||||||
|
- IPK=ON
|
||||||
|
- BUILDDOC=OFF
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
|
||||||
|
|
||||||
|
rpm:
|
||||||
|
extends: all
|
||||||
|
environment:
|
||||||
|
- RPM=ON
|
||||||
|
- BUILDDOC=OFF
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
|
||||||
|
|
||||||
|
npm:
|
||||||
|
extends: all
|
||||||
|
environment:
|
||||||
|
- NPM=ON
|
||||||
|
- BUILDDOC=OFF
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 npmpkg"
|
||||||
|
|
||||||
|
sonar-scan:
|
||||||
|
extends: all
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGPYTHON=ON
|
||||||
|
- BUILDSWIGNODE=ON
|
||||||
|
- BUILDSWIGJAVA=ON
|
||||||
|
- BUILDEXAMPLES=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: inteliotdevkit/upm-python
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGPYTHON=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
|
||||||
|
|
||||||
|
java:
|
||||||
|
extends: base
|
||||||
|
image: inteliotdevkit/upm-java
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGJAVA=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
|
||||||
|
|
||||||
|
android:
|
||||||
|
extends: java
|
||||||
|
image: inteliotdevkit/upm-android
|
||||||
|
environment:
|
||||||
|
- BUILDTESTS=OFF
|
||||||
|
command: bash -c "./scripts/build-android.sh"
|
||||||
|
|
||||||
|
cordova:
|
||||||
|
extends: all
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGJAVA=ON
|
||||||
|
- BUILDCORDOVA=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8"
|
||||||
|
|
||||||
|
node4:
|
||||||
|
extends: base
|
||||||
|
image: inteliotdevkit/upm-node4
|
||||||
|
environment:
|
||||||
|
- BUILDSWIGNODE=ON
|
||||||
|
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure -E examplenames_js"
|
||||||
|
|
||||||
|
node5:
|
||||||
|
extends: node4
|
||||||
|
image: inteliotdevkit/upm-node5
|
||||||
|
|
||||||
|
node6:
|
||||||
|
extends: node4
|
||||||
|
image: inteliotdevkit/upm-node6
|
@ -4,11 +4,45 @@ 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:
|
||||||
|
|
||||||
|
# vNext
|
||||||
|
* The interface of **kx122** has been modified to return values instead of
|
||||||
|
receiving pointers. This applies to member functions: getWhoAmI,
|
||||||
|
getInterruptSource, getBufferStatus, getRawBufferSamples, and getBufferSamples.
|
||||||
|
|
||||||
|
# v1.6.0
|
||||||
|
|
||||||
|
* Several C libraries had their init function pin type modified from uint8_t
|
||||||
|
to int allowing usage with subplatforms
|
||||||
|
* Our **led** class constructor has been overloaded with a string based
|
||||||
|
variant that uses the new MRAA LED APIs
|
||||||
|
* The **i2clcd** library has finally been renamed to **lcd** and is now
|
||||||
|
mostly considered a bundle for ssd lcd display controllers only
|
||||||
|
* The **zfm20** class constructor has been overloaded with a string variant
|
||||||
|
that allows initialization using any UART device
|
||||||
|
|
||||||
|
# v1.5.0
|
||||||
|
|
||||||
|
* **VEML6070** This sensor class no longer needs an I2C address when
|
||||||
|
initialized, since they are fixed. Only the I2C bus number needs to
|
||||||
|
be provided.
|
||||||
|
|
||||||
|
# v1.3.0
|
||||||
|
|
||||||
|
* **The lsm303 driver has been renamed** There are a variety of
|
||||||
|
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
|
||||||
@ -120,13 +154,13 @@ compatibility between releases:
|
|||||||
* **lcm1602/jhd1313m1** These drivers had been rewritten in C, with
|
* **lcm1602/jhd1313m1** These drivers had been rewritten in C, with
|
||||||
C++ wrappers and placed into their own libraries in the previous
|
C++ wrappers and placed into their own libraries in the previous
|
||||||
version of UPM, however, the original C++ implementation was kept in
|
version of UPM, however, the original C++ implementation was kept in
|
||||||
the lcd/i2clcd library for compatibility reasons with existing code.
|
the lcd library for compatibility reasons with existing code.
|
||||||
To avoid collisions with the header files, the new *lcm1602* and
|
To avoid collisions with the header files, the new *lcm1602* and
|
||||||
*jhd1313m1* drivers had their C++ headers renamed to use a **.hxx**
|
*jhd1313m1* drivers had their C++ headers renamed to use a **.hxx**
|
||||||
suffix.
|
suffix.
|
||||||
|
|
||||||
In this version of UPM, the *lcm1602* and *jhd1313m1* drivers have
|
In this version of UPM, the *lcm1602* and *jhd1313m1* drivers have
|
||||||
been removed from the lcd/i2clcd library. In addition, the header
|
been removed from the lcd library. In addition, the header
|
||||||
files for the new implementation have been renamed from their
|
files for the new implementation have been renamed from their
|
||||||
**.hxx** suffix to the normal **.hpp** suffix.
|
**.hxx** suffix to the normal **.hpp** suffix.
|
||||||
|
|
||||||
|
153
docs/building.md
@ -34,7 +34,12 @@ make install
|
|||||||
|
|
||||||
The last command will create the include/ and lib/ directories with a copy of
|
The last command will create the include/ and lib/ directories with a copy of
|
||||||
the headers and library objects respectively in your build location. Note that
|
the headers and library objects respectively in your build location. Note that
|
||||||
doing an out-of-source build may cause issues when rebuilding later on.
|
doing an out-of-source build may cause issues when rebuilding later on. In many
|
||||||
|
cases you'll need elevated permissions to install:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~{.sh}
|
||||||
|
sudo make install
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
Our cmake configure has a number of options, *cmake-gui* or *ccmake* can show
|
Our cmake configure has a number of options, *cmake-gui* or *ccmake* can show
|
||||||
you all the options. The interesting ones are detailed below:
|
you all the options. The interesting ones are detailed below:
|
||||||
@ -64,10 +69,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
|
||||||
@ -105,22 +106,22 @@ make install
|
|||||||
Often developers are only interested in building one module or even just the
|
Often developers are only interested in building one module or even just the
|
||||||
python/node module to do some quick testing using scripting. In order to do
|
python/node module to do some quick testing using scripting. In order to do
|
||||||
this you need to use the target name for the python or node module you want to
|
this you need to use the target name for the python or node module you want to
|
||||||
rebuild. For example the lcd module target name is i2clcd. Therefore the python
|
rebuild. For example, the lcd module target will have a python2 target prefixed
|
||||||
module target name will be prefixed by _pyupm_. Just do the following to build
|
by _pyupm_ (_pyupm_lcd-python2). Modules not using the UPM cmake macros may
|
||||||
only that module. Modules not using the UPM cmake macros may have different
|
have different naming. To build the python2 lcd module (and all dependencies),
|
||||||
naming.
|
use the following make target:
|
||||||
|
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
make _pyupm_i2clcd
|
make _pyupm_lcd-python2
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
Sometimes you want to build a small C++ example against an installed library.
|
Sometimes you want to build a small C++ example against an installed library.
|
||||||
This is fairly easy if installed system-wide. Just link against the correct
|
This is fairly easy if installed system-wide. Just link against the correct
|
||||||
library (in this case libupm-i2clcd) and then add /usr/include/upm to the
|
library (in this case libupm-lcd) and then add /usr/include/upm to the
|
||||||
loader path:
|
loader path:
|
||||||
|
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
g++ test.cxx -lupm-i2clcd -I/usr/include/upm
|
g++ test.cxx -lupm-lcd -I/usr/include/upm
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
You can also use pkg-config to return the information to you, which is
|
You can also use pkg-config to return the information to you, which is
|
||||||
@ -128,5 +129,131 @@ considered the correct way if including UPM in a build system like cmake or
|
|||||||
autotools on linux.
|
autotools on linux.
|
||||||
|
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
pkg-config --cflags --libs upm-i2clcd
|
pkg-config --cflags --libs upm-lcd
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
## Building for Android Things
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
* [io.mraa.at](https://search.maven.org/#artifactdetails%7Cio.mraa.at%7Cmraa%7C1.8.0%7Caar)
|
||||||
|
* [io.mraa.at.upm](https://search.maven.org/#artifactdetails%7Cio.mraa.at.upm%7Cupm_zfm20%7C1.3.0%7Caar)
|
||||||
|
* [Android NDK](https://developer.android.com/ndk/downloads/index.html) >= 14b
|
||||||
|
|
||||||
|
### Android NDK r14b
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~{.sh}
|
||||||
|
NDK_HOME="/path/to/android-ndk-r14b"
|
||||||
|
MRAA_INSTALL_DIR="/path/to/mraa/install"
|
||||||
|
|
||||||
|
cmake -DBUILDSWIG=ON \
|
||||||
|
-DBUILDSWIGPYTHON=OFF \
|
||||||
|
-DBUILDSWIGNODE=OFF \
|
||||||
|
-DBUILDSWIGJAVA=ON \
|
||||||
|
-DANDROID_COMPILER_FLAGS_CXX='-std=c++11' \
|
||||||
|
-DANDROID_PIE=1 \
|
||||||
|
-DANDROID_PLATFORM=android-24 \
|
||||||
|
-DANDROID_STL_FORCE_FEATURES=ON \
|
||||||
|
-DANDROID_STL=c++_shared \
|
||||||
|
-DANDROID_TOOLCHAIN_NAME=x86-i686 \
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE=$NDK_HOME/build/cmake/android.toolchain.cmake \
|
||||||
|
-DCMAKE_FIND_ROOT_PATH=$MRAA_INSTALL_DIR \
|
||||||
|
..
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
## Building with Docker
|
||||||
|
|
||||||
|
You can use `docker` and `docker-compose` to generate a complete build environment
|
||||||
|
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 \
|
||||||
|
inteliotdevkit/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 \
|
||||||
|
inteliotdevkit/upm-python \
|
||||||
|
bash -c "./scripts/run-cmake.sh && make -Cbuild"
|
||||||
|
```
|
||||||
|
@ -4,6 +4,41 @@ 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.6.0
|
||||||
|
|
||||||
|
* Extended LED library to support the new MRAA gpio-leds APIs
|
||||||
|
* Many CMake changes around SWIG wrapper generation and improved FindNodejs
|
||||||
|
detection module
|
||||||
|
* Several code fixes based on static code analysis
|
||||||
|
* Improved documentation generation and Travis CI builds
|
||||||
|
* Cleaned-up doxygen tags in headers and class names in JSON library files
|
||||||
|
* New sensor: lis3dh
|
||||||
|
|
||||||
|
### v1.5.0
|
||||||
|
|
||||||
|
* Introduced a flexible JSON format for technical sensor specifications, notes
|
||||||
|
and classification. This is also used by our [new UPM website](http://upm.mraa.io)
|
||||||
|
* Revised all C++ sensor examples and switched to stack allocations where
|
||||||
|
possible along with other code and formatting clean-up
|
||||||
|
* Significantly improved docker workflow, CI integration, sanity and
|
||||||
|
consistency tests, static code scans and documentation generation
|
||||||
|
* Several improvements to a couple of existing sensor drivers and better
|
||||||
|
compatibility with subplatforms
|
||||||
|
* Added new std::vector to AbstractList<> typemap for Java bindings and
|
||||||
|
examples
|
||||||
|
* New sensors: lis2ds12, lsm6ds3h, lsm6dsl, lidarlitev3
|
||||||
|
|
||||||
|
### v1.3.0
|
||||||
|
|
||||||
|
* Finalized all required build system and JAVA binding changes to release the
|
||||||
|
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}
|
||||||
@ -124,6 +125,8 @@ function make_new_sensor {
|
|||||||
# Search/replace the new files, replacing all instances of sensortemplate
|
# Search/replace the new files, replacing all instances of sensortemplate
|
||||||
perl -p -i -e "s/SensorTemplate/${SensorName}/g" src/${sensorname}/* examples/*/*${sensorname}* examples/*/*${SensorName}*
|
perl -p -i -e "s/SensorTemplate/${SensorName}/g" src/${sensorname}/* examples/*/*${sensorname}* examples/*/*${SensorName}*
|
||||||
perl -p -i -e "s/sensortemplate/${sensorname}/g" src/${sensorname}/* examples/*/*${sensorname}* examples/*/*${SensorName}*
|
perl -p -i -e "s/sensortemplate/${sensorname}/g" src/${sensorname}/* examples/*/*${sensorname}* examples/*/*${SensorName}*
|
||||||
|
# Remove objects starting with "//" from the new library descriptor .json file
|
||||||
|
perl -p -i -e 'BEGIN{undef $/;} s/\s+"\/\/.*?},//smg' src/${sensorname}/${sensorname}.json
|
||||||
# Add mynewmodule example target for java
|
# Add mynewmodule example target for java
|
||||||
perl -p -i -e "s/^((.*)SensorTemplateSample sensortemplate(.*))/\1\n\2${SensorName}Sample ${sensorname}\3/g" examples/java/CMakeLists.txt
|
perl -p -i -e "s/^((.*)SensorTemplateSample sensortemplate(.*))/\1\n\2${SensorName}Sample ${sensorname}\3/g" examples/java/CMakeLists.txt
|
||||||
# Add mynewmodule example mappings for doxygen
|
# Add mynewmodule example mappings for doxygen
|
||||||
|
@ -67,7 +67,6 @@ As much as possible, avoid passing values/returning values through pointers give
|
|||||||
```
|
```
|
||||||
|
|
||||||
3. Functions that return N values through pointers, that do not make sense to grouped together (e.g. a general purpose function that returns both the light intensity and air pollution), should be __replaced by__ N functions (one for each value) that read only one specific value. E.g.:
|
3. Functions that return N values through pointers, that do not make sense to grouped together (e.g. a general purpose function that returns both the light intensity and air pollution), should be __replaced by__ N functions (one for each value) that read only one specific value. E.g.:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
/*
|
/*
|
||||||
* Function returns the light intensity and air pollution
|
* Function returns the light intensity and air pollution
|
||||||
@ -82,7 +81,6 @@ As much as possible, avoid passing values/returning values through pointers give
|
|||||||
```
|
```
|
||||||
|
|
||||||
4. Functions that return N values through pointers; values that do not make sense to be grouped together, but are time dependent, and make sense to be read at the same time. For example, a sensor that reads air humidity and temperature. A user may want to know the temperature value _temp_ read at the exact moment the humidity value _humid_ was read. These should be __replaced by__ N+1 functions: a _getData()_ function that reads all values at the same time and stores them in global variables; and N getter functions, one for each value. E.g.
|
4. Functions that return N values through pointers; values that do not make sense to be grouped together, but are time dependent, and make sense to be read at the same time. For example, a sensor that reads air humidity and temperature. A user may want to know the temperature value _temp_ read at the exact moment the humidity value _humid_ was read. These should be __replaced by__ N+1 functions: a _getData()_ function that reads all values at the same time and stores them in global variables; and N getter functions, one for each value. E.g.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
/*
|
/*
|
||||||
* Function returns the light intensity and air pollution
|
* Function returns the light intensity and air pollution
|
||||||
@ -259,30 +257,19 @@ __Callbacks in the UPM Java library are implemented as follows (we use the a110x
|
|||||||
|
|
||||||
We extend the sensor class with another method, _installISR\(jobject runnable\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _mraa\_java\_isr\_callback\(\)_ method as the interrupt service routine \(ISR\) to be called, with _jobject runnable_ as argument.
|
We extend the sensor class with another method, _installISR\(jobject runnable\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _mraa\_java\_isr\_callback\(\)_ method as the interrupt service routine \(ISR\) to be called, with _jobject runnable_ as argument.
|
||||||
|
|
||||||
SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _installISR\(jobject runnable\)_ method in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
|
Java callbacks are added at the SWIG interface level. For ease-of-use, a collection of macros are available in src/_upm.i.
|
||||||
|
|
||||||
|
src/a110x/a110x.i:
|
||||||
```c++
|
```c++
|
||||||
#if defined(SWIGJAVA)
|
JAVA_ADD_INSTALLISR(upm::A110X)
|
||||||
void A110X::installISR(jobject runnable)
|
|
||||||
{
|
|
||||||
installISR(mraa_java_isr_callback, runnable);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
```
|
```
|
||||||
|
|
||||||
We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(jobject runnable\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
|
Will expand to the following SWIG wrapper code:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
public:
|
SWIGINTERN void upm_A110X_installISR__SWIG_1(upm::A110X *self,jobject runnable){
|
||||||
#if defined(SWIGJAVA)
|
self->installISR(mraa_java_isr_callback, runnable);
|
||||||
void installISR(jobject runnable);
|
}
|
||||||
#else
|
|
||||||
void installISR(void (*isr)(void *), void *arg);
|
|
||||||
#endif
|
|
||||||
private:
|
|
||||||
#if defined(SWIGJAVA)
|
|
||||||
void installISR(void (*isr)(void *), void *arg);
|
|
||||||
#endif
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To use callback in java, we create a ISR class, which implements the Java Runnable interface, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
|
To use callback in java, we create a ISR class, which implements the Java Runnable interface, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
|
||||||
@ -313,41 +300,3 @@ class A110XISR implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
####Issues with java callbacks and workarounds
|
|
||||||
|
|
||||||
__SWIGJAVA not defined at compile time__
|
|
||||||
|
|
||||||
Consider the following files:
|
|
||||||
* example.h - Header file for our source file
|
|
||||||
* example.cxx - Source file containing the class Example, for which we build java bindings
|
|
||||||
* example.i - The SWIG interface, that includes the example.h header file
|
|
||||||
|
|
||||||
The build process of a java module using SWIG is split into two steps:
|
|
||||||
|
|
||||||
1. Generating the intermediate files, from the SWIG interface file. This will produce the java class file (Example.java), the JNI file (exampleJNI.java) and wrapper file (example_wrap.cxx). The source file (example.cxx) is not needed in the first step.
|
|
||||||
|
|
||||||
```
|
|
||||||
swig -c++ -java example.i
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Generating the shared library from the C++ sources and wrapper file
|
|
||||||
```
|
|
||||||
g++ -fPIC -c example.cxx example_wrap.cxx -I/usr/lib/jvm/java-1.8.0/include -I/usr/lib/jvm/java-1.8.0/include/linux
|
|
||||||
g++ -shared example_wrap.o sensor.o -o libexample.so
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
SWIGJAVA is always defined when SWIG parses the interface file, meaning it will be defined when it parses the header file (example.h) that is included in the interface file (example.i).
|
|
||||||
SWIG also adds the "#define SWIGJAVA" directive in the wrapper file (example_wrap.cxx).
|
|
||||||
However, in generating the shared library the SWIGJAVA symbol is only defined in the example_wrap.cxx file, because of the added "#define SWIGJAVA" directive. But we have also used the "#if defined(SWIGJAVA)" check in the source file (example.cxx), and thus need to define SWIGJAVA for it too. If we define the SWIGJAVA symbol as a compile flag, when compiling the source code to object code, the SWIGJAVA compile flag and #define SWIGJAVA" directive will clash and give a double definition warning (only a warning).
|
|
||||||
|
|
||||||
In this example it is simple to compile the two source codes separately, one with the compile flag, the other without, and then create the shared library (libexample.so).
|
|
||||||
But in a big automatic build like the java upm libraries, this may prove too hard or too complicated to do. A workaround to this would be to define a custom symbol (e.q. JAVACALLBACK in the upm library) and also test for it. In short, replace:
|
|
||||||
```c++
|
|
||||||
#if defined(SWIGJAVA)
|
|
||||||
```
|
|
||||||
by
|
|
||||||
```c++
|
|
||||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
|
||||||
```
|
|
||||||
|
|
||||||
|
@ -10,93 +10,132 @@ sensors that you want to add to UPM:
|
|||||||
- Have the specific sensor manufacturer/model & version that you used, if you
|
- Have the specific sensor manufacturer/model & version that you used, if you
|
||||||
support multiple versions please list.
|
support multiple versions please list.
|
||||||
- Simple comments do not need full stops.
|
- Simple comments do not need full stops.
|
||||||
- Stick to <80 chars per line even in comments.
|
- Stick to <80 chars per line where possible.
|
||||||
- No text is allowed on the same line as the start or end of a comment /** */.
|
- No text is allowed on the same line as the start or end of a comment /** */.
|
||||||
|
|
||||||
####The sensor block
|
We currently document our libraries in the following way:
|
||||||
|
|
||||||
This is added just before the class declaration in your header(.h) file and has
|
* **Doxygen** is used for documenting the API and generating the categories on
|
||||||
mandatory fields. For single sensor libraries, this block will actually
|
the [UPM Libraries page](https://iotdk.intel.com/docs/master/upm/modules.html).
|
||||||
follow immediately after the library block. If you have multiple physical
|
You can learn more about the Doxygen syntax [here](http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html).
|
||||||
sensors, add this to every one.
|
* **JSON** is used to provide sensor specifications, descriptions, supported
|
||||||
Here's an example (disregard the "@verbatim" tags in your actual code):
|
platforms, links and other details.
|
||||||
|
|
||||||
```
|
When submitting a new driver, you will have to at least fill out the mandatory
|
||||||
@verbatim
|
fields as described below.
|
||||||
/**
|
|
||||||
* @library <lib-name>
|
### The library JSON file
|
||||||
* @sensor <chip-id>
|
|
||||||
* @comname <component-name>
|
Let's use the BME280 class snippet from the bmp280.json file as an example:
|
||||||
* @altname <alt-name>
|
|
||||||
* @altid <alt-id>
|
```json
|
||||||
* @type <component-category>
|
{
|
||||||
* @man <component-manufacturer>
|
"Library": "bmp280",
|
||||||
* @web <component-weblinks>
|
"Description": "Bosch Atmospheric Sensor Library",
|
||||||
* @con <connection-type>
|
"Sensor Class":
|
||||||
* @kit <component-kit>
|
{
|
||||||
*
|
"BME280":
|
||||||
* @brief Short class/sensor description
|
{
|
||||||
*
|
"Name": "Digital Humidity, Pressure, and Temperature Sensor",
|
||||||
* Then add a longer
|
"Description": "The BME280 is as combined digital humidity, pressure and temperature sensor based on proven sensing principles. The sensor module is housed in an extremely compact metal-lid LGA package with a footprint of only 2.5 * 2.5 mm2 with a height of 0.93 mm. Its small dimensions and its low power consumption allow the implementation in battery driven devices such as handsets, GPS modules or watches. The BME280 is register and performance compatible to the Bosch Sensortec BMP280 digital pressure sensor",
|
||||||
* description here.
|
"Aliases": ["bme280", "Grove - Barometer Sensor(BME280)"],
|
||||||
*
|
"Categories": ["pressure", "humidity", "temperature"],
|
||||||
* @image html <component-img.jpeg>
|
"Connections": ["gpio", "i2c", "spi"],
|
||||||
* @snippet <example-name.cxx> Interesting
|
"Project Type": ["prototyping", "industrial"],
|
||||||
*/
|
"Manufacturers": ["adafruit", "seeed", "bosch"],
|
||||||
@endverbatim
|
"Examples":
|
||||||
|
{
|
||||||
|
"Java": ["BMP280_Example.java"],
|
||||||
|
"Python": ["bmp280.py"],
|
||||||
|
"Node.js": ["bmp280.js"],
|
||||||
|
"C++": ["bmp280.cxx"],
|
||||||
|
"C": ["bmp280.c"]
|
||||||
|
},
|
||||||
|
"Specifications":
|
||||||
|
{
|
||||||
|
"Vdd": {"unit": "v", "low" : 1.7, "high": 3.6},
|
||||||
|
"Ioff" : {"unit": "mA", "low" : 0.0, "high": 0.0},
|
||||||
|
"Iavg": {"unit": "mA", "low" : 1, "high": 2},
|
||||||
|
"Pressure Range": {"unit": "hpA", "low" : 300, "high": 1100},
|
||||||
|
"Temperature Range": {"unit": "C", "low" : -40, "high": 85}
|
||||||
|
},
|
||||||
|
"Platforms":
|
||||||
|
{
|
||||||
|
"Intel Joule Module":
|
||||||
|
{
|
||||||
|
"Notes": ["Requires pull-up resistors with carrier board"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Urls" :
|
||||||
|
{
|
||||||
|
"Product Pages": ["https://www.adafruit.com/products/2652"],
|
||||||
|
"Datasheets": ["https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf"],
|
||||||
|
"Schematics": ["https://learn.adafruit.com/assets/26693"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- `<lib-name>` When adding to an existing library this needs to match that
|
#### Mandatory fields:
|
||||||
library's "@defgroup", otherwise this is a new library name, generally the
|
|
||||||
same as chip id. *Mandatory*
|
|
||||||
- `<chip-id>` Usually the chip number used by the sensor. When this is not
|
|
||||||
available or relevant, use a unique descriptor that makes sense. Must match
|
|
||||||
class name. *Mandatory*
|
|
||||||
- `<component-name>` Title Case descriptive name for your sensor, try to avoid
|
|
||||||
including the manufacturer's name here. Examples: Digital Pressure Sensor,
|
|
||||||
Serial MP3 Module, etc... *Mandatory*
|
|
||||||
- `<alt-name>` Alternative names that your sensor driver might have. This may
|
|
||||||
include manufacturer's name. *Optional*
|
|
||||||
- `<alt-id>` Alternative chip-ids that your sensor driver supports. *Optional*
|
|
||||||
- `<component-category>` Mention one or more categories the sensor fits in. Can
|
|
||||||
be 'other'. *Mandatory*
|
|
||||||
- `<component-manufacturer>` Sensor manufacturer. Can be 'generic'. *Mandatory*
|
|
||||||
- `<component-weblinks>` Links to vendors or data-sheets. *Optional*
|
|
||||||
- `<connection-type>` Specifies how does the sensor connect to the board
|
|
||||||
*Mandatory*
|
|
||||||
- `<component-kit>` Specifies if the sensor is part of a kit. *Optional*
|
|
||||||
|
|
||||||
Existing groups that can be used for the manufacturer, connection, category and
|
For the library:
|
||||||
kit tags are found in the *src/groups.md* file.
|
|
||||||
|
|
||||||
Optionally, a small representative image can be placed in the "docs/images"
|
- `Library` The name of the library. This is appended to the upm prefix during
|
||||||
subfolder and linked with the "@image" tag.
|
a build.
|
||||||
**Please do not use existing, copyrighted images with your sensors!**
|
- `Description` A short description of the library and what it contains.
|
||||||
|
|
||||||
The example should have an 'Interesting' section which will be highlighted as
|
For the sensor classes:
|
||||||
a code sample in doxygen. Everything in between such tags will show up in the
|
|
||||||
class documentation when "@snippet" is added at the end of a class docstring.
|
|
||||||
Tags use this format (in "example-name.cxx"):
|
|
||||||
|
|
||||||
```
|
- `Sensor Class` This is the object containing the sensor class(es) within the
|
||||||
@verbatim
|
library. Class objects need to match the name used in code.
|
||||||
//! [Interesting]
|
- `Name` Title Case descriptive names for your sensor. Multiple values can be
|
||||||
|
used to capture the chip name, generic name, or specific name for a vendor.
|
||||||
|
Examples: Digital Pressure Sensor, Serial MP3 Module
|
||||||
|
- `Description` A more detailed explanation what the sensor does and how it
|
||||||
|
works.
|
||||||
|
- `Categories` Mention one or more categories the sensor fits in. Accepted
|
||||||
|
values are listed in the groups.md file.
|
||||||
|
- `Connections` Specifies how does the sensor connect to the board. Accepted
|
||||||
|
values are listed in the groups.md file.
|
||||||
|
- `Project Type` What time of projects is the sensor suited for. For example:
|
||||||
|
prototyping, industrial, commercial.
|
||||||
|
- `Manufacturers` List of sensor manufacturers or vendors. Can be 'generic',
|
||||||
|
other accepted values in groups.md.
|
||||||
|
- `Examples` Names of the example files provided with the library. At a minimum,
|
||||||
|
the `C++` example needs to be provided.
|
||||||
|
- `Urls` At least one link for `Product Pages` needs to be provided. Additional
|
||||||
|
links to `Datasheets` or `Schematics` can be added.
|
||||||
|
|
||||||
...example code here...
|
#### Optional and customizable fields
|
||||||
|
|
||||||
//! [Interesting]
|
- `Kits` Specifies if the sensor is part of a kit. Accepted values are listed
|
||||||
@endverbatim
|
in the groups.md file.
|
||||||
```
|
- `Image` Name of the image file provided with the sensor class.
|
||||||
|
- `Specifications` Relevant sensor specifications as listed in the datasheet.
|
||||||
|
- `Platforms` Platform specific notes or known limitations and workarounds.
|
||||||
|
|
||||||
For more examples take a look at the existing headers in our github repository.
|
As mentioned, accepted values for some of the fields are listed under the
|
||||||
|
[groups.md](../src/groups.md) file. If needed, you can add new categories
|
||||||
|
for your sensor library following the existing format.
|
||||||
|
|
||||||
####The library block
|
JSON files are automatically checked for correctness and required fields on
|
||||||
|
code submissions.
|
||||||
|
|
||||||
|
**Please do not use copyrighted images with your sensors!**
|
||||||
|
|
||||||
|
Images from Seeed, DFRobot, Sparkfun or Adafruit are permitted.
|
||||||
|
|
||||||
|
### Doxygen tags
|
||||||
|
|
||||||
|
#### The library doxygen block
|
||||||
|
|
||||||
New libraries must have the "@brief", "@defgroup" and "@ingroup" tags in one
|
New libraries must have the "@brief", "@defgroup" and "@ingroup" tags in one
|
||||||
block. This usually follows the namespace and it is common to have one sensor
|
block. This usually follows the namespace and it is common to have one sensor
|
||||||
per library.
|
per library.
|
||||||
|
|
||||||
You should end up with something like this:
|
You should end up with something like this (disregard the "@verbatim" tags in
|
||||||
|
your actual code):
|
||||||
|
|
||||||
```
|
```
|
||||||
@verbatim
|
@verbatim
|
||||||
@ -111,8 +150,43 @@ You should end up with something like this:
|
|||||||
@endverbatim
|
@endverbatim
|
||||||
```
|
```
|
||||||
|
|
||||||
In "@defgroup" use the same `<lib-name>` used in the sensor block. Multiple
|
Use `<lib-name>` to name the library.
|
||||||
sensors can be added to the same library this way.
|
|
||||||
For "@ingroup" add the same values as in the sensor block for manufacturer,
|
For "@ingroup" add the same values as in the sensor block for manufacturer,
|
||||||
category, connection type and kit. If you have multiple classes or sensors
|
category, connection type and kit. If you have multiple classes or sensors
|
||||||
per library, only use the "@ingroup" tags that are common for all of them.
|
per library, only use the "@ingroup" tags that are common for all of them.
|
||||||
|
|
||||||
|
Existing groups that can be used for the manufacturer, connection, category and
|
||||||
|
kit tags are found in the *src/groups.md* file.
|
||||||
|
|
||||||
|
#### The sensor doxygen block
|
||||||
|
|
||||||
|
This is added just before the class declaration in your header(.hpp) file and has
|
||||||
|
one mandatory field. For single sensor libraries, this block will actually follow
|
||||||
|
immediately after the library block. If you have multiple sensor classes, add
|
||||||
|
this to every one.
|
||||||
|
|
||||||
|
Here's an example:
|
||||||
|
|
||||||
|
```
|
||||||
|
@verbatim
|
||||||
|
/**
|
||||||
|
* @library <lib-name>
|
||||||
|
* @brief Short class/sensor description
|
||||||
|
*
|
||||||
|
* Then add a longer
|
||||||
|
* description here.
|
||||||
|
*/
|
||||||
|
@endverbatim
|
||||||
|
```
|
||||||
|
|
||||||
|
When adding to an existing library, `<lib-name>` needs to match that library's
|
||||||
|
"@defgroup".
|
||||||
|
|
||||||
|
For more examples take a look at the existing headers in our github repository.
|
||||||
|
Also, make sure to check our [sensortemplate](contributions.md#creating-a-new-sensor-library-using-the-sensortemplate)
|
||||||
|
as it can facilitate new sensor additions.
|
||||||
|
|
||||||
|
Existing header files might have additional fields under the sensor block. These
|
||||||
|
have been used in the past to generate sensor pages outside of doxygen, but they
|
||||||
|
are now deprecated and not required for new additions.
|
||||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 14 KiB |
BIN
docs/icons/upm_logo.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
docs/images/lidarlitev3.jpg
Normal file
After Width: | Height: | Size: 156 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
BIN
docs/images/noelstemplightreader.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
docs/images/tca9548a.jpg
Normal file
After Width: | Height: | Size: 616 KiB |
@ -48,11 +48,11 @@ To install:
|
|||||||
```bash
|
```bash
|
||||||
sudo add-apt-repository ppa:mraa/mraa
|
sudo add-apt-repository ppa:mraa/mraa
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install libupm-dev python-upm python3-upm upm-examples
|
sudo apt-get install libupm-dev libupm-java python-upm python3-upm node-upm upm-examples
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that the Ubuntu PPA only provides the C/C++ and Python packages. Node.js
|
Running UPM applications on Ubuntu systems requires elevated permissions
|
||||||
developers will have to install MRAA and UPM using NPM instead.
|
(e.g. run with `sudo`).
|
||||||
|
|
||||||
### Node.js bindings only (NPM)
|
### Node.js bindings only (NPM)
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -14,8 +14,7 @@ First thing to do is to create a tree structure like this in upm/src/max31855:
|
|||||||
|
|
||||||
* max31855.cxx
|
* max31855.cxx
|
||||||
* max31855.hpp
|
* max31855.hpp
|
||||||
* jsupm_max31855.i
|
* max31855.i
|
||||||
* pyupm_max31855.i
|
|
||||||
* CMakeLists.txt
|
* CMakeLists.txt
|
||||||
|
|
||||||
And then an example file to use & test our lib with in upm/examples/max31855.cxx.
|
And then an example file to use & test our lib with in upm/examples/max31855.cxx.
|
||||||
|
@ -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
|
||||||
@ -704,7 +702,7 @@ CITE_BIB_FILES =
|
|||||||
# messages are off.
|
# messages are off.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
QUIET = NO
|
QUIET = YES
|
||||||
|
|
||||||
# The WARNINGS tag can be used to turn on/off the warning messages that are
|
# The WARNINGS tag can be used to turn on/off the warning messages that are
|
||||||
# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES
|
# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES
|
||||||
@ -862,7 +860,8 @@ EXCLUDE_SYMLINKS = NO
|
|||||||
# bmi160 driver contains code provided by bosch. This source contains
|
# bmi160 driver contains code provided by bosch. This source contains
|
||||||
# tags which are picked up by doxygen (namely \mainpage) and
|
# tags which are picked up by doxygen (namely \mainpage) and
|
||||||
# incorrectly get added to docs.
|
# incorrectly get added to docs.
|
||||||
EXCLUDE_PATTERNS = bosch_*
|
EXCLUDE_PATTERNS = bosch_* \
|
||||||
|
sensortemplate*
|
||||||
|
|
||||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||||
@ -1861,18 +1860,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
|
||||||
@ -704,7 +702,7 @@ CITE_BIB_FILES =
|
|||||||
# messages are off.
|
# messages are off.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
QUIET = NO
|
QUIET = YES
|
||||||
|
|
||||||
# The WARNINGS tag can be used to turn on/off the warning messages that are
|
# The WARNINGS tag can be used to turn on/off the warning messages that are
|
||||||
# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES
|
# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES
|
||||||
@ -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/doxyport
Submodule
@ -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
@ -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;
|
|
@ -1,79 +1,79 @@
|
|||||||
# Mapping examples across provided languages
|
# Mapping examples across provided languages
|
||||||
a110x.cxx A110XSample.java a110x.js a110x.py
|
a110x.cxx A110X_Example.java a110x.js a110x.py
|
||||||
a110x-intr.cxx A110X_intrSample.java a110x-intr.js a110x-intr.py
|
a110x-intr.cxx A110X_intr_Example.java a110x-intr.js a110x-intr.py
|
||||||
adc121c021.cxx ADC121C021Sample.java adc121c021.js adc121c021.py
|
adc121c021.cxx ADC121C021_Example.java adc121c021.js adc121c021.py
|
||||||
adxl345.cxx Adxl345Sample.java adxl345.js adxl345.py
|
adxl345.cxx Adxl345_Example.java adxl345.js adxl345.py
|
||||||
biss0001.cxx BISS0001Sample.java biss0001.js biss0001.py
|
biss0001.cxx BISS0001_Example.java biss0001.js biss0001.py
|
||||||
bmpx8x.cxx BMPX8XSample.java bmpx8x.js bmpx8x.py
|
bmpx8x.cxx BMPX8X_Example.java bmpx8x.js bmpx8x.py
|
||||||
bno055.cxx BNO055_Example.java bno055.js bno055.py
|
bno055.cxx BNO055_Example.java bno055.js bno055.py
|
||||||
button.cxx ButtonSample.java button.js button.py
|
button.cxx Button_Example.java button.js button.py
|
||||||
buzzer.cxx BuzzerSample.java buzzer.js buzzer.py
|
buzzer.cxx Buzzer_Example.java buzzer.js buzzer.py
|
||||||
cjq4435.cxx CJQ4435Sample.java cjq4435.js cjq4435.py
|
cjq4435.cxx CJQ4435_Example.java cjq4435.js cjq4435.py
|
||||||
ds1307.cxx DS1307Sample.java ds1307.js ds1307.py
|
ds1307.cxx DS1307_Example.java ds1307.js ds1307.py
|
||||||
enc03r.cxx ENC03RSample.java enc03r.js enc03r.py
|
enc03r.cxx ENC03R_Example.java enc03r.js enc03r.py
|
||||||
servo-es08a.cxx ES08ASample.java es08a.js es08a.py
|
servo-es08a.cxx ES08A_Example.java es08a.js es08a.py
|
||||||
groveehr.cxx GroveEHRSample.java groveehr.js groveehr.py
|
groveehr.cxx GroveEHR_Example.java groveehr.js groveehr.py
|
||||||
my9221-groveledbar.cxx GroveLEDBar.java groveledbar.js groveledbar.py
|
my9221-groveledbar.cxx GroveLEDBar_Example.java groveledbar.js groveledbar.py
|
||||||
grove-groveled.cxx GroveLEDSample.java groveled.js groveled.py
|
grove-groveled.cxx GroveLED_Example.java groveled.js groveled.py
|
||||||
grovelinefinder.cxx GroveLineFinderSample.java grovelinefinder.js grovelinefinder.py
|
grovelinefinder.cxx GroveLineFinder_Example.java grovelinefinder.js grovelinefinder.py
|
||||||
grovemoisture.cxx GroveMoistureSample.java grovemoisture.js grovemoisture.py
|
grovemoisture.cxx GroveMoisture_Example.java grovemoisture.js grovemoisture.py
|
||||||
grovescam.cxx GROVESCAMSample.java grovescam.js grovescam.py
|
grovescam.cxx GROVESCAM_Example.java grovescam.js grovescam.py
|
||||||
grovewfs.cxx GroveWFSSample.java grovewfs.js grovewfs.py
|
grovewfs.cxx GroveWFS_Example.java grovewfs.js grovewfs.py
|
||||||
guvas12d.cxx GUVAS12DSample.java guvas12d.js guvas12d.py
|
guvas12d.cxx GUVAS12D_Example.java guvas12d.js guvas12d.py
|
||||||
h3lis331dl.cxx H3LIS331DLSample.java h3lis331dl.js h3lis331dl.py
|
h3lis331dl.cxx H3LIS331DL_Example.java h3lis331dl.js h3lis331dl.py
|
||||||
hcsr04.cxx HCSR04Sample.java hcsr04.js hcsr04.py
|
hcsr04.cxx HCSR04_Example.java hcsr04.js hcsr04.py
|
||||||
hm11.cxx HM11Sample.java hm11.js hm11.py
|
hm11.cxx HM11_Example.java hm11.js hm11.py
|
||||||
hmc5883l.cxx Hmc5883lSample.java hmc5883l.js hmc5883l.py
|
hmc5883l.cxx Hmc5883l_Example.java hmc5883l.js hmc5883l.py
|
||||||
htu21d.cxx HTU21DSample.java htu21d.js htu21d.py
|
htu21d.cxx HTU21D_Example.java htu21d.js htu21d.py
|
||||||
ims.cxx IMS_Example.java ims.js ims.py
|
ims.cxx IMS_Example.java ims.js ims.py
|
||||||
itg3200.cxx Itg3200Sample.java itg3200.js itg3200.py
|
itg3200.cxx Itg3200_Example.java itg3200.js itg3200.py
|
||||||
jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java jhd1313m1-lcd.js jhd1313m1-lcd.py
|
jhd1313m1-lcd.cxx Jhd1313m1_lcd_Example.java jhd1313m1-lcd.js jhd1313m1-lcd.py
|
||||||
joystick12.cxx Joystick12Sample.java joystick12.js joystick12.py
|
joystick12.cxx Joystick12_Example.java joystick12.js joystick12.py
|
||||||
lcm1602-i2c.cxx Lcm1602_i2cSample.java lcm1602-i2c.js lcm1602-i2c.py
|
lcm1602-i2c.cxx Lcm1602_i2c_Example.java lcm1602-i2c.js lcm1602-i2c.py
|
||||||
ldt0028.cxx LDT0028Sample.java ldt0028.js ldt0028.py
|
ldt0028.cxx LDT0028_Example.java ldt0028.js ldt0028.py
|
||||||
light.cxx LightSample.java light.js light.py
|
light.cxx Light_Example.java light.js light.py
|
||||||
lol.cxx LoLSample.java lol.js lol.py
|
lol.cxx LoL_Example.java lol.js lol.py
|
||||||
lsm303.cxx LSM303Sample.java lsm303.js lsm303.py
|
lsm303dlh.cxx LSM303DLH_Example.java lsm303dlh.js lsm303dlh.py
|
||||||
m24lr64e.cxx M24LR64ESample.java m24lr64e.js m24lr64e.py
|
m24lr64e.cxx M24LR64E_Example.java m24lr64e.js m24lr64e.py
|
||||||
max44000.cxx MAX44000Sample.java max44000.js max44000.py
|
max44000.cxx MAX44000_Example.java max44000.js max44000.py
|
||||||
mic.cxx MicrophoneSample.java mic.js mic.py
|
mic.cxx Microphone_Example.java mic.js mic.py
|
||||||
mma7455.cxx MMA7455Sample.java mma7455.js mma7455.py
|
mma7455.cxx MMA7455_Example.java mma7455.js mma7455.py
|
||||||
mma7660.cxx MMA7660Sample.java mma7660.js mma7660.py
|
mma7660.cxx MMA7660_Example.java mma7660.js mma7660.py
|
||||||
mpl3115a2.cxx MPL3115A2Sample.java mpl3115a2.js mpl3115a2.py
|
mpl3115a2.cxx MPL3115A2_Example.java mpl3115a2.js mpl3115a2.py
|
||||||
mpr121.cxx MPR121Sample.java mpr121.js mpr121.py
|
mpr121.cxx MPR121_Example.java mpr121.js mpr121.py
|
||||||
mpu9150.cxx MPU9150Sample.java mpu9150.js mpu9150.py
|
mpu9150.cxx MPU9150_Example.java mpu9150.js mpu9150.py
|
||||||
gas-mq2.cxx MQ2Sample.java mq2.js mq2.py
|
gas-mq2.cxx MQ2_Example.java mq2.js mq2.py
|
||||||
mq303a.cxx MQ303ASample.java mq303a.js mq303a.py
|
mq303a.cxx MQ303A_Example.java mq303a.js mq303a.py
|
||||||
gas-mq5.cxx MQ5Sample.java mq5.js mq5.py
|
gas-mq5.cxx MQ5_Example.java mq5.js mq5.py
|
||||||
nrf24l01-receiver.cxx NRF24L01_receiverSample.java nrf24l01-receiver.js nrf24l01-receiver.py
|
nrf24l01-receiver.cxx NRF24L01_receiver_Example.java nrf24l01-receiver.js nrf24l01-receiver.py
|
||||||
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java nrf24l01-transmitter.js nrf24l01-transmitter.py
|
nrf24l01-transmitter.cxx NRF24L01_transmitter_Example.java nrf24l01-transmitter.js nrf24l01-transmitter.py
|
||||||
nunchuck.cxx NUNCHUCKSample.java nunchuck.js nunchuck.py
|
nunchuck.cxx NUNCHUCK_Example.java nunchuck.js nunchuck.py
|
||||||
otp538u.cxx OTP538USample.java otp538u.js otp538u.py
|
otp538u.cxx OTP538U_Example.java otp538u.js otp538u.py
|
||||||
ppd42ns.cxx PPD42NSSample.java ppd42ns.js ppd42ns.py
|
ppd42ns.cxx PPD42NS_Example.java ppd42ns.js ppd42ns.py
|
||||||
pulsensor.cxx PulsensorSample.java pulsensor.js pulsensor.py
|
pulsensor.cxx Pulsensor_Example.java pulsensor.js pulsensor.py
|
||||||
relay.cxx RelaySample.java relay.js relay.py
|
relay.cxx Relay_Example.java relay.js relay.py
|
||||||
rfr359f.cxx RFR359FSample.java rfr359f.js rfr359f.py
|
rfr359f.cxx RFR359F_Example.java rfr359f.js rfr359f.py
|
||||||
rotary.cxx RotarySample.java rotary.js rotary.py
|
rotary.cxx Rotary_Example.java rotary.js rotary.py
|
||||||
rotaryencoder.cxx RotaryEncoderSample.java rotaryencoder.js rotaryencoder.py
|
rotaryencoder.cxx RotaryEncoder_Example.java rotaryencoder.js rotaryencoder.py
|
||||||
rpr220.cxx RPR220Sample.java rpr220.js rpr220.py
|
rpr220.cxx RPR220_Example.java rpr220.js rpr220.py
|
||||||
rpr220-intr.cxx RPR220_intrSample.java rpr220-intr.js rpr220-intr.py
|
rpr220-intr.cxx RPR220_intr_Example.java rpr220-intr.js rpr220-intr.py
|
||||||
slide.cxx SlideSample.java slide.js slide.py
|
slide.cxx Slide_Example.java slide.js slide.py
|
||||||
speaker.cxx SpeakerSample.java speaker.js speaker.py
|
speaker.cxx Speaker_Example.java speaker.js speaker.py
|
||||||
i2clcd-ssd1308-oled.cxx SSD1308_oledSample.java ssd1308-oled.js ssd1308-oled.py
|
lcd-ssd1308-oled.cxx SSD1308_oled_Example.java ssd1308-oled.js ssd1308-oled.py
|
||||||
i2clcd-ssd1327-oled.cxx SSD1327_oledSample.java ssd1327-oled.js ssd1327-oled.py
|
lcd-ssd1327-oled.cxx SSD1327_oled_Example.java ssd1327-oled.js ssd1327-oled.py
|
||||||
st7735.cxx ST7735Sample.java st7735.js st7735.py
|
st7735.cxx ST7735_Example.java st7735.js st7735.py
|
||||||
stepmotor.cxx StepMotorSample.java stepmotor.js stepmotor.py
|
stepmotor.cxx StepMotor_Example.java stepmotor.js stepmotor.py
|
||||||
tm1637.cxx TM1637Sample.java tm1637.js tm1637.py
|
tm1637.cxx TM1637_Example.java tm1637.js tm1637.py
|
||||||
gas-tp401.cxx TP401Sample.java tp401.js tp401.py
|
gas-tp401.cxx TP401_Example.java tp401.js tp401.py
|
||||||
tsl2561.cxx TSL2561Sample.java tsl2561.js tsl2561.py
|
tsl2561.cxx TSL2561_Example.java tsl2561.js tsl2561.py
|
||||||
ttp223.cxx TTP223Sample.java ttp223.js ttp223.py
|
ttp223.cxx TTP223_Example.java ttp223.js ttp223.py
|
||||||
uln200xa.cxx ULN200XASample.java uln200xa.js uln200xa.py
|
uln200xa.cxx ULN200XA_Example.java uln200xa.js uln200xa.py
|
||||||
vdiv.cxx VDivSample.java vdiv.js vdiv.py
|
vdiv.cxx VDiv_Example.java vdiv.js vdiv.py
|
||||||
water.cxx WaterSample.java water.js water.py
|
water.cxx Water_Example.java water.js water.py
|
||||||
wt5001.cxx WT5001Sample.java wt5001.js wt5001.py
|
wt5001.cxx WT5001_Example.java wt5001.js wt5001.py
|
||||||
yg1006.cxx YG1006Sample.java yg1006.js yg1006.py
|
yg1006.cxx YG1006_Example.java yg1006.js yg1006.py
|
||||||
sensortemplate.cxx SensorTemplateSample.java sensortemplate.js sensortemplate.py
|
sensortemplate.cxx SensorTemplate_Example.java sensortemplate.js sensortemplate.py
|
||||||
p9813.cxx P9813Sample.java p9813.js p9813.py
|
p9813.cxx P9813_Example.java p9813.js p9813.py
|
||||||
tcs37727.cxx tcs37727.py
|
tcs37727.cxx tcs37727.py
|
||||||
tmp006.cxx tmp006.py
|
tmp006.cxx tmp006.py
|
||||||
mma8x5x.cxx mma8x5x.py
|
mma8x5x.cxx mma8x5x.py
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
# a110x.c Requires libupmc-a110x
|
# a110x.c Requires libupmc-a110x
|
||||||
# lcm1602-i2c.c Requires libupmc-lcm1602
|
# lcm1602-i2c.c Requires libupmc-lcm1602
|
||||||
# bmp280-bme280.c Requires libupmc-bmp280
|
# bmp280-bme280.c Requires libupmc-bmp280
|
||||||
# i2clcd-eboled.cxx Requires libupm-i2clcd
|
# lcd-eboled.cxx Requires libupm-lcd
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
function (add_example example_src)
|
function (add_example example_src)
|
||||||
@ -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 ()
|
||||||
@ -94,12 +99,8 @@ function (add_example example_src)
|
|||||||
|
|
||||||
# Add each dependency to the library target
|
# Add each dependency to the library target
|
||||||
foreach(_dep_target ${lib_target_names})
|
foreach(_dep_target ${lib_target_names})
|
||||||
target_link_libraries(${this_target_name} ${_dep_target} ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(${this_target_name} ${_dep_target} ${CMAKE_THREAD_LIBS_INIT} utilities-c)
|
||||||
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
|
||||||
@ -116,4 +117,16 @@ if(BUILDEXAMPLES)
|
|||||||
if(BUILDSWIGJAVA)
|
if(BUILDSWIGJAVA)
|
||||||
add_subdirectory (java)
|
add_subdirectory (java)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Add all examples as an install component (if building examples)
|
||||||
|
install (DIRECTORY ${PROJECT_SOURCE_DIR}/examples
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/upm
|
||||||
|
COMPONENT ${CMAKE_PROJECT_NAME}-examples
|
||||||
|
FILES_MATCHING
|
||||||
|
PATTERN "*.c"
|
||||||
|
PATTERN "*.cxx"
|
||||||
|
PATTERN "*.hpp"
|
||||||
|
PATTERN "*.java"
|
||||||
|
PATTERN "*.js"
|
||||||
|
PATTERN "*.py")
|
||||||
endif()
|
endif()
|
||||||
|
@ -4,15 +4,15 @@ file (GLOB example_src_list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cxx")
|
|||||||
# - Handle special cases here --------------------------------------------------
|
# - Handle special cases here --------------------------------------------------
|
||||||
|
|
||||||
# Test humidity interface for 2 sensor libraries
|
# Test humidity interface for 2 sensor libraries
|
||||||
add_example(interfaces-humiditysensor.cxx TARGETS si7005 bmp280)
|
add_example(core-humiditysensor.cxx TARGETS si7005 bmp280)
|
||||||
# Test pressure interface for 2 sensor libraries
|
# Test pressure interface for 2 sensor libraries
|
||||||
add_example(interfaces-pressuresensor.cxx TARGETS bmp280 bmpx8x)
|
add_example(core-pressuresensor.cxx TARGETS bmp280 bmpx8x)
|
||||||
# Test temperature interface for 3 sensor libraries
|
# Test temperature interface for 3 sensor libraries
|
||||||
add_example(interfaces-temperaturesensor.cxx TARGETS bmp280 bmpx8x si7005)
|
add_example(core-temperaturesensor.cxx TARGETS bmp280 bmpx8x si7005)
|
||||||
# Test light interface for 2 sensor libraries
|
# Test light interface for 2 sensor libraries
|
||||||
add_example(interfaces-lightsensor.cxx TARGETS si1132 max44009)
|
add_example(core-lightsensor.cxx TARGETS si1132 max44009)
|
||||||
# Test light controller interface for 3 sensor libraries
|
# Test light controller interface for 3 sensor libraries
|
||||||
add_example(interfaces-lightcontroller.cxx TARGETS lp8860 ds1808lc hlg150h)
|
add_example(core-lightcontroller.cxx TARGETS lp8860 ds1808lc hlg150h)
|
||||||
|
|
||||||
# - Create an executable for all other src files in this directory -------------
|
# - Create an executable for all other src files in this directory -------------
|
||||||
foreach (_example_src ${example_src_list})
|
foreach (_example_src ${example_src_list})
|
||||||
|
@ -22,16 +22,19 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "a110x.hpp"
|
#include "a110x.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
@ -41,36 +44,36 @@ void sig_handler(int signo)
|
|||||||
volatile unsigned int counter = 0;
|
volatile unsigned int counter = 0;
|
||||||
|
|
||||||
// Our interrupt handler
|
// Our interrupt handler
|
||||||
void hallISR(void *arg)
|
void
|
||||||
|
hallISR(void* arg)
|
||||||
{
|
{
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main ()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an A110X sensor on digital pin D2
|
// Instantiate an A110X sensor on digital pin D2
|
||||||
upm::A110X* hall = new upm::A110X(2);
|
upm::A110X hall(2);
|
||||||
|
|
||||||
// This example uses a user-supplied interrupt handler to count
|
// This example uses a user-supplied interrupt handler to count
|
||||||
// pulses that occur when a magnetic field of the correct polarity
|
// pulses that occur when a magnetic field of the correct polarity
|
||||||
// is detected. This could be used to measure the rotations per
|
// is detected. This could be used to measure the rotations per
|
||||||
// minute (RPM) of a rotor for example.
|
// minute (RPM) of a rotor for example.
|
||||||
|
|
||||||
hall->installISR(hallISR, NULL);
|
hall.installISR(hallISR, NULL);
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
cout << "Pulses detected: " << counter << endl;
|
cout << "Pulses detected: " << counter << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete hall;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,46 +22,46 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "a110x.hpp"
|
#include "a110x.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main ()
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an A110X sensor on digital pin D2
|
// Instantiate an A110X sensor on digital pin D2
|
||||||
upm::A110X* hall = new upm::A110X(2);
|
upm::A110X hall(2);
|
||||||
|
|
||||||
// check every second for the presence of a magnetic field (south
|
// check every second for the presence of a magnetic field (south
|
||||||
// polarity)
|
// polarity)
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
bool val = hall.magnetDetected();
|
||||||
bool val = hall->magnetDetected();
|
|
||||||
if (val)
|
if (val)
|
||||||
cout << "Magnet (south polarity) detected." << endl;
|
cout << "Magnet (south polarity) detected." << endl;
|
||||||
else
|
else
|
||||||
cout << "No magnet detected." << endl;
|
cout << "No magnet detected." << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete hall;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,40 +22,41 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "abp.hpp"
|
#include "abp.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main ()
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an ABP sensor on i2c bus 0
|
// Instantiate an ABP sensor on i2c bus 0
|
||||||
upm::ABP* abp = new upm::ABP(0, ABP_DEFAULT_ADDRESS);
|
upm::ABP abp(0, ABP_DEFAULT_ADDRESS);
|
||||||
while (shouldRun) {
|
while (shouldRun) {
|
||||||
abp->update();
|
abp.update();
|
||||||
cout << "Retrieved pressure: " << abp->getPressure() << endl;
|
cout << "Retrieved pressure: " << abp.getPressure() << endl;
|
||||||
cout << "Retrieved Temperature: " << abp->getTemperature() << endl;
|
cout << "Retrieved Temperature: " << abp.getTemperature() << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete abp;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,44 +22,45 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "ad8232.hpp"
|
#include "ad8232.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
|
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
|
||||||
// and an analog pin, 0 (OUTPUT)
|
// and an analog pin, 0 (OUTPUT)
|
||||||
upm::AD8232 *ad8232 = new upm::AD8232(10, 11, 0);
|
upm::AD8232 ad8232(10, 11, 0);
|
||||||
|
|
||||||
// Output the raw numbers from the ADC, for plotting elsewhere.
|
// Output the raw numbers from the ADC, for plotting elsewhere.
|
||||||
// A return of 0 indicates a Lead Off (LO) condition.
|
// A return of 0 indicates a Lead Off (LO) condition.
|
||||||
// In theory, this data could be fed to software like Processing
|
// In theory, this data could be fed to software like Processing
|
||||||
// (https://www.processing.org/) to plot the data just like an
|
// (https://www.processing.org/) to plot the data just like an
|
||||||
// EKG you would see in a hospital.
|
// EKG you would see in a hospital.
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
cout << ad8232.value() << endl;
|
||||||
cout << ad8232->value() << endl;
|
upm_delay_us(1000);
|
||||||
usleep(1000);
|
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete ad8232;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,61 +22,56 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "adafruitms1438.hpp"
|
#include "adafruitms1438.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an Adafruit MS 1438 on I2C bus 0
|
// Instantiate an Adafruit MS 1438 on I2C bus 0
|
||||||
|
|
||||||
upm::AdafruitMS1438 *ms =
|
upm::AdafruitMS1438 ms(ADAFRUITMS1438_I2C_BUS, ADAFRUITMS1438_DEFAULT_I2C_ADDR);
|
||||||
new upm::AdafruitMS1438(ADAFRUITMS1438_I2C_BUS,
|
|
||||||
ADAFRUITMS1438_DEFAULT_I2C_ADDR);
|
|
||||||
|
|
||||||
// Setup for use with a stepper motor connected to the M1 & M2 ports
|
// Setup for use with a stepper motor connected to the M1 & M2 ports
|
||||||
|
|
||||||
// set a PWM period of 50Hz
|
// set a PWM period of 50Hz
|
||||||
|
|
||||||
// disable first, to be safe
|
// disable first, to be safe
|
||||||
ms->disableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
ms.disableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||||
|
|
||||||
// configure for a NEMA-17, 200 steps per revolution
|
// configure for a NEMA-17, 200 steps per revolution
|
||||||
ms->stepConfig(AdafruitMS1438::STEPMOTOR_M12, 200);
|
ms.stepConfig(AdafruitMS1438::STEPMOTOR_M12, 200);
|
||||||
|
|
||||||
// set speed at 10 RPM's
|
// set speed at 10 RPM's
|
||||||
ms->setStepperSpeed(AdafruitMS1438::STEPMOTOR_M12, 10);
|
ms.setStepperSpeed(AdafruitMS1438::STEPMOTOR_M12, 10);
|
||||||
ms->setStepperDirection(AdafruitMS1438::STEPMOTOR_M12,
|
ms.setStepperDirection(AdafruitMS1438::STEPMOTOR_M12, AdafruitMS1438::DIR_CW);
|
||||||
AdafruitMS1438::DIR_CW);
|
|
||||||
|
|
||||||
// enable
|
// enable
|
||||||
cout << "Enabling..." << endl;
|
cout << "Enabling..." << endl;
|
||||||
ms->enableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
ms.enableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||||
|
|
||||||
cout << "Rotating 1 full revolution at 10 RPM speed." << endl;
|
cout << "Rotating 1 full revolution at 10 RPM speed." << endl;
|
||||||
ms->stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 200);
|
ms.stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 200);
|
||||||
|
|
||||||
cout << "Sleeping for 2 seconds..." << endl;
|
cout << "Sleeping for 2 seconds..." << endl;
|
||||||
sleep(2);
|
upm_delay(2);
|
||||||
cout << "Rotating 1/2 revolution in opposite direction at 10 RPM speed."
|
cout << "Rotating 1/2 revolution in opposite direction at 10 RPM speed." << endl;
|
||||||
<< endl;
|
|
||||||
|
|
||||||
ms->setStepperDirection(AdafruitMS1438::STEPMOTOR_M12,
|
ms.setStepperDirection(AdafruitMS1438::STEPMOTOR_M12, AdafruitMS1438::DIR_CCW);
|
||||||
AdafruitMS1438::DIR_CCW);
|
ms.stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 100);
|
||||||
ms->stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 100);
|
|
||||||
|
|
||||||
cout << "Disabling..." << endl;
|
cout << "Disabling..." << endl;
|
||||||
ms->disableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
ms.disableStepper(AdafruitMS1438::STEPMOTOR_M12);
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
delete ms;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,54 +22,51 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "adafruitms1438.hpp"
|
#include "adafruitms1438.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an Adafruit MS 1438 on I2C bus 0
|
// Instantiate an Adafruit MS 1438 on I2C bus 0
|
||||||
|
|
||||||
upm::AdafruitMS1438 *ms =
|
upm::AdafruitMS1438 ms(ADAFRUITMS1438_I2C_BUS, ADAFRUITMS1438_DEFAULT_I2C_ADDR);
|
||||||
new upm::AdafruitMS1438(ADAFRUITMS1438_I2C_BUS,
|
|
||||||
ADAFRUITMS1438_DEFAULT_I2C_ADDR);
|
|
||||||
|
|
||||||
// Setup for use with a DC motor connected to the M3 port
|
// Setup for use with a DC motor connected to the M3 port
|
||||||
|
|
||||||
// set a PWM period of 50Hz
|
// set a PWM period of 50Hz
|
||||||
ms->setPWMPeriod(50);
|
ms.setPWMPeriod(50);
|
||||||
|
|
||||||
// disable first, to be safe
|
// disable first, to be safe
|
||||||
ms->disableMotor(AdafruitMS1438::MOTOR_M3);
|
ms.disableMotor(AdafruitMS1438::MOTOR_M3);
|
||||||
|
|
||||||
// set speed at 50%
|
// set speed at 50%
|
||||||
ms->setMotorSpeed(AdafruitMS1438::MOTOR_M3, 50);
|
ms.setMotorSpeed(AdafruitMS1438::MOTOR_M3, 50);
|
||||||
ms->setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CW);
|
ms.setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CW);
|
||||||
|
|
||||||
cout << "Spin M3 at half speed for 3 seconds, then reverse for 3 seconds."
|
cout << "Spin M3 at half speed for 3 seconds, then reverse for 3 seconds." << endl;
|
||||||
<< endl;
|
|
||||||
|
|
||||||
ms->enableMotor(AdafruitMS1438::MOTOR_M3);
|
ms.enableMotor(AdafruitMS1438::MOTOR_M3);
|
||||||
|
|
||||||
sleep(3);
|
upm_delay(3);
|
||||||
|
|
||||||
cout << "Reversing M3" << endl;
|
cout << "Reversing M3" << endl;
|
||||||
ms->setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CCW);
|
ms.setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CCW);
|
||||||
|
|
||||||
sleep(3);
|
upm_delay(3);
|
||||||
|
|
||||||
cout << "Stopping M3" << endl;
|
cout << "Stopping M3" << endl;
|
||||||
ms->disableMotor(AdafruitMS1438::MOTOR_M3);
|
ms.disableMotor(AdafruitMS1438::MOTOR_M3);
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
delete ms;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,55 +22,56 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description
|
* Description
|
||||||
* Demo program for Adafruit 16 channel servo shield/controller
|
* Demo program for Adafruit 16 channel servo shield/controller
|
||||||
* Physical setup for tests is a single servo attached to one channel.
|
* Physical setup for tests is a single servo attached to one channel.
|
||||||
* Note - when 3 or more GWS servos attached results unpredictable.
|
* Note - when 3 or more GWS servos attached results unpredictable.
|
||||||
* Adafruit do recommend a Cap be installed on the board which should alleviate the issue.
|
* Adafruit do recommend a Cap be installed on the board which should alleviate
|
||||||
|
* the issue.
|
||||||
* I (and Adafruit) are unable to give any Capacitor sizing data.
|
* I (and Adafruit) are unable to give any Capacitor sizing data.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "adafruitss.hpp"
|
#include "adafruitss.hpp"
|
||||||
#include <unistd.h>
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
upm::adafruitss* servos = new upm::adafruitss(6,0x40);
|
upm::adafruitss servos(6, 0x40);
|
||||||
|
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
cout << "Setting all to 0" << endl;
|
cout << "Setting all to 0" << endl;
|
||||||
for (n = 0; n < 16; n++)
|
for (n = 0; n < 16; n++)
|
||||||
servos->servo(n, 1, 0); // GWS Mini Servo = Type 1.
|
servos.servo(n, 1, 0); // GWS Mini Servo = Type 1.
|
||||||
usleep(1000000); // Wait 1 second
|
upm_delay_us(1000000); // Wait 1 second
|
||||||
|
|
||||||
cout << "Setting all to 45" << endl;
|
cout << "Setting all to 45" << endl;
|
||||||
for (n = 0; n < 16; n++)
|
for (n = 0; n < 16; n++)
|
||||||
servos->servo(n, 1, 45);
|
servos.servo(n, 1, 45);
|
||||||
usleep(1000000); // Wait 1 second
|
upm_delay_us(1000000); // Wait 1 second
|
||||||
|
|
||||||
cout << "Setting all to 90" << endl;
|
cout << "Setting all to 90" << endl;
|
||||||
for (n = 0; n < 16; n++)
|
for (n = 0; n < 16; n++)
|
||||||
servos->servo(n, 1, 90);
|
servos.servo(n, 1, 90);
|
||||||
usleep(1000000); // Wait 1 second
|
upm_delay_us(1000000); // Wait 1 second
|
||||||
|
|
||||||
cout << "Setting all to 135" << endl;
|
cout << "Setting all to 135" << endl;
|
||||||
for (n = 0; n < 16; n++)
|
for (n = 0; n < 16; n++)
|
||||||
servos->servo(n, 1, 135);
|
servos.servo(n, 1, 135);
|
||||||
usleep(1000000); // Wait 1 second
|
upm_delay_us(1000000); // Wait 1 second
|
||||||
|
|
||||||
cout << "Setting all to 180" << endl;
|
cout << "Setting all to 180" << endl;
|
||||||
for (n = 0; n < 16; n++)
|
for (n = 0; n < 16; n++)
|
||||||
servos->servo(n, 1, 160);
|
servos.servo(n, 1, 160);
|
||||||
usleep(2000000); // Wait 1 second
|
upm_delay_us(2000000); // Wait 1 second
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,45 +22,44 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include "adc121c021.hpp"
|
#include "adc121c021.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an ADC121C021 on I2C bus 0
|
// Instantiate an ADC121C021 on I2C bus 0
|
||||||
|
|
||||||
upm::ADC121C021 *adc = new upm::ADC121C021(ADC121C021_I2C_BUS,
|
upm::ADC121C021 adc(ADC121C021_I2C_BUS, ADC121C021_DEFAULT_I2C_ADDR);
|
||||||
ADC121C021_DEFAULT_I2C_ADDR);
|
|
||||||
|
|
||||||
// An analog sensor, such as a Grove light sensor,
|
// An analog sensor, such as a Grove light sensor,
|
||||||
// must be attached to the adc
|
// must be attached to the adc
|
||||||
// Prints the value and corresponding voltage every 50 milliseconds
|
// Prints the value and corresponding voltage every 50 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
uint16_t val = adc.value();
|
||||||
uint16_t val = adc->value();
|
cout << "ADC value: " << val << " Volts = " << adc.valueToVolts(val) << endl;
|
||||||
cout << "ADC value: " << val << " Volts = "
|
upm_delay_us(50000);
|
||||||
<< adc->valueToVolts(val) << endl;
|
|
||||||
usleep(50000);
|
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete adc;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,12 @@
|
|||||||
// This example code runs on an Intel Edison and uses mraa to acquire data
|
// This example code runs on an Intel Edison and uses mraa to acquire data
|
||||||
// from an ADIS16448. This data is then scaled and printed onto the terminal.
|
// from an ADIS16448. This data is then scaled and printed onto the terminal.
|
||||||
//
|
//
|
||||||
// This software has been tested to connect to an ADIS16448 through a level shifter
|
// This software has been tested to connect to an ADIS16448 through a level
|
||||||
// such as the TI TXB0104. The SPI lines (DIN, DOUT, SCLK, /CS) are all wired through
|
// shifter
|
||||||
// the level shifter and the ADIS16448 is also being powered by the Intel Edison.
|
// such as the TI TXB0104. The SPI lines (DIN, DOUT, SCLK, /CS) are all wired
|
||||||
|
// through
|
||||||
|
// the level shifter and the ADIS16448 is also being powered by the Intel
|
||||||
|
// Edison.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
@ -36,31 +39,29 @@
|
|||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "adis16448.hpp"
|
#include "adis16448.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
while(true)
|
while (true) {
|
||||||
{
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
upm::ADIS16448* imu = new upm::ADIS16448(0,3); //upm::ADIS16448(SPI,RST)
|
upm::ADIS16448 imu(0, 3); // upm::ADIS16448(SPI,RST)
|
||||||
|
|
||||||
// Read the specified register, scale it, and display it on the screen
|
// Read the specified register, scale it, and display it on the screen
|
||||||
std::cout << "XGYRO_OUT:" << imu->gyroScale(imu->regRead(XGYRO_OUT)) << std::endl;
|
std::cout << "XGYRO_OUT:" << imu.gyroScale(imu.regRead(XGYRO_OUT)) << std::endl;
|
||||||
std::cout << "YGYRO_OUT:" << imu->gyroScale(imu->regRead(YGYRO_OUT)) << std::endl;
|
std::cout << "YGYRO_OUT:" << imu.gyroScale(imu.regRead(YGYRO_OUT)) << std::endl;
|
||||||
std::cout << "ZGYRO_OUT:" << imu->gyroScale(imu->regRead(ZGYRO_OUT)) << std::endl;
|
std::cout << "ZGYRO_OUT:" << imu.gyroScale(imu.regRead(ZGYRO_OUT)) << std::endl;
|
||||||
std::cout << " " << std::endl;
|
std::cout << " " << std::endl;
|
||||||
std::cout << "XACCL_OUT:" << imu->accelScale(imu->regRead(XACCL_OUT)) << std::endl;
|
std::cout << "XACCL_OUT:" << imu.accelScale(imu.regRead(XACCL_OUT)) << std::endl;
|
||||||
std::cout << "YACCL_OUT:" << imu->accelScale(imu->regRead(YACCL_OUT)) << std::endl;
|
std::cout << "YACCL_OUT:" << imu.accelScale(imu.regRead(YACCL_OUT)) << std::endl;
|
||||||
std::cout << "ZACCL_OUT:" << imu->accelScale(imu->regRead(ZACCL_OUT)) << std::endl;
|
std::cout << "ZACCL_OUT:" << imu.accelScale(imu.regRead(ZACCL_OUT)) << std::endl;
|
||||||
std::cout << " " << std::endl;
|
std::cout << " " << std::endl;
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -22,44 +22,35 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "ads1015.hpp"
|
#include "ads1015.hpp"
|
||||||
|
#include "iADC.hpp"
|
||||||
#include "mraa/gpio.hpp"
|
#include "mraa/gpio.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
#define EDISON_I2C_BUS 1
|
||||||
#define FT4222_I2C_BUS 0
|
#define FT4222_I2C_BUS 0
|
||||||
#define EDISON_GPIO_SI7005_CS 20
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
int
|
||||||
//! [Interesting]
|
main()
|
||||||
// Simple example of using IADC to determine
|
|
||||||
// which sensor is present and return its name.
|
|
||||||
// IADC is then used to get readings from sensor
|
|
||||||
|
|
||||||
|
|
||||||
upm::IADC* getADC()
|
|
||||||
{
|
{
|
||||||
upm::IADC* adc = NULL;
|
/* Create an instance of the ADS1015 sensor */
|
||||||
try {
|
upm::ADS1015 sensor(EDISON_I2C_BUS);
|
||||||
adc = new upm::ADS1015(EDISON_I2C_BUS);
|
|
||||||
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
|
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
|
||||||
gpio.dir(mraa::DIR_OUT_HIGH);
|
gpio.dir(mraa::DIR_OUT_HIGH);
|
||||||
return adc;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "ADS1015: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return adc;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main ()
|
/* Show usage from the iADC interface */
|
||||||
{
|
upm::iADC* adc = static_cast<upm::iADC*>(&sensor);
|
||||||
upm::IADC* adc = getADC();
|
|
||||||
if (adc == NULL) {
|
if (adc == NULL) {
|
||||||
std::cout << "ADC not detected" << std::endl;
|
std::cout << "ADC not detected" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::cout << "ADC " << adc->getModuleName() << " detected. " ;
|
std::cout << "ADC " << adc->Name() << " detected. ";
|
||||||
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
||||||
while (true) {
|
while (true) {
|
||||||
for (unsigned int i = 0; i < adc->getNumInputs(); ++i) {
|
for (unsigned int i = 0; i < adc->getNumInputs(); ++i) {
|
||||||
@ -71,9 +62,9 @@ int main ()
|
|||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
delete adc;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +29,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "ads1015.hpp"
|
#include "ads1015.hpp"
|
||||||
|
#include "ads1x15.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
@ -41,13 +43,15 @@ using namespace upm;
|
|||||||
bool running = true; // Controls main read/write loop
|
bool running = true; // Controls main read/write loop
|
||||||
|
|
||||||
// Thread function
|
// Thread function
|
||||||
void stop()
|
void
|
||||||
|
stop()
|
||||||
{
|
{
|
||||||
sleep(10);
|
upm_delay(10);
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
long id = 0; // Sample number
|
long id = 0; // Sample number
|
||||||
@ -55,20 +59,20 @@ int main()
|
|||||||
ofstream f;
|
ofstream f;
|
||||||
|
|
||||||
// Initialize and configure the ADS1015
|
// Initialize and configure the ADS1015
|
||||||
ADS1015 *ads1015 = new upm::ADS1015(0, 0x48);
|
ADS1015 ads1015(0, 0x48);
|
||||||
|
|
||||||
// Put the ADC into differential mode for pins A0 and A1
|
// Put the ADC into differential mode for pins A0 and A1
|
||||||
ads1015->getSample(ADS1X15::DIFF_0_1);
|
ads1015.getSample(ADS1X15::DIFF_0_1);
|
||||||
|
|
||||||
// Set the gain based on expected VIN range to -/+ 2.048 V
|
// Set the gain based on expected VIN range to -/+ 2.048 V
|
||||||
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
|
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
|
||||||
// documentation for details
|
// documentation for details
|
||||||
ads1015->setGain(ADS1X15::GAIN_TWO);
|
ads1015.setGain(ADS1X15::GAIN_TWO);
|
||||||
|
|
||||||
// Set the sample rate to 3300 samples per second (max) and turn on continuous
|
// Set the sample rate to 3300 samples per second (max) and turn on continuous
|
||||||
// sampling
|
// sampling
|
||||||
ads1015->setSPS(ADS1015::SPS_3300);
|
ads1015.setSPS(ADS1015::SPS_3300);
|
||||||
ads1015->setContinuous(true);
|
ads1015.setContinuous(true);
|
||||||
|
|
||||||
// Enable exceptions from the output stream
|
// Enable exceptions from the output stream
|
||||||
f.exceptions(ofstream::failbit | ofstream::badbit);
|
f.exceptions(ofstream::failbit | ofstream::badbit);
|
||||||
@ -85,14 +89,13 @@ int main()
|
|||||||
|
|
||||||
// Read sensor data and write it to the output file every ms
|
// Read sensor data and write it to the output file every ms
|
||||||
while (running) {
|
while (running) {
|
||||||
f << id++ << " " << ads1015->getLastSample() << endl;
|
f << id++ << " " << ads1015.getLastSample() << endl;
|
||||||
usleep(1000);
|
upm_delay_us(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean-up and exit
|
// Clean-up and exit
|
||||||
timer.join();
|
timer.join();
|
||||||
f.close();
|
f.close();
|
||||||
delete ads1015;
|
|
||||||
} catch (ios_base::failure& e) {
|
} catch (ios_base::failure& e) {
|
||||||
cout << "Failed to write to file: " << e.what() << endl;
|
cout << "Failed to write to file: " << e.what() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -101,4 +104,3 @@ int main()
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +28,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "ads1115.hpp"
|
#include "ads1115.hpp"
|
||||||
|
#include "ads1x15.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
@ -40,13 +42,15 @@ using namespace upm;
|
|||||||
bool running = true; // Controls main read/write loop
|
bool running = true; // Controls main read/write loop
|
||||||
|
|
||||||
// Thread function
|
// Thread function
|
||||||
void stop()
|
void
|
||||||
|
stop()
|
||||||
{
|
{
|
||||||
sleep(10);
|
upm_delay(10);
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
long id = 0; // Sample number
|
long id = 0; // Sample number
|
||||||
@ -57,21 +61,21 @@ int main()
|
|||||||
// There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus
|
// There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus
|
||||||
// - 0x48 gives access to pins A0 - A3
|
// - 0x48 gives access to pins A0 - A3
|
||||||
// - 0x49 gives access to pins A4 - A7
|
// - 0x49 gives access to pins A4 - A7
|
||||||
ADS1115 *ads1115 = new upm::ADS1115(0, 0x48);
|
ADS1115 ads1115(0, 0x48);
|
||||||
|
|
||||||
// Put the ADC into differential mode for pins A0 and A1,
|
// Put the ADC into differential mode for pins A0 and A1,
|
||||||
// the SM-24 Geophone is connected to these pins
|
// the SM-24 Geophone is connected to these pins
|
||||||
ads1115->getSample(ADS1X15::DIFF_0_1);
|
ads1115.getSample(ADS1X15::DIFF_0_1);
|
||||||
|
|
||||||
// Set the gain based on expected VIN range to -/+ 2.048 V
|
// Set the gain based on expected VIN range to -/+ 2.048 V
|
||||||
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
|
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
|
||||||
// documentation for details
|
// documentation for details
|
||||||
ads1115->setGain(ADS1X15::GAIN_TWO);
|
ads1115.setGain(ADS1X15::GAIN_TWO);
|
||||||
|
|
||||||
// Set the sample rate to 860 samples per second (max) and turn on continuous
|
// Set the sample rate to 860 samples per second (max) and turn on continuous
|
||||||
// sampling
|
// sampling
|
||||||
ads1115->setSPS(ADS1115::SPS_860);
|
ads1115.setSPS(ADS1115::SPS_860);
|
||||||
ads1115->setContinuous(true);
|
ads1115.setContinuous(true);
|
||||||
|
|
||||||
// Enable exceptions from the output stream
|
// Enable exceptions from the output stream
|
||||||
f.exceptions(ofstream::failbit | ofstream::badbit);
|
f.exceptions(ofstream::failbit | ofstream::badbit);
|
||||||
@ -88,14 +92,13 @@ int main()
|
|||||||
|
|
||||||
// Read sensor data and write it to the output file every ms
|
// Read sensor data and write it to the output file every ms
|
||||||
while (running) {
|
while (running) {
|
||||||
f << id++ << " " << ads1115->getLastSample() << endl;
|
f << id++ << " " << ads1115.getLastSample() << endl;
|
||||||
usleep(1000);
|
upm_delay_us(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean-up and exit
|
// Clean-up and exit
|
||||||
timer.join();
|
timer.join();
|
||||||
f.close();
|
f.close();
|
||||||
delete ads1115;
|
|
||||||
} catch (ios_base::failure& e) {
|
} catch (ios_base::failure& e) {
|
||||||
cout << "Failed to write to file: " << e.what() << endl;
|
cout << "Failed to write to file: " << e.what() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -104,4 +107,3 @@ int main()
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,36 +22,32 @@
|
|||||||
* 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 "mraa.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
|
||||||
#include "ads1015.hpp"
|
#include "ads1015.hpp"
|
||||||
#include "ads1115.hpp"
|
#include "ads1115.hpp"
|
||||||
|
#include "ads1x15.hpp"
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
int main()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
int command;
|
int command;
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
//Select the device you are testing here and adjust case 6 for the correct sample rates.
|
// Select the device you are testing here and adjust case 6 for the correct
|
||||||
//upm::ADS1015 *ads = new upm::ADS1015(1);
|
// sample rates.
|
||||||
upm::ADS1115 *ads = new upm::ADS1115(1, 0x49);
|
upm::ADS1115 ads(1, 0x49);
|
||||||
float inputVoltage;
|
float inputVoltage;
|
||||||
int ans;
|
int ans;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
cout << "1 - get Conversion \t";
|
cout << "1 - get Conversion \t";
|
||||||
cout << "2 - get last conversion" << endl;
|
cout << "2 - get last conversion" << endl;
|
||||||
cout << "3 - get Gain \t\t";
|
cout << "3 - get Gain \t\t";
|
||||||
cout << "4 - set Gain" << endl;;
|
cout << "4 - set Gain" << endl;
|
||||||
|
;
|
||||||
cout << "5 - get Data Rate \t";
|
cout << "5 - get Data Rate \t";
|
||||||
cout << "6 - set Data Rate" << endl;
|
cout << "6 - set Data Rate" << endl;
|
||||||
cout << "7 - Set Upper Threshold \t";
|
cout << "7 - Set Upper Threshold \t";
|
||||||
@ -73,17 +69,15 @@ int main()
|
|||||||
cout << "Enter a command: ";
|
cout << "Enter a command: ";
|
||||||
cin >> command;
|
cin >> command;
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
switch(command)
|
|
||||||
{
|
|
||||||
case 2:
|
case 2:
|
||||||
cout << ads->getLastSample() << endl;
|
cout << ads.getLastSample() << endl;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
cout << std::hex << ads->getGain() << endl;
|
cout << std::hex << ads.getGain() << endl;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
cout << std::hex << ads->getSPS() << endl;
|
cout << std::hex << ads.getSPS() << endl;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
int gain;
|
int gain;
|
||||||
@ -114,13 +108,14 @@ int main()
|
|||||||
default:
|
default:
|
||||||
set_gain = ADS1X15::GAIN_ONE;
|
set_gain = ADS1X15::GAIN_ONE;
|
||||||
}
|
}
|
||||||
ads->setGain(set_gain);
|
ads.setGain(set_gain);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
int rate;
|
int rate;
|
||||||
/*ADS1015::ADSDATARATE set_rate;
|
/*ADS1015::ADSDATARATE set_rate;
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
cout << "1 -> SPS_120 \t 2 -> SPS_250 \t 3 -> SPS_490 \t 4 -> SPS_920" << endl;
|
cout << "1 -> SPS_120 \t 2 -> SPS_250 \t 3 -> SPS_490 \t 4 -> SPS_920" <<
|
||||||
|
endl;
|
||||||
cout << "5 -> SPS_1600 \t 6 -> SPS_2400 \t 7 -> SPS_3300" << endl;
|
cout << "5 -> SPS_1600 \t 6 -> SPS_2400 \t 7 -> SPS_3300" << endl;
|
||||||
cin >> rate;
|
cin >> rate;
|
||||||
switch(rate){
|
switch(rate){
|
||||||
@ -182,14 +177,16 @@ int main()
|
|||||||
set_rate = ADS1115::SPS_128;
|
set_rate = ADS1115::SPS_128;
|
||||||
}
|
}
|
||||||
|
|
||||||
ads->setSPS(set_rate);
|
ads.setSPS(set_rate);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
int mode;
|
int mode;
|
||||||
ADS1X15::ADSMUXMODE set_mode;
|
ADS1X15::ADSMUXMODE set_mode;
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
cout << "1 -> MUX_0_1 \t 2 -> MUX_0_3 \t 3 -> MUX_1_3 \t 4 -> MUX_2_3" << endl;
|
cout << "1 -> MUX_0_1 \t 2 -> MUX_0_3 \t 3 -> MUX_1_3 \t 4 -> MUX_2_3" << endl;
|
||||||
cout << "5 -> SINGLE_0 \t 6 -> SINGLE_1 \t 7 -> SINGLE_2 \t 8 -> SINGLE_3" << endl;
|
cout << "5 -> SINGLE_0 \t 6 -> SINGLE_1 \t 7 -> SINGLE_2 \t 8 -> "
|
||||||
|
"SINGLE_3"
|
||||||
|
<< endl;
|
||||||
cin >> mode;
|
cin >> mode;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -220,91 +217,101 @@ int main()
|
|||||||
set_mode = ADS1X15::DIFF_0_1;
|
set_mode = ADS1X15::DIFF_0_1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cout << ads->getSample(set_mode) << endl;
|
cout << ads.getSample(set_mode) << endl;
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
cout << " enter a float value: ";
|
cout << " enter a float value: ";
|
||||||
cin >> inputVoltage;
|
cin >> inputVoltage;
|
||||||
ads->setThresh(ADS1115::THRESH_HIGH, inputVoltage);
|
ads.setThresh(ADS1115::THRESH_HIGH, inputVoltage);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
cout << " enter a float value: ";
|
cout << " enter a float value: ";
|
||||||
cin >> inputVoltage;
|
cin >> inputVoltage;
|
||||||
ads->setThresh(ADS1115::THRESH_LOW, inputVoltage);
|
ads.setThresh(ADS1115::THRESH_LOW, inputVoltage);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
cout << "Upper " << ads->getThresh(ADS1X15::THRESH_HIGH) << endl;
|
cout << "Upper " << ads.getThresh(ADS1X15::THRESH_HIGH) << endl;
|
||||||
cout << "Lower " << ads->getThresh(ADS1X15::THRESH_LOW) << endl;
|
cout << "Lower " << ads.getThresh(ADS1X15::THRESH_LOW) << endl;
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
ads->setThresh(ADS1115::THRESH_DEFAULT);
|
ads.setThresh(ADS1115::THRESH_DEFAULT);
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
ads->setThresh(ADS1015::CONVERSION_RDY);
|
ads.setThresh(ADS1015::CONVERSION_RDY);
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
cout << ads->getCompQue() << endl;
|
cout << ads.getCompQue() << endl;
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
int que;
|
int que;
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
cout << "1 -> CQUE_1CONV \t 2 -> CQUE_2CONV \t 3 -> CQUE_3CONV \t 4 -> CQUE_NONE" << endl;
|
cout << "1 -> CQUE_1CONV \t 2 -> CQUE_2CONV \t 3 -> CQUE_3CONV \t 4 -> "
|
||||||
|
"CQUE_NONE"
|
||||||
|
<< endl;
|
||||||
cin >> que;
|
cin >> que;
|
||||||
switch (que) {
|
switch (que) {
|
||||||
case 1:
|
case 1:
|
||||||
ads->setCompQue(ADS1X15::CQUE_1CONV);
|
ads.setCompQue(ADS1X15::CQUE_1CONV);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
ads->setCompQue(ADS1X15::CQUE_2CONV);
|
ads.setCompQue(ADS1X15::CQUE_2CONV);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
ads->setCompQue(ADS1X15::CQUE_4CONV);
|
ads.setCompQue(ADS1X15::CQUE_4CONV);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
default:
|
default:
|
||||||
ads->setCompQue(ADS1X15::CQUE_NONE);
|
ads.setCompQue(ADS1X15::CQUE_NONE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
cout << ads->getCompPol() << endl;
|
cout << ads.getCompPol() << endl;
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
cout << "1 -> active high \t 2 -> active low" << endl;
|
cout << "1 -> active high \t 2 -> active low" << endl;
|
||||||
cin >> ans;
|
cin >> ans;
|
||||||
if(ans == 1) ads->setCompPol(true);
|
if (ans == 1)
|
||||||
else ads->setCompPol(false);
|
ads.setCompPol(true);
|
||||||
|
else
|
||||||
|
ads.setCompPol(false);
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
cout << ads->getCompMode() << endl;
|
cout << ads.getCompMode() << endl;
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
cout << "1 -> Window \t 2 -> Traditional (default)" << endl;
|
cout << "1 -> Window \t 2 -> Traditional (default)" << endl;
|
||||||
cin >> ans;
|
cin >> ans;
|
||||||
if(ans == 1) ads->setCompMode(true);
|
if (ans == 1)
|
||||||
else ads->setCompMode();
|
ads.setCompMode(true);
|
||||||
|
else
|
||||||
|
ads.setCompMode();
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
cout << ads->getCompLatch() << endl;
|
cout << ads.getCompLatch() << endl;
|
||||||
break;
|
break;
|
||||||
case 19:
|
case 19:
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
cout << "1 -> Latching \t 2 -> Non-latching (default)" << endl;
|
cout << "1 -> Latching \t 2 -> Non-latching (default)" << endl;
|
||||||
cin >> ans;
|
cin >> ans;
|
||||||
if(ans == 1) ads->setCompLatch(true);
|
if (ans == 1)
|
||||||
else ads->setCompLatch();
|
ads.setCompLatch(true);
|
||||||
|
else
|
||||||
|
ads.setCompLatch();
|
||||||
break;
|
break;
|
||||||
case 20:
|
case 20:
|
||||||
cout << ads->getContinuous() << endl;
|
cout << ads.getContinuous() << endl;
|
||||||
break;
|
break;
|
||||||
case 21:
|
case 21:
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
cout << "1 -> Power Down (default) \t 2 -> Continuous" << endl;
|
cout << "1 -> Power Down (default) \t 2 -> Continuous" << endl;
|
||||||
cin >> ans;
|
cin >> ans;
|
||||||
if(ans == 1) ads->setContinuous(true);
|
if (ans == 1)
|
||||||
else ads->setContinuous();
|
ads.setContinuous(true);
|
||||||
|
else
|
||||||
|
ads.setContinuous();
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
break;
|
break;
|
||||||
@ -312,10 +319,8 @@ int main()
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (command != -1);
|
} while (command != -1);
|
||||||
|
|
||||||
delete ads;
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,57 +22,58 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "adxl335.hpp"
|
#include "adxl335.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main ()
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2
|
// Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2
|
||||||
upm::ADXL335* accel = new upm::ADXL335(0, 1, 2);
|
upm::ADXL335 accel(0, 1, 2);
|
||||||
|
|
||||||
cout << "Please make sure the sensor is completely still. Sleeping for"
|
cout << "Please make sure the sensor is completely still. Sleeping for"
|
||||||
<< " 2 seconds." << endl;
|
<< " 2 seconds." << endl;
|
||||||
sleep(2);
|
upm_delay(2);
|
||||||
cout << "Calibrating..." << endl;
|
cout << "Calibrating..." << endl;
|
||||||
|
|
||||||
accel->calibrate();
|
accel.calibrate();
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
float aX, aY, aZ;
|
float aX, aY, aZ;
|
||||||
|
|
||||||
accel->values(&x, &y, &z);
|
accel.values(&x, &y, &z);
|
||||||
cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl;
|
cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl;
|
||||||
|
|
||||||
accel->acceleration(&aX, &aY, &aZ);
|
accel.acceleration(&aX, &aY, &aZ);
|
||||||
cout << "Acceleration: X: " << aX << "g" << endl;
|
cout << "Acceleration: X: " << aX << "g" << endl;
|
||||||
cout << "Acceleration: Y: " << aY << "g" << endl;
|
cout << "Acceleration: Y: " << aY << "g" << endl;
|
||||||
cout << "Acceleration: Z: " << aZ << "g" << endl;
|
cout << "Acceleration: Z: " << aZ << "g" << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
usleep(200000);
|
upm_delay_us(200000);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete accel;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,10 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "adxl345.hpp"
|
#include "adxl345.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
@ -33,18 +35,18 @@ main(int argc, char **argv)
|
|||||||
float* acc;
|
float* acc;
|
||||||
|
|
||||||
// Note: Sensor only works at 3.3V on the Intel Edison with Arduino breakout
|
// Note: Sensor only works at 3.3V on the Intel Edison with Arduino breakout
|
||||||
upm::Adxl345* accel = new upm::Adxl345(0);
|
upm::Adxl345 accel(0);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
accel->update(); // Update the data
|
accel.update(); // Update the data
|
||||||
raw = accel->getRawValues(); // Read raw sensor data
|
raw = accel.getRawValues(); // Read raw sensor data
|
||||||
acc = accel->getAcceleration(); // Read acceleration (g)
|
acc = accel.getAcceleration(); // Read acceleration (g)
|
||||||
fprintf(stdout, "Current scale: 0x%2xg\n", accel->getScale());
|
fprintf(stdout, "Current scale: 0x%2xg\n", accel.getScale());
|
||||||
fprintf(stdout, "Raw: %6d %6d %6d\n", raw[0], raw[1], raw[2]);
|
fprintf(stdout, "Raw: %6d %6d %6d\n", raw[0], raw[1], raw[2]);
|
||||||
fprintf(stdout, "AccX: %5.2f g\n", acc[0]);
|
fprintf(stdout, "AccX: %5.2f g\n", acc[0]);
|
||||||
fprintf(stdout, "AccY: %5.2f g\n", acc[1]);
|
fprintf(stdout, "AccY: %5.2f g\n", acc[1]);
|
||||||
fprintf(stdout, "AccZ: %5.2f g\n", acc[2]);
|
fprintf(stdout, "AccZ: %5.2f g\n", acc[2]);
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,22 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "adxrs610.hpp"
|
#include "adxrs610.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
@ -46,26 +49,24 @@ int main()
|
|||||||
// Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and
|
// Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and
|
||||||
// analog A1 (temp out) with an analog reference voltage of
|
// analog A1 (temp out) with an analog reference voltage of
|
||||||
// 5.0
|
// 5.0
|
||||||
upm::ADXRS610 *sensor = new upm::ADXRS610(0, 1, 5.0);
|
upm::ADXRS610 sensor(0, 1, 5.0);
|
||||||
|
|
||||||
// set a deadband region around the zero point to report 0.0 (optional)
|
// set a deadband region around the zero point to report 0.0 (optional)
|
||||||
sensor->setDeadband(0.015);
|
sensor.setDeadband(0.015);
|
||||||
|
|
||||||
// Every tenth of a second, sample the ADXRS610 and output it's
|
// Every tenth of a second, sample the ADXRS610 and output it's
|
||||||
// corresponding temperature and angular velocity
|
// corresponding temperature and angular velocity
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
cout << "Vel (deg/s): " << sensor.getAngularVelocity() << endl;
|
||||||
cout << "Vel (deg/s): " << sensor->getAngularVelocity() << endl;
|
cout << "Temp (C): " << sensor.getTemperature() << endl;
|
||||||
cout << "Temp (C): " << sensor->getTemperature() << endl;
|
|
||||||
|
|
||||||
usleep(100000);
|
upm_delay_us(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,15 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "am2315.hpp"
|
#include "am2315.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
volatile int doWork = 0;
|
volatile int doWork = 0;
|
||||||
|
|
||||||
upm::AM2315 *sensor = NULL;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sig_handler(int signo)
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
@ -51,25 +50,21 @@ main(int argc, char **argv)
|
|||||||
float humidity = 0.0;
|
float humidity = 0.0;
|
||||||
float temperature = 0.0;
|
float temperature = 0.0;
|
||||||
|
|
||||||
sensor = new upm::AM2315(0, AM2315_I2C_ADDRESS);
|
upm::AM2315 sensor(0, AM2315_I2C_ADDRESS);
|
||||||
|
|
||||||
sensor->testSensor();
|
sensor.testSensor();
|
||||||
|
|
||||||
while (!doWork) {
|
while (!doWork) {
|
||||||
humidity = sensor->getHumidity();
|
humidity = sensor.getHumidity();
|
||||||
temperature = sensor->getTemperature();
|
temperature = sensor.getTemperature();
|
||||||
|
|
||||||
std::cout << "humidity value = " <<
|
std::cout << "humidity value = " << humidity << ", temperature value = " << temperature
|
||||||
humidity <<
|
<< std::endl;
|
||||||
", temperature value = " <<
|
upm_delay_us(500000);
|
||||||
temperature << std::endl;
|
|
||||||
usleep (500000);
|
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
std::cout << "exiting application" << std::endl;
|
std::cout << "exiting application" << std::endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "apa102.hpp"
|
#include "apa102.hpp"
|
||||||
#include <iostream>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -34,18 +31,17 @@ main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a strip of 30 LEDs on SPI bus 0
|
// Instantiate a strip of 30 LEDs on SPI bus 0
|
||||||
upm::APA102* ledStrip = new upm::APA102(800, 0);
|
upm::APA102 ledStrip(800, 0);
|
||||||
|
|
||||||
// Set all LEDs to Red
|
// Set all LEDs to Red
|
||||||
ledStrip->setAllLeds(31, 255, 0, 0);
|
ledStrip.setAllLeds(31, 255, 0, 0);
|
||||||
|
|
||||||
// Set a section (10 to 20) to blue
|
// Set a section (10 to 20) to blue
|
||||||
ledStrip->setLeds(10, 20, 31, 0, 0, 255);
|
ledStrip.setLeds(10, 20, 31, 0, 0, 255);
|
||||||
|
|
||||||
// Set a single LED to green
|
// Set a single LED to green
|
||||||
ledStrip->setLed(15, 31, 0, 255, 0);
|
ledStrip.setLed(15, 31, 0, 255, 0);
|
||||||
|
|
||||||
delete ledStrip;
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,41 +22,41 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "apds9002.hpp"
|
#include "apds9002.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main ()
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a Grove Luminance sensor on analog pin A0
|
// Instantiate a Grove Luminance sensor on analog pin A0
|
||||||
upm::APDS9002* luminance = new upm::APDS9002(0);
|
upm::APDS9002 luminance(0);
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
int val = luminance.value();
|
||||||
int val = luminance->value();
|
|
||||||
cout << "Luminance value is " << val << endl;
|
cout << "Luminance value is " << val << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete luminance;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "apds9930.hpp"
|
#include "apds9930.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -44,31 +45,30 @@ main()
|
|||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a Digital Proximity and Ambient Light sensor on iio device 4
|
// Instantiate a Digital Proximity and Ambient Light sensor on iio device 4
|
||||||
upm::APDS9930* light_proximity = new upm::APDS9930(4);
|
upm::APDS9930 light_proximity(4);
|
||||||
|
|
||||||
// Kernel driver implement sleep 5000-5100us after enable illuminance sensor
|
// Kernel driver implement upm_delay 5000-5100us after enable illuminance
|
||||||
light_proximity->enableIlluminance(true);
|
// sensor
|
||||||
|
light_proximity.enableIlluminance(true);
|
||||||
|
|
||||||
// Kernel driver implement sleep 5000-5100us after enable proximity sensor
|
// Kernel driver implement upm_delay 5000-5100us after enable proximity sensor
|
||||||
light_proximity->enableProximity(true);
|
light_proximity.enableProximity(true);
|
||||||
|
|
||||||
// Tested this value works. Please change it on your platform
|
// Tested this value works. Please change it on your platform
|
||||||
usleep(120000);
|
upm_delay_us(120000);
|
||||||
|
|
||||||
while (shouldRun) {
|
while (shouldRun) {
|
||||||
float lux = light_proximity->getAmbient();
|
float lux = light_proximity.getAmbient();
|
||||||
cout << "Luminance value is " << lux << endl;
|
cout << "Luminance value is " << lux << endl;
|
||||||
float proximity = light_proximity->getProximity();
|
float proximity = light_proximity.getProximity();
|
||||||
cout << "Proximity value is " << proximity << endl;
|
cout << "Proximity value is " << proximity << endl;
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
light_proximity->enableProximity(false);
|
light_proximity.enableProximity(false);
|
||||||
light_proximity->enableIlluminance(false);
|
light_proximity.enableIlluminance(false);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete light_proximity;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,31 +22,32 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include "at42qt1070.hpp"
|
#include "at42qt1070.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printButtons(upm::AT42QT1070 *touch)
|
void
|
||||||
|
printButtons(upm::AT42QT1070& touch)
|
||||||
{
|
{
|
||||||
bool buttonPressed = false;
|
bool buttonPressed = false;
|
||||||
uint8_t buttons = touch->getButtons();
|
uint8_t buttons = touch.getButtons();
|
||||||
|
|
||||||
cout << "Buttons Pressed: ";
|
cout << "Buttons Pressed: ";
|
||||||
for (int i=0; i<7; i++)
|
for (int i = 0; i < 7; i++) {
|
||||||
{
|
if (buttons & (1 << i)) {
|
||||||
if (buttons & (1 << i))
|
|
||||||
{
|
|
||||||
cout << i << " ";
|
cout << i << " ";
|
||||||
buttonPressed = true;
|
buttonPressed = true;
|
||||||
}
|
}
|
||||||
@ -57,34 +58,32 @@ void printButtons(upm::AT42QT1070 *touch)
|
|||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
if (touch->isCalibrating())
|
if (touch.isCalibrating())
|
||||||
cout << "Calibration is occurring." << endl;
|
cout << "Calibration is occurring." << endl;
|
||||||
|
|
||||||
if (touch->isOverflowed())
|
if (touch.isOverflowed())
|
||||||
cout << "Overflow was detected." << endl;
|
cout << "Overflow was detected." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an AT42QT1070 on I2C bus 0
|
// Instantiate an AT42QT1070 on I2C bus 0
|
||||||
|
|
||||||
upm::AT42QT1070 *touch = new upm::AT42QT1070(AT42QT1070_I2C_BUS,
|
upm::AT42QT1070 touch(AT42QT1070_I2C_BUS, AT42QT1070_DEFAULT_I2C_ADDR);
|
||||||
AT42QT1070_DEFAULT_I2C_ADDR);
|
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
touch.updateState();
|
||||||
touch->updateState();
|
|
||||||
printButtons(touch);
|
printButtons(touch);
|
||||||
usleep(100000);
|
upm_delay_us(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete touch;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,22 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bh1750.hpp"
|
#include "bh1750.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
@ -46,20 +49,18 @@ int main()
|
|||||||
// Instantiate a BH1750 sensor using defaults (I2C bus (0), using
|
// Instantiate a BH1750 sensor using defaults (I2C bus (0), using
|
||||||
// the default I2C address (0x23), and setting the mode to highest
|
// the default I2C address (0x23), and setting the mode to highest
|
||||||
// resolution, lowest power mode).
|
// resolution, lowest power mode).
|
||||||
upm::BH1750 *sensor = new upm::BH1750();
|
upm::BH1750 sensor;
|
||||||
|
|
||||||
// Every second, sample the BH1750 and output the measured lux value
|
// Every second, sample the BH1750 and output the measured lux value
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
cout << "Detected Light Level (lux): " << sensor.getLux() << endl;
|
||||||
cout << "Detected Light Level (lux): " << sensor->getLux() << endl;
|
upm_delay(1);
|
||||||
sleep(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,33 +22,34 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "biss0001.hpp"
|
#include "biss0001.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main ()
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a Grove Motion sensor on GPIO pin D2
|
// Instantiate a Grove Motion sensor on GPIO pin D2
|
||||||
upm::BISS0001* motion = new upm::BISS0001(2);
|
upm::BISS0001 motion(2);
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
bool val = motion.value();
|
||||||
bool val = motion->value();
|
|
||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
cout << "Detecting moving object";
|
cout << "Detecting moving object";
|
||||||
@ -57,12 +58,11 @@ int main ()
|
|||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete motion;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,49 +22,48 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bma220.hpp"
|
#include "bma220.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate an BMA220 using default parameters (bus 0, addr 0x0a)
|
// Instantiate an BMA220 using default parameters (bus 0, addr 0x0a)
|
||||||
upm::BMA220 *sensor = new upm::BMA220();
|
upm::BMA220 sensor;
|
||||||
|
|
||||||
// Output data every half second until interrupted
|
// Output data every half second until interrupted
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
sensor.update();
|
||||||
sensor->update();
|
|
||||||
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor->getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer: ";
|
cout << "Accelerometer: ";
|
||||||
cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
|
cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
|
||||||
|
|
||||||
usleep(500000);
|
upm_delay_us(500000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bma250e.hpp"
|
#include "bma250e.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
@ -50,27 +52,21 @@ int main(int argc, char **argv)
|
|||||||
// for CS: BMA250E(0, -1, 10);
|
// for CS: BMA250E(0, -1, 10);
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
sensor.getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer x: " << x
|
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " g"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
// we show both C and F for temperature
|
// we show both C and F for temperature
|
||||||
cout << "Compensation Temperature: " << sensor.getTemperature()
|
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
|
||||||
<< " C / " << sensor.getTemperature(true) << " F"
|
<< sensor.getTemperature(true) << " F" << endl;
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
usleep(250000);
|
upm_delay_us(250000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bmg160.hpp"
|
#include "bmg160.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
@ -50,27 +52,21 @@ int main(int argc, char **argv)
|
|||||||
// for CS: BMG160(0, -1, 10);
|
// for CS: BMG160(0, -1, 10);
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
sensor.getGyroscope(&x, &y, &z);
|
sensor.getGyroscope(&x, &y, &z);
|
||||||
cout << "Gyroscope x: " << x
|
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " degrees/s"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
// we show both C and F for temperature
|
// we show both C and F for temperature
|
||||||
cout << "Compensation Temperature: " << sensor.getTemperature()
|
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
|
||||||
<< " C / " << sensor.getTemperature(true) << " F"
|
<< sensor.getTemperature(true) << " F" << endl;
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
usleep(250000);
|
upm_delay_us(250000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -22,61 +22,57 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bmi160.hpp"
|
#include "bmi160.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate a BMI160 instance using default i2c bus and address
|
// Instantiate a BMI160 instance using default i2c bus and address
|
||||||
upm::BMI160 *sensor = new upm::BMI160();
|
upm::BMI160 sensor;
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
float dataX, dataY, dataZ;
|
float dataX, dataY, dataZ;
|
||||||
|
|
||||||
sensor->getAccelerometer(&dataX, &dataY, &dataZ);
|
sensor.getAccelerometer(&dataX, &dataY, &dataZ);
|
||||||
cout << "Accelerometer: ";
|
cout << "Accelerometer: ";
|
||||||
cout << "AX: " << dataX << " AY: " << dataY << " AZ: "
|
cout << "AX: " << dataX << " AY: " << dataY << " AZ: " << dataZ << endl;
|
||||||
<< dataZ << endl;
|
|
||||||
|
|
||||||
sensor->getGyroscope(&dataX, &dataY, &dataZ);
|
sensor.getGyroscope(&dataX, &dataY, &dataZ);
|
||||||
cout << "Gryoscope: ";
|
cout << "Gryoscope: ";
|
||||||
cout << "GX: " << dataX << " GY: " << dataY << " GZ: "
|
cout << "GX: " << dataX << " GY: " << dataY << " GZ: " << dataZ << endl;
|
||||||
<< dataZ << endl;
|
|
||||||
|
|
||||||
sensor->getMagnetometer(&dataX, &dataY, &dataZ);
|
sensor.getMagnetometer(&dataX, &dataY, &dataZ);
|
||||||
cout << "Magnetometer: ";
|
cout << "Magnetometer: ";
|
||||||
cout << "MX: " << dataX << " MY: " << dataY << " MZ: "
|
cout << "MX: " << dataX << " MY: " << dataY << " MZ: " << dataZ << endl;
|
||||||
<< dataZ << endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
usleep(500000);
|
upm_delay_us(500000);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bmm150.hpp"
|
#include "bmm150.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
@ -50,22 +52,17 @@ int main(int argc, char **argv)
|
|||||||
// for CS: BMM150(0, -1, 10);
|
// for CS: BMM150(0, -1, 10);
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
sensor.getMagnetometer(&x, &y, &z);
|
sensor.getMagnetometer(&x, &y, &z);
|
||||||
cout << "Magnetometer x: " << x
|
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " uT"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
usleep(250000);
|
upm_delay_us(250000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -22,57 +22,54 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bme280.hpp"
|
#include "bme280.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate a BME280 instance using default i2c bus and address
|
// Instantiate a BME280 instance using default i2c bus and address
|
||||||
upm::BME280 *sensor = new upm::BME280();
|
upm::BME280 sensor;
|
||||||
|
|
||||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||||
// BME280(0, -1, 10);
|
// BME280(0, -1, 10);
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
// we show both C and F for temperature
|
// we show both C and F for temperature
|
||||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
|
||||||
<< " C / " << sensor->getTemperature(true) << " F"
|
<< sensor.getTemperature(true) << " F" << endl;
|
||||||
<< endl;
|
cout << "Pressure: " << sensor.getPressure() << " Pa" << endl;
|
||||||
cout << "Pressure: " << sensor->getPressure() << " Pa" << endl;
|
cout << "Computed Altitude: " << sensor.getAltitude() << " m" << endl;
|
||||||
cout << "Computed Altitude: " << sensor->getAltitude() << " m" << endl;
|
cout << "Humidity: " << sensor.getHumidity() << " %RH" << endl;
|
||||||
cout << "Humidity: " << sensor->getHumidity() << " %RH" << endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -24,56 +24,53 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bmp280.hpp"
|
#include "bmp280.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate a BMP280 instance using default i2c bus and address
|
// Instantiate a BMP280 instance using default i2c bus and address
|
||||||
upm::BMP280 *sensor = new upm::BMP280();
|
upm::BMP280 sensor;
|
||||||
|
|
||||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||||
// BMP280(0, -1, 10);
|
// BMP280(0, -1, 10);
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
// we show both C and F for temperature
|
// we show both C and F for temperature
|
||||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
|
||||||
<< " C / " << sensor->getTemperature(true) << " F"
|
<< sensor.getTemperature(true) << " F" << endl;
|
||||||
<< endl;
|
cout << "Pressure: " << sensor.getPressure() << " Pa" << endl;
|
||||||
cout << "Pressure: " << sensor->getPressure() << " Pa" << endl;
|
cout << "Computed Altitude: " << sensor.getAltitude() << " m" << endl;
|
||||||
cout << "Computed Altitude: " << sensor->getAltitude() << " m" << endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -27,23 +27,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bmpx8x.hpp"
|
#include "bmpx8x.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
@ -53,22 +55,15 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Print the pressure, altitude, sea level, and
|
// Print the pressure, altitude, sea level, and
|
||||||
// temperature values every 0.5 seconds
|
// temperature values every 0.5 seconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
cout << "Pressure: "
|
cout << "Pressure: " << sensor.getPressure()
|
||||||
<< sensor.getPressure()
|
<< " Pa, Temperature: " << sensor.getTemperature()
|
||||||
<< " Pa, Temperature: "
|
<< " C, Altitude: " << sensor.getAltitude()
|
||||||
<< sensor.getTemperature()
|
<< " m, Sea level: " << sensor.getSealevelPressure() << " Pa" << endl;
|
||||||
<< " C, Altitude: "
|
|
||||||
<< sensor.getAltitude()
|
|
||||||
<< " m, Sea level: "
|
|
||||||
<< sensor.getSealevelPressure()
|
|
||||||
<< " Pa"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
usleep(500000);
|
upm_delay_us(500000);
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bmc150.hpp"
|
#include "bmc150.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
@ -47,29 +49,20 @@ int main(int argc, char **argv)
|
|||||||
upm::BMC150 sensor;
|
upm::BMC150 sensor;
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
sensor.getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer x: " << x
|
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " g"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
sensor.getMagnetometer(&x, &y, &z);
|
sensor.getMagnetometer(&x, &y, &z);
|
||||||
cout << "Magnetometer x: " << x
|
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " uT"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
usleep(250000);
|
upm_delay_us(250000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bmi055.hpp"
|
#include "bmi055.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
@ -47,29 +49,20 @@ int main(int argc, char **argv)
|
|||||||
upm::BMI055 sensor;
|
upm::BMI055 sensor;
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
sensor.getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer x: " << x
|
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " g"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
sensor.getGyroscope(&x, &y, &z);
|
sensor.getGyroscope(&x, &y, &z);
|
||||||
cout << "Gyroscope x: " << x
|
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " degrees/s"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
usleep(250000);
|
upm_delay_us(250000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bmx055.hpp"
|
#include "bmx055.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
@ -47,36 +49,23 @@ int main(int argc, char **argv)
|
|||||||
upm::BMX055 sensor;
|
upm::BMX055 sensor;
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor.update();
|
sensor.update();
|
||||||
|
|
||||||
sensor.getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer x: " << x
|
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " g"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
sensor.getGyroscope(&x, &y, &z);
|
sensor.getGyroscope(&x, &y, &z);
|
||||||
cout << "Gyroscope x: " << x
|
cout << "Gyroscope x: " << x << " y: " << y << " z: " << z << " degrees/s" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " degrees/s"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
sensor.getMagnetometer(&x, &y, &z);
|
sensor.getMagnetometer(&x, &y, &z);
|
||||||
cout << "Magnetometer x: " << x
|
cout << "Magnetometer x: " << x << " y: " << y << " z: " << z << " uT" << endl;
|
||||||
<< " y: " << y
|
|
||||||
<< " z: " << z
|
|
||||||
<< " uT"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
usleep(250000);
|
upm_delay_us(250000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "bno055.hpp"
|
#include "bno055.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
@ -46,34 +48,25 @@ int main(int argc, char **argv)
|
|||||||
// Instantiate an BNO055 using default parameters (bus 0, addr
|
// Instantiate an BNO055 using default parameters (bus 0, addr
|
||||||
// 0x28). The default running mode is NDOF absolute orientation
|
// 0x28). The default running mode is NDOF absolute orientation
|
||||||
// mode.
|
// mode.
|
||||||
upm::BNO055 *sensor = new upm::BNO055();
|
upm::BNO055 sensor;
|
||||||
|
|
||||||
// First we need to calibrate....
|
// First we need to calibrate....
|
||||||
cout << "First we need to calibrate. 4 numbers will be output every"
|
cout << "First we need to calibrate. 4 numbers will be output every" << endl;
|
||||||
<< endl;
|
cout << "second for each sensor. 0 means uncalibrated, and 3 means" << endl;
|
||||||
cout << "second for each sensor. 0 means uncalibrated, and 3 means"
|
cout << "fully calibrated." << endl;
|
||||||
<< endl;
|
cout << "See the UPM documentation on this sensor for instructions on" << endl;
|
||||||
cout << "fully calibrated."
|
cout << "what actions are required to calibrate." << endl;
|
||||||
<< endl;
|
|
||||||
cout << "See the UPM documentation on this sensor for instructions on"
|
|
||||||
<< endl;
|
|
||||||
cout << "what actions are required to calibrate."
|
|
||||||
<< endl;
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
// do the calibration...
|
// do the calibration...
|
||||||
while (shouldRun && !sensor->isFullyCalibrated())
|
while (shouldRun && !sensor.isFullyCalibrated()) {
|
||||||
{
|
|
||||||
int mag, acc, gyr, sys;
|
int mag, acc, gyr, sys;
|
||||||
sensor->getCalibrationStatus(&mag, &acc, &gyr, &sys);
|
sensor.getCalibrationStatus(&mag, &acc, &gyr, &sys);
|
||||||
|
|
||||||
cout << "Magnetometer: " << mag
|
cout << "Magnetometer: " << mag << " Accelerometer: " << acc << " Gyroscope: " << gyr
|
||||||
<< " Accelerometer: " << acc
|
<< " System: " << sys << endl;
|
||||||
<< " Gyroscope: " << gyr
|
|
||||||
<< " System: " << sys
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
@ -81,49 +74,30 @@ int main(int argc, char **argv)
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
// now output various fusion data every 250 milliseconds
|
// now output various fusion data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
float w, x, y, z;
|
float w, x, y, z;
|
||||||
|
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
sensor->getEulerAngles(&x, &y, &z);
|
sensor.getEulerAngles(&x, &y, &z);
|
||||||
cout << "Euler: Heading: " << x
|
cout << "Euler: Heading: " << x << " Roll: " << y << " Pitch: " << z << " degrees" << endl;
|
||||||
<< " Roll: " << y
|
|
||||||
<< " Pitch: " << z
|
|
||||||
<< " degrees"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
sensor->getQuaternions(&w, &x, &y, &z);
|
sensor.getQuaternions(&w, &x, &y, &z);
|
||||||
cout << "Quaternion: W: " << w
|
cout << "Quaternion: W: " << w << " X: " << x << " Y: " << y << " Z: " << z << endl;
|
||||||
<< " X: " << x
|
|
||||||
<< " Y: " << y
|
|
||||||
<< " Z: " << z
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
sensor->getLinearAcceleration(&x, &y, &z);
|
sensor.getLinearAcceleration(&x, &y, &z);
|
||||||
cout << "Linear Acceleration: X: " << x
|
cout << "Linear Acceleration: X: " << x << " Y: " << y << " Z: " << z << " m/s^2" << endl;
|
||||||
<< " Y: " << y
|
|
||||||
<< " Z: " << z
|
|
||||||
<< " m/s^2"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
sensor->getGravityVectors(&x, &y, &z);
|
sensor.getGravityVectors(&x, &y, &z);
|
||||||
cout << "Gravity Vector: X: " << x
|
cout << "Gravity Vector: X: " << x << " Y: " << y << " Z: " << z << " m/s^2" << endl;
|
||||||
<< " Y: " << y
|
|
||||||
<< " Z: " << z
|
|
||||||
<< " m/s^2"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
usleep(250000);
|
upm_delay_us(250000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,10 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
@ -33,16 +34,15 @@ main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Create the button object using GPIO pin 0
|
// Create the button object using GPIO pin 0
|
||||||
upm::Button* button = new upm::Button(0);
|
upm::Button button(0);
|
||||||
|
|
||||||
// Read the input and print, waiting one second between readings
|
// Read the input and print, waiting one second between readings
|
||||||
while (1) {
|
while (1) {
|
||||||
std::cout << button->name() << " value is " << button->value() << std::endl;
|
std::cout << button.name() << " value is " << button.value() << std::endl;
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the button object
|
// Delete the button object
|
||||||
delete button;
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,36 +22,32 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
|
||||||
#include "buzzer.hpp"
|
|
||||||
|
|
||||||
|
#include "buzzer.hpp"
|
||||||
|
#include "buzzer_tones.h"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv) {
|
main(int argc, char** argv)
|
||||||
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
int chord[] = { BUZZER_DO, BUZZER_RE, BUZZER_MI,
|
int chord[] = { BUZZER_DO, BUZZER_RE, BUZZER_MI, BUZZER_FA, BUZZER_SOL, BUZZER_LA, BUZZER_SI };
|
||||||
BUZZER_FA, BUZZER_SOL, BUZZER_LA,
|
|
||||||
BUZZER_SI };
|
|
||||||
|
|
||||||
// create Buzzer instance
|
// create Buzzer instance
|
||||||
upm::Buzzer* sound = new upm::Buzzer(5);
|
upm::Buzzer sound(5);
|
||||||
// print sensor name
|
// print sensor name
|
||||||
std::cout << sound->name() << std::endl;
|
std::cout << sound.name() << std::endl;
|
||||||
|
|
||||||
// play each sound (DO, RE, MI, etc...) for .5 seconds, pausing
|
// play each sound (DO, RE, MI, etc...) for .5 seconds, pausing
|
||||||
// for 0.1 seconds between notes
|
// for 0.1 seconds between notes
|
||||||
for (int chord_ind = 0; chord_ind < 7; chord_ind++)
|
for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
|
||||||
{
|
std::cout << sound.playSound(chord[chord_ind], 500000) << std::endl;
|
||||||
std::cout << sound->playSound(chord[chord_ind], 500000) << std::endl;
|
|
||||||
upm_delay_ms(100);
|
upm_delay_ms(100);
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
std::cout << "exiting application" << std::endl;
|
std::cout << "exiting application" << std::endl;
|
||||||
|
|
||||||
delete sound;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,56 +22,54 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "cjq4435.hpp"
|
#include "cjq4435.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main ()
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3
|
// Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3
|
||||||
upm::CJQ4435* mosfet = new upm::CJQ4435(3);
|
upm::CJQ4435 mosfet(3);
|
||||||
|
|
||||||
mosfet->setPeriodMS(10);
|
mosfet.setPeriodMS(10);
|
||||||
mosfet->enable(true);
|
mosfet.enable(true);
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
// start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
|
// start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
|
||||||
for (float i=0.0; i <= 1.0; i+=0.1)
|
for (float i = 0.0; i <= 1.0; i += 0.1) {
|
||||||
{
|
mosfet.setDutyCycle(i);
|
||||||
mosfet->setDutyCycle(i);
|
upm_delay_us(100000);
|
||||||
usleep(100000);
|
|
||||||
}
|
}
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
// Now take it back down
|
// Now take it back down
|
||||||
// start with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
|
// start with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
|
||||||
for (float i=1.0; i >= 0.0; i-=0.1)
|
for (float i = 1.0; i >= 0.0; i -= 0.1) {
|
||||||
{
|
mosfet.setDutyCycle(i);
|
||||||
mosfet->setDutyCycle(i);
|
upm_delay_us(100000);
|
||||||
usleep(100000);
|
|
||||||
}
|
}
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete mosfet;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,40 +22,38 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "collision.hpp"
|
#include "collision.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// The was tested with the Collision Sensor
|
// The was tested with the Collision Sensor
|
||||||
// Instantiate a Collision on digital pin D2
|
// Instantiate a Collision on digital pin D2
|
||||||
upm::Collision* collision = new upm::Collision(2);
|
upm::Collision collision(2);
|
||||||
|
|
||||||
bool collisionState = false;
|
bool collisionState = false;
|
||||||
cout << "No collision" << endl;
|
cout << "No collision" << endl;
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
if (collision.isColliding() && !collisionState) {
|
||||||
if (collision->isColliding() && !collisionState)
|
|
||||||
{
|
|
||||||
cout << "Collision!" << endl;
|
cout << "Collision!" << endl;
|
||||||
collisionState = true;
|
collisionState = true;
|
||||||
}
|
} else if (collisionState) {
|
||||||
else if (collisionState)
|
|
||||||
{
|
|
||||||
cout << "No collision" << endl;
|
cout << "No collision" << endl;
|
||||||
collisionState = false;
|
collisionState = false;
|
||||||
}
|
}
|
||||||
@ -64,6 +62,5 @@ int main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete collision;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
92
examples/c++/core-humiditysensor.cxx
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "bme280.hpp"
|
||||||
|
#include "iHumiditySensor.hpp"
|
||||||
|
#include "mraa/common.h"
|
||||||
|
#include "si7005.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using iHumiditySensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// iHumiditySensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
upm::iHumiditySensor*
|
||||||
|
getHumiditySensor()
|
||||||
|
{
|
||||||
|
upm::iHumiditySensor* humiditySensor = NULL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
humiditySensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return humiditySensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BME280: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
humiditySensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
|
return humiditySensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI7005: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return humiditySensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
upm::iHumiditySensor* sensor = getHumiditySensor();
|
||||||
|
|
||||||
|
if (sensor == NULL) {
|
||||||
|
std::cout << "Humidity sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Humidity sensor " << sensor->Name() << " detected" << std::endl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::map<std::string, float> values = sensor->HumidityAll();
|
||||||
|
for (std::map<std::string, float>::const_iterator it = values.begin();
|
||||||
|
it != values.end(); ++it)
|
||||||
|
std::cout << it->first << " = " << it->second
|
||||||
|
<< sensor->Unit(it->first) << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
98
examples/c++/core-lightcontroller.cxx
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "ds1808lc.hpp"
|
||||||
|
#include "hlg150h.hpp"
|
||||||
|
#include "iLightController.hpp"
|
||||||
|
#include "lp8860.hpp"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||||
|
#define GPIO_SI7005_CS 20 // Edison GP12
|
||||||
|
#define HLG150H_GPIO_RELAY 21
|
||||||
|
#define HLG150H_GPIO_PWM 22
|
||||||
|
#define LP8860_GPIO_PWR 45 // Edison GP45
|
||||||
|
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||||
|
#define DS1808_GPIO_EDISON_LIVE 36 // Edison GP14
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightController to determine
|
||||||
|
// which controller is present and return its name.
|
||||||
|
// ILightController is then used to get readings from sensor
|
||||||
|
|
||||||
|
upm::ILightController*
|
||||||
|
getLightController()
|
||||||
|
{
|
||||||
|
upm::ILightController* lightController = NULL;
|
||||||
|
try {
|
||||||
|
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "LP8860: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "DS1808LC: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "HLG150H: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return lightController;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
printState(upm::ILightController* lightController)
|
||||||
|
{
|
||||||
|
if (lightController->isPowered()) {
|
||||||
|
std::cout << "Light is powered, brightness = " << lightController->getBrightness()
|
||||||
|
<< std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Light is not powered." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
// MraaUtils::setGpio(GPIO_SI7005_CS, 1);
|
||||||
|
|
||||||
|
upm::ILightController* lightController = getLightController();
|
||||||
|
if (lightController != NULL) {
|
||||||
|
//std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cerr << "Error. Unsupported platform." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::cout << "Existing state: ";
|
||||||
|
printState(lightController);
|
||||||
|
if (argc == 2) {
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";
|
||||||
|
printState(lightController);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete lightController;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
88
examples/c++/core-lightsensor.cxx
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "iLightSensor.hpp"
|
||||||
|
#include "max44009.hpp"
|
||||||
|
#include "mraa/common.h"
|
||||||
|
#include "si1132.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using iLightSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// iLightSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
upm::iLightSensor*
|
||||||
|
getLightSensor()
|
||||||
|
{
|
||||||
|
upm::iLightSensor* lightSensor = NULL;
|
||||||
|
try {
|
||||||
|
lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI1132: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
|
||||||
|
return lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "MAX44009: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return lightSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
upm::iLightSensor* sensor = getLightSensor();
|
||||||
|
|
||||||
|
if (sensor == NULL) {
|
||||||
|
std::cout << "Light sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Light sensor " << sensor->Name() << " detected" << std::endl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::map<std::string, float> values = sensor->LightAll();
|
||||||
|
for (std::map<std::string, float>::const_iterator it = values.begin();
|
||||||
|
it != values.end(); ++it)
|
||||||
|
std::cout << it->first << " = " << it->second
|
||||||
|
<< sensor->Unit(it->first) << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
89
examples/c++/core-pressuresensor.cxx
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "bme280.hpp"
|
||||||
|
#include "bmpx8x.hpp"
|
||||||
|
#include "iPressureSensor.hpp"
|
||||||
|
#include "mraa/common.h"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using iPressureSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// iPressureSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
upm::iPressureSensor*
|
||||||
|
getPressureSensor()
|
||||||
|
{
|
||||||
|
upm::iPressureSensor* pressureSensor = NULL;
|
||||||
|
try {
|
||||||
|
pressureSensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return pressureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BME280: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
pressureSensor = new upm::BMPX8X(EDISON_I2C_BUS);
|
||||||
|
return pressureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BMPX8X: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return pressureSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
upm::iPressureSensor* sensor = getPressureSensor();
|
||||||
|
|
||||||
|
if (sensor == NULL) {
|
||||||
|
std::cout << "Pressure sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Pressure sensor " << sensor->Name() << " detected" << std::endl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::map<std::string, float> values = sensor->PressureAll();
|
||||||
|
for (std::map<std::string, float>::const_iterator it = values.begin();
|
||||||
|
it != values.end(); ++it)
|
||||||
|
std::cout << it->first << " = " << it->second
|
||||||
|
<< sensor->Unit(it->first) << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
99
examples/c++/core-temperaturesensor.cxx
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "bme280.hpp"
|
||||||
|
#include "bmpx8x.hpp"
|
||||||
|
#include "iTemperatureSensor.hpp"
|
||||||
|
#include "mraa/common.h"
|
||||||
|
#include "si7005.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using iTemperatureSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// iTemperatureSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
upm::iTemperatureSensor*
|
||||||
|
getTemperatureSensor()
|
||||||
|
{
|
||||||
|
upm::iTemperatureSensor* temperatureSensor = NULL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BME280: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI7005: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::BMPX8X(EDISON_I2C_BUS);
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BMPX8X: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return temperatureSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
upm::iTemperatureSensor* sensor = getTemperatureSensor();
|
||||||
|
|
||||||
|
if (sensor == NULL) {
|
||||||
|
std::cout << "Temperature sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Temperature sensor " << sensor->Name() << " detected" << std::endl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::map<std::string, float> values = sensor->TemperatureAll();
|
||||||
|
for (std::map<std::string, float>::const_iterator it = values.begin();
|
||||||
|
it != values.end(); ++it)
|
||||||
|
std::cout << it->first << " = " << it->second
|
||||||
|
<< sensor->Unit(it->first) << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
@ -24,12 +24,13 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "curieimu.hpp"
|
#include "curieimu.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
#include "mraa.h"
|
#include "mraa.h"
|
||||||
#include "mraa/firmata.h"
|
#include "mraa/firmata.h"
|
||||||
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
@ -38,44 +39,35 @@ main(int argc, char **argv)
|
|||||||
mraa_init();
|
mraa_init();
|
||||||
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
|
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||||
|
|
||||||
upm::CurieImu* sensor = new upm::CurieImu();
|
upm::CurieImu sensor;
|
||||||
|
|
||||||
std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
|
std::cout << "temperature is: " << (sensor.getTemperature() * pow(0.5, 9) + 23) << std::endl;
|
||||||
|
|
||||||
sensor->updateAccel();
|
sensor.updateAccel();
|
||||||
int x = sensor->getAccelX(),
|
int x = sensor.getAccelX(), y = sensor.getAccelY(), z = sensor.getAccelZ();
|
||||||
y = sensor->getAccelY(),
|
|
||||||
z = sensor->getAccelZ();
|
|
||||||
printf("accelerometer is: %d, %d, %d\n", x, y, z);
|
printf("accelerometer is: %d, %d, %d\n", x, y, z);
|
||||||
|
|
||||||
sensor->updateGyro();
|
sensor.updateGyro();
|
||||||
int a = sensor->getGyroX(),
|
int a = sensor.getGyroX(), b = sensor.getGyroY(), c = sensor.getGyroZ();
|
||||||
b = sensor->getGyroY(),
|
|
||||||
c = sensor->getGyroZ();
|
|
||||||
printf("gyroscope is: %d, %d, %d\n", a, b, c);
|
printf("gyroscope is: %d, %d, %d\n", a, b, c);
|
||||||
|
|
||||||
int axis, direction;
|
int axis, direction;
|
||||||
sensor->enableShockDetection(true);
|
sensor.enableShockDetection(true);
|
||||||
for (int i = 0; i < 300; i++) {
|
for (int i = 0; i < 300; i++) {
|
||||||
if (sensor->isShockDetected()) {
|
if (sensor.isShockDetected()) {
|
||||||
sensor->getNextShock();
|
sensor.getNextShock();
|
||||||
axis = sensor->getAxis();
|
axis = sensor.getAxis();
|
||||||
direction = sensor->getDirection();
|
direction = sensor.getDirection();
|
||||||
printf("shock data is: %d, %d\n", axis, direction);
|
printf("shock data is: %d, %d\n", axis, direction);
|
||||||
}
|
}
|
||||||
usleep(10000);
|
upm_delay_us(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
sensor->updateMotion();
|
sensor.updateMotion();
|
||||||
int m = sensor->getAccelX(),
|
int m = sensor.getAccelX(), n = sensor.getAccelY(), o = sensor.getAccelZ(),
|
||||||
n = sensor->getAccelY(),
|
p = sensor.getGyroX(), q = sensor.getGyroY(), r = sensor.getGyroZ();
|
||||||
o = sensor->getAccelZ(),
|
|
||||||
p = sensor->getGyroX(),
|
|
||||||
q = sensor->getGyroY(),
|
|
||||||
r = sensor->getGyroZ();
|
|
||||||
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
|
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "cwlsxxa.hpp"
|
#include "cwlsxxa.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
@ -48,34 +50,28 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||||
// humidity and A2 for temperature
|
// humidity and A2 for temperature
|
||||||
upm::CWLSXXA *sensor = new upm::CWLSXXA(0, 1, 2);
|
upm::CWLSXXA sensor(0, 1, 2);
|
||||||
|
|
||||||
// update and print available values every second
|
// update and print available values every second
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
// update our values from the sensor
|
// update our values from the sensor
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
// we show both C and F for temperature
|
// we show both C and F for temperature
|
||||||
cout << "Temperature: " << sensor->getTemperature()
|
cout << "Temperature: " << sensor.getTemperature() << " C / " << sensor.getTemperature(true)
|
||||||
<< " C / " << sensor->getTemperature(true) << " F"
|
<< " F" << endl;
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Humidity: " << sensor->getHumidity()
|
cout << "Humidity: " << sensor.getHumidity() << " %" << endl;
|
||||||
<< " %" << endl;
|
|
||||||
|
|
||||||
cout << "CO2: " << sensor->getCO2()
|
cout << "CO2: " << sensor.getCO2() << " ppm" << endl;
|
||||||
<< " ppm" << endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "dfrec.hpp"
|
#include "dfrec.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
@ -48,34 +50,25 @@ int main()
|
|||||||
// temperature sensor connected to UART 0, and a device index (for
|
// temperature sensor connected to UART 0, and a device index (for
|
||||||
// the ds1820b uart bus) of 0, and an analog reference voltage of
|
// the ds1820b uart bus) of 0, and an analog reference voltage of
|
||||||
// 5.0.
|
// 5.0.
|
||||||
upm::DFREC *sensor = new upm::DFREC(0, 0, 0, 5.0);
|
upm::DFREC sensor(0, 0, 0, 5.0);
|
||||||
|
|
||||||
// Every 2 seconds, update and print values
|
// Every 2 seconds, update and print values
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
sensor.update();
|
||||||
sensor->update();
|
|
||||||
|
|
||||||
cout << "EC = "
|
cout << "EC = " << sensor.getEC() << " ms/cm" << endl;
|
||||||
<< sensor->getEC()
|
|
||||||
<< " ms/cm"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Volts = "
|
cout << "Volts = " << sensor.getVolts() << ", Temperature = " << sensor.getTemperature()
|
||||||
<< sensor->getVolts()
|
<< " C" << endl;
|
||||||
<< ", Temperature = "
|
|
||||||
<< sensor->getTemperature()
|
|
||||||
<< " C"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
sleep(2);
|
upm_delay(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "dfrorp.hpp"
|
#include "dfrorp.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ int main()
|
|||||||
|
|
||||||
// Instantiate a DFRobot ORP sensor on analog pin A0 with an analog
|
// Instantiate a DFRobot ORP sensor on analog pin A0 with an analog
|
||||||
// reference voltage of 5.0.
|
// reference voltage of 5.0.
|
||||||
upm::DFRORP *sensor = new upm::DFRORP(0, 5.0);
|
upm::DFRORP sensor(0, 5.0);
|
||||||
|
|
||||||
// To calibrate:
|
// To calibrate:
|
||||||
//
|
//
|
||||||
@ -61,27 +63,22 @@ int main()
|
|||||||
//
|
//
|
||||||
// DO NOT press the calibrate button on the interface board while
|
// DO NOT press the calibrate button on the interface board while
|
||||||
// the probe is attached or you can permanently damage the probe.
|
// the probe is attached or you can permanently damage the probe.
|
||||||
sensor->setCalibrationOffset(0.97);
|
sensor.setCalibrationOffset(0.97);
|
||||||
|
|
||||||
// Every second, update and print values
|
// Every second, update and print values
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
sensor.update();
|
||||||
sensor->update();
|
|
||||||
|
|
||||||
cout << "ORP: "
|
cout << "ORP: " << sensor.getORP() << " mV" << endl;
|
||||||
<< sensor->getORP()
|
|
||||||
<< " mV"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "dfrph.hpp"
|
#include "dfrph.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -33,13 +34,15 @@ bool shouldRun = true;
|
|||||||
|
|
||||||
#define DFRPH_AREF 5.0
|
#define DFRPH_AREF 5.0
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
@ -47,30 +50,27 @@ int main()
|
|||||||
|
|
||||||
// Instantiate a DFRPH sensor on analog pin A0, with an analog
|
// Instantiate a DFRPH sensor on analog pin A0, with an analog
|
||||||
// reference voltage of DFRPH_AREF
|
// reference voltage of DFRPH_AREF
|
||||||
upm::DFRPH *sensor = new upm::DFRPH(0, DFRPH_AREF);
|
upm::DFRPH sensor(0, DFRPH_AREF);
|
||||||
|
|
||||||
|
|
||||||
// After calibration, set the offset (based on calibration with a pH
|
// After calibration, set the offset (based on calibration with a pH
|
||||||
// 7.0 buffer solution). See the UPM sensor documentation for
|
// 7.0 buffer solution). See the UPM sensor documentation for
|
||||||
// calibrations instructions.
|
// calibrations instructions.
|
||||||
sensor->setOffset(0.065);
|
sensor.setOffset(0.065);
|
||||||
|
|
||||||
// Every second, sample the pH and output it's corresponding
|
// Every second, sample the pH and output it's corresponding
|
||||||
// analog voltage.
|
// analog voltage.
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
cout << "Detected volts: " << sensor.volts() << endl;
|
||||||
cout << "Detected volts: " << sensor->volts() << endl;
|
cout << "pH value: " << sensor.pH() << endl;
|
||||||
cout << "pH value: " << sensor->pH() << endl;
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,25 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "ds1307.hpp"
|
#include "ds1307.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void printTime(upm::DS1307 *rtc)
|
void
|
||||||
|
printTime(upm::DS1307& rtc)
|
||||||
{
|
{
|
||||||
cout << "The time is: " <<
|
cout << "The time is: " << rtc.month << "/" << rtc.dayOfMonth << "/" << rtc.year << " "
|
||||||
rtc->month << "/" << rtc->dayOfMonth << "/" << rtc->year << " "
|
<< rtc.hours << ":" << rtc.minutes << ":" << rtc.seconds;
|
||||||
<< rtc->hours << ":" << rtc->minutes << ":" << rtc->seconds;
|
|
||||||
|
|
||||||
if (rtc->amPmMode)
|
if (rtc.amPmMode)
|
||||||
cout << ((rtc->pm) ? " PM " : " AM ");
|
cout << ((rtc.pm) ? " PM " : " AM ");
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
cout << "Clock is in " << ((rtc->amPmMode) ? "AM/PM mode" : "24hr mode")
|
cout << "Clock is in " << ((rtc.amPmMode) ? "AM/PM mode" : "24hr mode") << endl;
|
||||||
<< endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -48,13 +48,12 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a DS1037 on I2C bus 0
|
// Instantiate a DS1037 on I2C bus 0
|
||||||
upm::DS1307 *rtc = new upm::DS1307(0);
|
upm::DS1307 rtc(0);
|
||||||
|
|
||||||
// always do this first
|
// always do this first
|
||||||
cout << "Loading the current time... " << endl;
|
cout << "Loading the current time... " << endl;
|
||||||
if (!rtc->loadTime())
|
if (!rtc.loadTime()) {
|
||||||
{
|
cerr << "rtc.loadTime() failed." << endl;
|
||||||
cerr << "rtc->loadTime() failed." << endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,16 +61,15 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
// set the year as an example
|
// set the year as an example
|
||||||
cout << "setting the year to 50" << endl;
|
cout << "setting the year to 50" << endl;
|
||||||
rtc->year = 50;
|
rtc.year = 50;
|
||||||
|
|
||||||
rtc->setTime();
|
rtc.setTime();
|
||||||
|
|
||||||
// reload the time and print it
|
// reload the time and print it
|
||||||
rtc->loadTime();
|
rtc.loadTime();
|
||||||
printTime(rtc);
|
printTime(rtc);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
delete rtc;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,41 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "ds1808lc.hpp"
|
#include "ds1808lc.hpp"
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||||
#define DS1808_GPIO_PWR 15 // Edison GP165
|
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||||
|
|
||||||
void printState(upm::ILightController &lightController)
|
void
|
||||||
{
|
printState(upm::ILightController& lightController)
|
||||||
if (lightController.isPowered())
|
|
||||||
{
|
|
||||||
std::cout << "Light is powered, brightness = " << lightController.getBrightness() << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
if (lightController.isPowered()) {
|
||||||
|
std::cout << "Light is powered, brightness = " << lightController.getBrightness()
|
||||||
|
<< std::endl;
|
||||||
|
} else {
|
||||||
std::cout << "Light is not powered." << std::endl;
|
std::cout << "Light is not powered." << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
upm::DS1808LC lightController(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
upm::DS1808LC lightController(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
std::cout << "Existing state: "; printState(lightController);
|
std::cout << "Existing state: ";
|
||||||
if (argc == 2)
|
printState(lightController);
|
||||||
{
|
if (argc == 2) {
|
||||||
std::string arg = argv[1];
|
std::string arg = argv[1];
|
||||||
int brightness = ::atoi(argv[1]);
|
int brightness = ::atoi(argv[1]);
|
||||||
if (brightness > 0)
|
if (brightness > 0) {
|
||||||
{
|
|
||||||
lightController.setPowerOn();
|
lightController.setPowerOn();
|
||||||
lightController.setBrightness(brightness);
|
lightController.setBrightness(brightness);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
lightController.setPowerOff();
|
lightController.setPowerOff();
|
||||||
}
|
}
|
||||||
std::cout << "Now: ";printState(lightController);
|
std::cout << "Now: ";
|
||||||
|
printState(lightController);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,25 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "ds18b20.hpp"
|
#include "ds18b20.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
@ -57,25 +59,19 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// update and print available values every 2 seconds
|
// update and print available values every 2 seconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
// update our values for all of the detected sensors
|
// update our values for all of the detected sensors
|
||||||
sensor.update(-1);
|
sensor.update(-1);
|
||||||
|
|
||||||
// we show both C and F for temperature for the sensors
|
// we show both C and F for temperature for the sensors
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<sensor.devicesFound(); i++)
|
for (i = 0; i < sensor.devicesFound(); i++) {
|
||||||
{
|
cout << "Device " << i << ": Temperature: " << sensor.getTemperature(i) << " C / "
|
||||||
cout << "Device "
|
<< sensor.getTemperature(i, true) << " F" << endl;
|
||||||
<< i
|
|
||||||
<< ": Temperature: "
|
|
||||||
<< sensor.getTemperature(i)
|
|
||||||
<< " C / " << sensor.getTemperature(i, true) << " F"
|
|
||||||
<< endl;
|
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
sleep(2);
|
upm_delay(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
@ -22,38 +22,37 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdio.h>
|
|
||||||
#include "ds2413.hpp"
|
#include "ds2413.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a DS2413 Module on a Dallas 1-wire bus connected to UART 0
|
// Instantiate a DS2413 Module on a Dallas 1-wire bus connected to UART 0
|
||||||
upm::DS2413* sensor = new upm::DS2413(0);
|
upm::DS2413 sensor(0);
|
||||||
|
|
||||||
// find all of the DS2413 devices present on the bus
|
// find all of the DS2413 devices present on the bus
|
||||||
sensor->init();
|
sensor.init();
|
||||||
|
|
||||||
// how many devices were found?
|
// how many devices were found?
|
||||||
cout << "Found "<< sensor->devicesFound() << " device(s)" << endl;
|
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
|
||||||
|
|
||||||
// read the gpio and latch values from the first device
|
// read the gpio and latch values from the first device
|
||||||
// the lower 4 bits are of the form:
|
// the lower 4 bits are of the form:
|
||||||
// <gpioB latch> <gpioB value> <gpioA latch> <gpioA value>
|
// <gpioB latch> <gpioB value> <gpioA latch> <gpioA value>
|
||||||
cout << "GPIO device 0 values: " << sensor->readGpios(0) << endl;
|
cout << "GPIO device 0 values: " << sensor.readGpios(0) << endl;
|
||||||
|
|
||||||
// set the gpio latch values of the first device
|
// set the gpio latch values of the first device
|
||||||
cout << "Setting GPIO latches to on" << endl;
|
cout << "Setting GPIO latches to on" << endl;
|
||||||
sensor->writeGpios(0, 0x03);
|
sensor.writeGpios(0, 0x03);
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,24 +22,27 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "e50hx.hpp"
|
#include "e50hx.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
@ -62,50 +65,40 @@ int main(int argc, char **argv)
|
|||||||
// as it's unique Device Object Instance ID. NOTE: You will
|
// as it's unique Device Object Instance ID. NOTE: You will
|
||||||
// certainly want to change this to the correct value for your
|
// certainly want to change this to the correct value for your
|
||||||
// device(s).
|
// device(s).
|
||||||
E50HX *sensor = new E50HX(1075425);
|
E50HX sensor(1075425);
|
||||||
|
|
||||||
// Initialize our BACnet master, if it has not already been
|
// Initialize our BACnet master, if it has not already been
|
||||||
// initialized, with the device and baudrate, choosing 1000001 as
|
// initialized, with the device and baudrate, choosing 1000001 as
|
||||||
// our unique Device Object Instance ID, 2 as our MAC address and
|
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||||
// using default values for maxMaster and maxInfoFrames
|
// using default values for maxMaster and maxInfoFrames
|
||||||
sensor->initMaster(defaultDev, 38400, 1000001, 2);
|
sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||||
|
|
||||||
// Uncomment to enable debugging output
|
// Uncomment to enable debugging output
|
||||||
// sensor->setDebug(true);
|
// sensor.setDebug(true);
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
cout << "Device Description: " << sensor->getDeviceDescription() << endl;
|
cout << "Device Description: " << sensor.getDeviceDescription() << endl;
|
||||||
cout << "Device Location: " << sensor->getDeviceLocation() << endl;
|
cout << "Device Location: " << sensor.getDeviceLocation() << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
// update and print a few values every 5 seconds
|
// update and print a few values every 5 seconds
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
cout << "System Voltage: " << sensor.getAnalogValue(E50HX::AV_System_Voltage) << " "
|
||||||
cout << "System Voltage: "
|
<< sensor.getAnalogValueUnits(E50HX::AV_System_Voltage) << endl;
|
||||||
<< sensor->getAnalogValue(E50HX::AV_System_Voltage)
|
|
||||||
<< " " << sensor->getAnalogValueUnits(E50HX::AV_System_Voltage)
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "System Type: "
|
cout << "System Type: " << sensor.getAnalogValue(E50HX::AV_System_Type) << endl;
|
||||||
<< sensor->getAnalogValue(E50HX::AV_System_Type)
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Energy Consumption: " << sensor->getAnalogInput(E50HX::AI_Energy)
|
cout << "Energy Consumption: " << sensor.getAnalogInput(E50HX::AI_Energy) << " "
|
||||||
<< " " << sensor->getAnalogInputUnits(E50HX::AI_Energy)
|
<< sensor.getAnalogInputUnits(E50HX::AI_Energy) << endl;
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Power Up Counter: "
|
cout << "Power Up Counter: " << sensor.getAnalogInput(E50HX::AI_Power_Up_Count) << endl;
|
||||||
<< sensor->getAnalogInput(E50HX::AI_Power_Up_Count)
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
sleep(5);
|
upm_delay(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,51 +22,44 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include <upm_utilities.h>
|
|
||||||
#include <ecezo.hpp>
|
#include <ecezo.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <upm_utilities.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
bool shouldRun = true;
|
bool shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||||
upm::ECEZO *sensor = new upm::ECEZO(0, 9600, false);
|
upm::ECEZO sensor(0, 9600, false);
|
||||||
|
|
||||||
// For I2C, assuming the device is configured for address 0x64 on
|
// For I2C, assuming the device is configured for address 0x64 on
|
||||||
// I2C bus 0, you could use something like:
|
// I2C bus 0, you could use something like:
|
||||||
//
|
//
|
||||||
// upm::ECEZO *sensor = new upm::ECEZO(0, 0x64, true);
|
// upm::ECEZO sensor(0, 0x64, true);
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
// this will take about 1 second to complete
|
// this will take about 1 second to complete
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
cout << "EC "
|
cout << "EC " << sensor.getEC() << " uS/cm, TDS " << sensor.getTDS() << " mg/L, Salinity "
|
||||||
<< sensor->getEC()
|
<< sensor.getSalinity() << " PSS-78, SG " << sensor.getSG() << endl;
|
||||||
<< " uS/cm, TDS "
|
|
||||||
<< sensor->getTDS()
|
|
||||||
<< " mg/L, Salinity "
|
|
||||||
<< sensor->getSalinity()
|
|
||||||
<< " PSS-78, SG "
|
|
||||||
<< sensor->getSG()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
upm_delay(5);
|
upm_delay(5);
|
||||||
}
|
}
|
||||||
@ -75,7 +68,5 @@ int main()
|
|||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,13 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "ecs1030.hpp"
|
#include "ecs1030.hpp"
|
||||||
|
|
||||||
int is_running = 0;
|
int is_running = 0;
|
||||||
upm::ECS1030 *sensor = NULL;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sig_handler(int signo)
|
sig_handler(int signo)
|
||||||
@ -44,18 +43,18 @@ sig_handler(int signo)
|
|||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
sensor = new upm::ECS1030(0);
|
upm::ECS1030 sensor(0);
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
while (!is_running) {
|
while (!is_running) {
|
||||||
std::cout << "I = " << sensor->getCurrency_A () << ", Power = " << sensor->getPower_A () << std::endl;
|
std::cout << "I = " << sensor.getCurrency_A() << ", Power = " << sensor.getPower_A()
|
||||||
std::cout << "I = " << sensor->getCurrency_B () << ", Power = " << sensor->getPower_B () << std::endl;
|
<< std::endl;
|
||||||
|
std::cout << "I = " << sensor.getCurrency_B() << ", Power = " << sensor.getPower_B()
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "exiting application" << std::endl;
|
std::cout << "exiting application" << std::endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -22,57 +22,57 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "ehr.hpp"
|
#include "ehr.hpp"
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int shouldRun = true;
|
int shouldRun = true;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int main()
|
main()
|
||||||
{
|
{
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a Ear-clip Heart Rate sensor on digital pin D2
|
// Instantiate a Ear-clip Heart Rate sensor on digital pin D2
|
||||||
upm::EHR* heart = new upm::EHR(2);
|
upm::EHR heart(2);
|
||||||
|
|
||||||
// set the beat counter to 0, init the clock and start counting beats
|
// set the beat counter to 0, init the clock and start counting beats
|
||||||
heart->clearBeatCounter();
|
heart.clearBeatCounter();
|
||||||
heart->initClock();
|
heart.initClock();
|
||||||
heart->startBeatCounter();
|
heart.startBeatCounter();
|
||||||
|
|
||||||
while (shouldRun)
|
while (shouldRun) {
|
||||||
{
|
|
||||||
// we grab these just for display purposes in this example
|
// we grab these just for display purposes in this example
|
||||||
uint32_t millis = heart->getMillis();
|
uint32_t millis = heart.getMillis();
|
||||||
uint32_t beats = heart->beatCounter();
|
uint32_t beats = heart.beatCounter();
|
||||||
|
|
||||||
// heartRate() requires that at least 5 seconds pass before
|
// heartRate() requires that at least 5 seconds pass before
|
||||||
// returning anything other than 0
|
// returning anything other than 0
|
||||||
int hr = heart->heartRate();
|
int hr = heart.heartRate();
|
||||||
|
|
||||||
// output milliseconds passed, beat count, and computed heart rate
|
// output milliseconds passed, beat count, and computed heart rate
|
||||||
cout << "Millis: " << millis << " Beats: " << beats;
|
cout << "Millis: " << millis << " Beats: " << beats;
|
||||||
cout << " Heart Rate: " << hr << endl;
|
cout << " Heart Rate: " << hr << endl;
|
||||||
|
|
||||||
sleep(1);
|
upm_delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
heart->stopBeatCounter();
|
heart.stopBeatCounter();
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete heart;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|