Compare commits

..

46 Commits

Author SHA1 Message Date
8734767a5c cmake: disable TGZ from builds when IPK used
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-22 18:42:31 +00:00
b4535a6403 curieimu: Adds examples for both JS and Python that load MRAA Firmata subplatform
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-22 17:05:13 +00:00
3d37f957bf cmake: add workaround for cmake 2.7
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-22 17:05:13 +00:00
3722dfc780 cmake: Fix issues with node v4/v5
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-22 17:05:13 +00:00
b113a46813 .travis.yml: Make travis test node4/node5 and node0.12
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-22 17:05:13 +00:00
aa30b59e44 cmake: add BUILDPYTHON3 flag
Use the same methodology as in mraa, by default build for python2, if requested
use python3 for everything

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-22 17:05:13 +00:00
159d2eee07 FindNode.cmake: Improve FindNode cmake module
Use mraa's FindNode since it's alot more robus and can handle NVM better

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-21 17:32:23 +00:00
7fd9f0c508 curieimu: Add WIP for Python example
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-21 17:13:25 +00:00
3ca9bfe80f Updates implementation and examples to use dynamic-friendly interface
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-21 17:13:25 +00:00
90983fde9d Complete accel and gyro implementations for new dynamic friendly interface
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-21 17:13:25 +00:00
ee19daedee curieimu: modify calls to use update methodology to fix python/java/js API
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-18 14:56:23 +00:00
61dbfe4f23 curieimu: Make compilation dependant on mraa_firmata_init
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-18 12:40:32 +00:00
224a915538 curieimu: Plugin to interface with the arduino101's IMU
Internal sensor onboard the Curie/Arduino101 can be accessed via Firmata using
this plugin. You will need mraa compiled with -DFIRMATA=ON for this to work and
be using Firmata with the CurieIMU firmata extension for ExtensibleFirmata

Signed-off-by: Ron Evans <ron@hybridgroup.com>
Signed-off-by: Justin Zemlyansky <jlstigman@live.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-18 12:40:32 +00:00
1aa445b74e Java:Added example for Flex Sensor and added newly added sensors to the CMakeLists.txt
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-10 15:55:21 -08:00
e6ad752a2c Example: gp2y0a, Grove - 80 cm Infrared Proximity Sensor
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-08 15:12:52 -08:00
144937995c ssd1351: Initial implementation
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-04 08:19:56 -08:00
0b49cbab9b Java: Exampled added for heart rate monitor and Grove temp and humidity sensor (high accuracy)
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-03 11:21:05 -08:00
f1f9d9ec2e upm: version 0.5.1
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 18:08:35 -08:00
74d625c797 a110x: trigger ISR on both edges
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 18:07:28 -08:00
2695ef3361 itg3200: fixed calibration off by one
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 18:00:45 -08:00
a9548f3ff4 adafruitms1438: stop RPATH being added in CMakeLists.txt
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 17:23:32 -08:00
3ed0e14487 h3lis331dl: Fix sensor init
Signed-off-by: Alexandru Palalau <alexandru.palalau@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 15:38:52 -08:00
1a80400fa9 my9221: java: CMakelists: remove MY9221* add GroveLEDBar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:52:32 -08:00
9845b24dea my9221: java: rename example from MY9221_ledbarSample to GroveLEDBar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:51:50 -08:00
af7f544387 my9221: fixup groveledbar java example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:51:07 -08:00
ac5c20afad my9221: remove duplicate MY9221Sample.java example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:50:26 -08:00
9f3557aa20 my9221: remove old grovecircularled driver
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:49:46 -08:00
d112266170 my9221: python: rename example from my9221 to groveledbar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:49:00 -08:00
94fdd86896 my9221: fixup groveledbar python example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:48:18 -08:00
c0c99fd87a my9221: fixup grovecircularled python example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:47:37 -08:00
684919f069 my9221: fixup grovecircularled JS example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:46:56 -08:00
37add7eb33 my9221: JS: rename example from my9221 to groveledbar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:46:16 -08:00
e17dc9a22e my9221: fixup JS example and interface files
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:45:32 -08:00
84c3445412 my9221: fixup example CMakelists after upstream rebase
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:44:48 -08:00
6b2850557e my9221: remove old ledbar example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:44:04 -08:00
f94ee6a388 my9221: rename my9221-updown example to groveledbar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:43:18 -08:00
cbb289438e my9221: rewrite to include new functionality and serve as a base class
This driver has been rewritten to support some new functionality, be
more generic and fix up some old bugs.  Multiple MY9221's can now be
chained together and are supported by the MY9221 base class.

In addition, the Grove LED Bar and Grove Circular LED drivers have
been incoporated into the my9221 library, using the new MY9221 class
as their base class.  Examples have been fixed to work with the new
library, and renamed where needed.

The current grovecircularled driver has been removed as it is now a
part of the my9221 library.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:42:21 -08:00
71b0791239 java: Corrected Java button sample and added it to auto build examples
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 10:56:50 -08:00
757a2ce342 docs: Modified building_java_bindings guide to use Runnables instead of IsrCallbacks
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 10:49:35 -08:00
3fab5625c7 java: Updated install path for Java library file
Signed-off-by: Andrei Vasiliu <andrei.vasiliu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 10:35:45 -08:00
5324808e82 docs: minor doc, image and example fixes for some lcds
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-10 12:58:23 -08:00
7d64e5458f docs: added new sensor images
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-10 10:59:42 -08:00
ab15d1e98f ads1015: fixed sensor typo in doxygen tags
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-08 14:09:26 -08:00
d9b761469d jhd1313m1: renamed node and python examples to match class name
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-08 13:12:18 -08:00
2098449c56 upm: sync build requirements with new MRAA version
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-08 12:41:03 -08:00
63c75be370 docs: fixed manufacturer name for ak8975 & groveultrasonic
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-08 12:07:47 -08:00
96 changed files with 3347 additions and 643 deletions

View File

@ -1,8 +1,12 @@
language: cpp
compiler:
- gcc
- clang
env:
- CC=gcc CXX=gcc
- CC=clang CXX=clang++
- NODE4=true
- NODE5=true
- NODE012=true
install:
- if [ "${NODE4}" ]; then export CC=gcc-4.8 CXX=g++-4.8; fi
- sudo add-apt-repository --yes ppa:kalakris/cmake
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
- sudo apt-get update -qq
@ -10,12 +14,24 @@ install:
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
- sudo update-java-alternatives -s java-8-oracle
before_script:
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36"
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
- if [ "${NODE4}" ]; then nvm install 4.1; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
- if [ "${NODE5}" ]; then nvm install 5; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
script:
- git clone --branch=master https://github.com/intel-iot-devkit/mraa.git
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include .. && make && make install
- git clone --branch=firmata https://github.com/intel-iot-devkit/mraa.git
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=OFF -DFIRMATA=ON -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. .. && make && make install
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
- export CPLUS_INCLUDE_PATH=$PWD/include
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
- cd ../.. && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
- cd ../.. && mkdir build && cd build && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
addons:
apt:
sources:
- llvm-toolchain-precise-3.6
- ubuntu-toolchain-r-test
packages:
- clang-3.6
- g++-4.8

View File

@ -10,7 +10,7 @@ find_package (PkgConfig REQUIRED)
# Force a libmraa search and minimum required version every time a config is generated
unset(MRAA_FOUND CACHE)
pkg_check_modules (MRAA REQUIRED mraa>=0.9.0)
pkg_check_modules (MRAA REQUIRED mraa>=0.9.1)
message (INFO " found mraa version: ${MRAA_VERSION}")
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
@ -25,7 +25,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
message (WARNING " - Install git to compile a production UPM!")
set (VERSION "v0.5.0-dirty")
set (VERSION "v0.5.1-dirty")
endif ()
message (INFO " - UPM Version ${VERSION}")
@ -51,6 +51,7 @@ set (CMAKE_SWIG_FLAGS "")
option (BUILDDOC "Build all doc." OFF)
option (BUILDSWIG "Build swig modules." ON)
option (BUILDSWIGPYTHON "Build swig python modules." ON)
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
option (BUILDSWIGNODE "Build swig node modules." ON)
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
@ -156,7 +157,7 @@ if (IPK)
endif ()
message (INFO " - Package arch is ${TARGET_ARCH}")
set(CPACK_GENERATOR "DEB" "TGZ")
set(CPACK_GENERATOR "DEB")
set(OPKG_ARCH ${TARGET_ARCH})
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
@ -210,10 +211,18 @@ if(BUILDJAVAEXAMPLES)
add_subdirectory (examples/java)
endif()
if(BUILDTESTS)
find_package (PythonInterp REQUIRED)
if (${PYTHONINTERP_FOUND})
enable_testing ()
add_subdirectory (tests)
endif ()
if (BUILDSWIGPYTHON OR BUILDTESTS)
if (BUILDPYTHON3)
set (PYTHONBUILD_VERSION 3)
else ()
set (PYTHONBUILD_VERSION 2.7)
endif ()
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
include_directories(${PYTHON_INCLUDE_PATH})
endif ()
if (BUILDTESTS)
enable_testing ()
add_subdirectory (tests)
endif()

View File

