mirror of
https://github.com/eclipse/upm.git
synced 2025-07-06 11:51:10 +03:00
Compare commits
86 Commits
v1.3.0
...
json-testi
Author | SHA1 | Date | |
---|---|---|---|
c66bcc656a | |||
d52c2df7c6 | |||
02d8a16d4b | |||
4bb652cb4b | |||
59dfed087e | |||
e7f4529711 | |||
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 |
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@ -0,0 +1,3 @@
|
||||
Dockerfile
|
||||
docker-compose.yaml
|
||||
build
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -11,3 +11,6 @@ build*/
|
||||
# Temp files
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# Node modules
|
||||
**/node_modules
|
||||
|
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
[submodule "doxy/doxygen2jsdoc"]
|
||||
path = doxy/doxygen2jsdoc
|
||||
url = https://github.com/intel-iot-devkit/doxygen2jsdoc
|
||||
[submodule "doxy/doxyport"]
|
||||
path = doxy/doxyport
|
||||
url = https://github.com/intel-iot-devkit/doxyport
|
128
.travis.yml
128
.travis.yml
@ -1,48 +1,82 @@
|
||||
dist: trusty
|
||||
sudo: required
|
||||
|
||||
language: cpp
|
||||
env:
|
||||
global:
|
||||
- MRAA_ROOT=/tmp/mraa
|
||||
- MRAA_BUILD=$MRAA_ROOT/build
|
||||
- UPM_ROOT=$TRAVIS_BUILD_DIR
|
||||
- UPM_BUILD=$UPM_ROOT/build
|
||||
- JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
||||
matrix:
|
||||
- NODE010=true
|
||||
- NODE012=true
|
||||
- NODE4=true
|
||||
- NODE5=true
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
install:
|
||||
- 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:
|
||||
# Build/install MRAA
|
||||
- echo "CC=$CC BUILDJAVA=$BUILDJAVA NODE010=$NODE010 NODE012=$NODE012 NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR"
|
||||
- git clone https://github.com/intel-iot-devkit/mraa.git $MRAA_ROOT
|
||||
- mkdir -p $MRAA_BUILD && cd $_ && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=ON -DFIRMATA=ON -DENABLEEXAMPLES=OFF $MRAA_ROOT
|
||||
- sudo make install
|
||||
- sudo ldconfig
|
||||
# Build/install UPM
|
||||
- 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
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- george-edison55-precise-backports
|
||||
packages:
|
||||
- cmake
|
||||
- cmake-data
|
||||
- g++-4.8
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_install:
|
||||
- sudo rm /usr/local/bin/docker-compose
|
||||
- curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > docker-compose
|
||||
- chmod +x docker-compose
|
||||
- sudo mv docker-compose /usr/local/bin
|
||||
|
||||
jobs:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- env: TARGET=sonar-scan
|
||||
- env: TARGET=ipk
|
||||
include:
|
||||
- &run-with-clang
|
||||
stage: Clang 3.8
|
||||
env: TARGET=python
|
||||
before_script: docker-compose pull ${TARGET}
|
||||
script:
|
||||
- export CC=clang-3.8 CXX=clang++-3.8
|
||||
- docker-compose run ${TARGET}
|
||||
- <<: *run-with-clang
|
||||
env: TARGET=node4
|
||||
- <<: *run-with-clang
|
||||
env: TARGET=node5
|
||||
- <<: *run-with-clang
|
||||
env: TARGET=node6
|
||||
- <<: *run-with-clang
|
||||
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=sonar-scan
|
||||
- <<: *run-additional-jobs
|
||||
env: TARGET=ipk
|
||||
- <<: *run-additional-jobs
|
||||
env: TARGET=rpm
|
||||
- <<: *run-additional-jobs
|
||||
env: TARGET=npm
|
||||
|
@ -126,7 +126,7 @@ unset(MRAA_FOUND CACHE)
|
||||
set(MRAA_MINIMUM 1.7.0)
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM})
|
||||
# Also, get full path to the mraa library
|
||||
find_library(MRAA_LIBRARY NAMES mraa PATHS ${MRAA_LIBDIR})
|
||||
find_library(MRAA_LIBRARY NAMES mraa HINTS ${MRAA_LIBDIR})
|
||||
|
||||
# Test MRAA for various compile options
|
||||
include (CheckLibraryExists)
|
||||
@ -149,6 +149,14 @@ find_package (JPEG)
|
||||
# Find nodejs
|
||||
if (BUILDSWIGNODE)
|
||||
find_package (Node REQUIRED)
|
||||
if (BUILDTESTS)
|
||||
find_package (Npm REQUIRED)
|
||||
if(NPM_EXECUTABLE)
|
||||
message(STATUS "NPM Executable found at: ${NPM_EXECUTABLE}")
|
||||
else()
|
||||
message(FATAL_ERROR "Please install NPM first, you can't run tests without it")
|
||||
endif()
|
||||
endif (BUILDTESTS)
|
||||
endif (BUILDSWIGNODE)
|
||||
|
||||
# Find JAVA/JNI
|
||||
@ -157,7 +165,7 @@ if (BUILDSWIGJAVA)
|
||||
find_package (JNI REQUIRED)
|
||||
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=${MRAA_MINIMUM})
|
||||
# Also, get full path to the mraajava library
|
||||
find_library(MRAAJAVA_LIBRARY NAMES mraajava PATHS ${MRAA_LIBDIR})
|
||||
find_library(MRAAJAVA_LIBRARY NAMES mraajava HINTS ${MRAA_LIBDIR})
|
||||
endif (BUILDSWIGJAVA)
|
||||
|
||||
# Find swig if any wrapper is enabled
|
||||
@ -318,7 +326,7 @@ if (BUILDDOC)
|
||||
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
||||
)
|
||||
|
||||
# Check if Sphinx is installed and add target to generate API documentationa
|
||||
# Check if Sphinx is installed and add target to generate API documentation
|
||||
# Currently, the per-module documentation for python is generated from the
|
||||
# python2 modules.
|
||||
if(BUILDSWIGPYTHON)
|
||||
@ -343,14 +351,10 @@ if (BUILDDOC)
|
||||
# Check if Yuidoc is installed and add target for API documentation
|
||||
if(BUILDSWIGNODE)
|
||||
find_package(Yuidoc REQUIRED)
|
||||
file(GLOB_RECURSE JSDOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/doxy/node doxy/node/*)
|
||||
foreach(JSDOC_FILE ${JSDOC_FILES})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy/node/${JSDOC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${JSDOC_FILE} COPYONLY)
|
||||
endforeach()
|
||||
add_custom_target(jsdoc ALL
|
||||
COMMAND ${NODEJS_EXECUTABLE} docgen -m upm -i xml -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
||||
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers generators/yuidoc/helper.js --themedir generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
|
||||
COMMAND ${NODEJS_EXECUTABLE} tolower -i html/node
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/docgen.js -m upm -i xml -o jsdoc -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
||||
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers ${CMAKE_SOURCE_DIR}/doxy/node/generators/yuidoc/helper.js --themedir ${CMAKE_SOURCE_DIR}/doxy/node/generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/doxy/doxygen2jsdoc/tolower.js -i html/node
|
||||
DEPENDS doc
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
||||
|
13
cmake/modules/FindNpm.cmake
Normal file
13
cmake/modules/FindNpm.cmake
Normal file
@ -0,0 +1,13 @@
|
||||
# Finding and pointing a variable to the npm executable if found
|
||||
# Only works on Linux systems as of now
|
||||
|
||||
find_program(NPM_EXECUTABLE NAMES npm
|
||||
HINTS
|
||||
/usr
|
||||
)
|
||||
|
||||
if(NPM_EXECUTABLE)
|
||||
message(STATUS "NPM Executable found at ${NPM_EXECUTABLE}")
|
||||
else()
|
||||
message(ERROR "Unable to find NPM installation, please install NPM")
|
||||
endif()
|
112
docker-compose.yaml
Normal file
112
docker-compose.yaml
Normal file
@ -0,0 +1,112 @@
|
||||
version: '2.1'
|
||||
|
||||
services:
|
||||
|
||||
base:
|
||||
image: dnoliver/upm-base
|
||||
environment:
|
||||
- http_proxy
|
||||
- https_proxy
|
||||
- no_proxy
|
||||
- BUILDDOC=${BUILDDOC:-OFF}
|
||||
- BUILDCPP=${BUILDCPP:-ON}
|
||||
- BUILDFTI=${BUILDFTI:-ON}
|
||||
- BUILDSWIGPYTHON=${BUILDSWIGPYTHON:-OFF}
|
||||
- BUILDSWIGJAVA=${BUILDSWIGJAVA:-OFF}
|
||||
- BUILDSWIGNODE=${BUILDSWIGNODE:-OFF}
|
||||
- BUILDEXAMPLES=${BUILDEXAMPLES:-ON}
|
||||
- IPK=${IPK:-OFF}
|
||||
- RPM=${RPM:-OFF}
|
||||
- NPM=${NPM:-OFF}
|
||||
- BUILDTESTS=${BUILDTESTS:-ON}
|
||||
- CC=${CC:-clang-3.8}
|
||||
- CXX=${CXX:-clang++-3.8}
|
||||
- NODE_VERSION=${NODE_VERSION:-v4.4.7}
|
||||
- WERROR=${WERROR:-ON}
|
||||
volumes:
|
||||
- .:${UPM_SRC_DIR:-/usr/src/app}
|
||||
|
||||
doc:
|
||||
extends: base
|
||||
image: dnoliver/upm-all
|
||||
environment:
|
||||
- BUILDSWIGPYTHON=ON
|
||||
- BUILDSWIGJAVA=ON
|
||||
- BUILDSWIGNODE=ON
|
||||
- BUILDDOC=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && ./scripts/build-doc.sh"
|
||||
|
||||
ipk:
|
||||
extends: base
|
||||
environment:
|
||||
- IPK=ON
|
||||
- BUILDDOC=OFF
|
||||
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
|
||||
|
||||
rpm:
|
||||
extends: doc
|
||||
environment:
|
||||
- RPM=ON
|
||||
- BUILDDOC=OFF
|
||||
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 package"
|
||||
|
||||
npm:
|
||||
extends: doc
|
||||
environment:
|
||||
- NPM=ON
|
||||
- BUILDDOC=OFF
|
||||
command: bash -c "./scripts/run-cmake.sh && make -Cbuild -j8 npmpkg"
|
||||
|
||||
sonar-scan:
|
||||
extends: base
|
||||
image: dnoliver/upm-all
|
||||
environment:
|
||||
- BUILDSWIGPYTHON=ON
|
||||
- BUILDSWIGNODE=ON
|
||||
- BUILDSWIGJAVA=ON
|
||||
- BUILDSWIGEXAMPLES=ON
|
||||
- SONAR_TOKEN
|
||||
- SONAR_ORG
|
||||
- SONAR_PROJ_KEY
|
||||
- TRAVIS_BRANCH
|
||||
- TRAVIS_PULL_REQUEST
|
||||
- TRAVIS_REPO_SLUG
|
||||
- TRAVIS_PULL_REQUEST_SLUG
|
||||
- GITHUB_TOKEN
|
||||
command: bash -c "./scripts/run-cmake.sh && cd build && ../scripts/sonar-scan.sh"
|
||||
|
||||
python:
|
||||
extends: base
|
||||
image: dnoliver/upm-python
|
||||
environment:
|
||||
- BUILDSWIGPYTHON=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
|
||||
|
||||
java:
|
||||
extends: base
|
||||
image: dnoliver/upm-java
|
||||
environment:
|
||||
- BUILDSWIGJAVA=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure"
|
||||
|
||||
android:
|
||||
extends: java
|
||||
image: dnoliver/upm-android
|
||||
environment:
|
||||
- BUILDTESTS=OFF
|
||||
command: bash -c "./scripts/build-android.sh"
|
||||
|
||||
node4:
|
||||
extends: base
|
||||
image: dnoliver/upm-node4
|
||||
environment:
|
||||
- BUILDSWIGNODE=ON
|
||||
command: bash -c "./scripts/run-cmake.sh && cd build && make -j8 && make -j8 install && ldconfig && ctest --output-on-failure -E examplenames_js"
|
||||
|
||||
node5:
|
||||
extends: node4
|
||||
image: dnoliver/upm-node5
|
||||
|
||||
node6:
|
||||
extends: node4
|
||||
image: dnoliver/upm-node6
|
102
docs/building.md
102
docs/building.md
@ -64,10 +64,6 @@ Building with an older version of swig (swig 2.0+) requires the disabling of jav
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDSWIGNODE=OFF
|
||||
~~~~~~~~~~~~~
|
||||
Generating python3 modules instead of python2.7
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDPYTHON3=ON
|
||||
~~~~~~~~~~~~~
|
||||
Disabling python module building
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDSWIGPYTHON=OFF
|
||||
@ -130,3 +126,101 @@ autotools on linux.
|
||||
~~~~~~~~~~~
|
||||
pkg-config --cflags --libs upm-i2clcd
|
||||
~~~~~~~~~~~
|
||||
|
||||
## Building with Docker
|
||||
|
||||
You can use `docker` and `docker-compose` to generate a complete build environment
|
||||
for upm without having to install any other tool.
|
||||
|
||||
Requirements:
|
||||
* [docker](https://www.docker.com/get-docker) >= 1.12.6
|
||||
* [docker-compose](https://docs.docker.com/compose/install/) >= 1.9.0
|
||||
|
||||
**NOTE:** docker-compose is an optional requirement. It actually make running complex
|
||||
docker build and run command easier. But you can just use docker to build and run.
|
||||
|
||||
### Using Docker Images to build Upm
|
||||
|
||||
**tl;dr:** Just use this commands to build upm:
|
||||
|
||||
```sh
|
||||
# Build upm documentation
|
||||
$ docker-compose run doc
|
||||
# Build upm python2 and python3 packages and run python tests
|
||||
$ docker-compose run python
|
||||
# Build upm java package and run java tests
|
||||
$ docker-compose run java
|
||||
# Build upm node4 package and run node tests
|
||||
$ docker-compose run node4
|
||||
# Build upm node5 package and run node tests
|
||||
$ docker-compose run node5
|
||||
# Build upm node6 package and run node tests
|
||||
$ docker-compose run node6
|
||||
# Build upm for android things package
|
||||
$ docker-compose run android
|
||||
```
|
||||
|
||||
**docker-compose** will take a look at the `docker-compose.yaml` file in the repository
|
||||
root directory, and run an specific command to build upm for the requested target.
|
||||
Once the build is completed, you will have a `build/` folder in the repository root with all
|
||||
the compiled code. This `build/` folder is created by using a docker volume. The `build\`
|
||||
folder contents is reused each time you execute `docker-compose run [TARGET]`.
|
||||
To know more about volumes in Docker, visit the [Docker Volume Documentation](https://docs.docker.com/engine/tutorials/dockervolumes/).
|
||||
|
||||
You can also start an interactive session inside the docker container if you need to run some
|
||||
custom build commands:
|
||||
|
||||
```sh
|
||||
# Start an interactive bash shell inside the container
|
||||
$ docker-compose run python bash
|
||||
# From now, all the commands are executed inside the container
|
||||
$ cd build && cmake -DBUILDSWIGPYTHON=ON .. && make clean all
|
||||
```
|
||||
|
||||
If you don't want to use docker-compose, you can also use `docker run` to build upm.
|
||||
For example, to build upm for python, you can do:
|
||||
|
||||
```sh
|
||||
# From the repository root folder
|
||||
$ docker run \
|
||||
--volume=$(pwd):/usr/src/app \
|
||||
--env BUILDSWIGPYTHON=ON \
|
||||
--env BUILDSWIGJAVA=OFF \
|
||||
--env BUILDSWIGNODE=OFF \
|
||||
dnoliver/upm-python \
|
||||
bash -c "./scripts/run-cmake.sh && make -Cbuild"
|
||||
```
|
||||
|
||||
### Proxy considerations
|
||||
|
||||
If, for some reason, you are behind a proxy, find below a list of common problems related
|
||||
to proxy settings:
|
||||
|
||||
**docker cannot pull images from docker.io**
|
||||
|
||||
Visit [this link](https://docs.docker.com/engine/admin/systemd/#httphttps-proxy)
|
||||
to configure docker daemon behind a proxy.
|
||||
|
||||
**docker run fails to access the internet**
|
||||
|
||||
docker-compose will automatically take `http_proxy`, `https_proxy`, and `no_proxy`
|
||||
environment variables and use it as build arguments. Be sure to properly configure
|
||||
this variables before building.
|
||||
|
||||
docker, unlinke docker-compose, do not take the proxy settings from the environment
|
||||
automatically. You need to send them as environment arguments:
|
||||
|
||||
```sh
|
||||
# From the repository root folder
|
||||
$ docker run \
|
||||
--volume=$(pwd):/usr/src/app \
|
||||
--env BUILDSWIG=ON \
|
||||
--env BUILDSWIGPYTHON=ON \
|
||||
--env BUILDSWIGJAVA=OFF \
|
||||
--env BUILDSWIGNODE=OFF \
|
||||
--env http_proxy=$http_proxy \
|
||||
--env https_proxy=$https_proxy \
|
||||
--env no_proxy=$no_proxy \
|
||||
dnoliver/upm-python \
|
||||
bash -c "./scripts/run-cmake.sh && make -Cbuild"
|
||||
```
|
||||
|
BIN
docs/images/lidarlitev3.jpg
Normal file
BIN
docs/images/lidarlitev3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 156 KiB |
@ -129,8 +129,6 @@ ABBREVIATE_BRIEF = "The $name class" \
|
||||
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
|
||||
DETAILS_AT_TOP = YES
|
||||
|
||||
# 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
|
||||
# members were ordinary class members. Constructors, destructors and assignment
|
||||
@ -1861,18 +1859,6 @@ GENERATE_XML = YES
|
||||
|
||||
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
|
||||
# listings (including syntax highlighting and cross-referencing information) to
|
||||
# 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
|
||||
|
||||
DETAILS_AT_TOP = YES
|
||||
|
||||
# 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
|
||||
# members were ordinary class members. Constructors, destructors and assignment
|
||||
@ -1818,18 +1816,6 @@ GENERATE_XML = YES
|
||||
|
||||
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
|
||||
# listings (including syntax highlighting and cross-referencing information) to
|
||||
# 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
|
||||
|
||||
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
|
||||
enumerable sensors for example may provide much clever instantiation. Displays
|
||||
|
1
doxy/doxygen2jsdoc
Submodule
1
doxy/doxygen2jsdoc
Submodule
Submodule doxy/doxygen2jsdoc added at 67cad69272
1
doxy/doxyport
Submodule
1
doxy/doxyport
Submodule
Submodule doxy/doxyport added at db3e1a6eb8
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Author: Heidi Pan <heidi.pan@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var xml2js = require('./xml2js')
|
||||
, fs = require('fs')
|
||||
, Promise = require('bluebird')
|
||||
, opts = require('commander')
|
||||
, _ = require('lodash')
|
||||
, mkdirp = require('mkdirp');
|
||||
|
||||
|
||||
// parse command line arguments
|
||||
_.extend(opts, { addOptions: function(module) { return module.addOptions(opts); } });
|
||||
opts
|
||||
.option('-m, --module [module]', 'module name for which to build documentation', 'mraa')
|
||||
.option('-f, --formats [formats]', 'format for js comments', 'yuidoc,ternjs')
|
||||
.option('-o, --outdir [directory]', 'top directory to build documentation', __dirname + '/jsdoc')
|
||||
.addOptions(xml2js)
|
||||
.parse(process.argv);
|
||||
|
||||
|
||||
// use promise-style programming rather than spaghetti callbacks
|
||||
Promise.promisifyAll(fs);
|
||||
Promise.promisifyAll(mkdirp);
|
||||
|
||||
|
||||
// main
|
||||
xml2js.parse().then(function(specjs) {
|
||||
var formats = opts.formats.split(',');
|
||||
Promise.all(_.map(formats, function(format) {
|
||||
var generateDocs = require(__dirname + '/generators/' + format + '/generator');
|
||||
var dir = opts.outdir + '/' + format + '/' + specjs.MODULE;
|
||||
return mkdirp.mkdirpAsync(dir).then(function() {
|
||||
return fs.writeFileAsync(dir + '/doc.js', generateDocs(specjs));
|
||||
});
|
||||
}));
|
||||
});
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"templates": {
|
||||
"default": {
|
||||
"outputSourceFiles": false
|
||||
}
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Author: Heidi Pan <heidi.pan@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var _ = require('lodash');
|
||||
|
||||
|
||||
// generate JSDoc-style documentation
|
||||
function generateDocs(specjs) {
|
||||
var docs = GENERATE_MODULE(specjs.MODULE);
|
||||
docs = _.reduce(specjs.METHODS, function(memo, methodSpec, methodName) {
|
||||
return memo += GENERATE_METHOD(methodName, methodSpec);
|
||||
}, docs);
|
||||
docs = _.reduce(specjs.ENUMS, function(memo, enumSpec, enumName) {
|
||||
return memo += GENERATE_ENUM(enumName, enumSpec);
|
||||
}, docs);
|
||||
docs = _.reduce(specjs.CLASSES, function(memo, classSpec, parentClass) {
|
||||
return _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
|
||||
return memo += GENERATE_METHOD(methodName, methodSpec, parentClass);
|
||||
}, memo);
|
||||
}, docs);
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
// comment wrapper around entire spec
|
||||
function GENERATE_DOC(text) {
|
||||
return '/**\n' + text + ' */\n';
|
||||
}
|
||||
|
||||
|
||||
// generate module spec
|
||||
function GENERATE_MODULE(module) {
|
||||
return GENERATE_DOC('@module ' + module + '\n');
|
||||
}
|
||||
|
||||
|
||||
// generate method spec with parent module/class
|
||||
function GENERATE_METHOD(name, spec, parent) {
|
||||
name = name.replace(/!+$/, '');
|
||||
return GENERATE_DOC(spec.description + '\n'
|
||||
+ '@method ' + name + '\n'
|
||||
+ '@instance\n'
|
||||
+ (parent ? ('@memberof ' + parent + '\n') : '')
|
||||
+ _.reduce(spec.params, function(memo, paramSpec, paramName) {
|
||||
return '@param {' + paramSpec.type + '} ' + paramName + ' ' + paramSpec.description + '\n';
|
||||
}, '')
|
||||
+ ( !_.isEmpty(spec.return) ? ('@return {' + spec.return.type + '} ' + spec.return.description + '\n') : ''));
|
||||
}
|
||||
|
||||
|
||||
// generate enum spec
|
||||
function GENERATE_ENUM(name, spec) {
|
||||
return GENERATE_DOC(spec.description + '\n\n'
|
||||
+ '@var ' + name + '\n'
|
||||
+ '@type Enum(' + spec.type + ')\n'
|
||||
+ '@instance\n');
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
// generate link spec
|
||||
function GENERATE_LINK(text) {
|
||||
return '{@link ' + text + '}';
|
||||
}
|
||||
|
||||
|
||||
module.exports = generateDocs;
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Author: Heidi Pan <heidi.pan@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var _ = require('lodash');
|
||||
|
||||
|
||||
// generate json for ternjs input
|
||||
function generateDocs(specjs) {
|
||||
GENERATE_TYPE = (function(enums) {
|
||||
return function(type) {
|
||||
return (_.contains(enums, type) ? ('Enum ' + type) : type);
|
||||
}
|
||||
})(_.keys(specjs.ENUMS_BY_GROUP));
|
||||
var docs = { '!name': specjs.MODULE + 'library' };
|
||||
_.extend(docs, GENERATE_MODULE(specjs.MODULE));
|
||||
_.each(specjs.ENUMS, function(enumSpec, enumName) {
|
||||
_.extend(docs[specjs.MODULE], GENERATE_ENUM(enumName, enumSpec));
|
||||
});
|
||||
_.each(specjs.METHODS, function(methodSpec, methodName) {
|
||||
_.extend(docs[specjs.MODULE], GENERATE_METHOD(methodName, methodSpec));
|
||||
});
|
||||
|
||||
if (_.isEmpty(specjs.CLASSGROUPS)) {
|
||||
_.extend(docs[specjs.MODULE], GENERATE_CLASSES(specjs.CLASSES));
|
||||
} else {
|
||||
var grouped = _.flatten(_.pluck(_.values(specjs.CLASSGROUPS), 'classes'));
|
||||
var ungrouped = _.difference(_.keys(specjs.CLASSES), grouped);
|
||||
_.extend(docs[specjs.MODULE], GENERATE_CLASSES(_.pick(specjs.CLASSES, ungrouped)));
|
||||
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
|
||||
_.extend(docs, GENERATE_MODULE(groupName));
|
||||
_.extend(docs[groupName], GENERATE_CLASSES(_.pick(specjs.CLASSES, groupSpec.classes), groupName));
|
||||
});
|
||||
}
|
||||
return JSON.stringify(docs, null, 2);
|
||||
}
|
||||
|
||||
|
||||
// generate module spec
|
||||
function GENERATE_MODULE(module) {
|
||||
var docs = {};
|
||||
docs[module] = {};
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
// generate the spec for the given list of classes
|
||||
function GENERATE_CLASSES(classes) {
|
||||
var docs = {};
|
||||
_.each(classes, function(classSpec, parentClass) {
|
||||
var constructor = classSpec.methods[parentClass];
|
||||
_.extend(docs, GENERATE_METHOD(parentClass, constructor ? constructor : { params: {}, return: {}, description: '' } ));
|
||||
if (_.has(docs, parentClass)) {
|
||||
_.each(classSpec.enums, function(enumSpec, enumName) {
|
||||
_.extend(docs[parentClass], GENERATE_ENUM(enumName, enumSpec));
|
||||
});
|
||||
docs[parentClass].prototype = {};
|
||||
_.each(_.omit(classSpec.methods, parentClass), function(methodSpec, methodName) {
|
||||
_.extend(docs[parentClass].prototype, GENERATE_METHOD(methodName, methodSpec));
|
||||
});
|
||||
_.each(classSpec.variables, function(variableSpec, variableName) {
|
||||
_.extend(docs[parentClass].prototype, GENERATE_VARIABLE(variableName, variableSpec));
|
||||
});
|
||||
}
|
||||
});
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
// generate method spec
|
||||
function GENERATE_METHOD(name, spec) {
|
||||
var doc = {};
|
||||
doc[name] = {
|
||||
'!type': 'fn(' + GENERATE_PARAMS(spec.params) + ')' + GENERATE_RETURN(spec.return),
|
||||
'!doc': spec.description
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
// generate parameter signatures for method
|
||||
function GENERATE_PARAMS(spec) {
|
||||
return _.map(spec, function(paramSpec, paramName) {
|
||||
return paramName + ': ' + paramSpec.type;
|
||||
}).join(', ');
|
||||
}
|
||||
|
||||
|
||||
// generate return signature for method
|
||||
function GENERATE_RETURN(spec) {
|
||||
return (_.isEmpty(spec) ? '' : (' -> ' + spec.type));
|
||||
}
|
||||
|
||||
|
||||
// generate enum spec
|
||||
function GENERATE_ENUM(name, spec) {
|
||||
var doc = {};
|
||||
doc[name] = 'Enum ' + spec.type ;
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
// generate variable spec
|
||||
function GENERATE_VARIABLE(name, spec) {
|
||||
var doc = {};
|
||||
doc[name]= spec.type ;
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
module.exports = generateDocs;
|
144
doxy/node/generators/yuidoc/generator.js
vendored
144
doxy/node/generators/yuidoc/generator.js
vendored
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Author: Heidi Pan <heidi.pan@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var _ = require('lodash');
|
||||
|
||||
|
||||
// generate YuiDocs-style documentation
|
||||
function generateDocs(specjs) {
|
||||
var docs = GENERATE_MODULE(specjs.MODULE, '');
|
||||
GENERATE_TYPE = (function(enums) {
|
||||
return function(type) {
|
||||
return (_.contains(enums, type) ? ('Enum ' + type) : type);
|
||||
}
|
||||
})(_.keys(specjs.ENUMS_BY_GROUP));
|
||||
docs = _.reduce(specjs.METHODS, function(memo, methodSpec, methodName) {
|
||||
return memo += GENERATE_METHOD(methodName, methodSpec);
|
||||
}, docs);
|
||||
docs = _.reduce(specjs.ENUMS, function(memo, enumSpec, enumName) {
|
||||
return memo += GENERATE_ENUM(enumName, enumSpec);
|
||||
}, docs);
|
||||
if (_.isEmpty(specjs.CLASSGROUPS)) {
|
||||
docs += GENERATE_CLASSES(specjs.CLASSES);
|
||||
} else {
|
||||
docs += GENERATE_MODULE('common', '');
|
||||
var grouped = _.flatten(_.pluck(_.values(specjs.CLASSGROUPS), 'classes'));
|
||||
var ungrouped = _.difference(_.keys(specjs.CLASSES), grouped);
|
||||
docs += GENERATE_CLASSES(_.pick(specjs.CLASSES, ungrouped), 'common');
|
||||
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
|
||||
docs += GENERATE_CLASSES(_.pick(specjs.CLASSES, groupSpec.classes), groupName);
|
||||
});
|
||||
// TODO: figure out why yuidoc won't associate the class with the right module if module definitions are interspersed
|
||||
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
|
||||
docs += GENERATE_MODULE(groupName, groupSpec.description);
|
||||
});
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
// comment wrapper around entire spec
|
||||
function GENERATE_DOC(text) {
|
||||
return '/**\n' + text + ' */\n';
|
||||
}
|
||||
|
||||
|
||||
// generate module spec
|
||||
function GENERATE_MODULE(name, description) {
|
||||
return GENERATE_DOC(description + '\n'
|
||||
+ '@module ' + name + '\n');
|
||||
}
|
||||
|
||||
|
||||
// generate spec for the given list of classes
|
||||
function GENERATE_CLASSES(classes, parent) {
|
||||
return _.reduce(classes, function(memo, classSpec, className) {
|
||||
return memo
|
||||
+ GENERATE_CLASS(className, classSpec.description, parent, classSpec.parent)
|
||||
+ _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
|
||||
return memo += GENERATE_METHOD(methodName, methodSpec, className);
|
||||
}, '')
|
||||
+ _.reduce(classSpec.variables, function(memo, variableSpec, variableName) {
|
||||
return memo += GENERATE_VAR(variableName, variableSpec, className);
|
||||
}, '')
|
||||
+ _.reduce(classSpec.enums, function(memo, enumSpec, enumName) {
|
||||
return memo += GENERATE_ENUM(enumName, enumSpec, className);
|
||||
}, '');
|
||||
}, '');
|
||||
}
|
||||
|
||||
|
||||
// generate class spec
|
||||
function GENERATE_CLASS(name, description, namespace, parent) {
|
||||
return GENERATE_DOC(description + '\n'
|
||||
+ '@class ' + name + '\n'
|
||||
+ (namespace ? ('@module ' + namespace + '\n') : '')
|
||||
/*
|
||||
TODO: leave out until figure out what swig does with inheritance
|
||||
+ (parent ? ('@extends ' + parent + '\n') : '')
|
||||
*/
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// generate method spec with parent module/class
|
||||
function GENERATE_METHOD(name, spec, parent) {
|
||||
name = name.replace(/!+$/, '');
|
||||
return GENERATE_DOC(spec.description + '\n'
|
||||
+ '@method ' + name + '\n'
|
||||
+ (parent ? ('@for ' + parent + '\n') : '@for common\n')
|
||||
+ _.reduce(spec.params, function(memo, paramSpec, paramName) {
|
||||
return memo + '@param {' + GENERATE_TYPE(paramSpec.type) + '} ' + paramName + ' ' + paramSpec.description + '\n';
|
||||
}, '')
|
||||
+ ( !_.isEmpty(spec.return) ? ('@return {' + GENERATE_TYPE(spec.return.type) + '} ' + spec.return.description + '\n') : ''));
|
||||
}
|
||||
|
||||
|
||||
// generate enum spec
|
||||
function GENERATE_ENUM(name, spec, parent) {
|
||||
return GENERATE_DOC(spec.description + '\n'
|
||||
+ '@property ' + name + '\n'
|
||||
+ '@type Enum ' + spec.type + '\n'
|
||||
+ '@for ' + (parent ? parent : 'common') + '\n');
|
||||
}
|
||||
|
||||
|
||||
// generate variable specs
|
||||
function GENERATE_VAR(name, spec, parent) {
|
||||
return GENERATE_DOC(spec.description + '\n'
|
||||
+ '@property ' + name + '\n'
|
||||
+ '@type ' + spec.type + '\n'
|
||||
+ '@for ' + parent + '\n');
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
// generate link spec
|
||||
function GENERATE_LINK(text) {
|
||||
return '{{#crossLink "' + text + '"}}{{/crossLink}}';
|
||||
}
|
||||
|
||||
|
||||
module.exports = generateDocs;
|
@ -1,45 +0,0 @@
|
||||
document
|
||||
= _ ignore* _ "<doxygen " _ attr:attr* _ ">" body:elements _ "</doxygen>" _ { return body; }
|
||||
|
||||
|
||||
elements
|
||||
= element*
|
||||
|
||||
element
|
||||
= _ "<" startTag:id _ attr:attr* _ ">" _ children:elements _ "</" endTag:id ">" _ {
|
||||
if (startTag != endTag) {
|
||||
throw new Error("Expected </" + startTag + "> but </" + endTag + "> found.");
|
||||
}
|
||||
return {name: startTag, attr: attr, children: children }
|
||||
}
|
||||
/ "<" tag:id _ attr:attr* _ "/>" _ {
|
||||
return {name: tag, attr: attr }
|
||||
}
|
||||
/ _ text:text _ { return text }
|
||||
|
||||
ignore
|
||||
= "<?xml" _ attr* _ "?>" { return }
|
||||
|
||||
attr
|
||||
= name:id _ "=" _ value:string { return { name:name, value:value } }
|
||||
|
||||
string
|
||||
= '"' '"' _ { return ""; }
|
||||
/ "'" "'" _ { return ""; }
|
||||
/ '"' text:quoted '"' _ { return text; }
|
||||
/ "'" text:quoted "'" _ { return text; }
|
||||
|
||||
quoted
|
||||
= chars:[^<>'" \t\n\r]+ { return chars.join(""); }
|
||||
|
||||
text
|
||||
= chars:[^<> \t\n\r]+ { return chars.join(""); }
|
||||
|
||||
id
|
||||
= chars:[^<>/'"=? \t\n\r]+ { return chars.join(""); }
|
||||
|
||||
_ "whitespace"
|
||||
= whitespace*
|
||||
|
||||
whitespace
|
||||
= [ \t\n\r]
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Author: Dina M Suehiro <dina.m.suehiro@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var opts = require('commander'), // for command line args
|
||||
fs = require('fs'), // for file system access
|
||||
path = require('path'); // for file path parsing
|
||||
|
||||
// parse command line arguments
|
||||
opts
|
||||
.option('-i, --inputdir [directory]', 'product documents directory', __dirname + '/docs/yuidoc/upm')
|
||||
.parse(process.argv);
|
||||
|
||||
// Set to true for console output
|
||||
var debug = true;
|
||||
|
||||
// Global arrays tracking the files that have been renamed
|
||||
var originalFiles = [];
|
||||
var renamedFiles = [];
|
||||
|
||||
// Filter to get html files from different directories
|
||||
var rootFiles = getHtmlFilenames(opts.inputdir);
|
||||
var classesFiles = getHtmlFilenames(opts.inputdir + "/classes");
|
||||
var modulesFiles = getHtmlFilenames(opts.inputdir + "/modules");
|
||||
|
||||
// Rename files in the classes directory to have lower-cased file names.
|
||||
renameFiles(classesFiles);
|
||||
|
||||
classesFiles = getHtmlFilenames(opts.inputdir + "/classes");
|
||||
|
||||
// Go through the html files and update links to reflect the file names that we changed.
|
||||
renameLinks(rootFiles);
|
||||
renameLinks(classesFiles);
|
||||
renameLinks(modulesFiles);
|
||||
|
||||
// Helper function that returns paths to the html files in the specified directory
|
||||
function getHtmlFilenames (directory)
|
||||
{
|
||||
return fs.readdirSync(directory).map(function (file) {
|
||||
return path.join(directory, file);
|
||||
}).filter(function (file) {
|
||||
return fs.statSync(file).isFile();
|
||||
}).filter(function (file) {
|
||||
return path.extname(file).toLowerCase() == ".html";
|
||||
});
|
||||
}
|
||||
|
||||
// Goes through the files and renames them to be lower-cased and tracks them the
|
||||
// renamed files in the originalFiles[] and renamedFiles[] arrays.
|
||||
function renameFiles(files)
|
||||
{
|
||||
files.forEach(function (file)
|
||||
{
|
||||
var originalName = path.basename(file);
|
||||
var newFileName = originalName.toLowerCase();
|
||||
var directory = path.dirname(file);
|
||||
if (originalName != newFileName)
|
||||
{
|
||||
fs.renameSync(file, directory + "/" + newFileName); //, function(err)
|
||||
|
||||
if (debug)
|
||||
console.log('Renamed: %s --> %s', originalName, newFileName);
|
||||
|
||||
originalFiles.push(originalName);
|
||||
renamedFiles.push(newFileName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Helper function goes through the specified files and does a file/replace of the
|
||||
// originalFiles to the renamedFiles so that the .html links match what has been renamed.
|
||||
function renameLinks (files)
|
||||
{
|
||||
if (originalFiles.length <= 0)
|
||||
{
|
||||
if (debug)
|
||||
console.log("No links to rename.");
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(function (file)
|
||||
{
|
||||
// Read the file
|
||||
data = fs.readFileSync(file, 'ascii');
|
||||
|
||||
// Find/replace the file names that were renamed
|
||||
for (var i = 0; i < originalFiles.length; i++)
|
||||
{
|
||||
var findString = '/' + originalFiles[i] + '\"';
|
||||
var replaceString = '/' + renamedFiles[i] + '\"';
|
||||
|
||||
data = data.replace(findString, replaceString);
|
||||
}
|
||||
|
||||
// Write back
|
||||
fs.writeFile(file, data, 'ascii', function (err) {
|
||||
if (err)
|
||||
throw err;
|
||||
});
|
||||
|
||||
if (debug)
|
||||
console.log('Renamed links in: %s', file);
|
||||
});
|
||||
}
|
@ -1,935 +0,0 @@
|
||||
/*
|
||||
* Author: Heidi Pan <heidi.pan@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var peg = require('pegjs')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, Promise = require('bluebird')
|
||||
, _ = require('lodash')
|
||||
, util = require('util');
|
||||
|
||||
|
||||
// use promise-style programming rather than spaghetti callbacks
|
||||
Promise.promisifyAll(fs);
|
||||
|
||||
|
||||
var xml2js = {
|
||||
|
||||
// js-format specs
|
||||
// MODULE: <module name>
|
||||
// ENUMS: {
|
||||
// <enum name>: {
|
||||
// type: <enum type>,
|
||||
// description: <enum description>
|
||||
// }, ...
|
||||
// }
|
||||
// ENUMS_BY_GROUP: {
|
||||
// <enum type>: {
|
||||
// description: <enum group description>
|
||||
// members: [ <enum name>, ... ]
|
||||
// }, ...
|
||||
// }
|
||||
// METHODS: {
|
||||
// <method name>: {
|
||||
// description: <method description>,
|
||||
// params: {
|
||||
// <param name>: {
|
||||
// type: <param type>,
|
||||
// description: <param description >
|
||||
// }, ...
|
||||
// },
|
||||
// return: {
|
||||
// type: <return type>,
|
||||
// description: <return description>
|
||||
// }
|
||||
// }, ...
|
||||
// }
|
||||
// CLASSES: {
|
||||
// <class name>: {
|
||||
// description: <class description>,
|
||||
// parent: <parent class name>,
|
||||
// group: <group name>,
|
||||
// methods: { ... },
|
||||
// variables: {
|
||||
// <variable name>: {
|
||||
// type: <variable type>,
|
||||
// description: <variable description>
|
||||
// }
|
||||
// },
|
||||
// enums: { ... },
|
||||
// enums_by_group: { ... }
|
||||
// }, ...
|
||||
// }
|
||||
// CLASSGROUPS: {
|
||||
// <group name>: {
|
||||
// description: <group description>,
|
||||
// classes: [ <class name>, ... ],
|
||||
// enums: { ... },
|
||||
// enums_by_group: { ... }
|
||||
// }, ...
|
||||
// }
|
||||
MODULE: '',
|
||||
ENUMS: {},
|
||||
ENUMS_BY_GROUP: {},
|
||||
METHODS: {},
|
||||
CLASSES: {},
|
||||
CLASSGROUPS: {},
|
||||
|
||||
|
||||
// baseline c -> js type mapping
|
||||
TYPEMAPS: {
|
||||
'^(const)?\\s*(unsigned|signed)?\\s*(int|short|long|float|double|size_t|u?int\\d{1,2}_t)?$': 'Number',
|
||||
'^bool$': 'Boolean',
|
||||
'^(const)?\\s*(unsigned|signed)?\\s*(char|char\\s*\\*|std::string)$': 'String', // TODO: verify that swig does this mapping
|
||||
'^void\\s*\\(\\s*\\*\\s*\\)\\s*\\(\\s*void\\s*\\*\\)\\s*$': 'Function'
|
||||
},
|
||||
|
||||
|
||||
// custom c -> js type mapping for pointers
|
||||
// ARRAY_TYPEMAPS: {
|
||||
// <pointer data type>: {
|
||||
// arrayType: <swig generated array type that will replace pointers of data type>,
|
||||
// classes: [ <class that contains arrayType>, ... ]
|
||||
// }, ...
|
||||
// }
|
||||
// POINTER_TYPEMAPS: {
|
||||
// <class that contains pointerType>: {
|
||||
// <c pointer data type>: <js swig generated pointer type that will replace pointers of data type>, ...
|
||||
// }, ...
|
||||
// }
|
||||
ARRAY_TYPEMAPS: {},
|
||||
POINTER_TYPEMAPS: {},
|
||||
|
||||
|
||||
// add command line options for this module
|
||||
addOptions: function(opts) {
|
||||
xml2js.opts = opts;
|
||||
return opts
|
||||
.option('-i, --inputdir [directory]', 'directory for xml files', __dirname + '/xml/mraa')
|
||||
.option('-c, --custom [file]', 'json for customizations')
|
||||
.option('-t, --typemaps [directory]', 'directory for custom pointer type maps')
|
||||
.option('-g, --imagedir [directory]', 'directory to link to where the images will be kept', '')
|
||||
.option('-s, --strict', 'leave out methods/variables if unknown type')
|
||||
},
|
||||
|
||||
|
||||
// parse doxygen xml -> js-format specs
|
||||
// TODO: figure out whether we need to document any protected methods/variables
|
||||
parse: function() {
|
||||
var XML_GRAMMAR_SPEC = 'grammars/xml.peg';
|
||||
var NAMESPACE_SPEC = xml2js.opts.inputdir + '/namespace' + xml2js.opts.module + '.xml';
|
||||
var CLASS_SPEC = function(c) { return xml2js.opts.inputdir + '/' + c + '.xml'; }
|
||||
var TYPES_SPEC = xml2js.opts.inputdir + '/types_8h.xml';
|
||||
xml2js.MODULE = xml2js.opts.module;
|
||||
return Promise.join(createXmlParser(XML_GRAMMAR_SPEC),
|
||||
xml2js.opts.typemaps ? initCustomPointerTypemaps(xml2js.opts.typemaps) : Promise.resolve(),
|
||||
fs.readFileAsync(NAMESPACE_SPEC, 'utf8'),
|
||||
fs.existsSync(TYPES_SPEC) ? fs.readFileAsync(TYPES_SPEC, 'utf8') : Promise.resolve(null),
|
||||
function(xmlparser, ignore, xml, xml_types) {
|
||||
if (xml_types != null) {
|
||||
_.extend(xml2js.ENUMS, getEnums(xmlparser.parse(xml_types)[0], false));
|
||||
_.extend(xml2js.ENUMS_BY_GROUP, getEnums(xmlparser.parse(xml_types)[0], true));
|
||||
}
|
||||
var spec_c = xmlparser.parse(xml)[0];
|
||||
_.extend(xml2js.ENUMS, getEnums(spec_c, false));
|
||||
_.extend(xml2js.ENUMS_BY_GROUP, getEnums(spec_c, true));
|
||||
_.extend(xml2js.METHODS, getMethods(spec_c));
|
||||
_.each(getSubclassNames(spec_c), function(className) { xml2js.CLASSES[className] = {} });
|
||||
var parseClasses = _.map(getSubclasses(spec_c), function(c) {
|
||||
return fs.readFileAsync(CLASS_SPEC(c), 'utf8').then(function(xml) {
|
||||
try {
|
||||
var spec_c = xmlparser.parse(xml)[0];
|
||||
var className = getName(spec_c);
|
||||
_.extend(xml2js.CLASSES[className], {
|
||||
description: getDescription(spec_c),
|
||||
parent: getParent(spec_c, className),
|
||||
enums: getEnums(spec_c, false, className),
|
||||
enums_by_group: getEnums(spec_c, true, className),
|
||||
variables: getVariables(spec_c, className),
|
||||
methods: getMethods(spec_c, className)
|
||||
});
|
||||
} catch(e) {
|
||||
console.log(e.toString() + ': class ' + className + ' was not parsed correctly.');
|
||||
}
|
||||
});
|
||||
});
|
||||
var parseGroups = fs.readdirAsync(xml2js.opts.inputdir).then(function(files) {
|
||||
var groupxmlfiles = _.filter(files, function(fn) {
|
||||
return ((path.extname(fn) == '.xml') && (path.basename(fn).search(/^group/) != -1));
|
||||
});
|
||||
return Promise.all(_.map(groupxmlfiles, function(fn) {
|
||||
return fs.readFileAsync(xml2js.opts.inputdir + '/' + fn, 'utf8').then(function(xml) {
|
||||
var spec_c = xmlparser.parse(xml)[0];
|
||||
if (_.isEmpty(getSubmodules(spec_c))) {
|
||||
var group = getName(spec_c);
|
||||
var classes = getSubclassNames(spec_c);
|
||||
xml2js.CLASSGROUPS[group] = {
|
||||
description: getDescription(spec_c),
|
||||
classes: classes
|
||||
};
|
||||
_.each(classes, function(c) {
|
||||
if (_.has(xml2js.CLASSES, c)) {
|
||||
xml2js.CLASSES[c].group = group;
|
||||
} else {
|
||||
console.log('Warning: Group ' + group + ' has unknown class ' + c);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
});
|
||||
return Promise.all(parseClasses.concat(parseGroups));
|
||||
}).then(function() {
|
||||
if (!_.isEmpty(xml2js.CLASSGROUPS)) {
|
||||
// try to categorize ungrouped classes, if any
|
||||
var grouped = _.flatten(_.pluck(_.values(xml2js.CLASSGROUPS), 'classes'));
|
||||
var ungrouped = _.difference(_.keys(xml2js.CLASSES), grouped);
|
||||
_.each(ungrouped, function(c) {
|
||||
_.each(findUsage(c), function(group) {
|
||||
xml2js.CLASSGROUPS[group].classes.push(c);
|
||||
});
|
||||
});
|
||||
grouped = _.flatten(_.pluck(_.values(xml2js.CLASSGROUPS), 'classes'));
|
||||
ungrouped = _.difference(_.keys(xml2js.CLASSES), grouped);
|
||||
// try to categorize ungrouped enums, if any
|
||||
_.each(xml2js.ENUMS_BY_GROUP, function(enumGroupSpec, enumGroupName) {
|
||||
_.each(findUsage(enumGroupName, true), function(c) {
|
||||
xml2js.CLASSES[c].enums_by_group[enumGroupName] = enumGroupSpec;
|
||||
_.each(enumGroupSpec.members, function(enumName) {
|
||||
xml2js.CLASSES[c].enums[enumName] = xml2js.ENUMS[enumName];
|
||||
delete xml2js.ENUMS[enumName];
|
||||
});
|
||||
delete xml2js.ENUMS_BY_GROUP[enumGroupName];
|
||||
});
|
||||
});
|
||||
}
|
||||
}).then(function() {
|
||||
if (xml2js.opts.custom && fs.existsSync(xml2js.opts.custom)) {
|
||||
return fs.readFileAsync(xml2js.opts.custom, 'utf8').then(function(custom) {
|
||||
try {
|
||||
customizeMethods(JSON.parse(custom));
|
||||
} catch(e) {
|
||||
console.log('invalid custom.json, ignored. ' + e.toString());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(xml2js.opts.custom ? ('Error: No such customization file exists: ' + xml2js.opts.custom) : 'No customizations given.');
|
||||
}
|
||||
}).then(function() {
|
||||
generateCustomPointerClasses();
|
||||
validateMethods();
|
||||
validateVars();
|
||||
return _.pick(xml2js, 'MODULE', 'ENUMS', 'ENUMS_BY_GROUP', 'METHODS', 'CLASSES', 'CLASSGROUPS');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// create an xml parser
|
||||
function createXmlParser(XML_GRAMMAR_SPEC) {
|
||||
return fs.readFileAsync(XML_GRAMMAR_SPEC, 'utf8').then(function(xmlgrammar) {
|
||||
return peg.buildParser(xmlgrammar);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// configure c->js typemaps from custom swig directives
|
||||
// TODO: many built in assumptions based on current upm file structures & .i customizations
|
||||
function initCustomPointerTypemaps(typemapsdir) {
|
||||
return fs.readdirAsync(typemapsdir).then(function(dirs) {
|
||||
return Promise.all(_.map(dirs, function(dir) {
|
||||
// get all js*.i directives from class-specific subdirectories, to be parsed below for %typemaps directives
|
||||
return fs.readdirAsync(typemapsdir + '/' + dir).then(function(files) {
|
||||
var directive = _.find(files, function(fn) {
|
||||
return ((path.extname(fn) == '.i') && (path.basename(fn).search(/^js/) != -1));
|
||||
});
|
||||
var data = {};
|
||||
if (directive) {
|
||||
data[dir] = typemapsdir + '/' + dir + '/' + directive;
|
||||
}
|
||||
return data;
|
||||
}).catch(function(e) {
|
||||
// get all .i directives from top level directory, and parse for %array_class directives
|
||||
if (e.code == 'ENOTDIR') {
|
||||
var fn = dir;
|
||||
if (path.extname(fn) == '.i') {
|
||||
return fs.readFileAsync(typemapsdir + '/' + fn, 'utf8').then(function(directives) {
|
||||
var arraytypes = _.filter(directives.split(/\n/), function(line) {
|
||||
return (line.search(/^%array_class/) != -1);
|
||||
});
|
||||
_.each(arraytypes, function(arraytype) {
|
||||
var parsed = arraytype.match(/%array_class\(([A-Za-z0-9_]+)[\s]*,[\s]*([A-Za-z0-9_]+)\)/);
|
||||
if (parsed) {
|
||||
var from = parsed[1];
|
||||
var to = parsed[2];
|
||||
xml2js.ARRAY_TYPEMAPS[from] = { arrayType: to, classes: [] };
|
||||
} else {
|
||||
console.log('Incorrectly parsed array_class from ' + fn + ': ' + arraytype);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}));
|
||||
}).then(function(__directivesFiles) {
|
||||
// parse for %typemaps & %pointer_functions directives
|
||||
var _directivesFiles = _.filter(__directivesFiles, function(data) { return !_.isEmpty(data); });
|
||||
var directivesFiles = _.object(_.map(_directivesFiles, _.keys), _.flatten(_.map(_directivesFiles, _.values)));
|
||||
return Promise.all(_.map(directivesFiles, function(directivesFn, className) {
|
||||
return fs.readFileAsync(directivesFn, 'utf8').then(function(directives) {
|
||||
var typemaps = _.filter(directives.split(/\n/), function(line) {
|
||||
return (line.search(/^%typemap/) != -1);
|
||||
});
|
||||
_.each(typemaps, function(typemap) {
|
||||
var parsed = typemap.match(/%typemap\((in|out)\)[\s]+([A-Za-z0-9_]+[\s]*[\*])/);
|
||||
if (parsed) {
|
||||
var dir = parsed[1]; // TODO: ignored for now
|
||||
var type = normalizePointer(parsed[2]);
|
||||
var datatype = getPointerDataType(type);
|
||||
if (_.has(xml2js.ARRAY_TYPEMAPS, datatype)) {
|
||||
xml2js.ARRAY_TYPEMAPS[datatype].classes.push(className);
|
||||
} else {
|
||||
console.log('Ignored typemap from ' + directivesFn + ': ' + typemap.replace('{', '') + ' (no %array_class directive found for ' + datatype + ')');
|
||||
}
|
||||
} else {
|
||||
console.log('Ignored typemap from ' + directivesFn + ': ' + typemap.replace('{', '') + ' (only considering in/out typemaps of pointer types)');
|
||||
}
|
||||
});
|
||||
var ptrfns = _.filter(directives.split(/\n/), function(line) {
|
||||
return (line.search(/^%pointer_functions/) != -1);
|
||||
});
|
||||
_.each(ptrfns, function(ptrfn) {
|
||||
var parsed = ptrfn.match(/%pointer_functions\(([A-Za-z0-9_]+)[\s]*,[\s]*([A-Za-z0-9_]+)\)/);
|
||||
if (parsed) {
|
||||
var from = parsed[1];
|
||||
var to = parsed[2];
|
||||
if (!_.has(xml2js.POINTER_TYPEMAPS, className)) {
|
||||
xml2js.POINTER_TYPEMAPS[className] = {};
|
||||
}
|
||||
xml2js.POINTER_TYPEMAPS[className][from] = to;
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// generate class specs for custom pointer types
|
||||
function generateCustomPointerClasses() {
|
||||
var arrayTypes = _.pluck(_.values(xml2js.ARRAY_TYPEMAPS), 'arrayType');
|
||||
var pointerTypes = _.uniq(_.flatten(_.map(_.values(xml2js.POINTER_TYPEMAPS), _.values)));
|
||||
_.each(arrayTypes, function(arrayType) {
|
||||
var dataType = _.findKey(xml2js.ARRAY_TYPEMAPS, function(to) { return to.arrayType == arrayType; });
|
||||
xml2js.CLASSES[arrayType] = {
|
||||
description: 'Array of type ' + dataType + '.',
|
||||
enums: {},
|
||||
enums_by_group: {},
|
||||
variables: {},
|
||||
methods: {}
|
||||
};
|
||||
xml2js.CLASSES[arrayType].methods[arrayType] = {
|
||||
description: 'Instantiates the array.',
|
||||
params: {
|
||||
nelements: {
|
||||
type: 'Number',
|
||||
description: 'number of elements in the array'
|
||||
}
|
||||
},
|
||||
return: {}
|
||||
};
|
||||
xml2js.CLASSES[arrayType].methods.getitem = {
|
||||
description: 'Access a particular element in the array.',
|
||||
params: {
|
||||
index: {
|
||||
type: 'Number',
|
||||
description: 'index of array to read from'
|
||||
},
|
||||
},
|
||||
return: {
|
||||
type: getType(dataType),
|
||||
description: 'the value of the element found at the given index of the array'
|
||||
}
|
||||
};
|
||||
xml2js.CLASSES[arrayType].methods.setitem = {
|
||||
description: 'Modify a particular element in the array.',
|
||||
params: {
|
||||
index: {
|
||||
type: 'Number',
|
||||
description: 'index of array to write to'
|
||||
},
|
||||
value: {
|
||||
type: getType(dataType),
|
||||
description: 'the value to set the element found at the given index of the array'
|
||||
}
|
||||
},
|
||||
return: {}
|
||||
};
|
||||
});
|
||||
var pointerDataTypeMap = _.reduce(_.map(_.values(xml2js.POINTER_TYPEMAPS), _.invert), function(memo, typemap) {
|
||||
return _.extend(memo, typemap);
|
||||
}, {});
|
||||
_.each(pointerTypes, function(pointerType) {
|
||||
var dataType = pointerDataTypeMap[pointerType];
|
||||
xml2js.CLASSES[pointerType] = {
|
||||
description: 'Proxy object to data of type ' + dataType + '.',
|
||||
enums: {},
|
||||
enums_by_group: {},
|
||||
variables: {},
|
||||
methods: {}
|
||||
};
|
||||
xml2js.CLASSES[pointerType].methods[pointerType] = {
|
||||
description: 'Instantiates the proxy object.',
|
||||
params: {},
|
||||
return: {}
|
||||
};
|
||||
xml2js.CLASSES[pointerType].methods.value = {
|
||||
description: 'Get the value of the object.',
|
||||
params: {},
|
||||
return: {
|
||||
type: getType(dataType),
|
||||
description: 'the value of the object'
|
||||
}
|
||||
};
|
||||
xml2js.CLASSES[pointerType].methods.assign = {
|
||||
description: 'Set the value of the object.',
|
||||
params: {
|
||||
value: {
|
||||
type: getType(dataType),
|
||||
description: 'the value to set the object to'
|
||||
}
|
||||
},
|
||||
return: {}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// search for usage of a type
|
||||
function findUsage(type, classOnly) {
|
||||
var filterClasses = function(fn) { return _.without(_.map(xml2js.CLASSES, fn), undefined); };
|
||||
var usesType = function(classSpec, className) {
|
||||
var methodsOfType = (_.find(classSpec.methods, function(methodSpec, methodName) {
|
||||
return ((!_.isEmpty(methodSpec.return) && methodSpec.return.type == type) ||
|
||||
(_.contains(_.pluck(methodSpec.params, 'type'), type)));
|
||||
}) != undefined);
|
||||
var variablesOfType = _.contains(_.pluck(classSpec.variable, 'type'), type);
|
||||
return ((methodsOfType || variablesOfType) ? className : undefined);
|
||||
};
|
||||
var extendsType = function(classSpec, className) {
|
||||
return ((classSpec.parent == type) ? className : undefined);
|
||||
};
|
||||
var classes = _.union(filterClasses(usesType), filterClasses(extendsType));
|
||||
if (classOnly) {
|
||||
return classes;
|
||||
} else {
|
||||
return _.without(_.uniq(_.pluck(_.pick(xml2js.CLASSES, classes), 'group')), undefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// override autogenerated methods with custom configuration
|
||||
function customizeMethods(custom) {
|
||||
_.each(custom, function(classMethods, className) {
|
||||
_.extend(xml2js.CLASSES[className].methods, _.pick(classMethods, function(methodSpec, methodName) {
|
||||
return isValidMethodSpec(methodSpec, className + '.' + methodName);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// make sure methods have valid types, otherwise warn (& don't include if strict)
|
||||
function validateMethods() {
|
||||
xml2js.METHODS = _.pick(xml2js.METHODS, function(methodSpec, methodName) {
|
||||
return hasValidTypes(methodSpec, methodName);
|
||||
});
|
||||
_.each(xml2js.CLASSES, function(classSpec, className) {
|
||||
var valid = _.pick(classSpec.methods, function(methodSpec, methodName) {
|
||||
return hasValidTypes(methodSpec, className + '.' + methodName, className);
|
||||
});
|
||||
if (xml2js.opts.strict) {
|
||||
xml2js.CLASSES[className].methods = valid;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// make sure variables have valid types, otherwise warn (& don't include if strict)
|
||||
function validateVars() {
|
||||
_.each(xml2js.CLASSES, function(classSpec, className) {
|
||||
var valid = _.pick(classSpec.variables, function(varSpec, varName) {
|
||||
return ofValidType(varSpec, className + '.' + varName, className);
|
||||
});
|
||||
if (xml2js.opts.strict) {
|
||||
xml2js.CLASSES[className].variables = valid;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// verify that the json spec is well formatted
|
||||
function isValidMethodSpec(methodSpec, methodName) {
|
||||
var valid = true;
|
||||
var printIgnoredMethodOnce = _.once(function() { console.log(methodName + ' from ' + path.basename(xml2js.opts.custom) + ' is omitted from JS documentation.'); });
|
||||
function checkRule(rule, errMsg) {
|
||||
if (!rule) {
|
||||
printIgnoredMethodOnce();
|
||||
console.log(' ' + errMsg);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
checkRule(_.has(methodSpec, 'description'), 'no description given');
|
||||
checkRule(_.has(methodSpec, 'params'), 'no params given (specify "params": {} for no params)');
|
||||
_.each(methodSpec.params, function(paramSpec, paramName) {
|
||||
checkRule(_.has(paramSpec, 'type'), 'no type given for param ' + paramName);
|
||||
checkRule(_.has(paramSpec, 'description'), 'no description given for param ' + paramName);
|
||||
});
|
||||
checkRule(_.has(methodSpec, 'return'), 'no return given (specify "return": {} for no return value)');
|
||||
checkRule(_.has(methodSpec.return, 'type'), 'no type given for return value');
|
||||
checkRule(_.has(methodSpec.return, 'description'), 'no description given for return value');
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
// get enum specifications
|
||||
function getEnums(spec_c, bygroup, parent) {
|
||||
var spec_js = {};
|
||||
var enumGroups = _.find(getChildren(spec_c, 'sectiondef'), function(section) {
|
||||
var kind = getAttr(section, 'kind');
|
||||
return ((kind == 'enum') || (kind == 'public-type'));
|
||||
});
|
||||
if (enumGroups) {
|
||||
_.each(enumGroups.children, function(enumGroup) {
|
||||
var enumGroupName = getText(getChild(enumGroup, 'name'), 'name');
|
||||
var enumGroupDescription = getText(getChild(enumGroup, 'detaileddescription'), 'description');
|
||||
var enumGroupVals = getChildren(enumGroup, 'enumvalue');
|
||||
if (bygroup) {
|
||||
spec_js[enumGroupName] = {
|
||||
description: enumGroupDescription,
|
||||
members: []
|
||||
};
|
||||
}
|
||||
_.each(enumGroupVals, function(e) {
|
||||
// TODO: get prefix as option
|
||||
var enumName = getText(getChild(e, 'name'), 'name').replace(/^MRAA_/, '');
|
||||
var enumDescription = getText(getChild(e, 'detaileddescription'), 'description');
|
||||
if (!bygroup) {
|
||||
spec_js[enumName] = {
|
||||
type: enumGroupName,
|
||||
description: enumDescription
|
||||
};
|
||||
} else {
|
||||
spec_js[enumGroupName].members.push(enumName);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return spec_js;
|
||||
}
|
||||
|
||||
|
||||
// get the name for the module/group/class
|
||||
function getName(spec_c) {
|
||||
return getText(getChild(spec_c, 'compoundname'), 'name').replace(xml2js.opts.module + '::', '');
|
||||
}
|
||||
|
||||
|
||||
// get the description for the module/group/class
|
||||
function getDescription(spec_c) {
|
||||
return getText(getChild(spec_c, 'detaileddescription'), 'description');
|
||||
}
|
||||
|
||||
|
||||
// get the classes (xml file names) for the given module
|
||||
function getSubclasses(spec_c) {
|
||||
return _.map(getChildren(spec_c, 'innerclass'), function(innerclass) {
|
||||
return getAttr(innerclass, 'refid');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// get the classes (class names) for the given module
|
||||
function getSubclassNames(spec_c) {
|
||||
return _.map(getChildren(spec_c, 'innerclass'), function(innerclass) {
|
||||
return getText(innerclass).replace(xml2js.opts.module + '::', '');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// get the submodules (xml file names) for the given module
|
||||
function getSubmodules(spec_c) {
|
||||
return _.map(getChildren(spec_c, 'innergroup'), function(innergroup) {
|
||||
return getAttr(innergroup, 'refid');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// get parent class, if any
|
||||
function getParent(spec_c, className) {
|
||||
var parent = getChild(spec_c, 'basecompoundref');
|
||||
if (parent) {
|
||||
parent = getText(parent);
|
||||
if (!_.has(xml2js.CLASSES, parent)) {
|
||||
console.log('WARNING: Class ' + className + ' has unknown parent class ' + parent);
|
||||
}
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
||||
function hasParams(paramsSpec) {
|
||||
return !(_.isEmpty(paramsSpec) ||
|
||||
((_.size(paramsSpec) == 1) && getText(getChild(paramsSpec[0], 'type')) == 'void'));
|
||||
}
|
||||
|
||||
|
||||
// get method specifications for top-level module or a given class
|
||||
// TODO: overloaded functions
|
||||
// TODO: functions w/ invalid parameter(s)/return
|
||||
function getMethods(spec_c, parent) {
|
||||
var spec_js = {};
|
||||
var methods = _.find(getChildren(spec_c, 'sectiondef'), function(section) {
|
||||
var kind = getAttr(section, 'kind');
|
||||
return ((kind == 'public-func') || (kind == 'func'));
|
||||
});
|
||||
if (methods) {
|
||||
_.each(methods.children, function(method) {
|
||||
var methodName = getText(getChild(method, 'name'), 'name');
|
||||
if (methodName[0] != '~') { // filter out destructors
|
||||
try {
|
||||
var description = getChild(method, 'detaileddescription');
|
||||
var methodDescription = getText(description, 'description');
|
||||
var paramsSpec = getChildren(method, 'param');
|
||||
var params = {};
|
||||
if (hasParams(paramsSpec)) {
|
||||
params = getParams(paramsSpec, getParamsDetails(description), methodName, parent);
|
||||
}
|
||||
var returnSpec = getChild(method, 'type');
|
||||
var retval = {};
|
||||
if (!_.isEmpty(returnSpec)) {
|
||||
retval = getReturn(returnSpec, getReturnDetails(description), methodName, parent);
|
||||
}
|
||||
methodName = getUniqueMethodName(methodName, spec_js, parent);
|
||||
spec_js[methodName] = {
|
||||
description: methodDescription,
|
||||
params: params,
|
||||
return: retval
|
||||
};
|
||||
} catch(e) {
|
||||
console.log((parent ? (parent + '.') : '') + methodName + ' is omitted from JS documentation.');
|
||||
console.log(' ' + e.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return spec_js;
|
||||
}
|
||||
|
||||
|
||||
// get a unique string to represent the name of an overloaded method
|
||||
function getUniqueMethodName(methodName, module, parent) {
|
||||
if (methodName in module) {
|
||||
do {
|
||||
methodName += '!';
|
||||
} while (methodName in module);
|
||||
}
|
||||
return methodName;
|
||||
}
|
||||
|
||||
|
||||
// get variable specifications for a class
|
||||
function getVariables(spec_c, parent) {
|
||||
var spec_js = {};
|
||||
var vars = _.find(getChildren(spec_c, 'sectiondef'), function(section) {
|
||||
var kind = getAttr(section, 'kind');
|
||||
return (kind == 'public-attrib');
|
||||
});
|
||||
if (vars) {
|
||||
_.each(_.filter(vars.children, function(variable) {
|
||||
return (getAttr(variable, 'kind') == 'variable');
|
||||
}), function(variable) {
|
||||
var varName = getText(getChild(variable, 'name'), 'name');
|
||||
var varType = getType(getText(getChild(variable, 'type')), parent);
|
||||
var varDescription = getText(getChild(variable, 'detaileddescription'));
|
||||
spec_js[varName] = {
|
||||
type: varType,
|
||||
description: varDescription
|
||||
}
|
||||
});
|
||||
}
|
||||
return spec_js;
|
||||
}
|
||||
|
||||
|
||||
// get return value specs of a method
|
||||
function getReturn(spec_c, details, method, parent) {
|
||||
var retType = getType(getText(spec_c, 'type'), parent);
|
||||
var retDescription = (details ? getText(details, 'description') : '');
|
||||
return ((retType == 'void') ? {} : {
|
||||
type: retType,
|
||||
description: retDescription
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// get paramater specs of a method
|
||||
function getParams(spec_c, details, method, parent) {
|
||||
var spec_js = {};
|
||||
_.each(spec_c, function(param) {
|
||||
try {
|
||||
var paramType = getType(getText(getChild(param, 'type'), 'type'), parent);
|
||||
var paramName = getText(getChild(param, 'declname'), 'name');
|
||||
spec_js[paramName] = { type: paramType };
|
||||
} catch(e) {
|
||||
if (paramType == '...') {
|
||||
spec_js['arguments'] = { type: paramType };
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
_.each(details, function(param) {
|
||||
var getParamName = function(p) { return getText(getChild(getChild(p, 'parameternamelist'), 'parametername'), 'name'); }
|
||||
var paramName = getParamName(param);
|
||||
var paramDescription = getText(getChild(param, 'parameterdescription'), 'description');
|
||||
if (_.has(spec_js, paramName)) {
|
||||
spec_js[paramName].description = paramDescription;
|
||||
} else {
|
||||
var msg = ' has documentation for an unknown parameter: ' + paramName + '. ';
|
||||
var suggestions = _.difference(_.keys(spec_js), _.map(details, getParamName));
|
||||
var msgAddendum = (!_.isEmpty(suggestions) ? ('Did you mean ' + suggestions.join(', or ') + '?') : '');
|
||||
console.log('Warning: ' + (parent ? (parent + '.') : '') + method + msg + msgAddendum);
|
||||
}
|
||||
});
|
||||
return spec_js;
|
||||
}
|
||||
|
||||
|
||||
// get the equivalent javascript type from the given c type
|
||||
function getType(type_c, parent) {
|
||||
var type_js = type_c;
|
||||
_.find(xml2js.TYPEMAPS, function(to, from) {
|
||||
var pattern = new RegExp(from, 'i');
|
||||
if (type_c.search(pattern) == 0) {
|
||||
type_js = to;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (isPointer(type_js)) {
|
||||
var dataType = getPointerDataType(type_js);
|
||||
var className = parent.toLowerCase();
|
||||
if (_.has(xml2js.ARRAY_TYPEMAPS, dataType) && _.contains(xml2js.ARRAY_TYPEMAPS[dataType].classes, className)) {
|
||||
type_js = xml2js.ARRAY_TYPEMAPS[dataType].arrayType;
|
||||
} else if (_.has(xml2js.POINTER_TYPEMAPS, className) && _.has(xml2js.POINTER_TYPEMAPS[className], dataType)) {
|
||||
type_js = xml2js.POINTER_TYPEMAPS[className][dataType];
|
||||
} else if (_.has(xml2js.CLASSES, dataType)) { // TODO: verify that swig does this mapping
|
||||
type_js = dataType;
|
||||
} else {
|
||||
type_js = dataType + ' *'
|
||||
}
|
||||
}
|
||||
return type_js;
|
||||
}
|
||||
|
||||
|
||||
// verify that all types associated with the method are valid
|
||||
function hasValidTypes(methodSpec, methodName, parent) {
|
||||
var valid = true;
|
||||
var msg = (xml2js.opts.strict ? ' is omitted from JS documentation.' : ' has invalid type(s).');
|
||||
var printIgnoredMethodOnce = _.once(function() { console.log(methodName + msg); });
|
||||
_.each(methodSpec.params, function(paramSpec, paramName) {
|
||||
if (!isValidType(paramSpec.type, parent)) {
|
||||
valid = false;
|
||||
printIgnoredMethodOnce();
|
||||
console.log(' Error: parameter ' + paramName + ' has invalid type ' + typeToString(paramSpec.type));
|
||||
}
|
||||
});
|
||||
if (!_.isEmpty(methodSpec.return) && !isValidType(methodSpec.return.type, parent)) {
|
||||
valid = false;
|
||||
printIgnoredMethodOnce();
|
||||
console.log(' Error: returns invalid type ' + typeToString(methodSpec.return.type));
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
// verify that type of variable is valid
|
||||
function ofValidType(varSpec, varName, parent) {
|
||||
if (isValidType(varSpec.type, parent)) {
|
||||
return true;
|
||||
} else {
|
||||
var msgAddendum = (xml2js.opts.strict ? ' Omitted from JS documentation.' : '');
|
||||
console.log('Error: ' + varName + ' is of invalid type ' + typeToString(varSpec.type) + '.' + msgAddendum);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// verify whether the given type is valid JS
|
||||
function isValidType(type, parent) {
|
||||
return (_.contains(_.values(xml2js.TYPEMAPS), type) ||
|
||||
_.has(xml2js.CLASSES, type) ||
|
||||
_.has(xml2js.ENUMS_BY_GROUP, type) ||
|
||||
_.contains(['Buffer', 'Function', 'mraa_result_t'], type) ||
|
||||
_.has((parent ? xml2js.CLASSES[parent].enums_by_group : []), type) ||
|
||||
isValidPointerType(type, parent));
|
||||
}
|
||||
|
||||
|
||||
function isValidPointerType(type, parent) {
|
||||
var className = parent.toLowerCase();
|
||||
var arrayTypemap = _.find(xml2js.ARRAY_TYPEMAPS, function(to) { return to.arrayType == type; });
|
||||
var valid = ((arrayTypemap && _.contains(arrayTypemap.classes, className)) ||
|
||||
(_.has(xml2js.POINTER_TYPEMAPS, className) && (_.contains(_.values(xml2js.POINTER_TYPEMAPS[className]), type))));
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
// determines whether a type looks like a c pointer
|
||||
function isPointer(type) {
|
||||
return (type.search(/\w+\s*(\*|&)$/) != -1);
|
||||
}
|
||||
|
||||
|
||||
// remove extraneous whitespace from pointer types as canonical representation
|
||||
function normalizePointer(ptr) {
|
||||
return ptr.replace(/\s*$/, '');
|
||||
}
|
||||
|
||||
|
||||
// get the data type of a pointer (e.g. int is the data type of int*)
|
||||
function getPointerDataType(ptr) {
|
||||
return ptr.replace(/\s*(\*|&)$/, '');
|
||||
}
|
||||
|
||||
|
||||
// print more human friendly type for error messages
|
||||
function typeToString(type) {
|
||||
return type.replace('*', '*');
|
||||
}
|
||||
|
||||
|
||||
// get the detailed description of a method's parameters
|
||||
function getParamsDetails(spec_c) {
|
||||
var paras = getChildren(spec_c, 'para');
|
||||
var details = _.find(_.map(paras, function(para) {
|
||||
return getChild(para, 'parameterlist');
|
||||
}), function(obj) { return (obj != undefined); });
|
||||
return (details ? details.children : undefined);
|
||||
}
|
||||
|
||||
|
||||
// get the detailed description of a method's return value
|
||||
function getReturnDetails(spec_c) {
|
||||
var paras = getChildren(spec_c, 'para');
|
||||
return _.find(_.map(paras, function(para) {
|
||||
return getChild(para, 'simplesect');
|
||||
}), function(obj) { return ((obj != undefined) && (getAttr(obj, 'kind') == 'return')); });
|
||||
}
|
||||
|
||||
|
||||
// get (and flatten) the text of the given object
|
||||
function getText(obj, why) {
|
||||
// TODO: links ignored for now, patched for types for
|
||||
var GENERATE_LINK = function(x) { return x + ' '; }
|
||||
return _.reduce(obj.children, function(text, elem) {
|
||||
if (_.isString(elem)) {
|
||||
return text += elem.trim() + ' ';
|
||||
} else if (_.isPlainObject(elem)) {
|
||||
switch(elem.name) {
|
||||
case 'para':
|
||||
return text += getText(elem, why) + ' \n';
|
||||
case 'ref':
|
||||
return text += GENERATE_LINK(getText(elem, why));
|
||||
case 'parameterlist':
|
||||
case 'simplesect':
|
||||
return text; // to be handled elsewhere
|
||||
case 'programlisting':
|
||||
case 'htmlonly':
|
||||
return text; // ignored
|
||||
// TODO: html doesn't seem to work for yuidoc, using markdown for now
|
||||
case 'itemizedlist':
|
||||
return text += '\n' + getText(elem, why) + ' \n \n';
|
||||
case 'listitem':
|
||||
return text += '+ ' + getText(elem, why) + '\n';
|
||||
case 'bold':
|
||||
return text += '__' + getText(elem, why).trim() + '__ ';
|
||||
case 'ulink':
|
||||
return text += '[' + getText(elem, why).trim() + '](' + getAttr(elem, 'url').trim() + ') ';
|
||||
case 'image':
|
||||
// TODO: copy images over; hard coded for now
|
||||
var fn = getAttr(elem, 'name');
|
||||
return text += ' \n \n ';
|
||||
case 'linebreak':
|
||||
return text += ' \n';
|
||||
case 'ndash':
|
||||
return text += '– ';
|
||||
default:
|
||||
// TODO: incomplete list of doxygen xsd implemented
|
||||
console.warn('NYI Unknown Object Type: ' + elem.name);
|
||||
return text;
|
||||
//throw new Error('NYI Unknown Object Type: ' + elem.name);
|
||||
}
|
||||
} else {
|
||||
throw new Error('NYI Unknown Type: ' + (typeof elem));
|
||||
}
|
||||
}, '').trim();
|
||||
}
|
||||
|
||||
|
||||
// get the value of attribute with the given name of the given object
|
||||
function getAttr(obj, name) {
|
||||
return _.find(obj.attr, function(item) {
|
||||
return item.name == name;
|
||||
}).value;
|
||||
}
|
||||
|
||||
|
||||
// get the child object with the given name of the given object
|
||||
function getChild(obj, name) {
|
||||
return _.find(obj.children, function(child) {
|
||||
return child.name == name;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// get all children objects with the given name of the given object
|
||||
function getChildren(obj, name) {
|
||||
return _.filter(obj.children, function(child) {
|
||||
return child.name == name;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// debug helper: print untruncated object
|
||||
function printObj(obj) {
|
||||
console.log(util.inspect(obj, false, null));
|
||||
}
|
||||
|
||||
|
||||
module.exports = xml2js;
|
@ -29,15 +29,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
upm::HCSR04 *sonar = NULL;
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
sonar->m_doWork = 1;
|
||||
shouldRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,20 +43,20 @@ sig_handler(int signo)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sonar = new upm::HCSR04(5, 6);
|
||||
upm::HCSR04 *sonar = new upm::HCSR04(2, 4);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
sleep(1);
|
||||
|
||||
for(;;){
|
||||
while(shouldRun){
|
||||
std::cout << "get distance" << std::endl;
|
||||
double distance = sonar->getDistance(CM);
|
||||
double distance = sonar->getDistance(HCSR04_CM);
|
||||
std::cout << "distance " << distance << std::endl;
|
||||
sleep(5);
|
||||
sleep(2);
|
||||
}
|
||||
std::cout << "Exiting... " << std::endl;
|
||||
|
||||
delete sonar;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -46,19 +46,25 @@ int main(int argc, char **argv)
|
||||
// Instantiate a IMS instance using i2c bus 0 and default address
|
||||
upm::IMS sensor(0);
|
||||
|
||||
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
|
||||
while (shouldRun)
|
||||
{
|
||||
std::cout << "Version: "
|
||||
std::cout << std::hex << "Version: 0x"
|
||||
<< sensor.get_version()
|
||||
<< " light: "
|
||||
<< " light: 0x"
|
||||
<< sensor.get_light()
|
||||
<< " moisture: "
|
||||
<< " moisture: 0x"
|
||||
<< sensor.get_moisture()
|
||||
<< " temp: "
|
||||
<< sensor.get_temperature()
|
||||
<< " C"
|
||||
<< std::endl;
|
||||
|
||||
// Change the address and continue
|
||||
if (i2c_addr_cur >= 128) i2c_addr_cur = 1;
|
||||
std::cout << "Changing device address to 0x" << i2c_addr_cur
|
||||
<< std::endl;
|
||||
sensor.reset_i2c_address(i2c_addr_cur++);
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
64
examples/c++/lidarlitev3.cxx
Normal file
64
examples/c++/lidarlitev3.cxx
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Author: Saloni Jain <saloni.jain@tcs.com>
|
||||
* Author: Niti Rohilla <niti.rohilla@tcs.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "lidarlitev3.hpp"
|
||||
|
||||
volatile int doWork = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
printf("\nCtrl-C received.\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
||||
// Register signal handler
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
upm::LIDARLITEV3 *sensor = new upm::LIDARLITEV3(0, ADDR);
|
||||
|
||||
while (!doWork) {
|
||||
std::cout << "Distance = " << sensor->getDistance () << std::endl;
|
||||
usleep (50000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
81
examples/c++/lis2ds12.cxx
Normal file
81
examples/c++/lis2ds12.cxx
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "lis2ds12.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an LIS2DS12 using default I2C parameters
|
||||
upm::LIS2DS12 sensor;
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: LIS2DS12(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||
<< " C / " << sensor.getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
88
examples/c++/lsm6ds3h.cxx
Normal file
88
examples/c++/lsm6ds3h.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "lsm6ds3h.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an LSM6DS3H using default I2C parameters
|
||||
upm::LSM6DS3H sensor;
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: LSM6DS3H(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " dps"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||
<< " C / " << sensor.getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
88
examples/c++/lsm6dsl.cxx
Normal file
88
examples/c++/lsm6dsl.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "lsm6dsl.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an LSM6DSL using default I2C parameters
|
||||
upm::LSM6DSL sensor;
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: LSM6DSL(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " dps"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||
<< " C / " << sensor.getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -42,7 +42,7 @@ int main()
|
||||
{
|
||||
float t;
|
||||
case 1:
|
||||
std::cout << "Temp: " << temp->getTemp() << "° " << (temp->isCelsius()? "Celsius" : "Fahrenheit")<< std::endl;
|
||||
std::cout << "Temp: " << temp->getTemp() << "* " << (temp->isCelsius()? "Celsius" : "Fahrenheit")<< std::endl;
|
||||
break;
|
||||
case 2:
|
||||
cout << "shutdown sensor (sleep mode)" << endl;
|
||||
|
@ -54,8 +54,7 @@ int main(int argc, char **argv)
|
||||
cout << "Using device: " << defaultDev << endl;
|
||||
|
||||
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||
upm::RN2903 sensor = upm::RN2903(defaultDev,
|
||||
RN2903_DEFAULT_BAUDRATE);
|
||||
upm::RN2903 sensor (defaultDev, RN2903_DEFAULT_BAUDRATE);
|
||||
|
||||
// To use an internal UART understood by MRAA, use the following
|
||||
// to inititialize rather than the above, which by default uses a
|
||||
|
@ -54,8 +54,7 @@ int main(int argc, char **argv)
|
||||
cout << "Using device: " << defaultDev << endl;
|
||||
|
||||
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||
upm::RN2903 sensor = upm::RN2903(defaultDev,
|
||||
RN2903_DEFAULT_BAUDRATE);
|
||||
upm::RN2903 sensor(defaultDev, RN2903_DEFAULT_BAUDRATE);
|
||||
|
||||
// To use an internal UART understood by MRAA, use the following
|
||||
// to inititialize rather than the above, which by default uses a
|
||||
|
@ -42,8 +42,7 @@ int main(int argc, char **argv)
|
||||
cout << "Using device: " << defaultDev << endl;
|
||||
|
||||
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
|
||||
upm::RN2903 sensor = upm::RN2903(defaultDev,
|
||||
RN2903_DEFAULT_BAUDRATE);
|
||||
upm::RN2903 sensor(defaultDev, RN2903_DEFAULT_BAUDRATE);
|
||||
|
||||
// To use an internal UART understood by MRAA, use the following
|
||||
// to inititialize rather than the above, which by default uses a
|
||||
|
@ -58,8 +58,8 @@ int main(int argc, char **argv)
|
||||
// update and print available values every second
|
||||
while (run)
|
||||
{
|
||||
// Print out temperature value in °C
|
||||
std::cout << "Temperature: " << mySensor->getTemperature(true) << " °C"
|
||||
// Print out temperature value in *C
|
||||
std::cout << "Temperature: " << mySensor->getTemperature(true) << " *C"
|
||||
<< std::endl;
|
||||
|
||||
sleep(1);
|
||||
|
@ -44,7 +44,7 @@ int main ()
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an VEML6070 sensor on i2c bus 0
|
||||
upm::VEML6070* veml = new upm::VEML6070(0, VEML6070_CTRL_REG);
|
||||
upm::VEML6070* veml = new upm::VEML6070(0);
|
||||
while (shouldRun) {
|
||||
cout << "Retrieved UV value: " << veml->getUVIntensity() << endl;
|
||||
sleep(1);
|
||||
|
48
examples/c/hcsr04.c
Normal file
48
examples/c/hcsr04.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "hcsr04.h"
|
||||
|
||||
int main() {
|
||||
hcsr04_context dev = hcsr04_init(2,4);
|
||||
if(dev == NULL) {
|
||||
printf("Unable to intialize the sensor\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
double distance;
|
||||
while(1) {
|
||||
distance = hcsr04_get_distance(dev, HCSR04_CM);
|
||||
printf("Distance detected: %f\n", distance);
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -50,6 +50,8 @@ int main()
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
|
||||
|
||||
// Every second, sample the sensor outputs
|
||||
while (shouldRun)
|
||||
{
|
||||
@ -62,8 +64,19 @@ int main()
|
||||
printf("Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C\n",
|
||||
version, light, moisture, temp/10.0);
|
||||
else
|
||||
{
|
||||
printf("Failed to read IMS sensor data...\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// Change the address and continue
|
||||
if (i2c_addr_cur >= 128) i2c_addr_cur = 1;
|
||||
printf("Changing device address to 0x%02x\n", i2c_addr_cur);
|
||||
if (ims_reset_i2c_address(sensor, i2c_addr_cur++) != UPM_SUCCESS)
|
||||
{
|
||||
printf("Failed to change IMS I2C address...\n");
|
||||
break;
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
|
100
examples/c/lis2ds12.c
Normal file
100
examples/c/lis2ds12.c
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "lis2ds12.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
#if defined(CONFIG_BOARD_ARDUINO_101_SSS)
|
||||
// ARDUINO_101_SSS (ARC core) must use I2C
|
||||
// Instantiate a LIS2DS12 instance using default i2c bus and address
|
||||
lis2ds12_context sensor = lis2ds12_init(LIS2DS12_DEFAULT_I2C_BUS,
|
||||
LIS2DS12_DEFAULT_I2C_ADDR, -1);
|
||||
#elif defined(CONFIG_BOARD_ARDUINO_101)
|
||||
// ARDUINO_101 (Quark core) must use SPI
|
||||
// Instantiate a LIS2DS12 instance using default SPI bus and pin 10 as CS
|
||||
lis2ds12_context sensor = lis2ds12_init(LIS2DS12_DEFAULT_SPI_BUS,
|
||||
-1, 10);
|
||||
#else
|
||||
// everything else use I2C by default
|
||||
// Instantiate a LIS2DS12 instance using default i2c bus and address
|
||||
lis2ds12_context sensor = lis2ds12_init(LIS2DS12_DEFAULT_I2C_BUS,
|
||||
LIS2DS12_DEFAULT_I2C_ADDR, -1);
|
||||
#endif
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("lis2ds12_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
if (lis2ds12_update(sensor))
|
||||
{
|
||||
printf("lis2ds12_update() failed\n");
|
||||
lis2ds12_close(sensor);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lis2ds12_get_accelerometer(sensor, &x, &y, &z);
|
||||
printf("Acceleration x: %f y: %f z: %f g\n",
|
||||
x, y, z);
|
||||
|
||||
printf("Compensation Temperature: %f C\n\n",
|
||||
lis2ds12_get_temperature(sensor));
|
||||
|
||||
upm_delay_ms(250);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
lis2ds12_close(sensor);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
104
examples/c/lsm6ds3h.c
Normal file
104
examples/c/lsm6ds3h.c
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "lsm6ds3h.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
#if defined(CONFIG_BOARD_ARDUINO_101_SSS)
|
||||
// ARDUINO_101_SSS (ARC core) must use I2C
|
||||
// Instantiate a LSM6DS3H instance using default i2c bus and address
|
||||
lsm6ds3h_context sensor = lsm6ds3h_init(LSM6DS3H_DEFAULT_I2C_BUS,
|
||||
LSM6DS3H_DEFAULT_I2C_ADDR, -1);
|
||||
#elif defined(CONFIG_BOARD_ARDUINO_101)
|
||||
// ARDUINO_101 (Quark core) must use SPI
|
||||
// Instantiate a LSM6DS3H instance using default SPI bus and pin 10 as CS
|
||||
lsm6ds3h_context sensor = lsm6ds3h_init(LSM6DS3H_DEFAULT_SPI_BUS,
|
||||
-1, 10);
|
||||
#else
|
||||
// everything else use I2C by default
|
||||
// Instantiate a LSM6DS3H instance using default i2c bus and address
|
||||
lsm6ds3h_context sensor = lsm6ds3h_init(LSM6DS3H_DEFAULT_I2C_BUS,
|
||||
LSM6DS3H_DEFAULT_I2C_ADDR, -1);
|
||||
#endif
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("lsm6ds3h_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
if (lsm6ds3h_update(sensor))
|
||||
{
|
||||
printf("lsm6ds3h_update() failed\n");
|
||||
lsm6ds3h_close(sensor);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lsm6ds3h_get_accelerometer(sensor, &x, &y, &z);
|
||||
printf("Acceleration x: %f y: %f z: %f g\n",
|
||||
x, y, z);
|
||||
|
||||
lsm6ds3h_get_gyroscope(sensor, &x, &y, &z);
|
||||
printf("Gyroscope x: %f y: %f z: %f dps\n",
|
||||
x, y, z);
|
||||
|
||||
printf("Compensation Temperature: %f C\n\n",
|
||||
lsm6ds3h_get_temperature(sensor));
|
||||
|
||||
upm_delay_ms(250);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
lsm6ds3h_close(sensor);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
104
examples/c/lsm6dsl.c
Normal file
104
examples/c/lsm6dsl.c
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "lsm6dsl.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
#if defined(CONFIG_BOARD_ARDUINO_101_SSS)
|
||||
// ARDUINO_101_SSS (ARC core) must use I2C
|
||||
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_I2C_BUS,
|
||||
LSM6DSL_DEFAULT_I2C_ADDR, -1);
|
||||
#elif defined(CONFIG_BOARD_ARDUINO_101)
|
||||
// ARDUINO_101 (Quark core) must use SPI
|
||||
// Instantiate a LSM6DSL instance using default SPI bus and pin 10 as CS
|
||||
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_SPI_BUS,
|
||||
-1, 10);
|
||||
#else
|
||||
// everything else use I2C by default
|
||||
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_I2C_BUS,
|
||||
LSM6DSL_DEFAULT_I2C_ADDR, -1);
|
||||
#endif
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("lsm6dsl_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
if (lsm6dsl_update(sensor))
|
||||
{
|
||||
printf("lsm6dsl_update() failed\n");
|
||||
lsm6dsl_close(sensor);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lsm6dsl_get_accelerometer(sensor, &x, &y, &z);
|
||||
printf("Acceleration x: %f y: %f z: %f g\n",
|
||||
x, y, z);
|
||||
|
||||
lsm6dsl_get_gyroscope(sensor, &x, &y, &z);
|
||||
printf("Gyroscope x: %f y: %f z: %f dps\n",
|
||||
x, y, z);
|
||||
|
||||
printf("Compensation Temperature: %f C\n\n",
|
||||
lsm6dsl_get_temperature(sensor));
|
||||
|
||||
upm_delay_ms(250);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
lsm6dsl_close(sensor);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -33,7 +33,7 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
veml6070_context dev = veml6070_init(0, VEML6070_CTRL_REG);
|
||||
veml6070_context dev = veml6070_init(0);
|
||||
if(dev == NULL) {
|
||||
printf("Unable to initialize sensor\n");
|
||||
return 0;
|
||||
|
46
examples/java/BMA220Sample.java
Normal file
46
examples/java/BMA220Sample.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class BMA220Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate an BMA220 using default parameters (bus 0, addr 0x0a)
|
||||
upm_bma220.BMA220 sensor = new upm_bma220.BMA220();
|
||||
|
||||
while (true) {
|
||||
float acc[];
|
||||
|
||||
sensor.update();
|
||||
acc = sensor.getAccelerometer();
|
||||
System.out.print("Accelerometer: ");
|
||||
System.out.println("AX: " + acc[0] + "AY: " + acc[1] + "AZ: " + acc[2]);
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
import upm_bma250e.BMA250E;
|
||||
import java.util.AbstractList;
|
||||
import java.lang.Float;
|
||||
|
||||
public class BMA250E_Example
|
||||
{
|
||||
@ -42,7 +44,7 @@ public class BMA250E_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
upm_bma250e.floatVector dataA = sensor.getAccelerometer();
|
||||
AbstractList<Float> dataA = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + dataA.get(0)
|
||||
+ " y: " + dataA.get(1)
|
||||
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
|
||||
import upm_bmx055.BMC150;
|
||||
import java.util.AbstractList;
|
||||
import java.lang.Float;
|
||||
|
||||
public class BMC150_Example
|
||||
{
|
||||
@ -40,7 +42,7 @@ public class BMC150_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
upm_bmx055.floatVector data = sensor.getAccelerometer();
|
||||
AbstractList<Float> data = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
|
@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
import upm_bmg160.BMG160;
|
||||
import java.util.AbstractList;
|
||||
import java.lang.Float;
|
||||
|
||||
public class BMG160_Example
|
||||
{
|
||||
@ -42,7 +44,7 @@ public class BMG160_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
upm_bmg160.floatVector data = sensor.getGyroscope();
|
||||
AbstractList<Float> data = sensor.getGyroscope();
|
||||
|
||||
System.out.println("Gyroscope x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
|
||||
import upm_bmx055.BMI055;
|
||||
import java.util.AbstractList;
|
||||
import java.lang.Float;
|
||||
|
||||
public class BMI055_Example
|
||||
{
|
||||
@ -40,7 +42,7 @@ public class BMI055_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
upm_bmx055.floatVector data = sensor.getAccelerometer();
|
||||
AbstractList<Float> data = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
|
||||
import upm_bmm150.BMM150;
|
||||
import java.util.AbstractList;
|
||||
import java.lang.Float;
|
||||
|
||||
public class BMM150_Example
|
||||
{
|
||||
@ -44,7 +46,7 @@ public class BMM150_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
upm_bmm150.floatVector data = sensor.getMagnetometer();
|
||||
AbstractList<Float> data = sensor.getMagnetometer();
|
||||
|
||||
System.out.println("Magnetometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
|
||||
import upm_bmx055.BMX055;
|
||||
import java.util.AbstractList;
|
||||
import java.lang.Float;
|
||||
|
||||
public class BMX055_Example
|
||||
{
|
||||
@ -40,7 +42,7 @@ public class BMX055_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
upm_bmx055.floatVector data = sensor.getAccelerometer();
|
||||
AbstractList<Float> data = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
|
@ -190,6 +190,9 @@ add_example(LSM303AGR_Example lsm303agr)
|
||||
add_example(LSM303D_Example lsm303d)
|
||||
add_example(VEML6070Sample veml6070)
|
||||
add_example(RN2903_Example rn2903)
|
||||
add_example(LIS2DS12_Example lis2ds12)
|
||||
add_example(LSM6DS3H_Example lsm6ds3h)
|
||||
add_example(LSM6DSL_Example lsm6dsl)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample jhd1313m1 jhd1313m1)
|
||||
add_example_with_path(Jhd1313m1Sample jhd1313m1 jhd1313m1)
|
||||
|
49
examples/java/DFRPHSample.java
Normal file
49
examples/java/DFRPHSample.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class DFRPHSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a DFRPH sensor on analog pin A0, with an analog
|
||||
// reference voltage of 5.0 V
|
||||
upm_dfrph.DFRPH sensor = new upm_dfrph.DFRPH(0, 5.0f);
|
||||
|
||||
// After calibration, set the offset (based on calibration with a pH
|
||||
// 7.0 buffer solution). See the UPM sensor documentation for
|
||||
// calibrations instructions.
|
||||
sensor.setOffset(0.065f);
|
||||
|
||||
// Every second, sample the pH and output it's corresponding
|
||||
// analog voltage.
|
||||
while (true) {
|
||||
System.out.println("Detected volts: = " + sensor.volts());
|
||||
System.out.println("pH value: " + sensor.pH());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
41
examples/java/GroveUltraSonicSample.java
Normal file
41
examples/java/GroveUltraSonicSample.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class GroveUltraSonicSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
upm_groveultrasonic.GroveUltraSonic sonar = new upm_groveultrasonic.GroveUltraSonic(2);
|
||||
|
||||
while (true) {
|
||||
int width = sonar.getDistance();
|
||||
System.out.println("Echo width = " + width);
|
||||
System.out.println("Distance inches = " + width / 148.0);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -23,17 +23,19 @@
|
||||
*/
|
||||
|
||||
//NOT TESTED!!!
|
||||
import upm_hcsr04.*;
|
||||
|
||||
public class HCSR04Sample {
|
||||
|
||||
// ! [Interesting]
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
upm_hcsr04.HCSR04 sonar = new upm_hcsr04.HCSR04((short) 5, (short) 6);
|
||||
HCSR04 sonar = new HCSR04((short) 2, (short) 4);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
while (true) {
|
||||
System.out.println("Get distance");
|
||||
double distance = sonar.getDistance(upm_hcsr04.javaupm_hcsr04Constants.CM);
|
||||
double distance = sonar.getDistance(HCSR04_U.swigToEnum(0));
|
||||
System.out.println("Distance: " + distance);
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
@ -22,29 +22,24 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//NOT TESTED!!!
|
||||
public class HTU21DSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
float humidity = 0;
|
||||
float temperature = 0;
|
||||
float compRH = 0;
|
||||
|
||||
upm_htu21d.HTU21D sensor = new upm_htu21d.HTU21D(0);
|
||||
sensor.testSensor();
|
||||
|
||||
while (true) {
|
||||
compRH = sensor.getCompRH();
|
||||
humidity = sensor.getHumidity();
|
||||
temperature = sensor.getTemperature();
|
||||
sensor.sampleData();
|
||||
|
||||
System.out.println("Humidity: " + humidity + ", Temperature: " + temperature
|
||||
+ ", compensated RH: " + compRH);
|
||||
System.out.println("Humidity: " + sensor.getHumidity() + "%");
|
||||
System.out.println("Compensated RH: " + sensor.getCompRH() + "%");
|
||||
System.out.println("Temperature: " + sensor.getTemperature() + "C");
|
||||
System.out.println("Dew Point: " + sensor.getDewPoint() + "C");
|
||||
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
47
examples/java/I2CLCD_EBOLEDSample.java
Normal file
47
examples/java/I2CLCD_EBOLEDSample.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class I2CLCD_EBOLEDSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate an Edison Block OLED using default values
|
||||
upm_i2clcd.EBOLED lcd = new upm_i2clcd.EBOLED();
|
||||
|
||||
lcd.clear();
|
||||
lcd.setCursor(10, 15);
|
||||
lcd.write("Hello");
|
||||
lcd.setCursor(30, 15);
|
||||
lcd.write("World!");
|
||||
lcd.refresh();
|
||||
|
||||
System.out.println("Sleeping for 5 secconds...");
|
||||
Thread.sleep(5000);
|
||||
|
||||
lcd.delete();
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
146
examples/java/I2CLCD_SSD1306Sample.java
Normal file
146
examples/java/I2CLCD_SSD1306Sample.java
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class I2CLCD_SSD1306Sample {
|
||||
|
||||
static private final int[] intel_logo = new int[]{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -128, -128, -128, -128, 192, 192, 192, 224,
|
||||
224, 224, 224, 240, 240, 248, 248, 120, 120, 120, 120, 60, 60, 60, 60, 60,
|
||||
62, 30, 30, 30, 30, 30, 30, 30, 31, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 31, 31, 31, 31, 31,
|
||||
30, 62, 62, 62, 62, 126, 126, 124, 124, 252, 252, 248, 248, 240, 240, 240,
|
||||
224, 224, 224, 192, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 0, 56, 56, 28, 30, 14, 15, 15, 7, 7, 7, 7, 3, 3, 1, 1, 1, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 192, 193, 195, 195,
|
||||
195, 7, 15, 15, 63, 127, 255, 255, 255, 254, 252, 252, 240, 192, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 128, 192, 192, 240, 248, 124, 124, 60, 0, 0, 0, 0, 159, 159,
|
||||
159, 159, 159, 159, 159, 159, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0,
|
||||
0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 128, 128, 128, 128,
|
||||
128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 192, 192, 192, 192, 192, 192, 128,
|
||||
128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 3, 7, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1, 255, 255, 255, 255, 255,
|
||||
255, 255, 0, 0, 224, 248, 252, 252, 255, 127, 15, 15, 3, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 15, 15, 15, 15, 15, 15, 255, 255, 255, 255, 255,
|
||||
255, 255, 252, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 15, 15,
|
||||
15, 15, 15, 224, 224, 252, 254, 255, 255, 255, 255, 159, 159, 143, 143,
|
||||
135, 135, 143, 159, 255, 255, 255, 255, 255, 255, 252, 248, 0, 0, 0, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,
|
||||
224, 248, 248, 255, 255, 255, 255, 255, 127, 15, 255, 255, 255, 255, 255,
|
||||
255, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 192, 192, 192, 192, 192, 31, 31, 255, 255, 255,
|
||||
255, 255, 255, 231, 231, 199, 199, 199, 199, 199, 199, 199, 199, 231, 231,
|
||||
231, 231, 199, 135, 0, 0, 0, 63, 255, 255, 255, 255, 255, 255, 255, 0, 0,
|
||||
0, 0, 224, 240, 248, 248, 252, 254, 255, 255, 255, 127, 63, 63, 31, 15, 7,
|
||||
7, 1, 0, 0, 63, 63, 255, 255, 255, 255, 255, 240, 192, 192, 128, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 3, 3, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 0, 0, 0, 1, 3, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7,
|
||||
7, 7, 3, 3, 3, 1, 0, 0, 0, 0, 1, 3, 3, 7, 135, 135, 135, 192, 192, 0, 0, 7,
|
||||
7, 3, 3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 15,
|
||||
31, 127, 127, 127, 255, 255, 252, 252, 252, 248, 240, 240, 240, 224, 224,
|
||||
224, 192, 192, 192, 192, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 192, 192, 192, 192, 192,
|
||||
224, 224, 224, 224, 240, 240, 240, 240, 248, 248, 248, 248, 252, 252, 252,
|
||||
254, 254, 255, 255, 255, 255, 255, 255, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
3, 3, 3, 7, 7, 7, 15, 15, 31, 31, 31, 63, 63, 63, 63, 63, 127, 127, 127,
|
||||
127, 127, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||
255, 255, 255, 255, 255, 255, 255, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||
63, 63, 63, 63, 63, 31, 31, 31, 31, 31, 15, 15, 15, 15, 7, 7, 7, 7, 3, 3,
|
||||
3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
upm_i2clcd.SSD1306 lcd = new upm_i2clcd.SSD1306(0x0, 0x3D);
|
||||
|
||||
byte[] image = new byte[intel_logo.length];
|
||||
for (int i = 0; i < intel_logo.length; i++)
|
||||
image[i] = (byte) intel_logo[i];
|
||||
|
||||
lcd.clear();
|
||||
lcd.stopscroll();
|
||||
lcd.draw(image);
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
lcd.clear();
|
||||
lcd.setCursor(2, 0);
|
||||
lcd.write("Hello");
|
||||
lcd.setCursor(3,0);
|
||||
lcd.write("World");
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
lcd.invert(true);
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
lcd.dim(true);
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
lcd.dim(false);
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
lcd.invert(false);
|
||||
lcd.startscrollright((short) 0x00, (short) 0x0F);
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
lcd.stopscroll();
|
||||
lcd.startscrollleft((short) 0x00, (short) 0x0F);
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
lcd.stopscroll();
|
||||
lcd.startscrolldiagleft((short) 0x00, (short) 0x0F);
|
||||
|
||||
Thread.sleep(5000);;
|
||||
|
||||
lcd.stopscroll();
|
||||
lcd.startscrolldiagright((short) 0x00,(short) 0x0F);
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
lcd.stopscroll();
|
||||
|
||||
lcd.delete();
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
64
examples/java/LIS2DS12_Example.java
Normal file
64
examples/java/LIS2DS12_Example.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_lis2ds12.*;
|
||||
|
||||
public class LIS2DS12_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a LIS2DS12 instance using default i2c bus and address
|
||||
LIS2DS12 sensor = new LIS2DS12();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// LIS2DS12(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
floatVector dataA = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + dataA.get(0)
|
||||
+ " y: " + dataA.get(1)
|
||||
+ " z: " + dataA.get(2)
|
||||
+ " g");
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
43
examples/java/LM35Sample.java
Normal file
43
examples/java/LM35Sample.java
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class LM35Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a LM35 on analog pin A0, with a default analog
|
||||
// reference voltage of 5.0
|
||||
upm_lm35.LM35 sensor = new upm_lm35.LM35(0);
|
||||
|
||||
// Every half second, sample the sensor and output the temperature
|
||||
|
||||
while (true) {
|
||||
System.out.println("Temperature: " + sensor.getTemperature() + " C");
|
||||
Thread.sleep(500);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
|
||||
import upm_lsm303agr.LSM303AGR;
|
||||
import java.util.AbstractList;
|
||||
import java.lang.Float;
|
||||
|
||||
public class LSM303AGR_Example
|
||||
{
|
||||
@ -40,7 +42,7 @@ public class LSM303AGR_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
upm_lsm303agr.floatVector data = sensor.getAccelerometer();
|
||||
AbstractList<Float> data = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
|
||||
import upm_lsm303d.LSM303D;
|
||||
import java.util.AbstractList;
|
||||
import java.lang.Float;
|
||||
|
||||
public class LSM303D_Example
|
||||
{
|
||||
@ -40,7 +42,7 @@ public class LSM303D_Example
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
upm_lsm303d.floatVector data = sensor.getAccelerometer();
|
||||
AbstractList<Float> data = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
|
71
examples/java/LSM6DS3H_Example.java
Normal file
71
examples/java/LSM6DS3H_Example.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_lsm6ds3h.*;
|
||||
|
||||
public class LSM6DS3H_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a LSM6DS3H instance using default i2c bus and address
|
||||
LSM6DS3H sensor = new LSM6DS3H();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// LSM6DS3H(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
floatVector data = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " g");
|
||||
|
||||
data = sensor.getGyroscope();
|
||||
|
||||
System.out.println("Gyroscope x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " dps");
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
71
examples/java/LSM6DSL_Example.java
Normal file
71
examples/java/LSM6DSL_Example.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_lsm6dsl.*;
|
||||
|
||||
public class LSM6DSL_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||
LSM6DSL sensor = new LSM6DSL();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// LSM6DSL(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
floatVector data = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " g");
|
||||
|
||||
data = sensor.getGyroscope();
|
||||
|
||||
System.out.println("Gyroscope x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " dps");
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
59
examples/java/LSM9DS0Sample.java
Normal file
59
examples/java/LSM9DS0Sample.java
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class LSM9DS0Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting
|
||||
|
||||
// Instantiate an LSM9DS0 using default parameters (bus 1, gyro addr 6b,
|
||||
// xm addr 1d)
|
||||
|
||||
upm_lsm9ds0.LSM9DS0 sensor = new upm_lsm9ds0.LSM9DS0();
|
||||
|
||||
sensor.init();
|
||||
|
||||
while (true) {
|
||||
sensor.update();
|
||||
|
||||
float[] accel = sensor.getAccelerometer();
|
||||
System.out.println("Accelerometer: ");
|
||||
System.out.println("AX: " + accel[0] + "; AY: " + accel[1] + "; AZ: " + accel[2]);
|
||||
|
||||
float[] gyro = sensor.getGyroscope();
|
||||
System.out.println("Gyroscope: ");
|
||||
System.out.println("GX: " + gyro[0] + "; GY: " + gyro[1] + "; GZ: " + gyro[2]);
|
||||
|
||||
float[] magnet = sensor.getMagnetometer();
|
||||
System.out.println("Magnetometer: ");
|
||||
System.out.println("MX: " + magnet[0] + "; MY: " + magnet[1] + "; MZ: " + magnet[2]);
|
||||
|
||||
System.out.println("Temperature: " + sensor.getTemperature());
|
||||
|
||||
Thread.sleep(500);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
42
examples/java/LoudnessSample.java
Normal file
42
examples/java/LoudnessSample.java
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class LoudnessSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// Instantiate a Loudness sensor on analog pin A0, with an analog
|
||||
// reference voltage of 5.0V
|
||||
upm_loudness.Loudness loud = new upm_loudness.Loudness(0, (float) 5.0);
|
||||
|
||||
// Every tenth of a second, sample the loudness and output it's
|
||||
// corresponding analog voltage.
|
||||
|
||||
while (true) {
|
||||
System.out.println("Detected loudness (volts): " + loud.loudness());
|
||||
Thread.sleep(100);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
216
examples/java/MCP9808Sample.java
Normal file
216
examples/java/MCP9808Sample.java
Normal file
@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import java.io.*;
|
||||
import upm_mcp9808.MCP9808;
|
||||
|
||||
public class MCP9808Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException, IOException {
|
||||
// ! [Interesting]
|
||||
|
||||
int command;
|
||||
upm_mcp9808.MCP9808 temp = new upm_mcp9808.MCP9808(6);
|
||||
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
do {
|
||||
System.out.println("1 - read temp");
|
||||
System.out.println("2 - sleep mode");
|
||||
System.out.println("3 - wake up");
|
||||
System.out.println("4 - set mode to " + (temp.isCelsius() == true ? "Fahrenheit" : "Celsius"));
|
||||
System.out.println("5 - show status bits");
|
||||
System.out.println("6 - Set Tcrit");
|
||||
System.out.println("7 - Set Tupper");
|
||||
System.out.println("8 - Set Tlower");
|
||||
System.out.println("9 - Display monitor temps");
|
||||
System.out.println("10 - Enable alert default");
|
||||
System.out.println("11 - Enable alert interrupt");
|
||||
System.out.println("12 - Clear interrupt");
|
||||
System.out.println("13 - Clear alert mode");
|
||||
System.out.println("14 - Get Hysteresis");
|
||||
System.out.println("15 - Set Hysteresis");
|
||||
System.out.println("16 - Get Resolution");
|
||||
System.out.println("17 - Set Resolution");
|
||||
System.out.println("18 - Get Manufacturer ID");
|
||||
System.out.println("19 - Get Device ID");
|
||||
System.out.println("-1 - exit");
|
||||
System.out.print("Enter a command:");
|
||||
|
||||
try {
|
||||
command = Integer.parseInt(read.readLine());
|
||||
} catch (Exception e) {
|
||||
System.err.println("Not valid command");
|
||||
command = -1;
|
||||
}
|
||||
|
||||
float t;
|
||||
switch (command) {
|
||||
case 1:
|
||||
System.out.println("Temp: " + temp.getTemp() + " degrees " + (temp.isCelsius() ? "Celsius" : "Fahrenheit"));
|
||||
break;
|
||||
case 2:
|
||||
System.out.println("shutdown sensor (sleep mode)");
|
||||
temp.shutDown();
|
||||
break;
|
||||
case 3:
|
||||
System.out.println("wake up sensor");
|
||||
temp.shutDown(false);
|
||||
break;
|
||||
case 4:
|
||||
System.out.println("set mode to " + (temp.isCelsius() ? "Fahrenheit" : "Celsius"));
|
||||
temp.setMode(!temp.isCelsius());
|
||||
break;
|
||||
case 5:
|
||||
System.out.println("Tcrit = " + temp.isTcrit());
|
||||
System.out.println("Tupper = " + temp.isTupper());
|
||||
System.out.println("Tlower = " + temp.isTlower());
|
||||
break;
|
||||
case 6:
|
||||
System.out.print("Enter a value: ");
|
||||
try {
|
||||
t = Float.valueOf(read.readLine()).floatValue();
|
||||
} catch (Exception e) {
|
||||
System.err.println("\nNot a valid value\n");
|
||||
break;
|
||||
}
|
||||
temp.setMonitorReg(MCP9808.MCP9808_REG.CRIT_TEMP, t);
|
||||
break;
|
||||
case 7:
|
||||
System.out.print("Enter a value: ");
|
||||
try {
|
||||
t = Float.valueOf(read.readLine()).floatValue();
|
||||
} catch (Exception e) {
|
||||
System.err.println("\nNot a valid value\n");
|
||||
break;
|
||||
}
|
||||
temp.setMonitorReg(MCP9808.MCP9808_REG.UPPER_TEMP, t);
|
||||
break;
|
||||
case 8:
|
||||
System.out.print("Enter a value: ");
|
||||
try {
|
||||
t = Float.valueOf(read.readLine()).floatValue();
|
||||
} catch (Exception e) {
|
||||
System.err.println("\nNot a valid value\n");
|
||||
break;
|
||||
}
|
||||
temp.setMonitorReg(MCP9808.MCP9808_REG.LOWER_TEMP, t);
|
||||
break;
|
||||
case 9:
|
||||
System.out.println("Tcrit = " + temp.getMonitorReg(MCP9808.MCP9808_REG.CRIT_TEMP));
|
||||
System.out.println("Tupper = " + temp.getMonitorReg(MCP9808.MCP9808_REG.UPPER_TEMP));
|
||||
System.out.println("Tlower = " + temp.getMonitorReg(MCP9808.MCP9808_REG.LOWER_TEMP));
|
||||
break;
|
||||
case 10:
|
||||
System.out.println("Set alert mode default");
|
||||
temp.setAlertMode(MCP9808.MCP9808_CONFIG.ALERTCTRL.swigValue());
|
||||
break;
|
||||
case 11:
|
||||
System.out.println("Set alert mode interrupt");
|
||||
temp.setAlertMode(
|
||||
MCP9808.MCP9808_CONFIG.ALERTMODE.swigValue() | MCP9808.MCP9808_CONFIG.ALERTCTRL.swigValue());
|
||||
break;
|
||||
case 12:
|
||||
temp.clearInterrupt();
|
||||
break;
|
||||
case 13:
|
||||
System.out.println("Clear alerts");
|
||||
temp.clearAlertMode();
|
||||
break;
|
||||
case 14:
|
||||
System.out.println("Hysteresis: " + temp.getHysteresis());
|
||||
break;
|
||||
case 15:
|
||||
int u;
|
||||
System.out.print("Enter 1 to 4: ");
|
||||
try {
|
||||
u = Integer.parseInt(read.readLine());
|
||||
} catch (Exception e) {
|
||||
System.err.println("\nNot a valid command\n");
|
||||
break;
|
||||
}
|
||||
switch (u) {
|
||||
case 1:
|
||||
temp.setHysteresis(MCP9808.MCP9808_CONFIG.HYST_0);
|
||||
break;
|
||||
case 2:
|
||||
temp.setHysteresis(MCP9808.MCP9808_CONFIG.HYST_1_5);
|
||||
break;
|
||||
case 3:
|
||||
temp.setHysteresis(MCP9808.MCP9808_CONFIG.HYST_3_0);
|
||||
break;
|
||||
case 4:
|
||||
temp.setHysteresis(MCP9808.MCP9808_CONFIG.HYST_6_0);
|
||||
break;
|
||||
default:
|
||||
System.out.println("\nNot a valid option\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
System.out.println("Resolution: " + temp.getResolution());
|
||||
break;
|
||||
case 17:
|
||||
int v;
|
||||
System.out.print("Enter 1 to 4: ");
|
||||
try {
|
||||
v = Integer.parseInt(read.readLine());
|
||||
} catch (Exception e) {
|
||||
System.err.println("\nNot a valid command\n");
|
||||
break;
|
||||
}
|
||||
switch (v) {
|
||||
case 1:
|
||||
temp.setResolution(MCP9808.MCP9808_RESOLUTION.RES_LOW);
|
||||
break;
|
||||
case 2:
|
||||
temp.setResolution(MCP9808.MCP9808_RESOLUTION.RES_MEDIUM);
|
||||
break;
|
||||
case 3:
|
||||
temp.setResolution(MCP9808.MCP9808_RESOLUTION.RES_HIGH);
|
||||
break;
|
||||
case 4:
|
||||
temp.setResolution(MCP9808.MCP9808_RESOLUTION.RES_PRECISION);
|
||||
break;
|
||||
default:
|
||||
System.out.println("\nNot a valid option\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
System.out.println("Manufacturer ID: " + temp.getManufacturer());
|
||||
break;
|
||||
case 19:
|
||||
System.out.println("Get device ID: " + temp.getDevicedId());
|
||||
break;
|
||||
case -1:
|
||||
break;
|
||||
default:
|
||||
System.out.println("That option is not available. Try again");
|
||||
break;
|
||||
}
|
||||
} while (command != -1);
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
|
44
examples/java/MG811Sample.java
Normal file
44
examples/java/MG811Sample.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MG811Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate an MG811 on analog pin A0, and digital pin D2 with an
|
||||
// analog reference voltage of 5.0V
|
||||
upm_mg811.MG811 sensor = new upm_mg811.MG811(0, 2, (float) 5.0);
|
||||
|
||||
// Every tenth of a second, sample the sensor and output it's
|
||||
// detected CO2 concentration in parts per million (ppm)
|
||||
|
||||
while (true) {
|
||||
System.out.println("CO2 concentration in PPM: " + sensor.ppm());
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
56
examples/java/MQ4Sample.java
Normal file
56
examples/java/MQ4Sample.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MQ4Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
short[] buffer = new short[128];
|
||||
|
||||
// Attach gas sensor to A0
|
||||
upm_gas.MQ4 sensor = new upm_gas.MQ4(0);
|
||||
|
||||
upm_gas.thresholdContext ctx = new upm_gas.thresholdContext();
|
||||
ctx.setAverageReading(0);
|
||||
ctx.setRunningAverage(0);
|
||||
ctx.setAveragedOver(2);
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asterisks as averages
|
||||
while (true) {
|
||||
int len = sensor.getSampledWindow(2, buffer);
|
||||
|
||||
if (len != 0) {
|
||||
int thresh = sensor.findThreshold(ctx, 30, buffer);
|
||||
sensor.printGraph(ctx, (short) 5);
|
||||
if (thresh != 0) {
|
||||
// do something...
|
||||
}
|
||||
}
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
56
examples/java/MQ6Sample.java
Normal file
56
examples/java/MQ6Sample.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MQ6Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
short[] buffer = new short[128];
|
||||
|
||||
// Attach gas sensor to A0
|
||||
upm_gas.MQ6 sensor = new upm_gas.MQ6(0);
|
||||
|
||||
upm_gas.thresholdContext ctx = new upm_gas.thresholdContext();
|
||||
ctx.setAverageReading(0);
|
||||
ctx.setRunningAverage(0);
|
||||
ctx.setAveragedOver(2);
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asterisks as averages
|
||||
while (true) {
|
||||
int len = sensor.getSampledWindow(2, buffer);
|
||||
|
||||
if (len != 0) {
|
||||
int thresh = sensor.findThreshold(ctx, 30, buffer);
|
||||
sensor.printGraph(ctx, (short) 5);
|
||||
if (thresh != 0) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
57
examples/java/MQ7Sample.java
Normal file
57
examples/java/MQ7Sample.java
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MQ7Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
short[] buffer = new short[128];
|
||||
|
||||
// Attach gas sensor to A0
|
||||
upm_gas.MQ7 sensor = new upm_gas.MQ7(0);
|
||||
|
||||
upm_gas.thresholdContext ctx = new upm_gas.thresholdContext();
|
||||
ctx.setAverageReading(0);
|
||||
ctx.setRunningAverage(0);
|
||||
ctx.setAveragedOver(2);
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asterisks as averages
|
||||
|
||||
while (true) {
|
||||
int len = sensor.getSampledWindow(2, buffer);
|
||||
|
||||
if (len != 0) {
|
||||
int thresh = sensor.findThreshold(ctx, 30, buffer);
|
||||
sensor.printGraph(ctx, (short) 5);
|
||||
if (thresh != 0) {
|
||||
// do something...
|
||||
}
|
||||
}
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
56
examples/java/MQ8Sample.java
Normal file
56
examples/java/MQ8Sample.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MQ8Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
short[] buffer = new short[128];
|
||||
|
||||
// Attach gas sensor to A0
|
||||
upm_gas.MQ8 sensor = new upm_gas.MQ8(0);
|
||||
|
||||
upm_gas.thresholdContext ctx = new upm_gas.thresholdContext();
|
||||
ctx.setAverageReading(0);
|
||||
ctx.setRunningAverage(0);
|
||||
ctx.setAveragedOver(2);
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of asterisks as averages
|
||||
while (true) {
|
||||
int len = sensor.getSampledWindow(2, buffer);
|
||||
|
||||
if (len != 0) {
|
||||
int thresh = sensor.findThreshold(ctx, 30, buffer);
|
||||
sensor.printGraph(ctx, (short) 5);
|
||||
if (thresh != 0) {
|
||||
// do something...
|
||||
}
|
||||
}
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
44
examples/java/NLGPIO16Sample.java
Normal file
44
examples/java/NLGPIO16Sample.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class NLGPIO16Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a NLGPIO16 Module on the default UART (/dev/ttyACM0)
|
||||
upm_nlgpio16.NLGPIO16 sensor = new upm_nlgpio16.NLGPIO16();
|
||||
|
||||
// get the Version
|
||||
System.out.println("Device Version: " + sensor.getVersion());
|
||||
// read the gpio at pin 3
|
||||
System.out.println("GPIO 3 Value: " + sensor.gpioRead(3));
|
||||
// read the analog voltage at pin 5
|
||||
System.out.println("Analog 5 Voltage: " + sensor.analogReadVolts(5));
|
||||
// set the gpio at pin 14 to HIGH
|
||||
sensor.gpioSet(14);
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
76
examples/java/PN532Sample.java
Normal file
76
examples/java/PN532Sample.java
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class PN532Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// Instantiate an PN532 on I2C bus 0 (default) using gpio 3 for the
|
||||
// IRQ, and gpio 2 for the reset pin.
|
||||
|
||||
upm_pn532.PN532 nfc = new upm_pn532.PN532(3, 2);
|
||||
|
||||
if (!nfc.init())
|
||||
System.out.println("init() failed");
|
||||
|
||||
long vers = nfc.getFirmwareVersion();
|
||||
|
||||
if (vers != 0)
|
||||
System.out.println("Got firmware version: " + String.format("0x%08x", vers));
|
||||
else {
|
||||
System.out.println("Could not identify PN532\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Now scan and identify any cards that come in range (1 for now)
|
||||
|
||||
// Retry forever
|
||||
nfc.setPassiveActivationRetries((short) 0xff);
|
||||
|
||||
nfc.SAMConfig();
|
||||
|
||||
short[] uidSize = new short[1];
|
||||
byte[] uid = new byte[7];
|
||||
|
||||
while (true) {
|
||||
if (nfc.readPassiveTargetID(PN532.BAUD_T.BAUD_MIFARE_ISO14443A, uid, uidSize, 2000)) {
|
||||
// found a card
|
||||
System.out.println("Found a card: UID len " + uidSize[0]);
|
||||
System.out.print("UID: ");
|
||||
|
||||
for (int i = 0; i < uidSize[0]; i++)
|
||||
System.out.print(String.format("%02x", uid[i]) + " ");
|
||||
|
||||
System.out.println("\nSAK: " + String.format("0x%02x", nfc.getSAK()));
|
||||
System.out.println("ATQA: " + String.format("0x%04x\n\n", nfc.getATQA()));
|
||||
|
||||
Thread.sleep(1000);
|
||||
} else {
|
||||
System.out.println("Waiting for a card...");
|
||||
}
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
97
examples/java/PN532_writeurlSample.java
Normal file
97
examples/java/PN532_writeurlSample.java
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// NOT TESTED!!!
|
||||
public class PN532_writeurlSample {
|
||||
|
||||
static private final String url = "iotdk.intel.com";
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// Instantiate an PN532 on I2C bus 0 (default) using gpio 3 for the
|
||||
// IRQ, and gpio 2 for the reset pin.
|
||||
|
||||
upm_pn532.PN532 nfc = new upm_pn532.PN532(3, 2);
|
||||
|
||||
if (!nfc.init())
|
||||
System.out.println("init() failed");
|
||||
|
||||
long vers = nfc.getFirmwareVersion();
|
||||
|
||||
if (vers != 0)
|
||||
System.out.println("Got firmware version: " + String.format("0x%08x", vers));
|
||||
else {
|
||||
System.out.println("Could not identify PN532\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Now scan and identify any cards that come in range (1 for now)
|
||||
|
||||
// Retry forever
|
||||
nfc.setPassiveActivationRetries((short) 0xff);
|
||||
|
||||
nfc.SAMConfig();
|
||||
|
||||
short[] uidSize = new short[1];
|
||||
byte[] uid = new byte[7];
|
||||
|
||||
boolean foundCard = false;
|
||||
while (!foundCard) {
|
||||
if (nfc.readPassiveTargetID(PN532.BAUD_T.BAUD_MIFARE_ISO14443A, uid, uidSize, 2000)) {
|
||||
// found a card
|
||||
System.out.println("Found a card: UID len " + uidSize[0]);
|
||||
System.out.print("UID: ");
|
||||
|
||||
for (int i = 0; i < uidSize[0]; i++)
|
||||
System.out.print(String.format("%02x", uid[i]) + " ");
|
||||
|
||||
System.out.println("\nSAK: " + String.format("0x%02x", nfc.getSAK()));
|
||||
System.out.println("ATQA: " + String.format("0x%04x\n\n", nfc.getATQA()));
|
||||
|
||||
foundCard = true;
|
||||
} else {
|
||||
System.out.println("Waiting for a card...");
|
||||
}
|
||||
}
|
||||
|
||||
if (uidSize[0] != 7) {
|
||||
System.out.println("This example will only write an NDEF URI to preformatted");
|
||||
System.out.println("Mifare Ultralight or NTAG2XX tags\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 48 bytes is maximum data area on ultralight cards, so we use that
|
||||
// as the maximum datasize here. Obviously if you have a bigger
|
||||
// card, you can write more data.
|
||||
if (!nfc.ntag2xx_WriteNDEFURI(PN532.NDEF_URI_T.NDEF_URIPREFIX_HTTP, url, (short) 48)) {
|
||||
// failure
|
||||
System.out.println("Failed to write NDEF record tag.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Success, URL record written to tag.\n");
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
60
examples/java/RHUSBSample.java
Normal file
60
examples/java/RHUSBSample.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class RHUSBSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
|
||||
String defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (args.length > 0)
|
||||
defaultDev = args[0];
|
||||
|
||||
System.out.println("Using device " + defaultDev);
|
||||
System.out.println("Initializing...");
|
||||
|
||||
// Instantiate an RHUSB instance on defaultDev
|
||||
upm_rhusb.RHUSB sensor = new upm_rhusb.RHUSB(defaultDev);
|
||||
|
||||
// output the firmware ID
|
||||
System.out.println("Firmware ID: " + sensor.getFirmwareID());
|
||||
|
||||
// update and print available values every second
|
||||
while (true) {
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
System.out.println("Temperature: " + sensor.getTemperature() + " C / " + sensor.getTemperature(true) + " F");
|
||||
|
||||
System.out.println("Humidity: " + sensor.getHumidity() + " %");
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ public class VEML6070Sample {
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a VEML6070 UV sensor
|
||||
VEML6070 veml = new VEML6070(0, 0x38);
|
||||
VEML6070 veml = new VEML6070(0);
|
||||
|
||||
while(true){
|
||||
System.out.println("UV Value: "+veml.getUVIntensity());
|
||||
|
45
examples/java/WheelEncoderSample.java
Normal file
45
examples/java/WheelEncoderSample.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class WheelEncoderSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// Instantiate a DFRobot Wheel Encoder on digital pin D2
|
||||
upm_wheelencoder.WheelEncoder sensor = new upm_wheelencoder.WheelEncoder(2);
|
||||
|
||||
// set the counter to 0 and start counting
|
||||
sensor.clearCounter();
|
||||
sensor.startCounter();
|
||||
|
||||
while (true) {
|
||||
// output milliseconds passed and current sensor count
|
||||
System.out.println("Millis: " + sensor.getMillis() + "; Count: " + sensor.counter());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
|
41
examples/javascript/hcsr04.js
Normal file
41
examples/javascript/hcsr04.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var HCSR04 = require('jsupm_hcsr04');
|
||||
|
||||
// Instantiate a HCSR04 ultrasonic distance sensor on digital pins D2 and D4
|
||||
var myHCSR04 = new HCSR04.HCSR04(2, 4);
|
||||
|
||||
// Check every second for the presence of a magnetic field (south polarity)
|
||||
setInterval(function()
|
||||
{
|
||||
console.log("Distance: " + myHCSR04.getDistance(0));
|
||||
}, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
65
examples/javascript/lis2ds12.js
Normal file
65
examples/javascript/lis2ds12.js
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_lis2ds12');
|
||||
|
||||
// Instantiate a LIS2DS12 instance using default i2c bus and address
|
||||
var sensor = new sensorObj.LIS2DS12();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// LIS2DS12(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
var data = sensor.getAccelerometer();
|
||||
console.log("Accelerometer x: "
|
||||
+ data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " g");
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
72
examples/javascript/lsm6ds3h.js
Normal file
72
examples/javascript/lsm6ds3h.js
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_lsm6ds3h');
|
||||
|
||||
// Instantiate a LSM6DS3H instance using default i2c bus and address
|
||||
var sensor = new sensorObj.LSM6DS3H();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// LSM6DS3H(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
var data = sensor.getAccelerometer();
|
||||
console.log("Accelerometer x: "
|
||||
+ data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " g");
|
||||
|
||||
data = sensor.getGyroscope();
|
||||
console.log("Gyroscope x: "
|
||||
+ data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " dps");
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
72
examples/javascript/lsm6dsl.js
Normal file
72
examples/javascript/lsm6dsl.js
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_lsm6dsl');
|
||||
|
||||
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||
var sensor = new sensorObj.LSM6DSL();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// LSM6DSL(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
var data = sensor.getAccelerometer();
|
||||
console.log("Accelerometer x: "
|
||||
+ data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " g");
|
||||
|
||||
data = sensor.getGyroscope();
|
||||
console.log("Gyroscope x: "
|
||||
+ data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " dps");
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
@ -25,7 +25,7 @@
|
||||
var veml6070 = require("jsupm_veml6070");
|
||||
|
||||
// Instantiate a Vishay UV sensor at bus 0
|
||||
var veml6070_sensor = new veml6070.VEML6070(0, 0x38);
|
||||
var veml6070_sensor = new veml6070.VEML6070(0);
|
||||
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
|
52
examples/python/hcsr04.py
Normal file
52
examples/python/hcsr04.py
Normal file
@ -0,0 +1,52 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||
# Copyright (c) 2017 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_hcsr04 as hcsr04
|
||||
|
||||
def main():
|
||||
# Instantiate a HCSR04 Distance sensor on digital pins 2 and 4
|
||||
hcsr04_sensor = hcsr04.HCSR04(2, 4);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# Read the value every second and detect the pressure
|
||||
while(1):
|
||||
print("Distance: {0}".format(hcsr04_sensor.getDistance(hcsr04.HCSR04_CM)))
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
68
examples/python/lis2ds12.py
Executable file
68
examples/python/lis2ds12.py
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016-2017 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_lis2ds12 as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a BMP250E instance using default i2c bus and address
|
||||
sensor = sensorObj.LIS2DS12()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# LIS2DS12(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
data = sensor.getAccelerometer()
|
||||
print("Accelerometer x:", data[0], end=' ')
|
||||
print(" y:", data[1], end=' ')
|
||||
print(" z:", data[2], end=' ')
|
||||
print(" g")
|
||||
|
||||
# we show both C and F for temperature
|
||||
print("Compensation Temperature:", sensor.getTemperature(), "C /", end=' ')
|
||||
print(sensor.getTemperature(True), "F")
|
||||
|
||||
print()
|
||||
time.sleep(.250)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
74
examples/python/lsm6ds3h.py
Executable file
74
examples/python/lsm6ds3h.py
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016-2017 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_lsm6ds3h as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a BMP250E instance using default i2c bus and address
|
||||
sensor = sensorObj.LSM6DS3H()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# LSM6DS3H(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
data = sensor.getAccelerometer()
|
||||
print("Accelerometer x:", data[0], end=' ')
|
||||
print(" y:", data[1], end=' ')
|
||||
print(" z:", data[2], end=' ')
|
||||
print(" g")
|
||||
|
||||
data = sensor.getGyroscope()
|
||||
print("Gyroscope x:", data[0], end=' ')
|
||||
print(" y:", data[1], end=' ')
|
||||
print(" z:", data[2], end=' ')
|
||||
print(" dps")
|
||||
|
||||
# we show both C and F for temperature
|
||||
print("Compensation Temperature:", sensor.getTemperature(), "C /", end=' ')
|
||||
print(sensor.getTemperature(True), "F")
|
||||
|
||||
print()
|
||||
time.sleep(.250)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
74
examples/python/lsm6dsl.py
Executable file
74
examples/python/lsm6dsl.py
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016-2017 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_lsm6dsl as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a BMP250E instance using default i2c bus and address
|
||||
sensor = sensorObj.LSM6DSL()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# LSM6DSL(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
data = sensor.getAccelerometer()
|
||||
print("Accelerometer x:", data[0], end=' ')
|
||||
print(" y:", data[1], end=' ')
|
||||
print(" z:", data[2], end=' ')
|
||||
print(" g")
|
||||
|
||||
data = sensor.getGyroscope()
|
||||
print("Gyroscope x:", data[0], end=' ')
|
||||
print(" y:", data[1], end=' ')
|
||||
print(" z:", data[2], end=' ')
|
||||
print(" dps")
|
||||
|
||||
# we show both C and F for temperature
|
||||
print("Compensation Temperature:", sensor.getTemperature(), "C /", end=' ')
|
||||
print(sensor.getTemperature(True), "F")
|
||||
|
||||
print()
|
||||
time.sleep(.250)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -27,7 +27,7 @@ from upm import pyupm_veml6070 as veml6070
|
||||
|
||||
def main():
|
||||
# Instantiate a Vishay UV Sensor on the I2C bus 0
|
||||
veml6070_sensor = veml6070.VEML6070(0, 0x38);
|
||||
veml6070_sensor = veml6070.VEML6070(0);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
|
125
scripts/build-android.sh
Executable file
125
scripts/build-android.sh
Executable file
@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
export PKG_CONFIG_LIBDIR="$NDK_HOME/platforms/android-24/arch-x86/usr/lib:$MRAA_INSTALL_DIR/lib/pkgconfig/"
|
||||
|
||||
cmake \
|
||||
-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 \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
-DJAVA_AWT_INCLUDE_PATH=$JAVA_HOME/include \
|
||||
-DJAVA_AWT_LIBRARY=$JAVA_HOME/jre/lib/amd64/libjawt.so \
|
||||
-DJAVA_INCLUDE_PATH=$JAVA_HOME/include \
|
||||
-DJAVA_INCLUDE_PATH2=$JAVA_HOME/include/linux \
|
||||
-DJAVA_JVM_LIBRARY=$JAVA_HOME/jre/lib/amd64/server/libjvm.so \
|
||||
-DBUILDSWIGJAVA=$BUILDSWIGJAVA \
|
||||
-DBUILDSWIGNODE=$BUILDSWIGNODE \
|
||||
-DBUILDSWIGPYTHON=$BUILDSWIGPYTHON \
|
||||
-DWERROR=$WERROR \
|
||||
-H. \
|
||||
-Bbuild
|
||||
|
||||
make -j8 -Cbuild
|
||||
|
||||
# Anotate the .java src from doxygen
|
||||
find src/ -name "javaupm_*.i" > build/upm.i.list
|
||||
# TODO: install doxy port tool
|
||||
#doxyport build/upm.i.list \
|
||||
# -s src/interfaces/,src/bacnetmstp,src/bmg160,src/bma250e,src/bmm150 \
|
||||
# -m doxy/samples.mapping.txt \
|
||||
# -d build/src/ \
|
||||
# --convert-protected-to-private \
|
||||
# -o build/upm-java-files.txt \
|
||||
# -c build/compile_commands.json
|
||||
|
||||
gen_and_upload() {
|
||||
# Skip any directories without .java src files
|
||||
if [ ! -f *.java ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# Get the MRAA version string from the .pom file
|
||||
VERSION=$(ls *.pom | perl -nle 'print $2 if /^(.*)-(\d+\.\d+\.\d+)\.pom/')
|
||||
# Get the MRAA name string from the .pom file
|
||||
LIB_NAME=$(ls *.pom | perl -nle 'print $1 if /^(.*)-(\d+\.\d+\.\d+)\.pom/')
|
||||
|
||||
# Bundle upload directory
|
||||
PKG_BUNDLE_DIR=BUNDLE_DIR
|
||||
mkdir -p ${PKG_BUNDLE_DIR}
|
||||
|
||||
# Create the aar directory structure
|
||||
AAR_DIRECTORY="$LIB_NAME-$VERSION"
|
||||
mkdir -p $AAR_DIRECTORY/jni/x86
|
||||
mkdir -p $AAR_DIRECTORY/res/values
|
||||
|
||||
# Write out res/values/values.xml to the aar
|
||||
echo "${values_xml/XXX_LIBRARY/$LIB_NAME}" > $AAR_DIRECTORY/res/values/values.xml
|
||||
|
||||
# Write out AndroidManifest.xml to the aar
|
||||
_tmp_manifest=${AndroidManifest_xml/XXX_PACKAGE/$JAVA_PKG_PREFIX_DOT}
|
||||
_tmp_manifest=${_tmp_manifest/XXX_LIBRARY/$LIB_NAME}
|
||||
echo "${_tmp_manifest/XXX_VERSION/$VERSION}" > $AAR_DIRECTORY/AndroidManifest.xml
|
||||
|
||||
# Copy over the so's
|
||||
cp *.so $AAR_DIRECTORY/jni/x86
|
||||
|
||||
# Create javadoc jar
|
||||
javadoc *.java -d $LIB_NAME-javadoc
|
||||
jar cf $PKG_BUNDLE_DIR/$LIB_NAME-$VERSION-javadoc.jar $LIB_NAME-javadoc/*
|
||||
|
||||
# Create sources jar file for upload
|
||||
jar cf $PKG_BUNDLE_DIR/$LIB_NAME-$VERSION-sources.jar *.java
|
||||
|
||||
# Copy pom file
|
||||
cp $LIB_NAME-$VERSION.pom $PKG_BUNDLE_DIR
|
||||
|
||||
# Copy the java module jar to classes.jar
|
||||
cp $LIB_NAME.jar $AAR_DIRECTORY/classes.jar
|
||||
|
||||
# Create the .aar
|
||||
pushd $AAR_DIRECTORY
|
||||
jar cf ../$PKG_BUNDLE_DIR/$LIB_NAME-$VERSION.aar *
|
||||
popd
|
||||
|
||||
# Create the bundle file
|
||||
pushd $PKG_BUNDLE_DIR
|
||||
# Create the tar bundle
|
||||
jar cvf ../$LIB_NAME-$VERSION-bundle.jar *
|
||||
popd
|
||||
}
|
||||
|
||||
# Template for res/values/values.xml in aar
|
||||
values_xml='<?xml version="1.0" encoding="utf-8"?><resources><string name="app_name">XXX_LIBRARY</string></resources>'
|
||||
|
||||
# Template for AndroidManifest.xml in aar
|
||||
AndroidManifest_xml='<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="XXX_PACKAGE.XXX_LIBRARY"
|
||||
android:versionCode="1"
|
||||
android:versionName="XXX_VERSION" >
|
||||
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="25"/>
|
||||
<application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" />
|
||||
</manifest>'
|
||||
|
||||
# Package prefix
|
||||
JAVA_PKG_PREFIX_DOT="io.mraa.at.upm"
|
||||
|
||||
# Work in the UPM build directory
|
||||
cd build/src
|
||||
|
||||
# For each directory in build/src which contains a .pom file...
|
||||
for lib_dir in `ls -d */`; do
|
||||
if ls $lib_dir/upm_*.pom 1> /dev/null 2>&1; then
|
||||
pushd $lib_dir
|
||||
# Allow for spawning multiple if necessary (&)
|
||||
gen_and_upload
|
||||
popd
|
||||
fi
|
||||
done
|
35
scripts/build-doc.sh
Executable file
35
scripts/build-doc.sh
Executable file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Folders Location
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
ROOT_DIR="${DIR}/.."
|
||||
BUILD_DIR="${ROOT_DIR}/build"
|
||||
BUILD_LOGS_DIR="${BUILD_DIR}/logs"
|
||||
|
||||
# Install doxygen2jsdoc dependencies
|
||||
cd ${ROOT_DIR}/doxy/doxygen2jsdoc && npm install
|
||||
|
||||
# Install doxyport dependencies
|
||||
cd ${ROOT_DIR}/doxy/doxyport && make setup
|
||||
|
||||
# Create logs folder if not exists
|
||||
mkdir -p ${BUILD_LOGS_DIR}
|
||||
|
||||
# Make Documentation
|
||||
cd ${ROOT_DIR} && make -j8 -Cbuild 2> ${BUILD_LOGS_DIR}/build-doc.log
|
||||
|
||||
# Make Java Documentation
|
||||
cd ${BUILD_DIR} && find ../src/ -name "javaupm_*.i" > upm.i.list && \
|
||||
../doxy/doxyport/doxyport upm.i.list \
|
||||
--cmake ./compile_commands.json \
|
||||
--source ../src/interfaces/,../src/bacnetmstp \
|
||||
--destination src/ \
|
||||
--convert-protected-to-private \
|
||||
--output upm-java-files.txt \
|
||||
--mapping ../doxy/samples.mapping.txt 1> ${BUILD_LOGS_DIR}/doxyport.log && \
|
||||
rm -fr java && mkdir java && cd java && \
|
||||
doxygen ../Doxyfile-java 2> ${BUILD_LOGS_DIR}/doxygen-java.log
|
||||
|
20
scripts/run-cmake.sh
Executable file
20
scripts/run-cmake.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Run cmake
|
||||
cmake \
|
||||
-DSWIG_EXECUTABLE=/usr/bin/swig \
|
||||
-DBUILDDOC=$BUILDDOC \
|
||||
-DBUILDCPP=$BUILDCPP \
|
||||
-DBUILDFTI=$BUILDFTI \
|
||||
-DBUILDSWIGPYTHON=$BUILDSWIGPYTHON \
|
||||
-DBUILDSWIGNODE=$BUILDSWIGNODE \
|
||||
-DBUILDSWIGJAVA=$BUILDSWIGJAVA \
|
||||
-DBUILDEXAMPLES=$BUILDEXAMPLES \
|
||||
-DIPK=$IPK \
|
||||
-DRPM=$RPM \
|
||||
-DNPM=$NPM \
|
||||
-DBUILDTESTS=$BUILDTESTS \
|
||||
-DWERROR=$WERROR \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
-H. \
|
||||
-Bbuild
|
77
scripts/sonar-scan.sh
Executable file
77
scripts/sonar-scan.sh
Executable file
@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# The script is used for determining options and running a static code
|
||||
# analysis scan via SonarCloud.
|
||||
#
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# All environment variables used are passed from either Travis or docker-compose.
|
||||
# See details at https://docs.sonarqube.org/display/SONAR/Analysis+Parameters.
|
||||
#
|
||||
# Travis ones are:
|
||||
# Created by us:
|
||||
# - SONAR_ORG - SonarCloud "organization", under which the project is located.
|
||||
# - SONAR_PROJ_KEY - SonarCloud project key (name) to report to.
|
||||
# - SONAR_TOKEN - access token for that project (must be protected in Travis).
|
||||
# - GITHUB_TOKEN - GH OAuth token used by SonarCloud's GH plugin to report status in PRs.
|
||||
# See details at https://docs.sonarqube.org/display/PLUG/GitHub+Plugin. Must be protected.
|
||||
# Default:
|
||||
# - All TRAVIS_* variables. They are described in Travis docs
|
||||
# at https://docs.travis-ci.com/user/environment-variables
|
||||
#
|
||||
# docker-compose ones are:
|
||||
# - UPM_SRC_DIR - path to upm's git clone in the Docker container.
|
||||
|
||||
# Check required environment variables and exit if they are not set
|
||||
UPM_SRC_DIR=${UPM_SRC_DIR:?value not provided}
|
||||
SONAR_PROJ_KEY=${SONAR_PROJ_KEY:?value not provided}
|
||||
SONAR_ORG=${SONAR_ORG:?value not provided}
|
||||
SONAR_TOKEN=${SONAR_TOKEN:?value not provided}
|
||||
|
||||
bw_output_path="${UPM_SRC_DIR}/build/bw-output"
|
||||
|
||||
sonar_cmd_base="build-wrapper-linux-x86-64 --out-dir ${bw_output_path} make -j8 clean all && \
|
||||
sonar-scanner \
|
||||
--debug \
|
||||
-Dsonar.projectKey=${SONAR_PROJ_KEY} \
|
||||
-Dsonar.projectBaseDir=${UPM_SRC_DIR} \
|
||||
-Dsonar.sources=${UPM_SRC_DIR} \
|
||||
-Dsonar.inclusions='CMakeLists.txt,examples/**/*,include/**/*,src/**/*,tests/**/*' \
|
||||
-Dsonar.java.binaries='src' \
|
||||
-Dsonar.coverage.exclusions='**/*' \
|
||||
-Dsonar.cfamily.build-wrapper-output=${bw_output_path} \
|
||||
-Dsonar.host.url=https://sonarqube.com \
|
||||
-Dsonar.organization=${SONAR_ORG} \
|
||||
-Dsonar.login=${SONAR_TOKEN} \
|
||||
"
|
||||
|
||||
# Some useful data for logs
|
||||
echo "TRAVIS_BRANCH: ${TRAVIS_BRANCH}"
|
||||
echo "TRAVIS_PULL_REQUEST: ${TRAVIS_PULL_REQUEST}"
|
||||
echo "TRAVIS_PULL_REQUEST_SLUG: ${TRAVIS_PULL_REQUEST_SLUG}"
|
||||
echo "TRAVIS_REPO_SLUG: ${TRAVIS_REPO_SLUG}"
|
||||
|
||||
if [ "${TRAVIS_BRANCH}" == "master" -a "${TRAVIS_PULL_REQUEST}" == "false" ]; then
|
||||
# Master branch push - do a full-blown scan
|
||||
echo "Performing master branch push scan"
|
||||
sonar_cmd="${sonar_cmd_base}"
|
||||
elif [ "${TRAVIS_PULL_REQUEST}" != "false" -a "${TRAVIS_PULL_REQUEST_SLUG}" == "${TRAVIS_REPO_SLUG}" ]; then
|
||||
# Internal PR - do a preview scan with report to the PR
|
||||
${GITHUB_TOKEN:?value not provided}
|
||||
|
||||
echo "Performing internal pull request scan"
|
||||
sonar_cmd="${sonar_cmd_base} \
|
||||
-Dsonar.analysis.mode=preview \
|
||||
-Dsonar.github.pullRequest=${TRAVIS_PULL_REQUEST} \
|
||||
-Dsonar.github.repository=${TRAVIS_REPO_SLUG} \
|
||||
-Dsonar.github.oauth=${GITHUB_TOKEN} \
|
||||
"
|
||||
else
|
||||
echo "Skipping the scan - external pull request or non-master branch push"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "About to run the scan, the command is:"
|
||||
echo "${sonar_cmd}"
|
||||
|
||||
eval "${sonar_cmd}"
|
@ -83,7 +83,7 @@ function (_gen_pkg_config_per_target LABEL)
|
||||
get_target_property(libname ${target} PKG_CONFIG_NAME)
|
||||
get_target_property(libdescription ${target} PKG_CONFIG_DESCRIPTION)
|
||||
get_target_property(reqlibname ${target} PKG_EXT_REQ_LIBS)
|
||||
get_target_property(BINARY_DIR ${target} BINARY_DIR)
|
||||
get_target_property(BINARY_DIR ${target} TARGET_BINARY_DIR)
|
||||
|
||||
# Get a list of in-project dependency targets for this target
|
||||
_get_dependency_targets(${target} DEPLIBS)
|
||||
@ -127,7 +127,7 @@ function (_gen_pom_per_target)
|
||||
get_target_property(libname ${target} PKG_CONFIG_NAME)
|
||||
get_target_property(libdescription ${target} PKG_CONFIG_DESCRIPTION)
|
||||
get_target_property(reqlibname ${target} PKG_EXT_REQ_LIBS)
|
||||
get_target_property(BINARY_DIR ${target} BINARY_DIR)
|
||||
get_target_property(BINARY_DIR ${target} TARGET_BINARY_DIR)
|
||||
|
||||
# Get a list of in-project dependency targets for this target
|
||||
_get_dependency_targets(${target} DEPLIBS)
|
||||
@ -436,6 +436,9 @@ macro(upm_swig_java)
|
||||
# depend on the JAVA interfaces
|
||||
if ("${_c_cxx_dependency_list}" MATCHES interfaces)
|
||||
add_dependencies(javaupm_${libname} javaupm_interfaces)
|
||||
# If this target depends on interfaces, include the java interfaces
|
||||
# target .jar file in the classpath, otherwise this variable will be empty
|
||||
set (INTERFACES_JAR_FILE ${CMAKE_BINARY_DIR}/src/interfaces/upm_interfaces.jar)
|
||||
endif ()
|
||||
swig_link_libraries (javaupm_${libname} ${MRAAJAVA_LIBRARY} ${JAVA_LIBRARIES} ${libname})
|
||||
target_include_directories ( ${SWIG_MODULE_javaupm_${libname}_REAL_NAME}
|
||||
@ -473,14 +476,16 @@ macro(upm_swig_java)
|
||||
set (JAR $ENV{JAVA_HOME_NATIVE}/bin/jar)
|
||||
endif ()
|
||||
|
||||
# Only include the upm_interfaces.jar in the classpath for targets which
|
||||
# depend on the interfaces target. This fixes an issue where javac
|
||||
# complains about an empty upm_interfaces.jar when trying to build a target
|
||||
# which does not depend on javaupm_interfaces. If not previously set,
|
||||
# INTERFACES_JAR_FILE will be empty, and javac *should* not complain.
|
||||
add_custom_command (TARGET javaupm_${libname}
|
||||
POST_BUILD
|
||||
COMMAND cmake -E echo "Compiling java.."
|
||||
COMMAND cmake -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}
|
||||
COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR} -cp ${CMAKE_BINARY_DIR}/src/interfaces/upm_interfaces.jar:.
|
||||
|
||||
COMMAND cmake -E echo "Creating jar"
|
||||
COMMAND ${JAR} cvf upm_${libname}.jar upm_${libname}
|
||||
COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR} -cp ${INTERFACES_JAR_FILE}:.
|
||||
COMMAND ${JAR} cf upm_${libname}.jar upm_${libname}
|
||||
)
|
||||
|
||||
# Keep track of all JAVA targets
|
||||
@ -730,10 +735,11 @@ function(upm_module_init)
|
||||
endif (BUILDSWIGJAVA)
|
||||
endif (NOT IS_C_LIBRARY)
|
||||
|
||||
# Add additional properties to this target (used later for .pc file creation)
|
||||
# Add additional properties to this target (used later for .pc/pom file creation)
|
||||
set_target_properties(${libname} PROPERTIES PKG_CONFIG_NAME "${libprefix}${basename}")
|
||||
set_target_properties(${libname} PROPERTIES PKG_CONFIG_DESCRIPTION "${libdescription}")
|
||||
set_target_properties(${libname} PROPERTIES PKG_EXT_REQ_LIBS "${reqlibname}")
|
||||
set_target_properties(${libname} PROPERTIES TARGET_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
# Skip doxygen run on C (for now)
|
||||
if (BUILDDOC AND NOT IS_C_LIBRARY)
|
||||
@ -772,7 +778,7 @@ if (BUILDDOC AND BUILDSWIGPYTHON)
|
||||
# doxy2swig the doxygen output
|
||||
add_custom_target (pyupm_doxy2swig ALL
|
||||
COMMAND ${PYTHON2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py
|
||||
${CMAKE_BINARY_DIR}/xml/index.xml
|
||||
${CMAKE_BINARY_DIR}/xml/index.xml --quiet
|
||||
${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i
|
||||
DEPENDS doc)
|
||||
# BUILDDOC not set but still building python modules, generate an empty
|
||||
@ -790,28 +796,34 @@ set(UPM_TARGETS_NODEJS "" CACHE INTERNAL "List of NodeJs target names")
|
||||
set(UPM_TARGETS_PYTHON2 "" CACHE INTERNAL "List of Python2 target names")
|
||||
set(UPM_TARGETS_PYTHON3 "" CACHE INTERNAL "List of Python3 target names")
|
||||
|
||||
# Add subdirectories from MODULE_LIST if defined
|
||||
# Example -DMODULE_LIST="dfrph;rotaryencoder"
|
||||
if (MODULE_LIST)
|
||||
set(SUBDIRS ${MODULE_LIST})
|
||||
# Add interfaces directory
|
||||
set(SUBDIRS ${SUBDIRS} interfaces)
|
||||
else()
|
||||
# Otherwise, add all subdirectories
|
||||
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
# MODULE_LIST can be specified on the CMake command line to specify
|
||||
# a list of directories under src to include in the build.
|
||||
# MODULE_LIST is optional.
|
||||
# If MODULE_LIST is provided, only add the directories specified
|
||||
# If MODULE_LIST is NOT provided, add all subdirectories under src
|
||||
# Example (-DMODULE_LIST="dfrph;rotaryencoder")
|
||||
if (NOT MODULE_LIST)
|
||||
# If no module list, add all subdirectories
|
||||
subdirlist(MODULE_LIST ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# If the SUBDIRS list does NOT include the utilities directory, add it since
|
||||
# If the module list does NOT include the utilities directory, prepend it since
|
||||
# most sensor library targets depend on utilities
|
||||
if (NOT "${SUBDIRS}" MATCHES utilities)
|
||||
add_subdirectory(${CMAKE_SOURCE_DIR}/src/utilities)
|
||||
if (NOT "${MODULE_LIST}" MATCHES ";utilities;")
|
||||
set(MODULE_LIST "utilities;${MODULE_LIST}")
|
||||
endif()
|
||||
|
||||
# Iterate over each directory in SUBDIRS
|
||||
foreach(subdir ${SUBDIRS})
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt)
|
||||
add_subdirectory(${subdir})
|
||||
endif()
|
||||
# If the module list does NOT include the interfaces directory, prepend it since
|
||||
# some sensor library targets depend on interfaces
|
||||
if (NOT "${MODULE_LIST}" MATCHES ";interfaces;")
|
||||
set(MODULE_LIST "interfaces;${MODULE_LIST}")
|
||||
endif()
|
||||
|
||||
# Iterate over each directory in MODULE_LIST
|
||||
foreach(subdir ${MODULE_LIST})
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt)
|
||||
add_subdirectory(${subdir})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Print stats for all targets
|
||||
|
@ -3,8 +3,6 @@
|
||||
%module pyupm_a110x
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "a110x.hpp"
|
||||
%{
|
||||
#include "a110x.hpp"
|
||||
|
69
src/abp/abp.json
Normal file
69
src/abp/abp.json
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"Library": "abp",
|
||||
"Description": "Honeywell Basic Amplified Board mount Pressure(ABP) Sensor Library",
|
||||
"Sensor Class":
|
||||
{
|
||||
"ABP":
|
||||
{
|
||||
"Name": "Honeywell ABP Pressure and Temperature Sensors",
|
||||
"Description": "This is the UPM Module for the ABP Honeywell Pressure and Temp sensor. This sensor uses an onboard ASIC to output values of pressure that are updated at approximately 2 KHz. It is capable of detecting pressure in the 0-5 psi range and it has an i2c based interface. Temperature calculation using this driver is possible but not all ABP sensors support that functionality.",
|
||||
"Aliases": ["abp"],
|
||||
"Categories": ["pressure", "temperature"],
|
||||
"Connections": ["i2c"],
|
||||
"Project Type": ["medical", "industrial", "commercial"],
|
||||
"Manufacturers": ["honeywell"],
|
||||
"Examples":
|
||||
{
|
||||
"Python": ["abp.py"],
|
||||
"Node.js": ["abp.js"],
|
||||
"C++": ["abp.cxx"],
|
||||
"C": ["abp.c"]
|
||||
},
|
||||
"Specifications":
|
||||
{
|
||||
"Vsupply": {"unit": "Vdc", "min" : -0.3, "max": 6.0},
|
||||
"Supply Current Digital" : {
|
||||
"3.3 Vdc" : {"unit": "mA", "min" : "0.0", "max": "3.9"},
|
||||
"5.0 Vdc" : {"unit": "mA", "min" : "0.0", "max": "4.6"},
|
||||
"Sleep Mode" : {"unit": "uA", "min" : "0.0", "max": "10"}
|
||||
},
|
||||
"Operating Temperature": {"unit": "°C", "min" : -40, "max": 85},
|
||||
"Start up Time Digital": {"unit": "ms", "time" : 3},
|
||||
"Response Time Digital": {"unit": "ms", "time" : 0.46},
|
||||
"Compensated Temperature Range" : {"unit": "°C", "min" : 0, "max" : 50},
|
||||
"Pressure Range" : {
|
||||
"Differential" : [
|
||||
{"unit" : "mbar", "min" : 60, "max" : 4000},
|
||||
{"unit" : "kPa", "min" : 6, "max" : 400},
|
||||
{"unit" : "psi", "min" : 1, "max" : 60}
|
||||
],
|
||||
"Gage" : [
|
||||
{"unit" : "mbar", "min" : 0, "max" : 10000},
|
||||
{"unit" : "kPa", "min" : 0, "max" : 1000},
|
||||
{"unit" : "psi", "min" : 0, "max" : 150}
|
||||
]
|
||||
}
|
||||
},
|
||||
"Platforms":
|
||||
{
|
||||
"Intel Joule Module":
|
||||
{
|
||||
"Notes": ["Might need pull up resistors"]
|
||||
},
|
||||
"Intel Edison":
|
||||
{
|
||||
"Notes": ["Might need pull up resistors"]
|
||||
},
|
||||
"Arduino 101":
|
||||
{
|
||||
"Notes": ["Might need pull up resistors"]
|
||||
}
|
||||
},
|
||||
"Urls" :
|
||||
{
|
||||
"Product Pages": ["https://sensing.honeywell.com/sensors/amplified-board-mount-pressure-sensors/basic-abp-series"],
|
||||
"Datasheets": ["https://sensing.honeywell.com/honeywell-sensing-basic-board-mount-pressure-abp-series-datasheet-2305128-e-en.pdf"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,8 +3,6 @@
|
||||
%module pyupm_abp
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "abp.hpp"
|
||||
%{
|
||||
#include "abp.hpp"
|
||||
|
@ -3,8 +3,6 @@
|
||||
%module pyupm_ad8232
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "ad8232.hpp"
|
||||
%{
|
||||
#include "ad8232.hpp"
|
||||
|
@ -208,6 +208,10 @@ namespace upm {
|
||||
void stepperSteps(STEPMOTORS_T motor, unsigned int steps);
|
||||
|
||||
private:
|
||||
/* Disable implicit copy and assignment operators */
|
||||
AdafruitMS1438(const AdafruitMS1438&) = delete;
|
||||
AdafruitMS1438 &operator=(const AdafruitMS1438&) = delete;
|
||||
|
||||
// SWIG will generate a warning for these 'nested structs'; however,
|
||||
// it can be ignored as these structs are never exposed.
|
||||
|
||||
|
@ -3,8 +3,6 @@
|
||||
%module pyupm_adafruitms1438
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
#ifdef DOXYGEN
|
||||
%include "adafruitms1438_doc.i"
|
||||
#endif
|
||||
|
@ -76,20 +76,17 @@ void adafruitss::setPWMFreq(float freq) {
|
||||
|
||||
|
||||
|
||||
mraa_i2c_address(m_i2c, pca9685_addr);
|
||||
mraa_i2c_read_byte_data(m_i2c,PCA9685_MODE1);
|
||||
|
||||
|
||||
m_rx_tx_buf[0]=PCA9685_MODE1;
|
||||
m_rx_tx_buf[1]=0x10; // sleep
|
||||
mraa_i2c_address(m_i2c, pca9685_addr);
|
||||
mraa_i2c_write(m_i2c,m_rx_tx_buf,2);
|
||||
|
||||
|
||||
|
||||
m_rx_tx_buf[0]=PCA9685_PRESCALE;
|
||||
m_rx_tx_buf[1]=prescale;
|
||||
mraa_i2c_address(m_i2c, pca9685_addr);
|
||||
mraa_i2c_write(m_i2c,m_rx_tx_buf,2);
|
||||
|
||||
|
||||
@ -97,7 +94,6 @@ void adafruitss::setPWMFreq(float freq) {
|
||||
|
||||
m_rx_tx_buf[0]=PCA9685_MODE1;
|
||||
m_rx_tx_buf[1]=0x00;
|
||||
mraa_i2c_address(m_i2c, pca9685_addr);
|
||||
mraa_i2c_write(m_i2c,m_rx_tx_buf,2);
|
||||
|
||||
// mraa_i2c_write_byte_data(m_i2c,0x00,PCA9685_MODE1);
|
||||
@ -107,7 +103,6 @@ void adafruitss::setPWMFreq(float freq) {
|
||||
|
||||
m_rx_tx_buf[0]=PCA9685_MODE1;
|
||||
m_rx_tx_buf[1]=0xa1;
|
||||
mraa_i2c_address(m_i2c, pca9685_addr);
|
||||
mraa_i2c_write(m_i2c,m_rx_tx_buf,2);
|
||||
}
|
||||
|
||||
@ -149,7 +144,6 @@ void adafruitss::servo(uint8_t port, uint8_t servo_type, float degrees) {
|
||||
}
|
||||
|
||||
uint16_t d= roundf(duration);
|
||||
mraa_i2c_address(m_i2c, pca9685_addr);
|
||||
m_rx_tx_buf[0]=LED0_REG+4*port;
|
||||
m_rx_tx_buf[1]=0;
|
||||
m_rx_tx_buf[2]=0;
|
||||
|
@ -3,8 +3,6 @@
|
||||
%module pyupm_adafruitss
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "adafruitss.hpp"
|
||||
%{
|
||||
#include "adafruitss.hpp"
|
||||
|
@ -3,8 +3,6 @@
|
||||
%module pyupm_adc121c021
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
#ifdef DOXYGEN
|
||||
%include "adc121c021_doc.i"
|
||||
#endif
|
||||
|
@ -116,7 +116,7 @@ ADS1X15::setContinuous(bool mode){
|
||||
|
||||
float
|
||||
ADS1X15::getThresh(ADSTHRESH reg){
|
||||
if( THRESH_HIGH && THRESH_LOW) return getLastSample(reg);
|
||||
if(reg == THRESH_HIGH || reg == THRESH_LOW) return getLastSample(reg);
|
||||
else return 0.0;
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ ADS1X15::setThresh(ADSTHRESH reg, float value){
|
||||
case 2:
|
||||
case 3:
|
||||
set_value = value / getMultiplier();
|
||||
set_value = set_value << m_bitShift;
|
||||
set_value = set_value << m_bitShift;
|
||||
if(i2c->writeWordReg(reg, swapWord(set_value)) != mraa::SUCCESS){
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + ": I2c.write() failed");
|
||||
return;
|
||||
|
@ -390,7 +390,7 @@ namespace upm {
|
||||
* @param reg ADSTHRES enum value.
|
||||
* Returns 0.0 unless THRESH_HIGH or THRESH_LOW requested.
|
||||
*/
|
||||
float getThresh(ADSTHRESH reg = THRESH_LOW);
|
||||
float getThresh(ADSTHRESH reg = THRESH_DEFAULT);
|
||||
|
||||
/**
|
||||
* Sets threshold levels or configures for conversion ready
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user