@ -1,4 +1,12 @@
find_program (NODE_EXECUTABLE NAMES node
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
macro(add_include_dir dir)
if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
endif()
endmacro()
find_program (NODEJS_EXECUTABLE NAMES node nodejs
HINTS
$ENV{NODE_DIR}
PATH_SUFFIXES bin
@ -7,26 +15,50 @@ find_program (NODE_EXECUTABLE NAMES node
include (FindPackageHandleStandardArgs)
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
PATHS /usr/include/nodejs /usr/local/include/nodejs)
# If compat-libuv package exists, it must be at start of include path
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
if (UV_ROOT_DIR)
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
add_include_dir(${UV_ROOT_DIR})
endif()
set (NODE_INCLUDE_DIRS
${NODE_ROOT_DIR}/src
${NODE_ROOT_DIR}/node
${NODE_ROOT_DIR}/deps/v8/include
${NODE_ROOT_DIR}/deps/uv/include
# Now look for node. Flag an error if not found
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
if (NODE_ROOT_DIR)
add_include_dir(${NODE_ROOT_DIR}/include/src)
add_include_dir(${NODE_ROOT_DIR}/include/node)
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
else()
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - node.h not found")
endif()
# Check that v8.h is in NODEJS_INCLUDE_DIRS
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
if (NOT V8_ROOT_DIR)
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - v8.h not found")
endif()
# Check that uv.h is in NODEJS_INCLUDE_DIRS
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
if (NOT UV_ROOT_DIR)
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - uv.h not found")
endif()
find_package_handle_standard_args (Nodejs DEFAULT_MSG
NODEJS_EXECUTABLE
NODEJS_INCLUDE_DIRS
)
find_package_handle_standard_args (Node DEFAULT_MSG
NODE_EXECUTABLE
NODE_INCLUDE_DIRS
)
if (NODE_EXECUTABLE)
execute_process(COMMAND ${NODE_EXECUTABLE} --version
if (NODEJS_EXECUTABLE)
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
OUTPUT_VARIABLE _VERSION
RESULT_VARIABLE _NODE_VERSION_RESULT)
execute_process(COMMAND ${NODE_EXECUTABLE} -e "console.log(process.versions.v8)"
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
OUTPUT_VARIABLE _V8_VERSION
RESULT_VARIABLE _V8_RESULT)
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
@ -55,7 +87,11 @@ if (NODE_EXECUTABLE)
set (V8_VERSION_STRING "3.28.72")
message ("defaulted to node 0.10.30")
endif ()
message ("INFO - Node version is " ${NODE_VERSION_STRING} "INFO - Node using v8 " ${V8_VERSION_STRING})
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
message ("INFO - Node version is " ${NODE_VERSION_STRING})
message ("INFO - Node using v8 " ${V8_VERSION_STRING})
mark_as_advanced (NODEJS_EXECUTABLE)
endif ()
mark_as_advanced (NODE_EXECUTABLE)

View File

@ -4,18 +4,28 @@ Changelog {#changelog}
Here's a list summarizing some of the key undergoing changes to our library
from earlier versions:
### v0.5.1
* Updated the API and added new functionality for the MY9221 class and derived
sensors: grovecircularled and groveledbar, along with new code samples that
show these changes
* Provided a fix for one JAVA example that uses interrupts and updated library
install paths
* Several documentation improvements and pictures were added for new sensors
* A few other sensors received minor patches
### v0.5.0
* First implementations for industrial grade Modbus sensors, along with first
sensor examples that use the new iio system driver in MRAA.
sensor examples that use the new iio system driver in MRAA
* Significant improvements to the stepmotor driver that will now allow precise
control using any GPIO pin and extended the API with new functionality.
control using any GPIO pin and extended the API with new functionality
* Further improved JAVA bindings and sensor ISRs have been modified to
implement Runnable objects.
implement Runnable objects
* Improved Python typemaps and error checking, documentation now includes
detailed function descriptions.
detailed function descriptions
* Simplified the build process by eliminating the need to define redundant
MRAA related environment variables.
MRAA related environment variables
* New sensors: nlgpio16, ads1x15, t3311, hdxxvxta, hwxpxx, rhusb, ili9341,
apds9930, kxcjk1013
@ -55,7 +65,7 @@ from earlier versions:
includes last remaining images and grouping sensors by kits
* Added support for Sparkfun Sensor Blocks (OLED & IMU)
* Fully reworked API for at42qt1070, mpu9150 and lcd classes, while
maintaining backwards compatibility for existing lcd displays.
maintaining backwards compatibility for existing lcd displays
* Extended doxygen tags for better integration with automated documentation
generators
* New sensors: rgbringcoder, hp20x, pn532, sainsmartks, lsm9ds0, eboled

View File

@ -253,61 +253,29 @@ __SWIG:__
###Implementing callbacks in Java
Method calls from the Java instance are passed to the C++ instance transparently via C wrapper functions. In the default usage of SWIG, this arrangement is asymmetric in the sense that no corresponding mechanism exists to pass method calls down the inheritance chain from C++ to Java. To address this problem, SWIG introduces new classes called directors at the bottom of the C++ inheritance chain. The job of the directors is to route method calls correctly, either to C++ implementations higher in the inheritance chain or to Java implementations lower in the inheritance chain. The upshot is that C++ classes can be extended in Java and from C++ these extensions look exactly like native C++ classes. For more on Java directors, read the ["Cross language polymorphism using directors"](http://www.swig.org/Doc3.0/SWIGDocumentation.html#Java_directors) chapter of the SWIG documentation.
To enable directors, add the "directors" option to the %module directive, and use the %feature("director") directive to tell SWIG which classes and methods should get directors. If only a class is specified, the %feature is applied to all virtual methods in that class. If no class or method is specified, the %feature is applied globally to all virtual methods.
```
%module(directors="1") modulename
%feature("director") IsrCallback;
```
Callbacks in the UPM Java library (as well as the MRAA Java library) make use of the _void mraa\_java\_isr\_callback(void\* data\)_ method from MRAA.
__Callbacks in the UPM Java library are implemented as follows (we use the a110x Hall Effect sensors as example):__
We create a new C++ class, that will be wrapped by SWIG, called _IsrCallback_; and a method _generic\_callback\_isr(void\* data)_ that takes an instance of IsrCallback as argument.
We extend the sensor class with another method, _installISR\(jobject runnable\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _mraa\_java\_isr\_callback\(\)_ method as the interrupt service routine \(ISR\) to be called, with _jobject runnable_ as argument.
SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _installISR\(jobject runnable\)_ method in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
```c++
#if defined(SWIGJAVA)
class IsrCallback
void A110X::installISR(jobject runnable)
{
public:
virtual ~IsrCallback()
{
}
virtual void run()
{ /* empty, overridden in Java*/
}
private:
};
static void generic_callback_isr (void* data)
{
IsrCallback* callback = (IsrCallback*) data;
if (callback == NULL)
return;
callback->run();
installISR(mraa_java_isr_callback, runnable);
}
#endif
```
SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _IsrCallback_ class and _generic\_callback\_isr()_ in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
We extend the sensor class with another method, _installISR\(IsrCallback \*cb\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _generic\_callback\_isr\(\)_ method as the interrupt service routine \(ISR\) to be called, with the _IsrCallback_ object (referenced by *cb) as argument.
```c++
#if defined(SWIGJAVA)
void A110X::installISR( IsrCallback *cb)
{
installISR(generic_callback_isr, cb);
}
#endif
```
We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(IsrCallback \*cb\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(jobject runnable\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
```c++
public:
#if defined(SWIGJAVA)
void installISR(IsrCallback *cb);
void installISR(jobject runnable);
#else
void installISR(void (*isr)(void *), void *arg);
#endif
@ -317,7 +285,7 @@ private:
#endif
```
To use callback in java, we create a ISR class, which extends the new IsrCallback class created by SWIG, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
To use callback in java, we create a ISR class, which implements the Java Runnable interface, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
```java
public class A110X_intrSample {
@ -326,7 +294,7 @@ public class A110X_intrSample {
public static void main(String[] args) throws InterruptedException {
upm_a110x.A110X hall = new upm_a110x.A110X(2);
IsrCallback callback = new A110XISR();
A110XISR callback = new A110XISR();
hall.installISR(callback);
while(true){
@ -336,7 +304,7 @@ public class A110X_intrSample {
}
}
class A110XISR extends IsrCallback {
class A110XISR implements Runnable {
public A110XISR(){
super();
}
@ -383,18 +351,3 @@ by
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
```
__Use GlobalRef instead of WeakRef__
By default, SWIG uses WeakRef to the Java objects handled by a director. Once Java objects run out of scope they can get cleaned up. In many cases WeakRef is undesirable as we may still want to be able to run methods or access fields in the objects passed to the JNI layer (e.g. we want to pass a runnable-like object which should be called when something happens). To use GlobalRefs instead, the following line must be added after the director declaration:
```
SWIG_DIRECTOR_OWNED(module)
```
For, example, in case of a module called IsrCallback (used for interrupts in MRAA and UPM), we would declare said module as such:
```
%feature ("director") IsrCallback;
SWIG_DIRECTOR_OWNED(IsrCallback)
```

BIN
docs/images/adxrs610.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
docs/images/bma220.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
docs/images/dfrph.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
docs/images/eboled.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
docs/images/keypadlcd.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
docs/images/lm35.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
docs/images/lsm9ds0.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
docs/images/mg811.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
docs/images/mpu60x0.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
docs/images/mpu9250.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
docs/images/pn532.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
docs/images/ssd1351.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
docs/images/urm37.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
docs/images/xbee.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

View File

@ -10,7 +10,7 @@ macro(get_module_name example_name module_name)
elseif ((${example_name} MATCHES "^mq" AND ${length} EQUAL 3) OR ${example_name} STREQUAL "tp401")
set (${module_name} "gas")
else()
set(${module_name} ${example_name})
set(${module_name} ${example_name})
endif()
endmacro()
@ -25,25 +25,25 @@ macro(add_custom_example example_bin example_src example_module_list)
if (MODULE_LIST)
list(FIND MODULE_LIST ${module} index)
if (${index} EQUAL -1)
set(found_all_modules FALSE)
set(found_all_modules FALSE)
endif()
endif()
endforeach()
if (found_all_modules)
add_executable (${example_bin} ${example_src})
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
foreach (module ${example_module_list})
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
include_directories (${module_dir})
if (${module} STREQUAL "lcd")
set(module "i2clcd")
set(module "i2clcd")
endif()
target_link_libraries (${example_bin} ${module})
target_link_libraries (${example_bin} ${module})
endforeach()
else()
MESSAGE(INFO " Ignored ${example_bin}")
set (example_bin "")
endif()
endif()
endmacro()
@ -56,13 +56,13 @@ macro(add_example example_name)
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
AND EXISTS ${module_dir}
AND IS_DIRECTORY ${module_dir})
AND IS_DIRECTORY ${module_dir})
add_custom_example(${example_bin} ${example_src} ${module_name})
if ((NOT ${example_bin} STREQUAL "") AND (${module_name} STREQUAL "grove"))
set(grove_module_path "${PROJECT_SOURCE_DIR}/src/${example_name}")
if (EXISTS ${grove_module_path})
include_directories(${grove_module_path})
target_link_libraries (${example_bin} ${example_name})
target_link_libraries (${example_bin} ${example_name})
endif()
endif()
else()
@ -91,8 +91,6 @@ add_example (grovebutton)
add_example (groverotary)
add_example (groveslide)
add_example (buzzer-sound)
add_example (my9221-ledbar)
add_example (my9221-updown)
add_example (nrf24l01-transmitter)
add_example (nrf24l01-receiver)
add_example (nrf24l01-broadcast)
@ -203,7 +201,6 @@ add_example (h3lis331dl)
add_example (ad8232)
add_example (grovescam)
add_example (m24lr64e)
add_example (grovecircularled)
add_example (rgbringcoder)
add_example (hp20x)
add_example (pn532)
@ -242,6 +239,10 @@ add_example (hdxxvxta)
add_example (rhusb)
add_example (apds9930)
add_example (kxcjk1013)
add_example (ssd1351)
if (HAVE_FIRMATA)
add_example (curieimu)
endif ()
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)
@ -258,3 +259,5 @@ add_custom_example (eboled-example eboled.cxx lcd)
add_custom_example (mpu60x0-example mpu60x0.cxx mpu9150)
add_custom_example (ak8975-example ak8975.cxx mpu9150)
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
add_custom_example (groveledbar-example groveledbar.cxx my9221)
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)

81
examples/c++/curieimu.cxx Normal file
View File

@ -0,0 +1,81 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Author: Ron Evans (@deadprogram)
* Author: Justin Zemlyansky (@JustInDevelopment)
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "curieimu.hpp"
#include "mraa.h"
#include "mraa/firmata.h"
#include <math.h>
int
main(int argc, char **argv)
{
//! [Interesting]
mraa_init();
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
upm::CurieImu* sensor = new upm::CurieImu();
std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
sensor->updateAccel();
int x = sensor->getAccelX(),
y = sensor->getAccelY(),
z = sensor->getAccelZ();
printf("accelerometer is: %d, %d, %d\n", x, y, z);
sensor->updateGyro();
int a = sensor->getGyroX(),
b = sensor->getGyroY(),
c = sensor->getGyroZ();
printf("gyroscope is: %d, %d, %d\n", a, b, c);
int axis, direction;
sensor->enableShockDetection(true);
for(int i=0; i<300; i++) {
if (sensor->isShockDetected()) {
sensor->getNextShock();
axis = sensor->getAxis();
direction = sensor->getDirection();
printf("shock data is: %d, %d\n", axis, direction);
}
usleep(10000);
}
sensor->updateMotion();
int m = sensor->getAccelX(),
n = sensor->getAccelY(),
o = sensor->getAccelZ(),
p = sensor->getGyroX(),
q = sensor->getGyroY(),
r = sensor->getGyroZ();
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
delete sensor;
return 0;
}

View File

@ -43,9 +43,9 @@ int main()
//! [Interesting]
// Instantiate a Grove Circular LED on gpio pins 5 and 4
// Instantiate a Grove Circular LED on D9 for data, D8 for clock
upm::GroveCircularLED *circle = new upm::GroveCircularLED(5, 4);
upm::GroveCircularLED *circle = new upm::GroveCircularLED(9, 8);
int level = 0;
while (shouldRun)
@ -54,6 +54,7 @@ int main()
level = (level + 1) % 24;
usleep(100000);
}
//! [Interesting]
cout << "Exiting" << endl;

View File

@ -25,7 +25,7 @@
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "my9221.h"
#include "groveledbar.h"
using namespace std;
@ -42,28 +42,27 @@ int main ()
{
signal(SIGINT, sig_handler);
//! [Interesting]
//! [Interesting]
// Instantiate a MY9221, we use D2 for the data, and D3 for the
// data clock. This was tested with a Grove LED bar.
// Instantiate a GroveLEDBar, we use D8 for the data, and D9 for the
// clock. This was tested with a Grove LED bar.
upm::GroveLEDBar* bar = new upm::GroveLEDBar(8, 9);
upm::MY9221* bar = new upm::MY9221(2, 3);
while (shouldRun)
{
// count up from green to red
for (int i=1; i<=10; i++)
for (int i=0; i<=10; i++)
{
bar->setBarLevel(i, true);
usleep(50000);
usleep(100000);
}
sleep(1);
// count down from red to green
for (int i=1; i<=10; i++)
for (int i=0; i<=10; i++)
{
bar->setBarLevel(i, false);
usleep(50000);
usleep(100000);
}
sleep(1);
}
@ -71,7 +70,7 @@ int main ()
cout << "Exiting..." << endl;
// turn off the LED's
bar->setBarLevel(0, true);
bar->setBarLevel(0);
delete bar;
return 0;

View File

@ -1,63 +0,0 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "my9221.h"
#include <signal.h>
int running = 0;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
int
main(int argc, char **argv)
{
//! [Interesting]
upm::MY9221 *bar = new upm::MY9221(8, 9);
signal(SIGINT, sig_handler);
while (!running) {
for (int idx = 1; idx < 11; idx++) {
bar->setBarLevel (idx);
usleep(1000);
}
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete bar;
return 0;
}

61
examples/c++/ssd1351.cxx Normal file
View File

@ -0,0 +1,61 @@
#include "mraa.hpp"
#include <iostream>
#include <unistd.h>
#include "ssd1351.h"
#define BLACK 0x0000
#define WHITE 0xFFFF
#define INTEL_BLUE 0x0BF8
int main(int argc, char **argv)
{
// Define colors (16-bit RGB on 5/6/5 bits)
int colors[] = {0x0000, 0x000F, 0x03E0, 0x03EF,
0x7800, 0x780F, 0x7BE0, 0xC618,
0x7BEF, 0x001F, 0x07E0, 0x07FF,
0xF800, 0xF81F, 0xFFE0, 0xFFFF};
//! [Interesting]
// Initialize display with pins
// oc = 0, dc = 1, r = 2, si = 11, cl = 13
upm::SSD1351* display = new upm::SSD1351(0, 1, 2);
// Test lines pixel by pixel
for(int i = 0; i < SSD1351HEIGHT; i++) {
for(int j = 0; j < SSD1351WIDTH; j++) {
display->drawPixel(i, j, colors[i/8]);
}
}
display->refresh();
sleep(5);
// Test rectangles
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
for (int j = 0; j < SSD1351WIDTH/32; j++) {
display->fillRect(i * 32, j * 32, 32, 32, colors[i * 4 + j]);
}
}
display->refresh();
sleep(5);
// Test circles
display->fillScreen(0x2104);
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
for (int j = 0; j < SSD1351WIDTH/32; j++) {
display->drawCircle(i * 32 + 15, j * 32 + 15, 15, colors[i * 4 + j]);
}
}
display->refresh();
sleep(5);
// Test Text
display->fillScreen(INTEL_BLUE);
display->setTextColor(WHITE, INTEL_BLUE);
display->setTextSize(4);
display->setCursor(7, 30);
display->print("Intel");
display->setCursor(5, 70);
display->print("IoTDK");
display->refresh();
//! [Interesting]
}

View File

@ -0,0 +1,62 @@
/*
* Author: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_ad8232.AD8232;
public class Ad8232Example {
static {
try {
System.loadLibrary("javaupm_ad8232");
System.loadLibrary("mraajava");
} catch (UnsatisfiedLinkError e) {
System.err.println(
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
e);
System.exit(1);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
// and an analog pin, 0 (OUTPUT)
AD8232 ad8232 = new AD8232(10, 11, 0);
while(true){
// Output the raw numbers from the ADC, for plotting elsewhere.
// A return of 0 indicates a Lead Off (LO) condition.
// In theory, this data could be fed to software like Processing
// (https://www.processing.org/) to plot the data just like an
// EKG you would see in a hospital.
System.out.println(ad8232.value());
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("The following error has occured: "+e.getMessage());
}
}
}
}

View File

@ -29,6 +29,7 @@ add_example(DS1307Sample ds1307)
add_example(ENC03RSample enc03r)
add_example(ES08ASample servo)
add_example(GroveButtonSample grove)
add_example(GroveButton_intrSample grove)
add_example(GroveCollision grovecollision)
add_example(GroveEHRSample groveehr)
add_example(GroveEmg groveemg)
@ -77,8 +78,7 @@ add_example(MPU9150Sample mpu9150)
add_example(MQ2Sample gas)
add_example(MQ303ASample mq303a)
add_example(MQ5Sample gas)
add_example(MY9221_ledbarSample my9221)
add_example(MY9221Sample my9221)
add_example(GroveLEDBar my9221)
add_example(NRF24L01_receiverSample nrf24l01)
add_example(NRF24L01_transmitterSample nrf24l01)
add_example(NUNCHUCKSample nunchuck)
@ -101,6 +101,10 @@ add_example(WaterLevelSensor waterlevel)
add_example(WT5001Sample wt5001)
add_example(YG1006Sample yg1006)
add_example(ZFM20Sample zfm20)
add_example(Ad8232Example ad8232)
add_example(Gp2y0aExample gp2y0a)
add_example(Th02Example th02)
add_example(FlexSensorExample flex)
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)

View File

@ -0,0 +1,41 @@
import upm_flex.Flex;
public class FlexSensorExample {
static {
try {
System.loadLibrary("javaupm_flex");
System.loadLibrary("mraajava");
} catch (UnsatisfiedLinkError e) {
System.err.println(
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
e);
System.exit(1);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// The was tested with a Spectra Symbol flex sensor.
// We attached a 22K resistor to a breadboard,
// with 1 end attached to GND and the other connected to
// both the flex sensor and A0.
// The flex sensor was connected on 1 pin to the 22K resistor and A0
// and on the other pin to 5V.
// Instantiate a Flex sensor on analog pin A0
Flex flex = new Flex(0);
while(true){
System.out.println("Flex Sensor value is: "+flex.value());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//! [Interesting]
}
}

View File

@ -0,0 +1,68 @@
/*
* Author: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_gp2y0a.GP2Y0A;
public class Gp2y0aExample {
public static final float GP2Y0A_AREF = 5;
public static final short SAMPLES_PER_QUERY = 20;
static {
try {
System.loadLibrary("javaupm_gp2y0a");
System.loadLibrary("mraajava");
} catch (UnsatisfiedLinkError e) {
System.err.println(
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
e);
System.exit(1);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// Note, for the Grove 80cm version of this sensor, due to the way
// it is wired, you need to plug this into the A0 port, where it
// will use the available A1 pin for data.
// Instantiate a GP2Y0A on analog pin A1
GP2Y0A gp2y0a = new GP2Y0A(1);
// The higher the voltage (closer to AREF) the closer the object is. NOTE:
// the measured voltage will probably not exceed 3.3 volts.
// Every second, print the averaged voltage value (averaged over 20 samples).
while(true){
System.out.println("AREF: " + GP2Y0A_AREF + "\t, Voltage Value (Higher means Closer): "+ gp2y0a.value(GP2Y0A_AREF, SAMPLES_PER_QUERY));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("The following exception occured: "+e.getMessage());
}
}
//! [Interesting]
}
}

View File

@ -22,9 +22,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_grove.IsrCallback;
//NOT TESTED!!!
public class GroveButton_intrSample {
public static int counter = 0;
@ -33,8 +30,8 @@ public class GroveButton_intrSample {
// ! [Interesting]
upm_grove.GroveButton b = new upm_grove.GroveButton(2);
IsrCallback callback = new ButtonISR();
b.installISR(mraa.Edge.EDGE_RISING.swigValue(), callback);
ButtonISR callback = new ButtonISR();
b.installISR(2, callback);
while (true) {
System.out.println("Counter: " + counter);
@ -44,7 +41,7 @@ public class GroveButton_intrSample {
}
}
class ButtonISR extends IsrCallback {
class ButtonISR implements Runnable {
public ButtonISR() {
super();
}

View File

@ -22,20 +22,20 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class MY9221_ledbarSample{
public class GroveLEDBar {
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
upm_my9221.MY9221 bar = new upm_my9221.MY9221((short) 8, (short) 9);
while (true) {
for (short idx = 1; idx < 11; idx++) {
bar.setBarLevel(idx);
Thread.sleep(100);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
}
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
upm_my9221.GroveLEDBar bar = new upm_my9221.GroveLEDBar((short) 8, (short) 9);
while (true) {
for (short idx = 1; idx < 11; idx++) {
bar.setBarLevel(idx);
Thread.sleep(100);
}
}
//! [Interesting]
}
}

View File

@ -1,39 +0,0 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class MY9221Sample {
public static void main(String[] args) throws InterruptedException {
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
upm_my9221.MY9221 bar = new upm_my9221.MY9221((short) 8, (short) 9);
while (true) {
for (short idx = 1; idx < 11; idx++) {
bar.setBarLevel(idx);
Thread.sleep(100);
}
}
}
}

View File

@ -0,0 +1,59 @@
/*
* Author: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_th02.TH02;
public class Th02Example {
static {
try {
System.loadLibrary("javaupm_th02");
System.loadLibrary("mraajava");
} catch (UnsatisfiedLinkError e) {
System.err.println(
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
e);
System.exit(1);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
float temperature = 0;
float humidity = 0;
TH02 sensor = new TH02();
while(true){
temperature = sensor.getTemperature();
humidity = sensor.getHumidity();
System.out.println("Temperature = "+temperature+", Humidity = "+humidity);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("The following exception has occured: "+e.getMessage());
}
}
}
}

View File

@ -0,0 +1,52 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Ron Evans (@deadprogram)
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var mraa = require('mraa');
console.log('MRAA Version: ' + mraa.getVersion());
// open connection to Firmata
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
var curieImu = require('jsupm_curieimu');
var myCurie = new curieImu.CurieImu();
var outputStr;
var myInterval = setInterval(function()
{
myCurie.updateAccel();
outputStr = "accel: x " + myCurie.getAccelX()
+ " - y " + myCurie.getAccelY()
+ " - z " + myCurie.getAccelZ();
console.log(outputStr);
}, 500);
// Print message when exiting
process.on('SIGINT', function()
{
clearInterval(myInterval);
console.log("Exiting");
process.exit(0);
});

View File

@ -25,9 +25,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Instantiate a Grove Circular LED on gpio pins 5 and 4
var GCL = require("jsupm_grovecircularled");
var circle = new GCL.GroveCircularLED(5, 4);
// Instantiate a Grove Circular LED on gpio pins 9 and 8
var GCL = require("jsupm_my9221");
var circle = new GCL.GroveCircularLED(9, 8);
var level = 0;
// Show a spinner.

View File

@ -26,9 +26,9 @@
var LEDBar = require("jsupm_my9221");
// Instantiate a MY9221, we use D2 for the data, and D3 for the
// Instantiate a MY9221, we use D8 for the data, and D9 for the
// data clock. This was tested with a Grove LED bar.
var myLEDBar = new LEDBar.MY9221(2, 3);
var myLEDBar = new LEDBar.GroveLEDBar(8, 9);
var directionBool = true;

View File

@ -0,0 +1,56 @@
#!/usr/bin/python
# Author: Ron Evans (@deadprogram)
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
import mraa
print (mraa.getVersion())
# open connection to Firmata
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0")
import time, sys, signal, atexit
import pyupm_curieimu as curieimu
sensor = curieimu.CurieImu()
## Exit handlers ##
def SIGINTHandler(signum, frame):
raise SystemExit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
while(1):
sensor.updateAccel();
outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
sensor.getAccelX(), sensor.getAccelY(),
sensor.getAccelZ())
print outputStr
time.sleep(1)

View File

@ -23,7 +23,7 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_grovecircularled as upmGroveCircularLED
import pyupm_my9221 as upmGroveCircularLED
# Exit handlers
def SIGINTHandler(signum, frame):
@ -39,8 +39,8 @@ atexit.register(exitHandler)
# This function stops python from printing a stacktrace when you hit control-C
signal.signal(signal.SIGINT, SIGINTHandler)
# Instantiate a Grove Circular LED on gpio pins 5 and 4
circle = upmGroveCircularLED.GroveCircularLED(5, 4)
# Instantiate a Grove Circular LED on gpio pins 9 and 8
circle = upmGroveCircularLED.GroveCircularLED(9, 8)
level = 0

View File

@ -24,9 +24,9 @@
import time, sys, signal, atexit
import pyupm_my9221 as upmMy9221
# Instantiate a MY9221, we use D2 for the data, and D3 for the
# Instantiate a MY9221, we use D8 for the data, and D9 for the
# data clock. This was tested with a Grove LED bar.
myLEDBar = upmMy9221.MY9221(2, 3)
myLEDBar = upmMy9221.GroveLEDBar(8, 9)
# Exit handlers

View File

@ -46,16 +46,28 @@ endmacro()
macro(upm_SWIG_NODE)
if (BUILDSWIGNODE AND BUILDSWIG)
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is
# required. This hardcodes V8_VERSION to be <10 but I assume that's not going
# to be a problem for a little while! SWIG uses a padded SWIG_V8 version which
# we hack together from our findnode module.
set (V8_VERSION_HEX 0x0${V8_VERSION_MAJOR}${V8_VERSION_MINOR}${V8_VERSION_PATCH})
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
while (V8_VERSION_HEX_length LESS 8)
set (V8_VERSION_HEX "${V8_VERSION_HEX}0")
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
endwhile ()
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
PUBLIC
"${NODE_INCLUDE_DIRS}"
)
)
set_target_properties (jsupm_${libname} PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=0x0${V8_DEFINE_STRING}"
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}"
PREFIX ""
SUFFIX ".node"
)
@ -67,10 +79,24 @@ macro(upm_SWIG_NODE)
endif()
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
message (FATAL_ERROR " FATAL ERROR: GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
endif ()
set (UPM_CXX11_WORKAROUND_OPTION "-std=gnu++11")
else ()
set (UPM_CXX11_WORKAROUND_OPTION "-std=c++11")
endif ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UPM_CXX11_WORKAROUND_OPTION} ")
endif ()
endif()
createpackagejson(${libname})
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
endif()
endmacro()
@ -100,12 +126,8 @@ macro(upm_SWIG_JAVA)
PREFIX "lib"
SUFFIX ".so"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libjavaupm_${libname}.so
DESTINATION lib/java
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar
DESTINATION lib/java
)
install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar DESTINATION ${CMAKE_INSTALL_LIBDIR}/../lib/java)
if (NOT DEFINED $ENV{JAVA_HOME_NATIVE})
set (JAVAC $ENV{JAVA_HOME}/bin/javac)
@ -143,30 +165,25 @@ macro(upm_doxygen)
endmacro()
if (SWIG_FOUND)
if(BUILDSWIGPYTHON)
find_package (PythonLibs)
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
endif(BUILDSWIGPYTHON)
if(BUILDSWIGNODE)
if (BUILDSWIGNODE)
if(NOT NODE_FOUND)
find_package(Node)
endif()
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
endif()
find_path (NODE_ROOT_DIR "node/node.h")
find_path (NODE_ROOT_DIR "include/node/node.h")
set (NODE_INCLUDE_DIRS
${NODE_ROOT_DIR}/src
${NODE_ROOT_DIR}/node
${NODE_ROOT_DIR}/deps/v8/include
${NODE_ROOT_DIR}/deps/uv/include
${NODE_ROOT_DIR}/include/src
${NODE_ROOT_DIR}/include/node
${NODE_ROOT_DIR}/include/deps/v8/include
${NODE_ROOT_DIR}/include/deps/uv/include
)
macro(createpackagejson)
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
endmacro()
endif(BUILDSWIGNODE)

View File

@ -70,7 +70,7 @@ void A110X::installISR(void (*isr)(void *), void *arg)
uninstallISR();
// install our interrupt handler
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_FALLING,
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_BOTH,
isr, arg);
m_isrInstalled = true;
}

View File

@ -9,9 +9,11 @@ add_dependencies(${libname} pca9685)
target_link_libraries(${libname} pca9685)
if (BUILDSWIG)
if (BUILDSWIGNODE)
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (jsupm_${libname} pca9685 ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
endif()
if (BUILDSWIGPYTHON)
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (pyupm_${libname} pca9685 ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES})
endif()
endif()

View File

@ -55,8 +55,8 @@
namespace upm {
/**
* @library ads1x15
* @sensor ADS1115
* @comname ADS1115 ADC
* @sensor ADS1015
* @comname ADS1015 ADC
* @type electric
* @man ti adafruit
* @con i2c

View File

@ -65,6 +65,7 @@ namespace upm {
*
* This driver was developed using the DFRobot ADXRS610 Gyro Beakout board.
*
* @image html adxrs610.jpg
* @snippet adxrs610.cxx Interesting
*/

View File

@ -63,6 +63,7 @@ namespace upm {
*
* This driver was developed on a DFRobot BMA (Tiny).
*
* @image html bma220.jpg
* @snippet bma220.cxx Interesting
*/

View File

@ -0,0 +1,11 @@
include (CheckFunctionExists)
include (CheckLibraryExists)
include (CheckIncludeFiles)
check_library_exists (${MRAA_LIBRARIES} mraa_firmata_init "" HAVE_FIRMATA)
if (HAVE_FIRMATA)
set (libname "curieimu")
set (libdescription "upm Curie IMU via Firmata")
set (module_src ${libname}.cpp)
set (module_h ${libname}.hpp)
upm_module_init ()
endif ()

458
src/curieimu/curieimu.cpp Normal file
View File

@ -0,0 +1,458 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Author: Ron Evans (@deadprogram)
* Author: Justin Zemlyansky (@JustInDevelopment)
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <string.h>
#include <stdexcept>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include "curieimu.hpp"
using namespace upm;
static CurieImu* awaitingReponse;
CurieImu::CurieImu (int subplatformoffset)
{
m_firmata = mraa_firmata_init(FIRMATA_CURIE_IMU);
if (m_firmata == NULL) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_firmata_init() failed");
return;
}
if (pthread_mutex_init(&m_responseLock, NULL)) {
throw std::runtime_error(std::string(__FUNCTION__) +
": pthread_mutex_init(m_responseLock) failed");
return;
}
if (pthread_cond_init(&m_responseCond, NULL)) {
throw std::runtime_error(std::string(__FUNCTION__) +
": pthread_cond_init(m_responseCond) failed");
return;
}
}
CurieImu::~CurieImu()
{
pthread_mutex_destroy(&m_responseLock);
pthread_cond_destroy(&m_responseCond);
}
void
CurieImu::lock()
{
pthread_mutex_lock(&m_responseLock);
}
void
CurieImu::unlock()
{
pthread_mutex_unlock(&m_responseLock);
}
void
CurieImu::waitForResponse()
{
awaitingReponse = this;
pthread_cond_wait(&m_responseCond, &m_responseLock);
}
void
CurieImu::proceed()
{
pthread_cond_broadcast(&m_responseCond);
}
void
CurieImu::setResults(uint8_t* buf, int length)
{
m_results = new char(length);
memcpy((void*)m_results, (void*)buf, length);
}
/*
* Handles a single syncronous response being returned from Firmata
*
* @param buffer the data beinig returned from Firmata
* @param length length of results buffer
*/
static void
handleSyncResponse(uint8_t* buf, int length)
{
awaitingReponse->setResults(buf, length);
awaitingReponse->proceed();
}
/*
* Handles asyncronous responses being returned from Firmata
*
* @param buffer the data beinig returned from Firmata
* @param length length of results buffer
*/
static void
handleAsyncResponses(uint8_t* buf, int length)
{
awaitingReponse->setResults(buf, length);
awaitingReponse->processResponse();
}
void
CurieImu::processResponse()
{
switch(m_results[2]) {
case FIRMATA_CURIE_IMU_SHOCK_DETECT:
{
IMUDataItem* item = new IMUDataItem();
item->axis = m_results[3];
item->direction = m_results[4];
m_shockData.push(item);
break;
}
case FIRMATA_CURIE_IMU_STEP_COUNTER:
{
int count = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
m_stepData.push(count);
break;
}
case FIRMATA_CURIE_IMU_TAP_DETECT:
{
IMUDataItem* item = new IMUDataItem();
item->axis = m_results[3];
item->direction = m_results[4];
m_tapData.push(item);
break;
}
}
return;
}
int16_t*
CurieImu::getAccel()
{
return &m_accel[0];
}
int16_t
CurieImu::getAccelX()
{
return m_accel[X];
}
int16_t
CurieImu::getAccelY()
{
return m_accel[Y];
}
int16_t
CurieImu::getAccelZ()
{
return m_accel[Z];
}
int16_t*
CurieImu::getGyro()
{
return &m_gyro[0];
}
int16_t
CurieImu::getGyroX()
{
return m_gyro[X];
}
int16_t
CurieImu::getGyroY()
{
return m_gyro[Y];
}
int16_t
CurieImu::getGyroZ()
{
return m_gyro[Z];
}
int16_t*
CurieImu::getMotion()
{
return &m_motion[0];
}
void
CurieImu::updateAccel()
{
char message[4];
message[0] = FIRMATA_START_SYSEX;
message[1] = FIRMATA_CURIE_IMU;
message[2] = FIRMATA_CURIE_IMU_READ_ACCEL;
message[3] = FIRMATA_END_SYSEX;
lock();
mraa_firmata_response_stop(m_firmata);
mraa_firmata_response(m_firmata, handleSyncResponse);
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
waitForResponse();
m_accel[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
m_accel[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
m_accel[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
delete m_results;
unlock();
return;
}
void
CurieImu::updateGyro()
{
char message[4];
message[0] = FIRMATA_START_SYSEX;
message[1] = FIRMATA_CURIE_IMU;
message[2] = FIRMATA_CURIE_IMU_READ_GYRO;
message[3] = FIRMATA_END_SYSEX;
lock();
mraa_firmata_response_stop(m_firmata);
mraa_firmata_response(m_firmata, handleSyncResponse);
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
waitForResponse();
m_gyro[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
m_gyro[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
m_gyro[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
delete m_results;
unlock();
return;
}
void
CurieImu::updateMotion()
{
char message[4];
message[0] = FIRMATA_START_SYSEX;
message[1] = FIRMATA_CURIE_IMU;
message[2] = FIRMATA_CURIE_IMU_READ_MOTION;
message[3] = FIRMATA_END_SYSEX;
lock();
mraa_firmata_response_stop(m_firmata);
mraa_firmata_response(m_firmata, handleSyncResponse);
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
waitForResponse();
m_motion[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
m_motion[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
m_motion[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
m_motion[3] = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
m_motion[4] = ((m_results[11] & 0x7f) | ((m_results[12] & 0x7f) << 7));
m_motion[5] = ((m_results[13] & 0x7f) | ((m_results[13] & 0x7f) << 7));
for (int i=0; i<3; i++)
m_accel[i] = m_motion[i];
for (int i=0; i<3; i++)
m_gyro[i] = m_motion[i+3];
delete m_results;
unlock();
return;
}
int16_t
CurieImu::getTemperature()
{
char message[4];
message[0] = FIRMATA_START_SYSEX;
message[1] = FIRMATA_CURIE_IMU;
message[2] = FIRMATA_CURIE_IMU_READ_TEMP;
message[3] = FIRMATA_END_SYSEX;
lock();
mraa_firmata_response_stop(m_firmata);
mraa_firmata_response(m_firmata, handleSyncResponse);
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
waitForResponse();
int16_t result;
result = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
result += ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7)) << 8;
delete m_results;
unlock();
return result;
}
int16_t
CurieImu::getAxis()
{
return m_axis;
}
int16_t
CurieImu::getDirection()
{
return m_direction;
}
void
CurieImu::enableShockDetection(bool enable)
{
char message[5];
message[0] = FIRMATA_START_SYSEX;
message[1] = FIRMATA_CURIE_IMU;
message[2] = FIRMATA_CURIE_IMU_SHOCK_DETECT;
message[3] = enable;
message[4] = FIRMATA_END_SYSEX;
lock();
mraa_firmata_response_stop(m_firmata);
mraa_firmata_response(m_firmata, handleAsyncResponses);
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
awaitingReponse = this;
unlock();
return;
}
bool
CurieImu::isShockDetected()
{
return (m_shockData.size() > 0);
}
void
CurieImu::getNextShock()
{
if (m_shockData.size() > 0) {
IMUDataItem* item = m_shockData.front();
m_axis = item->axis;
m_direction = item->direction;
m_shockData.pop();
delete item;
}
}
void
CurieImu::enableStepCounter(bool enable)
{
char message[5];
message[0] = FIRMATA_START_SYSEX;
message[1] = FIRMATA_CURIE_IMU;
message[2] = FIRMATA_CURIE_IMU_STEP_COUNTER;
message[3] = enable;
message[4] = FIRMATA_END_SYSEX;
lock();
mraa_firmata_response_stop(m_firmata);
mraa_firmata_response(m_firmata, handleAsyncResponses);
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
awaitingReponse = this;
unlock();
return;
}
bool
CurieImu::isStepDetected()
{
return (m_stepData.size() > 0);
}
int16_t
CurieImu::getStepCount()
{
int16_t count = 0;
if (m_stepData.size() > 0) {
count = m_stepData.front();
m_stepData.pop();
}
return count;
}
void
CurieImu::enableTapDetection(bool enable)
{
char message[5];
message[0] = FIRMATA_START_SYSEX;
message[1] = FIRMATA_CURIE_IMU;
message[2] = FIRMATA_CURIE_IMU_TAP_DETECT;
message[3] = enable;
message[4] = FIRMATA_END_SYSEX;
lock();
mraa_firmata_response_stop(m_firmata);
mraa_firmata_response(m_firmata, handleAsyncResponses);
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
awaitingReponse = this;
unlock();
return;
}
bool
CurieImu::isTapDetected()
{
return (m_tapData.size() > 0);
}
void
CurieImu::getNextTap()
{
if (m_tapData.size() > 0) {
IMUDataItem* item = m_tapData.front();
m_axis = item->axis;
m_direction = item->direction;
m_tapData.pop();
delete item;
}
}

307
src/curieimu/curieimu.hpp Normal file
View File

@ -0,0 +1,307 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Author: Ron Evans (@deadprogram)
* Author: Justin Zemlyansky (@JustInDevelopment)
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <mraa/firmata.h>
#include <queue>
namespace upm {
/**
* @brief CurieIMU sensor for Genuino 101 running Firmata
* @defgroup curieimu libupm-curieimu
* @ingroup firmata
*/
/**
* @library curieimu
* @sensor curieimu
* @comname Curie IMU sensor over Genuino 101 running Firmata
* @altname Curie Firmata IMU
* @type firmata
* @man firmata imu genuino
* @con firmata
*
* @brief API for the Curie IMU via Firmata
*
* Curie IMU is a 6-axxis acclerometer
*
* This module has been tested on an Genuino 101 running ConfigurableFirmata with CurieIMU
*
* @snippet curieimu.cxx Interesting
*/
#define FIRMATA_START_SYSEX 0xF0
#define FIRMATA_END_SYSEX 0xF7
#define FIRMATA_CURIE_IMU 0x11
#define FIRMATA_CURIE_IMU_READ_ACCEL 0x00
#define FIRMATA_CURIE_IMU_READ_GYRO 0x01
#define FIRMATA_CURIE_IMU_READ_TEMP 0x02
#define FIRMATA_CURIE_IMU_SHOCK_DETECT 0x03
#define FIRMATA_CURIE_IMU_STEP_COUNTER 0x04
#define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
#define FIRMATA_CURIE_IMU_READ_MOTION 0x06
#define X 0
#define Y 1
#define Z 2
struct IMUDataItem {
int axis;
int direction;
};
class CurieImu {
public:
/**
* Instantiates a CurieImu object
*
* @param subplatformoffset Subplatform offset
*/
CurieImu (int subplatform_offset=512);
/**
* Destructor for CurieImu object
*/
~CurieImu();
/**
* Updates the latest accelerometer readings by calling Firmata
*/
void updateAccel();
/**
* Updates the latest gyroscope readings by calling Firmata
*/
void updateGyro();
/**
* Updates the both the latest accelerometer & gyroscope readings
* by calling Firmata
*/
void updateMotion();
/**
* Returns last accelerometer reading X, Y, and Z axis
*
* @return pointer to array with X-axis, Y-axis & Z-axis value
*/
int16_t* getAccel();
/**
* Returns last accelerometer reading X axis
*
* @return X-axis value
*/
int16_t getAccelX();
/**
* Returns last accelerometer reading Y axis
*
* @return Y-axis value
*/
int16_t getAccelY();
/**
* Returns last accelerometer reading Z axis
*
* @return Z-axis value
*/
int16_t getAccelZ();
/**
* Read gyroscope X, Y, and Z axis
*
* @return pointer to array with X-axis, Y-axis & Z-axis value
*/
int16_t* getGyro();
/**
* Returns last gyroscope reading X axis
*
* @return X-axis value
*/
int16_t getGyroX();
/**
* Returns last gyroscope reading Y axis
*
* @return Y-axis value
*/
int16_t getGyroY();
/**
* Returns last gyroscope reading Z axis
*
* @return Z-axis value
*/
int16_t getGyroZ();
/**
* Reads the internal temperature
*
* @return 16-bit integer containing the scaled temperature reading
*/
int16_t getTemperature();
/**
* Reads the X, Y, and Z axis of both gyroscope and accelerometer
*
* @return pointer to array with X-axis, Y-axis & Z-axis values for
* accelerometer, and then X-axis, Y-axis & Z-axis values for
* gyroscope
*/
int16_t* getMotion();
/**
* Returns last shock or tap axis reading
*
* @return axis value
*/
int16_t getAxis();
/**
* Returns last shock or tap direction reading
*
* @return direction value
*/
int16_t getDirection();
/**
* Turns shock detection notifications on/off
*
* @param enable enables/disables notifications
*/
void enableShockDetection(bool enable);
/**
* Has there been a shock detected?
*
* @return true if any unprocessed shock notifications are in the queue
*/
bool isShockDetected();
/**
* Gets shock detect data from queue. Then m_axis gets axis data, and
* m_direction gets direction data
*/
void getNextShock();
/**
* Turns step counter notifications on/off
*
* @param enable enables/disables notifications
*/
void enableStepCounter(bool enable);
/**
* Has there been a step detected?
*
* @return true if any unprocessed step notifications are in the queue
*/
bool isStepDetected();
/**
* Gets step count data from queue
*
* @return the total number of steps taken
*/
int16_t getStepCount();
/**
* Turns tap detection notifications on/off
*
* @param enable enables/disables notifications
*/
void enableTapDetection(bool enable);
/**
* Has there been a tap detected?
*
* @return true if any unprocessed tap notifications are in the queue
*/
bool isTapDetected();
/**
* Gets tap detect data from queue. Then m_axis gets axis data, and
* m_direction gets direction data
*/
void getNextTap();
/**
* Locks responses from Firmata
*/
void lock();
/**
* Unlocks responses from Firmata
*/
void unlock();
/**
* Wait for a response from Firmata before proceeding
*/
void waitForResponse();
/**
* Proceed with original function call now that response
* from Firmata has been received
*/
void proceed();
/**
* Set results being returned from Firmata for processing
*
* @param buf is the buffer
* @param length is the length of results buffer
*/
void setResults(uint8_t* buf, int length);
/**
* Processes asyncronous responses returned from Firmata
*/
void processResponse();
private:
mraa_firmata_context m_firmata;
pthread_mutex_t m_responseLock;
pthread_cond_t m_responseCond;
char* m_results;
std::queue<IMUDataItem*> m_shockData;
std::queue<int> m_stepData;
std::queue<IMUDataItem*> m_tapData;
int16_t m_accel[3];
int16_t m_gyro[3];
int16_t m_motion[6];
int16_t m_axis;
int16_t m_direction;
};
}

View File

@ -0,0 +1,42 @@
%module javaupm_curieimu
%include "../upm.i"
%{
#include "curieimu.hpp"
%}
%typemap(jni) int16_t* "jshortArray"
%typemap(jstype) int16_t* "short[]"
%typemap(jtype) int16_t* "short[]"
%typemap(javaout) int16_t* {
return $jnicall;
}
%typemap(out) int16_t *getAccel {
$result = JCALL1(NewShortArray, jenv, 3);
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
}
%typemap(out) int16_t *getGyro {
$result = JCALL1(NewShortArray, jenv, 3);
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
}
%typemap(out) int16_t *getMotion {
$result = JCALL1(NewShortArray, jenv, 6);
JCALL4(SetShortArrayRegion, jenv, $result, 0, 6, (jshort*)$1);
}
%include "curieimu.hpp"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_curieimu");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}

View File

@ -0,0 +1,15 @@
%module jsupm_curieimu
%include "../upm.i"
%include "../carrays_int16_t.i"
// Adding this typemap because SWIG is converting int16 into a short by default
// This forces SWIG to convert it correctly
%typemap(out) int16_t* {
jsresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 );
}
%{
#include "curieimu.hpp"
%}
%include "curieimu.hpp"

View File

@ -0,0 +1,21 @@
// Include doxygen-generated documentation
%include "pyupm_doxy2swig.i"
%module pyupm_curieimu
%include "../upm.i"
%include "../carrays_int16_t.i"
%include "stdint.i"
%feature("autodoc", "3");
#ifdef DOXYGEN
%include "curieupm_doc.i"
#endif
%typemap(out) int16_t* {
$result = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 );
}
%include "curieimu.hpp"
%{
#include "curieimu.hpp"
%}

View File

@ -83,6 +83,7 @@ namespace upm {
* this calibration, you can measure the pH value of an alkaline
* solution.
*
* @image html dfrph.jpg
* @snippet dfrph.cxx Interesting
*/

View File

@ -1,5 +0,0 @@
set (libname "grovecircularled")
set (libdescription "upm grove circular led")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -1,141 +0,0 @@
/*
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* This module is based on the my9221 driver
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#include <unistd.h>
#include <stdlib.h>
#include "grovecircularled.h"
using namespace upm;
GroveCircularLED::GroveCircularLED (uint8_t di, uint8_t dcki)
: m_clkPinCtx(dcki),
m_dataPinCtx(di)
{
mraa::Result error = mraa::SUCCESS;
// set direction (out)
error = m_dataPinCtx.dir(mraa::DIR_OUT);
if (error != mraa::SUCCESS) {
printError(error);
}
error = m_clkPinCtx.dir(mraa::DIR_OUT);
if (error != mraa::SUCCESS) {
printError(error);
}
m_clkPinCtx.useMmap(true);
m_dataPinCtx.useMmap(true);
}
mraa::Result
GroveCircularLED::setSpinner (uint8_t position) {
if (position < 0 || position >= 24) {
return mraa::ERROR_INVALID_PARAMETER;
}
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
if (block_idx % 12 == 0) {
send16bitBlock (CMDMODE);
}
uint32_t state = (block_idx == position) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
}
return lockData ();
}
mraa::Result
GroveCircularLED::setLevel (uint8_t level, bool direction) {
if (level < 0 || level > 24) {
return mraa::ERROR_INVALID_PARAMETER;
}
if (direction) {
for(uint8_t block_idx = 24; block_idx > 0; block_idx--) {
if (block_idx % 12 == 0) {
send16bitBlock (CMDMODE);
}
uint32_t state = (block_idx <= level) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
}
} else {
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
if (block_idx % 12 == 0) {
send16bitBlock (CMDMODE);
}
uint32_t state = (block_idx <= level - 1) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
}
}
return lockData ();
}
mraa::Result
GroveCircularLED::setStatus (bool status[24]) {
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
if (block_idx % 12 == 0) {
send16bitBlock (CMDMODE);
}
send16bitBlock (status[block_idx] ? BIT_HIGH : BIT_LOW);
}
return lockData ();
}
mraa::Result
GroveCircularLED::lockData () {
mraa::Result error = mraa::SUCCESS;
error = m_dataPinCtx.write (LOW);
usleep(10);
for(int idx = 0; idx < 4; idx++) {
error = m_dataPinCtx.write(HIGH);
error = m_dataPinCtx.write(LOW);
}
return error;
}
mraa::Result
GroveCircularLED::send16bitBlock (short data) {
mraa::Result error = mraa::SUCCESS;
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
uint32_t state = (data & 0x8000) ? HIGH : LOW;
error = m_dataPinCtx.write (state);
state = m_clkPinCtx.read ();
if (state) {
state = LOW;
} else {
state = HIGH;
}
error = m_clkPinCtx.write (state);
data <<= 1;
}
return error;
}

View File

@ -1,8 +0,0 @@
%module jsupm_grovecircularled
%include "../upm.i"
%{
#include "grovecircularled.h"
%}
%include "grovecircularled.h"

View File

@ -1,11 +0,0 @@
// Include doxygen-generated documentation
%include "pyupm_doxy2swig.i"
%module pyupm_grovecircularled
%include "../upm.i"
%feature("autodoc", "3");
%include "grovecircularled.h"
%{
#include "grovecircularled.h"
%}

View File

@ -46,7 +46,7 @@ namespace upm {
* @sensor groveultrasonic
* @comname Grove Ultrasonic Ranger
* @type sound
* @man grove
* @man seeed
* @con gpio
*
* @brief API for Grove Ultrasonic Ranger
@ -57,6 +57,7 @@ namespace upm {
* to 4 m (13'1.5") and works best when the object is within a 30 degree angle
* relative to the sensor.
*
* @image html groveultrasonic.jpg
* @snippet groveultrasonic.cxx Interesting
*/
class GroveUltraSonic {

View File

@ -57,16 +57,20 @@ H3LIS331DL::~H3LIS331DL()
bool H3LIS331DL::init(DR_BITS_T odr, PM_BITS_T pm, FS_BITS_T fs)
{
if (!setDataRate(odr))
if (!setDataRate(odr)) {
return false;
if (!setPowerMode(pm))
}
if (!setPowerMode(pm)) {
return false;
if (!setFullScale(fs))
}
if (!setFullScale(fs)) {
return false;
}
// now enable X, Y, and Z axes
if (enableAxis(REG1_XEN | REG1_YEN | REG1_ZEN))
if (!enableAxis(REG1_XEN | REG1_YEN | REG1_ZEN)) {
return false;
}
return true;
}

View File

@ -52,6 +52,7 @@ namespace upm {
*
* This module defines the HC-SR04 interface for libhcsr04
*
* @image html groveultrasonic.jpg
* @snippet hcsr04.cxx Interesting
*/
class HCSR04 {

View File

@ -86,7 +86,7 @@ Itg3200::calibrate(void)
for(int i = 0; i < reads; i++){
Itg3200::update();
if (i > skip){
if (i >= skip){
for (int j = 0; j < 3; j++){
temp[j] += m_rotation[j];
}

View File

@ -45,6 +45,14 @@
namespace upm
{
const uint8_t COLOR_WHITE = 0x01;
const uint8_t COLOR_BLACK = 0x00;
const uint8_t COLOR_XOR = 0x02;
const uint8_t OLED_WIDTH = 0x40; // 64 pixels
const uint8_t VERT_COLUMNS = 0x20; // half width for hi/lo 16bit writes.
const uint8_t OLED_HEIGHT = 0x30; // 48 pixels
const int BUFFER_SIZE = 192;
/**
* @library i2clcd
* @sensor eboled
@ -66,17 +74,13 @@ namespace upm
* standard GPIO -- this driver only concerns itself with the
* display.
*
* @image html eboled.jpg
* <br><em>OLED Sensor image provided by SparkFun* under
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
* CC BY-NC-SA-3.0</a>.</em>
*
* @snippet eboled.cxx Interesting
*/
const uint8_t COLOR_WHITE = 0x01;
const uint8_t COLOR_BLACK = 0x00;
const uint8_t COLOR_XOR = 0x02;
const uint8_t OLED_WIDTH = 0x40; // 64 pixels
const uint8_t VERT_COLUMNS = 0x20; // half width for hi/lo 16bit writes.
const uint8_t OLED_HEIGHT = 0x30; // 48 pixels
const int BUFFER_SIZE = 192;
class EBOLED : public LCD
{
// SSD commands

View File

@ -32,7 +32,7 @@ namespace upm
/**
* @brief I2C LCD Display library
* @defgroup i2clcd libupm-i2clcd
* @ingroup seeed sparkfun adafruit i2c gpio display gsk
* @ingroup dfrobot sainsmart seeed sparkfun adafruit i2c gpio display gsk
*/
class LCD
{

View File

@ -62,7 +62,10 @@ namespace upm
* an I2C expander/backpack.
*
* @image html lcm1602.jpeg
* @snippet lcm1602-lcd.cxx Interesting
* Example for LCM1602 displays that use the I2C bus
* @snippet lcm1602-i2c.cxx Interesting
* Code sample for GPIO based LCM1602 displays
* @snippet lcm1602-parallel.cxx Interesting
*/
class Lcm1602 : public LCD
{

View File

@ -34,16 +34,20 @@ namespace upm
* @sensor sainsmartks
* @comname SainSmart LCD Keypad Shield
* @type display
* @man sainsmart
* @man sainsmart dfrobot sparkfun
* @web http://www.sainsmart.com/sainsmart-1602-lcd-keypad-shield-for-arduino-duemilanove-uno-mega2560-mega1280.html
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=51
* @web https://www.sparkfun.com/products/13293
* @con gpio analog
*
* @brief API for Sainsmart LCD Keypad Shield
*
* The Sainsmart LCD Keypad Shield uses 6 digital outputs and 1
* analog input (for the keypad). The outputs are used to drive an
* attached LCM1602 LCD controller.
* The Sainsmart LCD Keypad Shield uses 6 digital outputs and 1 analog input
* (for the keypad). The outputs are used to drive an attached LCM1602 LCD
* controller. This driver should also be compatible with the similar LCD
* keypad shields from DFRobot and Sparkfun.
*
* @image html keypadlcd.jpg
* @snippet sainsmartks.cxx Interesting
*/
class SAINSMARTKS : public Lcm1602

View File

@ -54,6 +54,7 @@ namespace upm {
* This driver was developed using the DFRobot LM35 Linear
* Temperature Sensor
*
* @image html lm35.jpg
* @snippet lm35.cxx Interesting
*/

View File

@ -68,6 +68,11 @@ namespace upm {
*
* This driver was developed on a Sparkfun 9DOF edison block.
*
* @image html lsm9ds0.jpg
* <br><em>LSM9DS0 Sensor image provided by SparkFun* under
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
* CC BY-NC-SA-3.0</a>.</em>
*
* @snippet lsm9ds0.cxx Interesting
*/

View File

@ -64,6 +64,7 @@ namespace upm {
* on the sensor will light, and the digital pin will be driven
* high.
*
* @image html mg811.jpg
* @snippet mg811.cxx Interesting
*/

View File

@ -38,7 +38,7 @@ namespace upm {
* @comname AK8975 3-axis Magnetometer
* @altname AK9875
* @type compass
* @man grove
* @man seeed
* @con i2c
*
* @brief API for the AK8975 magnetometer

View File

@ -55,6 +55,7 @@ namespace upm {
* should allow an end user to implement whatever features are
* required.
*
* @image html mpu60x0.jpg
* @snippet mpu60x0.cxx Interesting
*/
class MPU60X0 {

View File

@ -46,6 +46,7 @@ namespace upm {
*
* This module defines the MPU9250 interface for libmpu9150
*
* @image html mpu9250.jpg
* @snippet mpu9250.cxx Interesting
*/

View File

@ -1,5 +1,5 @@
set (libname "my9221")
set (libdescription "upm ledbar")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
set (libdescription "upm my9221")
set (module_src ${libname}.cxx groveledbar.cxx grovecircularled.cxx)
set (module_h ${libname}.h groveledbar.h grovecircularled.h)
upm_module_init()

View File

@ -0,0 +1,94 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* These modules were rewritten, based on original work by:
*
* (original my9221/groveledbar driver)
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* (grovecircularled driver)
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#include <unistd.h>
#include <stdlib.h>
#include "grovecircularled.h"
using namespace upm;
using namespace std;
GroveCircularLED::GroveCircularLED (uint8_t dataPin, uint8_t clockPin)
: MY9221(dataPin, clockPin, 2)
{
// auto refresh by default
setAutoRefresh(true);
clearAll();
}
GroveCircularLED::~GroveCircularLED()
{
}
void GroveCircularLED::setSpinner(uint8_t position)
{
if (position > 23)
position = 23;
for (uint8_t i=0; i<(LEDS_PER_INSTANCE * m_instances); i++)
m_bitStates[i] = (i == position) ? m_highIntensity : m_lowIntensity;
if (m_autoRefresh)
refresh();
return;
}
void GroveCircularLED::setLevel(uint8_t level, bool direction)
{
if (level > 23)
level = 23;
if (!direction)
{
for (int i=0; i<(LEDS_PER_INSTANCE * m_instances); i++)
m_bitStates[i] = (i < level) ? m_highIntensity : m_lowIntensity;
}
else
{
for (int i=0; i<(LEDS_PER_INSTANCE * m_instances); i++)
m_bitStates[i] = (((LEDS_PER_INSTANCE * m_instances) - i) <= level)
? m_highIntensity : m_lowIntensity;
}
if (m_autoRefresh)
refresh();
return;
}

View File

@ -1,10 +1,18 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* These modules were rewritten, based on original work by:
*
* (original my9221/groveledbar)
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* (grovecircularled)
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* This module is based on the my9221 driver
*
* 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
@ -27,29 +35,14 @@
#pragma once
#include <string>
#include <mraa/aio.hpp>
#include <mraa/common.hpp>
#include <mraa/gpio.hpp>
#define MAX_BIT_PER_BLOCK 16
#define CMDMODE 0x0000
#define BIT_HIGH 0x00ff
#define BIT_LOW 0x0000
#define HIGH 1
#define LOW 0
#include "my9221.h"
namespace upm {
/**
* @brief Grove Circular LED library
* @defgroup grovecircularled libupm-grovecircularled
* @ingroup seeed display gpio
*/
/**
* @library grovecircularled
* @library my9221
* @sensor grovecircularled
* @comname Grove Circular LED
* @type display
@ -65,52 +58,39 @@ namespace upm {
* @image html grovecircularled.jpg
* @snippet grovecircularled.cxx Interesting
*/
class GroveCircularLED {
class GroveCircularLED : public MY9221 {
public:
/**
* Instantiates an MY9221 object
* Instantiates an GroveCircularLED object
*
* @param di Data pin
* @param dcki Clock pin
* @param dataPin Data pin
* @param clockPin Clock pin
*/
GroveCircularLED (uint8_t di, uint8_t dcki);
GroveCircularLED(uint8_t dataPin, uint8_t clockPin);
/**
* Sets the lighting status
*
* @param level Selected level for the circular LED (0-24)
* @param direction Up or down; up is true and default
* GroveCircularLED destructor
*/
mraa::Result setLevel (uint8_t level, bool direction=true);
~GroveCircularLED();
/**
* Sets the spinner (lights up all the other LEDs but one)
* Sets the spinner (turns off all LEDs but selected one)
*
* @param position Selected position for the spinner (0-23)
*/
mraa::Result setSpinner (uint8_t position);
void setSpinner(uint8_t position);
/**
* Sets the lighting status
*
* @param status Boolean array (24 elements)
* @param level Selected level for the circular LED (0-23)
* @param direction Up or down; up is true and default
*/
mraa::Result setStatus (bool status[24]);
void setLevel(uint8_t level, bool direction=true);
/**
* Returns the name of the component
*/
std::string name()
{
return m_name;
}
protected:
private:
mraa::Result lockData ();
mraa::Result send16bitBlock (short data);
std::string m_name;
mraa::Gpio m_clkPinCtx;
mraa::Gpio m_dataPinCtx;
};
}

View File

@ -0,0 +1,88 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* These modules were rewritten, based on original work by:
*
* (original my9221/groveledbar driver)
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* (grovecircularled driver)
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#include <unistd.h>
#include <stdlib.h>
#include "groveledbar.h"
using namespace upm;
using namespace std;
GroveLEDBar::GroveLEDBar (uint8_t dataPin, uint8_t clockPin, int instances)
: MY9221(dataPin, clockPin, instances)
{
// auto refresh by default
setAutoRefresh(true);
clearAll();
}
GroveLEDBar::~GroveLEDBar()
{
}
void GroveLEDBar::setBarLevel(uint8_t level, bool greenToRed, int barNumber)
{
if (level > 10)
level = 10;
if (barNumber >= m_instances)
barNumber = m_instances - 1;
int start = barNumber * LEDS_PER_INSTANCE;
int end = start + LEDS_PER_INSTANCE;
if (!greenToRed)
{
for (int i=start; i<end; i++)
m_bitStates[i] = (i < (level + start)) ?
m_highIntensity : m_lowIntensity;
}
else
{
for (int i=start; i<end; i++)
m_bitStates[i] = ( ((start + LEDS_PER_INSTANCE) - i) <=
(level + 2 + start)) ?
m_highIntensity : m_lowIntensity;
}
if (m_autoRefresh)
refresh();
return;
}

99
src/my9221/groveledbar.h Normal file
View File

@ -0,0 +1,99 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* These modules were rewritten, based on original work by:
*
* (original my9221/groveledbar)
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* (grovecircularled)
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.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.
*/
#pragma once
#include <string>
#include <mraa/common.hpp>
#include <mraa/gpio.hpp>
#include "my9221.h"
namespace upm {
/**
* @library my9221
* @sensor groveledbar
* @comname Grove LED Bar
* @altname MY9221 LED Bar
* @type display
* @man seeed
* @web http://www.seeedstudio.com/wiki/Grove_-_LED_Bar
* @con gpio
* @kit eak
*
* @brief API for Grove LED Bars base on the MY9221
*
* This is a 10-segment LED bar, with 8 green segments, 1 yellow
* segment, and one red segment. They can be daisy chained together
* so that this module can control multiple LED bars.
*
* @image html my9221.jpg
* @snippet groveledbar.cxx Interesting
*/
class GroveLEDBar : public MY9221 {
public:
/**
* Instantiates an GroveLEDBar object
*
* @param dataPin Data pin
* @param clockPin Clock pin
* @param instances Number of daisy-chained Grove LED Bars, default 1
*/
GroveLEDBar(uint8_t dataPin, uint8_t clockPin, int instances=1);
/**
* GroveLEDBar destructor
*/
~GroveLEDBar();
/**
* Sets the bar level
*
* @param level Selected level for the bar (0 - 10). 0 is off
* @param greenToRed true if you start the level on the first
* green LED, false otherwise
* @param barNumber If you have multiple LED bars chained
* together, this argument selects a specific bar starting at 0.
* The default is 0.
*/
void setBarLevel(uint8_t level, bool greenToRed=true, int barNumber=0);
protected:
private:
};
}

View File

@ -1,11 +1,20 @@
%module javaupm_my9221
%include "../upm.i"
%include "my9221.h"
%{
#include "my9221.h"
%}
%include "my9221.h"
%include "groveledbar.h"
%{
#include "groveledbar.h"
%}
%include "grovecircularled.h"
%{
#include "grovecircularled.h"
%}
%pragma(java) jniclasscode=%{
static {
@ -16,4 +25,4 @@
System.exit(1);
}
}
%}
%}

View File

@ -1,8 +1,18 @@
%module jsupm_my9221
%include "../upm.i"
%include "my9221.h"
%{
#include "my9221.h"
%}
%include "my9221.h"
%include "groveledbar.h"
%{
#include "groveledbar.h"
%}
%include "grovecircularled.h"
%{
#include "grovecircularled.h"
%}

View File

@ -1,7 +1,18 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* These modules were rewritten, based on original work by:
*
* (original my9221/groveledbar driver)
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* (grovecircularled driver)
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.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
@ -31,76 +42,150 @@
#include "my9221.h"
using namespace upm;
using namespace std;
MY9221::MY9221 (uint8_t di, uint8_t dcki)
: m_clkPinCtx(dcki), m_dataPinCtx(di) {
mraa::Result error = mraa::SUCCESS;
// set direction (out)
error = m_clkPinCtx.dir(mraa::DIR_OUT);
if (error != mraa::SUCCESS) {
mraa::printError(error);
MY9221::MY9221 (uint8_t dataPin, uint8_t clockPin, int instances)
: m_gpioData(dataPin), m_gpioClk(clockPin), m_bitStates(0)
{
if (instances < 1)
{
throw std::out_of_range(std::string(__FUNCTION__) +
": instances must be at least 1");
}
// set direction (out)
error = m_dataPinCtx.dir(mraa::DIR_OUT);
if (error != mraa::SUCCESS) {
mraa::printError(error);
}
// set directions
m_gpioClk.dir(mraa::DIR_OUT);
m_gpioData.dir(mraa::DIR_OUT);
// we warn if these fail, since it may not be possible to handle
// more than one instance
if (m_gpioClk.useMmap(true) != mraa::SUCCESS)
cerr << __FUNCTION__
<< ": Warning: mmap of Clk pin failed, correct operation "
<< "may be affected."
<< endl;
if (m_gpioData.useMmap(true) != mraa::SUCCESS)
cerr << __FUNCTION__
<< ": Warning: mmap of Data pin failed, correct operation "
<< "may be affected."
<< endl;
setLowIntensityValue(0x00); // full off
setHighIntensityValue(0xff); // full brightness
m_commandWord = 0x0000; // all defaults
m_instances = instances;
m_bitStates = new uint16_t[instances * LEDS_PER_INSTANCE];
setAutoRefresh(true);
clearAll();
}
mraa::Result
MY9221::setBarLevel (uint8_t level, bool direction) {
if (level > 10) {
return mraa::ERROR_INVALID_PARAMETER;
}
MY9221::~MY9221()
{
clearAll();
send16bitBlock (CMDMODE);
if (direction) {
level += 3;
for(uint8_t block_idx = 12; block_idx > 0; block_idx--) {
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
}
} else {
for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
if (!m_autoRefresh)
refresh();
delete m_bitStates;
}
void MY9221::setLED(int led, bool on)
{
int maxLed = (LEDS_PER_INSTANCE * m_instances) - 1;
if (led > maxLed)
led = maxLed;
if (led < 0)
led = 0;
m_bitStates[led] = (on) ? m_highIntensity : m_lowIntensity;
if (m_autoRefresh)
refresh();
}
void MY9221::setLowIntensityValue(int intensity)
{
m_lowIntensity = (intensity & 0xff);
}
void MY9221::setHighIntensityValue(int intensity)
{
m_highIntensity = (intensity & 0xff);
}
void MY9221::setAll()
{
for (int i=0; i<(m_instances * LEDS_PER_INSTANCE); i++)
m_bitStates[i] = m_highIntensity;
if (m_autoRefresh)
refresh();
}
void MY9221::clearAll()
{
for (int i=0; i<(m_instances * LEDS_PER_INSTANCE); i++)
m_bitStates[i] = m_lowIntensity;
if (m_autoRefresh)
refresh();
}
void MY9221::refresh()
{
for (int i=0; i<(m_instances * LEDS_PER_INSTANCE); i++)
{
if (i % 12 == 0)
{
send16bitBlock(m_commandWord);
}
send16bitBlock(m_bitStates[i]);
}
return lockData ();
lockData();
}
mraa::Result
MY9221::lockData () {
mraa::Result error = mraa::SUCCESS;
error = m_dataPinCtx.write(LOW);
usleep(100);
void MY9221::lockData()
{
m_gpioData.write(0);
usleep(220);
for(int idx = 0; idx < 4; idx++) {
error = m_dataPinCtx.write(HIGH);
error = m_dataPinCtx.write(LOW);
for(int idx = 0; idx < 4; idx++)
{
m_gpioData.write(1);
m_gpioData.write(0);
}
return error;
// in reality, we only need > 200ns + (m_instances * 10ns), so the
// following should be good for up to m_instances < 80), if the
// datasheet is to be believed :)
usleep(1);
return;
}
mraa::Result
MY9221::send16bitBlock (short data) {
mraa::Result error = mraa::SUCCESS;
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
uint32_t state = (data & 0x8000) ? HIGH : LOW;
error = m_dataPinCtx.write(state);
state = m_clkPinCtx.read();
void MY9221::send16bitBlock(uint16_t data)
{
for (uint8_t bit_idx = 0; bit_idx < 16; bit_idx++)
{
uint32_t state = (data & 0x8000) ? 1 : 0;
m_gpioData.write(state);
state = m_gpioClk.read();
if (state) {
state = LOW;
} else {
state = HIGH;
}
error = m_clkPinCtx.write(state);
data <<= 1;
if (state)
state = 0;
else
state = 1;
m_gpioClk.write(state);
data <<= 1;
}
return error;
return;
}

View File

@ -1,7 +1,18 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* These modules were rewritten, based on original work by:
*
* (original my9221/groveledbar)
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* (grovecircularled)
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.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
@ -24,77 +35,118 @@
#pragma once
#include <string>
#include <mraa/aio.hpp>
#include <mraa/common.hpp>
#include <mraa/gpio.hpp>
#define MAX_BIT_PER_BLOCK 16
#define CMDMODE 0x0000
#define BIT_HIGH 0x00ff
#define BIT_LOW 0x0000
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief MY9221 LED Bar library
* @defgroup my9221 libupm-my9221
* @ingroup seeed display gpio eak
*/
/**
* @library my9221
* @sensor my9221
* @comname Grove LED Bar
* @altname MY9221 LED Bar
* @type display
* @man seeed
* @web http://www.seeedstudio.com/wiki/Grove_-_LED_Bar
* @con gpio
* @kit eak
*
* @brief API for MY9221-based LED Bars
*
* This module defines the MY9221 interface for libmy9221
*
* @image html my9221.jpg
* @snippet my9221-ledbar.cxx Interesting
* @snippet my9221-updown.cxx Interesting
*/
class MY9221 {
public:
/**
* Instantiates an MY9221 object
*
* @param di Data pin
* @param dcki Clock pin
*/
MY9221 (uint8_t di, uint8_t dcki);
/**
* @brief MY9221 LED Controller library
* @defgroup my9221 libupm-my9221
* @ingroup seeed display gpio eak
*/
class MY9221 {
public:
/**
* Sets the bar level
*
* @param level Selected level for the bar (1 - 10)
* @param direction Up or down; up is true and default
*/
mraa::Result setBarLevel (uint8_t level, bool direction=true);
// 12 LED channels per chip (instance)
static const int LEDS_PER_INSTANCE = 12;
/**
* Returns the name of the component
*/
std::string name()
{
return m_name;
}
private:
mraa::Result lockData ();
mraa::Result send16bitBlock (short data);
/**
* Instantiates an MY9221 object
*
* @param dataPin Data pin
* @param clockPin Clock pin
* @param instances Number of daisy-chained my9221s, default 1
*/
MY9221(uint8_t dataPin, uint8_t clockPin, int instances=1);
std::string m_name;
mraa::Gpio m_clkPinCtx;
mraa::Gpio m_dataPinCtx;
};
/**
* MY9221 destructor
*/
~MY9221();
/**
* Enable or disable auto refresh. When auto refresh is enabled,
* update the LED display as soon as the internal state changes.
* When false, the display(s) will not be updated until the
* refresh() method is called.
*
* @param enable true to enable auto refresh, false otherwise
*/
void setAutoRefresh(bool enable)
{
m_autoRefresh = enable;
}
/**
* Set an LED to a specific on (high intensity) or off (low
* intensity) value.
*
* @param led The LED whose state you wish to change
* @param on true to turn on the LED, false to turn the LED off
*/
void setLED(int led, bool on);
/**
* Set the greyscale intensity of an LED in the OFF state. The
* intensity is a value from 0 (fully off) to 255 (fully on).
* This will take effect on any future LED set or clear
* operations.
*
* @param intensity a value from 0 (fully off) to 255 (fully on)
*/
void setLowIntensityValue(int intensity);
/**
* Set the greyscale intensity of an LED in the ON state. The
* intensity is a value from 0 (fully off) to 255 (fully on).
* This will take effect on any future LED set or clear
* operations.
*
* @param intensity a value from 0 (fully off) to 255 (fully on)
*/
void setHighIntensityValue(int intensity);
/**
* Set all of the LEDS to the ON (high intensity value) state.
*/
void setAll();
/**
* Set all of the LEDS to the OFF (low intensity value) state.
*/
void clearAll();
/**
* Set the LED states to match the internal stored states. This
* is useful when auto refresh (setAutoRefresh()) is false to
* update the display.
*/
void refresh();
protected:
virtual void lockData();
virtual void send16bitBlock(uint16_t data);
bool m_autoRefresh;
// we're only doing 8-bit greyscale, so the high order bits are
// always 0
uint16_t m_lowIntensity;
uint16_t m_highIntensity;
unsigned int m_instances;
// an array of uint16_t's representing our bit states (on/off)
// intensities. Only the low 8 bits are used, but in the future
// 16bit support can work here as well.
uint16_t *m_bitStates;
uint16_t m_commandWord;
mraa::Gpio m_gpioClk;
mraa::Gpio m_gpioData;
private:
};
}

View File

@ -9,3 +9,13 @@
%{
#include "my9221.h"
%}
%include "groveledbar.h"
%{
#include "groveledbar.h"
%}
%include "grovecircularled.h"
%{
#include "grovecircularled.h"
%}

View File

@ -66,6 +66,7 @@ namespace upm {
*
* @brief API for the PN532 based NFC/RFID reader/writer
*
* @image html pn532.jpg
* Identify a card and print out basic info
* @snippet pn532.cxx Interesting
* Add a URI to an already NDEF formatted ultralight or NTAG2XX tag

View File

@ -0,0 +1,5 @@
set (libname "ssd1351")
set (libdescription "libupm SSD1351 SPI LCD")
set (module_src gfx.cxx ssd1351.cxx)
set (module_h gfx.h ssd1351.h)
upm_module_init()

218
src/ssd1351/gfx.cxx Normal file
View File

@ -0,0 +1,218 @@
/*
* Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
*
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include "gfx.h"
using namespace upm;
GFX::GFX (int width, int height) : m_width(width), m_height(height),
m_textSize(1), m_textColor(0xFFFF), m_textBGColor(0x0000),
m_cursorX(0), m_cursorY(0), m_font(font) {
}
GFX::~GFX () {
}
void
GFX::fillScreen (uint16_t color) {
fillRect(0, 0, m_width, m_height, color);
}
void
GFX::fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
for (int16_t i=x; i<x+w; i++) {
drawFastVLine(i, y, h, color);
}
}
void
GFX::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
drawLine(x, y, x, y+h-1, color);
}
void
GFX::drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
swap(x0, y0);
swap(x1, y1);
}
if (x0 > x1) {
swap(x0, x1);
swap(y0, y1);
}
int16_t dx, dy;
dx = x1 - x0;
dy = abs (y1 - y0);
int16_t err = dx / 2;
int16_t ystep;
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
for (; x0 <= x1; x0++) {
if (steep) {
drawPixel(y0, x0, color);
} else {
drawPixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
}
void
GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
drawLine(x0, y0, x1, y1, color);
drawLine(x1, y1, x2, y2, color);
drawLine(x2, y2, x0, y0, color);
}
void
GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
drawPixel(x0 , y0+r, color);
drawPixel(x0 , y0-r, color);
drawPixel(x0+r, y0 , color);
drawPixel(x0-r, y0 , color);
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
drawPixel(x0 + x, y0 + y, color);
drawPixel(x0 - x, y0 + y, color);
drawPixel(x0 + x, y0 - y, color);
drawPixel(x0 - x, y0 - y, color);
drawPixel(x0 + y, y0 + x, color);
drawPixel(x0 - y, y0 + x, color);
drawPixel(x0 + y, y0 - x, color);
drawPixel(x0 - y, y0 - x, color);
}
}
void
GFX::setCursor (int16_t x, int16_t y) {
m_cursorX = x;
m_cursorY = y;
}
void
GFX::setTextColor (uint16_t textColor, uint16_t textBGColor) {
m_textColor = textColor;
m_textBGColor = textBGColor;
}
void
GFX::setTextSize (uint8_t size) {
m_textSize = (size > 0) ? size : 1;
}
void
GFX::setTextWrap (uint8_t wrap) {
m_wrap = wrap;
}
void
GFX::drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size) {
if( (x >= m_width) || // Clip right
(y >= m_height) || // Clip bottom
((x + 6 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
for (int8_t i=0; i<6; i++ ) {
uint8_t line;
if (i == 5) {
line = 0x0;
} else {
line = *(m_font+(data * 5)+i);
for (int8_t j = 0; j<8; j++) {
if (line & 0x1) {
if (size == 1) // default size
drawPixel (x+i, y+j, color);
else { // big size
fillRect (x+(i*size), y+(j*size), size, size, color);
}
} else if (bg != color) {
if (size == 1) // default size
drawPixel (x+i, y+j, bg);
else { // big size
fillRect (x+i*size, y+j*size, size, size, bg);
}
}
line >>= 1;
}
}
}
}
void
GFX::print (std::string msg) {
int len = msg.length();
for (int idx = 0; idx < len; idx++) {
if (msg[idx] == '\n') {
m_cursorY += m_textSize * 8;
m_cursorX = 0;
} else if (msg[idx] == '\r') {
// skip em
} else {
drawChar(m_cursorX, m_cursorY, msg[idx], m_textColor, m_textBGColor, m_textSize);
m_cursorX += m_textSize * 6;
if (m_wrap && ((m_cursorX + m_textSize * 6) >= m_width)) {
m_cursorY += m_textSize * 8;
m_cursorX = 0;
}
}
}
}

453
src/ssd1351/gfx.h Normal file
View File

@ -0,0 +1,453 @@
/*
* Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
*
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#define swap(a, b) { int16_t t = a; a = b; b = t; }
namespace upm {
const unsigned char font[] = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x21, 0x54, 0x54, 0x78, 0x41,
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0xF0, 0x29, 0x24, 0x29, 0xF0,
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x32, 0x48, 0x48, 0x48, 0x32,
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x39, 0x44, 0x44, 0x44, 0x39,
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0xAA, 0x00, 0x55, 0x00, 0xAA,
0xAA, 0x55, 0xAA, 0x55, 0xAA,
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0x7C, 0x2A, 0x2A, 0x3E, 0x14,
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00
};
/**
* @brief GFX helper class
*
* This file is used by the screen.
*/
class GFX {
public:
/**
* Instantiates a GFX object
*
* @param width Screen width
* @param height Screen height
*/
GFX (int width, int height);
/**
* GFX object destructor
*/
~GFX ();
/**
* Sends a pixel color (RGB) to the chip. Must be implemented by the
* inherited class.
*
* @param x Axis on the horizontal scale
* @param y Axis on the vertical scale
* @param color RGB value
*/
virtual void drawPixel (int16_t x, int16_t y, uint16_t color) = 0;
/**
* Copies the buffer to the chip via the SPI.
*/
virtual void refresh () = 0;
/**
*
*
* @param x Axis on the horizontal scale
* @param y Axis on the vertical scale
* @param data Character to write
* @param color Character color
* @param bg Character background color
* @param size Size of the font
*/
void drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size);
/**
* Prints a message on the screen
*
* @param msg Message to print
*/
void print (std::string msg);
/**
* Fills the screen with a selected color
*
* @param color Selected color
*/
void fillScreen (uint16_t color);
/**
* Fills a rectangle with a selected color
*
* @param x Axis on the horizontal scale (top-left corner)
* @param y Axis on the vertical scale (top-left corner)
* @param w Distanse from x
* @param h Distanse from y
* @param color Selected color
*/
void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
/**
* Draws a line on the vertical scale
*
* @param x Axis on the horizontal scale
* @param y Axis on the vertical scale
* @param h Distanse from y
* @param color Selected color
*/
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
/**
* Draws a line from coordinate C0 to coordinate C1
*
* @param x0 First coordinate
* @param y0 First coordinate
* @param x1 Second coordinate
* @param y1 Second coordinate
* @param color selected color
*/
void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
/**
* Draws a triangle
*
* @param x0 First coordinate
* @param y0 First coordinate
* @param x1 Second coordinate
* @param y1 Second coordinate
* @param x2 Third coordinate
* @param y2 Third coordinate
* @param color Selected color
*/
void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
/**
* Draws a circle
*
* @param x Center of the circle on the horizontal scale
* @param y Center of the circle on the vertical scale
* @param r Radius of the circle
* @param color Color of the circle
*/
void drawCircle (int16_t x, int16_t y, int16_t r, uint16_t color);
/**
* Sets the cursor for a text message
*
* @param x Axis on the horizontal scale
* @param y Axis on the vertical scale
*/
void setCursor (int16_t x, int16_t y);
/**
* Sets a text color for a message
*
* @param textColor Font color
* @param textBGColor Background color
*/
void setTextColor (uint16_t textColor, uint16_t textBGColor);
/**
* Sets the size of the font
*
* @param size Font size
*/
void setTextSize (uint8_t size);
/**
* Wraps a printed message
*
* @param wrap True (0x1) or false (0x0)
*/
void setTextWrap (uint8_t wrap);
protected:
int m_width; /**< Screen width */
int m_height; /**< Screen height */
int m_textSize; /**< Printed text size */
int m_textColor; /**< Printed text color */
int m_textBGColor; /**< Printed text background color */
int m_cursorX; /**< Cursor X coordinate */
int m_cursorY; /**< Cursor Y coordinate */
int m_wrap; /**< Wrapper flag (true or false) */
const unsigned char * m_font;
};
}

View File

@ -1,17 +1,25 @@
%module javaupm_grovecircularled
%module javaupm_ssd1351
%include "../upm.i"
%include "arrays_java.i";
%include "typemaps.i"
%include "stdint.i"
%ignore m_map;
%ignore font;
%include "gfx.h"
%{
#include "grovecircularled.h"
#include "gfx.h"
%}
%include "grovecircularled.h"
%include "ssd1351.h"
%{
#include "ssd1351.h"
%}
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_grovecircularled");
System.loadLibrary("javaupm_ssd1351");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);

View File

@ -0,0 +1,12 @@
%module jsupm_ssd1351
%include "../upm.i"
%include "gfx.h"
%{
#include "gfx.h"
%}
%include "ssd1351.h"
%{
#include "ssd1351.h"
%}

View File

@ -0,0 +1,17 @@
// Include doxygen-generated documentation
%include "pyupm_doxy2swig.i"
%module pyupm_ssd1351
%include "../upm.i"
%feature("autodoc", "3");
%rename("printString") print(std::string msg);
%include "gfx.h"
%{
#include "gfx.h"
%}
%include "ssd1351.h"
%{
#include "ssd1351.h"
%}

225
src/ssd1351/ssd1351.cxx Normal file
View File

@ -0,0 +1,225 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Based on Adafruit SSD1351 library.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include <stdexcept>
#include <unistd.h>
#include <stdlib.h>
#include "ssd1351.h"
using namespace upm;
using namespace std;
SSD1351::SSD1351 (uint8_t oc, uint8_t dc, uint8_t rst) :
GFX(SSD1351WIDTH, SSD1351HEIGHT),
m_spi(0), m_oc(oc), m_dc(dc), m_rst(rst) {
m_name = "SSD1351";
m_usemap = true;
// Setup SPI bus
m_spi.frequency(8 * 1000000);
m_spi.mode(mraa::SPI_MODE3);
m_spi.writeByte(0x00); // Need to bring clk high before init
// Init pins
if (m_oc.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
throw std::runtime_error(string(__FUNCTION__) +
": Could not initialize CS pin");
return;
}
m_oc.useMmap(true);
if (m_dc.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
throw std::runtime_error(string(__FUNCTION__) +
": Could not initialize data/cmd pin");
return;
}
m_dc.useMmap(true);
if (m_rst.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
throw std::runtime_error(string(__FUNCTION__) +
": Could not initialize reset pin");
return;
}
// Toggle reset pin
ocLow();
m_rst.write(1);
usleep(500000);
m_rst.write(0);
usleep(500000);
m_rst.write(1);
usleep(500000);
// Configure and init display
writeCommand(SSD1351_CMD_COMMANDLOCK);
writeData(0x12);
writeCommand(SSD1351_CMD_COMMANDLOCK);
writeData(0xB1);
writeCommand(SSD1351_CMD_DISPLAYOFF);
writeCommand(SSD1351_CMD_CLOCKDIV);
writeCommand(0xF1);
writeCommand(SSD1351_CMD_MUXRATIO);
writeData(127);
writeCommand(SSD1351_CMD_SETREMAP);
writeData(0x74);
writeCommand(SSD1351_CMD_SETCOLUMN);
writeData(0x00);
writeData(0x7F);
writeCommand(SSD1351_CMD_SETROW);
writeData(0x00);
writeData(0x7F);
writeCommand(SSD1351_CMD_STARTLINE);
if (SSD1351HEIGHT == 96) {
writeData(96);
} else {
writeData(0);
}
writeCommand(SSD1351_CMD_DISPLAYOFFSET);
writeData(0x0);
writeCommand(SSD1351_CMD_SETGPIO);
writeData(0x00);
writeCommand(SSD1351_CMD_FUNCTIONSELECT);
writeData(0x01);
writeCommand(SSD1351_CMD_PRECHARGE);
writeCommand(0x32);
writeCommand(SSD1351_CMD_VCOMH);
writeCommand(0x05);
writeCommand(SSD1351_CMD_NORMALDISPLAY);
writeCommand(SSD1351_CMD_CONTRASTABC);
writeData(0xC8);
writeData(0x80);
writeData(0xC8);
writeCommand(SSD1351_CMD_CONTRASTMASTER);
writeData(0x0F);
writeCommand(SSD1351_CMD_SETVSL );
writeData(0xA0);
writeData(0xB5);
writeData(0x55);
writeCommand(SSD1351_CMD_PRECHARGE2);
writeData(0x01);
writeCommand(SSD1351_CMD_DISPLAYON);
}
SSD1351::~SSD1351() {
}
void
SSD1351::writeCommand (uint8_t value) {
dcLow();
m_spi.writeByte(value);
}
void
SSD1351::writeData (uint8_t value) {
dcHigh ();
m_spi.writeByte(value);
}
void
SSD1351::drawPixel(int16_t x, int16_t y, uint16_t color) {
if ((x < 0) || (y < 0) || (x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT))
return;
if(m_usemap) {
int index = (y * SSD1351WIDTH + x) * 2;
m_map[index] = color >> 8;
m_map[index + 1] = color;
} else {
writeCommand(SSD1351_CMD_SETCOLUMN);
writeData(x);
writeData(SSD1351WIDTH-1);
writeCommand(SSD1351_CMD_SETROW);
writeData(y);
writeData(SSD1351HEIGHT-1);
writeCommand(SSD1351_CMD_WRITERAM);
writeData(color >> 8);
writeData(color);
}
}
void
SSD1351::refresh () {
writeCommand(SSD1351_CMD_WRITERAM);
int blockSize = SSD1351HEIGHT * SSD1351WIDTH * 2 / BLOCKS;
dcHigh();
for (int block = 0; block < BLOCKS; block++) {
m_spi.write(&m_map[block * blockSize], blockSize);
}
}
void
SSD1351::ocLow() {
if (m_oc.write(LOW) != mraa::SUCCESS) {
throw std::runtime_error(string(__FUNCTION__) +
": Failed to write CS pin");
}
}
void
SSD1351::ocHigh() {
if (m_oc.write(HIGH) != mraa::SUCCESS) {
throw std::runtime_error(string(__FUNCTION__) +
": Failed to write CS pin");
}
}
void
SSD1351::dcLow() {
if (m_dc.write(LOW) != mraa::SUCCESS) {
throw std::runtime_error(string(__FUNCTION__) +
": Failed to write data/cmd pin");
}
}
void
SSD1351::dcHigh() {
if (m_dc.write(HIGH) != mraa::SUCCESS) {
throw std::runtime_error(string(__FUNCTION__) +
": Failed to write data/cmd pin");
}
}
void
upm::SSD1351::useMemoryMap(bool var) {
m_usemap = var;
}

188
src/ssd1351/ssd1351.h Normal file
View File

@ -0,0 +1,188 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Based on Adafruit SSD1351 library.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/common.hpp>
#include <mraa/gpio.hpp>
#include <mraa/spi.hpp>
#include "gfx.h"
// Display Size
#define SSD1351WIDTH 128
#define SSD1351HEIGHT 128 // Set this to 96 for 1.27"
// SSD1351 Commands
#define SSD1351_CMD_SETCOLUMN 0x15
#define SSD1351_CMD_SETROW 0x75
#define SSD1351_CMD_WRITERAM 0x5C
#define SSD1351_CMD_READRAM 0x5D
#define SSD1351_CMD_SETREMAP 0xA0
#define SSD1351_CMD_STARTLINE 0xA1
#define SSD1351_CMD_DISPLAYOFFSET 0xA2
#define SSD1351_CMD_DISPLAYALLOFF 0xA4
#define SSD1351_CMD_DISPLAYALLON 0xA5
#define SSD1351_CMD_NORMALDISPLAY 0xA6
#define SSD1351_CMD_INVERTDISPLAY 0xA7
#define SSD1351_CMD_FUNCTIONSELECT 0xAB
#define SSD1351_CMD_DISPLAYOFF 0xAE
#define SSD1351_CMD_DISPLAYON 0xAF
#define SSD1351_CMD_PRECHARGE 0xB1
#define SSD1351_CMD_DISPLAYENHANCE 0xB2
#define SSD1351_CMD_CLOCKDIV 0xB3
#define SSD1351_CMD_SETVSL 0xB4
#define SSD1351_CMD_SETGPIO 0xB5
#define SSD1351_CMD_PRECHARGE2 0xB6
#define SSD1351_CMD_SETGRAY 0xB8
#define SSD1351_CMD_USELUT 0xB9
#define SSD1351_CMD_PRECHARGELEVEL 0xBB
#define SSD1351_CMD_VCOMH 0xBE
#define SSD1351_CMD_CONTRASTABC 0xC1
#define SSD1351_CMD_CONTRASTMASTER 0xC7
#define SSD1351_CMD_MUXRATIO 0xCA
#define SSD1351_CMD_COMMANDLOCK 0xFD
#define SSD1351_CMD_HORIZSCROLL 0x96
#define SSD1351_CMD_STOPSCROLL 0x9E
#define SSD1351_CMD_STARTSCROLL 0x9F
#define HIGH 1
#define LOW 0
// Number of blocks for SPI transfer of buffer
#define BLOCKS 8
namespace upm {
/**
* @brief SSD1351 OLED library
* @defgroup ssd1351 libupm-ssd1351
* @ingroup adafruit spi display
*/
/**
* @library ssd1351
* @sensor ssd1351
* @comname SSD1351 OLED
* @type display
* @man adafruit
* @web http://www.adafruit.com/products/1431
* @con spi
*
* @brief API for SSD1351 OLED displays
*
* This module defines the interface for the SSD1351 display library
*
* @image html ssd1351.jpg
* @snippet ssd1351.cxx Interesting
*/
class SSD1351 : public GFX{
public:
/**
* Instantiates an SSD1351 object
*
* @param oc LCD chip select pin
* @param dc Data/command pin
* @param rst Reset pin
*/
SSD1351 (uint8_t oc, uint8_t dc, uint8_t rst);
/**
* SSD1351 object destructor
*/
~SSD1351();
/**
* Returns the name of the component
*/
std::string name()
{
return m_name;
}
/**
* Sends a command to an SPI bus
*
* @param value Command
*/
void writeCommand (uint8_t value);
/**
* Sends data to an SPI bus
*
* @param value Data
*/
void writeData (uint8_t value);
/**
* Sends a pixel color (RGB) to the display buffer or chip
*
* @param x Axis on the horizontal scale
* @param y Axis on the vertical scale
* @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15])
*/
void drawPixel (int16_t x, int16_t y, uint16_t color);
/**
* Copies the buffer to the chip via the SPI bus
*/
void refresh ();
/**
* Set OLED chip select LOW
*/
void ocLow ();
/**
* Set OLED chip select HIGH
*/
void ocHigh ();
/**
* Data select LOW
*/
void dcLow ();
/**
* Data select HIGH
*/
void dcHigh ();
/**
* Use memory mapped (buffered) writes to the display
*
* @param var true for yes (default), false for no
*/
void useMemoryMap (bool var);
private:
mraa::Spi m_spi;
uint8_t m_map[SSD1351HEIGHT * SSD1351WIDTH * 2]; /**< Screen buffer */
bool m_usemap;
mraa::Gpio m_oc;
mraa::Gpio m_dc;
mraa::Gpio m_rst;
std::string m_name;
};
}

View File

@ -74,6 +74,7 @@ namespace upm {
*
* (https://www.dfrobot.com/wiki/index.php?title=URM37_V4.0_Ultrasonic_Sensor_%28SKU:SEN0001%29)
*
* @image html urm37.jpg
* An example using analog mode
* @snippet urm37.cxx Interesting
* An example using UART mode

View File

@ -59,6 +59,7 @@ namespace upm {
* correlate the number of counts to a time period for calculating
* an RPM or other value as needed.
*
* @image html wheelencoder.jpg
* @snippet wheelencoder.cxx Interesting
*/
class WheelEncoder {

View File

@ -70,6 +70,11 @@ namespace upm {
* windows software, however it is possible of course to configure
* them manually using AT commands. See the examples.
*
* @image html xbee.jpg
* <br><em>XBee Sensor image provided by SparkFun* under
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
* CC BY-NC-SA-3.0</a>.</em>
*
* @snippet xbee.cxx Interesting
*/